Skip to content

Commit 858ab3e

Browse files
authored
nc.files.find() with "name" param bug fix (#89)
Fixes #87. @CooperGerman if you wish, we could add your name to the Authors.md, just need to know it ) P.S: mention me anywhere or create a PR with updated Authors if you want ;) Signed-off-by: Alexander Piskun <[email protected]>
1 parent 92ad66a commit 858ab3e

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- `FsNode` can be created from Nextcloud `UiActionFileInfo` reply.
10-
- Finished documentation.
10+
11+
### Fixed
12+
13+
- `files.find` error when searching by `"name"`. Thanks to @CooperGerman
1114

1215
## [0.0.30 - 2023-08-15]
1316

docs/FirstSteps.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,12 @@ A very simple example of downloading an image as one piece of data to memory and
8383
.. note:: For big files, it is always better to use ``download2stream`` method, as it uses chunks.
8484

8585
.. literalinclude:: ../examples/as_client/files/download.py
86+
87+
Searching for a file
88+
""""""""""""""""""""
89+
90+
Example of using ``file.find()`` to search for file objects.
91+
92+
.. note:: We welcome the idea of how to make the definition of search queries more friendly.
93+
94+
.. literalinclude:: ../examples/as_client/files/find.py

examples/as_client/files/find.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import nc_py_api
2+
3+
if __name__ == "__main__":
4+
# create Nextcloud client instance class
5+
nc = nc_py_api.Nextcloud(nextcloud_url="http://nextcloud.local", nc_auth_user="admin", nc_auth_pass="admin")
6+
7+
print("Searching for all files which names ends with `.txt`:")
8+
result = nc.files.find(["like", "name", "%.txt"])
9+
for i in result:
10+
print(i)
11+
print("")
12+
print("Searching for all files which name is equal to `Nextcloud_Server_Administration_Manual.pdf`:")
13+
result = nc.files.find(["eq", "name", "Nextcloud_Server_Administration_Manual.pdf"])
14+
for i in result:
15+
print(i)
16+
exit(0)

nc_py_api/files/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
]
4545

4646
SEARCH_PROPERTIES_MAP = {
47-
"name:": "d:displayname", # like, eq
47+
"name": "d:displayname", # like, eq
4848
"mime": "d:getcontenttype", # like, eq
4949
"last_modified": "d:getlastmodified", # gt, eq, lt
5050
"size": "oc:size", # gt, gte, eq, lt

tests/files_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_find_files_listdir_depth(nc):
410410
nc.files.mkdir("test_root_folder")
411411
nc.files.mkdir("test_root_folder/child_folder")
412412
nc.files.upload("test_root_folder/image1.png", content=im1.read())
413-
nc.files.upload("test_root_folder/test_root.txt", content="content!")
413+
nc.files.upload("test_root_folder/test_root_very_unique_name768.txt", content="content!")
414414
nc.files.upload("test_root_folder/child_folder/image2.gif", content=im2.read())
415415
nc.files.upload("test_root_folder/child_folder/image3.jpg", content=im3.read())
416416
nc.files.upload("test_root_folder/child_folder/test.txt", content="content!")
@@ -429,6 +429,14 @@ def test_find_files_listdir_depth(nc):
429429
["or", "and", "gt", "size", 0, "like", "mime", "image/%", "like", "mime", "text/%"], path="test_root_folder"
430430
)
431431
assert len(result) == 5
432+
result = nc.files.find(["eq", "name", "test_root_very_unique_name768.txt"])
433+
assert len(result) == 1
434+
result = nc.files.find(["like", "name", "test_root_very_unique_name76%"])
435+
assert len(result) == 1
436+
result = nc.files.find(["eq", "name", "test_root_very_unique_name768.txt"], path="test_root_folder/child_folder")
437+
assert not result
438+
result = nc.files.find(["like", "name", "test_root_very_unique_name76%"], path="test_root_folder/child_folder")
439+
assert not result
432440
result = nc.files.find(["gte", "size", 0], path="test_root_folder")
433441
assert len(result) == 6 # 1 sub dir + 3 images + 2 text files
434442
result = nc.files.find(["like", "mime", "text/%"], path="test_root_folder")

0 commit comments

Comments
 (0)