Skip to content

Commit

Permalink
nc.files.find() with "name" param bug fix (#89)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bigcat88 authored Aug 17, 2023
1 parent 92ad66a commit 858ab3e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ All notable changes to this project will be documented in this file.
### Added

- `FsNode` can be created from Nextcloud `UiActionFileInfo` reply.
- Finished documentation.

### Fixed

- `files.find` error when searching by `"name"`. Thanks to @CooperGerman

## [0.0.30 - 2023-08-15]

Expand Down
9 changes: 9 additions & 0 deletions docs/FirstSteps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ A very simple example of downloading an image as one piece of data to memory and
.. note:: For big files, it is always better to use ``download2stream`` method, as it uses chunks.

.. literalinclude:: ../examples/as_client/files/download.py

Searching for a file
""""""""""""""""""""

Example of using ``file.find()`` to search for file objects.

.. note:: We welcome the idea of how to make the definition of search queries more friendly.

.. literalinclude:: ../examples/as_client/files/find.py
16 changes: 16 additions & 0 deletions examples/as_client/files/find.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import nc_py_api

if __name__ == "__main__":
# create Nextcloud client instance class
nc = nc_py_api.Nextcloud(nextcloud_url="http://nextcloud.local", nc_auth_user="admin", nc_auth_pass="admin")

print("Searching for all files which names ends with `.txt`:")
result = nc.files.find(["like", "name", "%.txt"])
for i in result:
print(i)
print("")
print("Searching for all files which name is equal to `Nextcloud_Server_Administration_Manual.pdf`:")
result = nc.files.find(["eq", "name", "Nextcloud_Server_Administration_Manual.pdf"])
for i in result:
print(i)
exit(0)
2 changes: 1 addition & 1 deletion nc_py_api/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
]

SEARCH_PROPERTIES_MAP = {
"name:": "d:displayname", # like, eq
"name": "d:displayname", # like, eq
"mime": "d:getcontenttype", # like, eq
"last_modified": "d:getlastmodified", # gt, eq, lt
"size": "oc:size", # gt, gte, eq, lt
Expand Down
10 changes: 9 additions & 1 deletion tests/files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_find_files_listdir_depth(nc):
nc.files.mkdir("test_root_folder")
nc.files.mkdir("test_root_folder/child_folder")
nc.files.upload("test_root_folder/image1.png", content=im1.read())
nc.files.upload("test_root_folder/test_root.txt", content="content!")
nc.files.upload("test_root_folder/test_root_very_unique_name768.txt", content="content!")
nc.files.upload("test_root_folder/child_folder/image2.gif", content=im2.read())
nc.files.upload("test_root_folder/child_folder/image3.jpg", content=im3.read())
nc.files.upload("test_root_folder/child_folder/test.txt", content="content!")
Expand All @@ -429,6 +429,14 @@ def test_find_files_listdir_depth(nc):
["or", "and", "gt", "size", 0, "like", "mime", "image/%", "like", "mime", "text/%"], path="test_root_folder"
)
assert len(result) == 5
result = nc.files.find(["eq", "name", "test_root_very_unique_name768.txt"])
assert len(result) == 1
result = nc.files.find(["like", "name", "test_root_very_unique_name76%"])
assert len(result) == 1
result = nc.files.find(["eq", "name", "test_root_very_unique_name768.txt"], path="test_root_folder/child_folder")
assert not result
result = nc.files.find(["like", "name", "test_root_very_unique_name76%"], path="test_root_folder/child_folder")
assert not result
result = nc.files.find(["gte", "size", 0], path="test_root_folder")
assert len(result) == 6 # 1 sub dir + 3 images + 2 text files
result = nc.files.find(["like", "mime", "text/%"], path="test_root_folder")
Expand Down

0 comments on commit 858ab3e

Please sign in to comment.