Skip to content

Commit

Permalink
Fix for #1628 (#1631)
Browse files Browse the repository at this point in the history
* Fix #1628

- unset the get paramter in Service QuerystringSearchGet
- rename test_querystringsearch_metadata_fields
- add test_querystringsearch_metadata_fields_get

* Add news

* FixCode Formatting
- Format with Black
  • Loading branch information
1letter committed May 3, 2023
1 parent f760d9c commit 2822641
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions news/1628.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix missing metadata_fields in Response via GET Request to Endpoint /@querystring-search
[1letter]
6 changes: 5 additions & 1 deletion src/plone/restapi/services/querystringsearch/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ class QuerystringSearchGet(Service):
def reply(self):
# We need to copy the JSON query parameters from the querystring
# into the request body, because that's where other code expects to find them
self.request["BODY"] = parse.unquote(self.request.form.get("query", "{}"))
self.request["BODY"] = parse.unquote(
self.request.form.get("query", "{}")
).encode(self.request.charset)

# unset the get parameters
self.request.form = {}
querystring_search = QuerystringSearch(self.context, self.request)
return querystring_search()
20 changes: 19 additions & 1 deletion src/plone/restapi/tests/test_services_querystringsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_querystringsearch_fullobjects(self):
self.assertEqual(response.json()["items_total"], 1)
self.assertEqual(len(response.json()["items"]), 1)

def test_querystringsearch_metadata_fields(self):
def test_querystringsearch_metadata_fields_post(self):
response = self.api_session.post(
"/@querystring-search",
json={
Expand Down Expand Up @@ -124,6 +124,24 @@ def test_querystringsearch_metadata_fields(self):

self.assertIn("effective", response.json()["items"][0])

def test_querystringsearch_metadata_fields_get(self):

response = self.api_session.get(
"/@querystring-search?query=%7B%22query%22%3A%20%5B%7B%22i%22%3A%20%22portal_type%22%2C%20%22o%22%3A%20%22plone.app.querystring.operation.selection.is%22%2C%20%22v%22%3A%20%5B%22Document%22%5D%7D%5D%7D"
)

self.assertEqual(response.status_code, 200)
self.assertIn("items", response.json())
self.assertIn("items_total", response.json())
self.assertNotIn("effective", response.json()["items"][0])

# request with metadata_fields
response = self.api_session.get(
"/@querystring-search?query=%7B%22query%22%3A%20%5B%7B%22i%22%3A%20%22portal_type%22%2C%20%22o%22%3A%20%22plone.app.querystring.operation.selection.is%22%2C%20%22v%22%3A%20%5B%22Document%22%5D%7D%5D%2C%20%22metadata_fields%22%3A%20%5B%22effective%22%5D%7D"
)

self.assertIn("effective", response.json()["items"][0])

def test_querystringsearch_complex(self):

for a in range(1, 10):
Expand Down

0 comments on commit 2822641

Please sign in to comment.