Skip to content

Commit

Permalink
NXPY-233: Allow to pass additional arguments when querying document
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Jul 5, 2021
1 parent 74cf8de commit 8be7026
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ Release date: ``2021-0x-xx``
- `NXPY-228 <https://jira.nuxeo.com/browse/NXPY-228>`__: Use proper job names in GitHub workflows
- `NXPY-230 <https://jira.nuxeo.com/browse/NXPY-230>`__: Allow to pass requests arguments to the OAuth2 client
- `NXPY-231 <https://jira.nuxeo.com/browse/NXPY-231>`__: Prevent warnings when packaging the module
- `NXPY-233 <https://jira.nuxeo.com/browse/NXPY-233>`__: Allow to pass additional arguments when querying document

Technical changes
-----------------

- Added ``subclient_kwargs`` keyword argument to ``OAuth2.__init__()``
- Added ``kwargs`` keyword arguments to nuxeo/documents.py::\ ``API.query()``

6.0.2
-----
Expand Down
8 changes: 4 additions & 4 deletions nuxeo/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ def move(self, uid, dst, name=None):
command="Document.Move", input_obj=uid, params=params
)

def query(self, opts=None):
# type: (Optional[Dict[str, str]]) -> Dict[str, Any]
def query(self, opts=None, **kwargs):
# type: (Optional[Dict[str, str]], Any) -> Dict[str, Any]
"""
Run a query on the documents.
Expand All @@ -319,12 +319,12 @@ def query(self, opts=None):
if "query" in opts:
query = "NXQL"
elif "pageProvider" in opts:
query = opts["pageProvider"]
query = opts.pop("pageProvider")
else:
raise BadQuery("Need either a pageProvider or a query")

path = f"query/{query}"
res = super().get(path=path, params=opts, cls=dict)
res = super().get(path=path, params=opts, cls=dict, **kwargs)
res["entries"] = [
Document.parse(entry, service=self) for entry in res["entries"]
]
Expand Down
24 changes: 23 additions & 1 deletion tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_document_create_bytes_warning(server):


def test_document_get_blobs(server):
""" Fetch all blobs of a given document. """
"""Fetch all blobs of a given document."""

number = 4
with Doc(server, blobs=number) as doc:
Expand Down Expand Up @@ -148,6 +148,28 @@ def test_document_get_children_with_permissions(server):
assert not server.documents.exists(path=doc.path)


def test_document_get_children_with_with_provider(server):
root = server.documents.get(path=WORKSPACE_ROOT)
doc = Document(
name=WORKSPACE_NAME, type="Folder", properties={"dc:title": "folder"}
)
doc = server.documents.create(doc, parent_path=root.path)
try:
enrichers = ["permissions", "hasFolderishChild"]
opts = {
"pageProvider": "tree_children",
"pageSize": 1,
"queryParams": root.uid,
}
children = server.documents.query(opts=opts, enrichers=enrichers)
assert len(children["entries"]) == 1
entry = children["entries"][0]
assert entry.contextParameters["permissions"]
assert "hasFolderishChild" in entry.contextParameters
finally:
doc.delete()


def test_document_trash(server):
doc = Document(name=WORKSPACE_NAME, type="File", properties={"dc:title": "bar.txt"})
doc = server.documents.create(doc, parent_path=WORKSPACE_ROOT)
Expand Down

0 comments on commit 8be7026

Please sign in to comment.