Skip to content

Commit

Permalink
search: all parameters are optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaraBi committed Sep 25, 2019
1 parent 97c8f3c commit b548c35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
6 changes: 0 additions & 6 deletions asclepias_broker/search/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ def search_factory(self, search, query_parser=None):
from invenio_records_rest.sorter import default_sorter_factory
search_index = search._index[0]

# TODO: make "scheme" optional?
for field in ('id', 'scheme', 'relation'):
if field not in request.values:
raise RESTValidationError(
errors=[FieldError(field, 'Required field.')])

search, urlkwargs = default_facets_factory(search, search_index)
search, sortkwargs = default_sorter_factory(search, search_index)
for key, value in sortkwargs.items():
Expand Down
32 changes: 19 additions & 13 deletions tests/api/test_relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,34 @@
from asclepias_broker.events.api import EventAPI


def test_invalid_search_parameters(client):
def test_optional_search_parameters(client):
search_url = url_for('invenio_records_rest.relid_list')

# TODO: the results should not be 0
params = {}
resp = client.get(search_url)
assert resp.status_code == 400
assert resp.json['message'] == 'Validation error.'
assert resp.json['errors'][0]['field'] == 'id'
assert resp.status_code == 200
assert resp.json['hits']['total'] == 0

params['id'] = 'some-id'
params['id'] = 'X'
resp = client.get(search_url, query_string=params)
assert resp.status_code == 400
assert resp.json['message'] == 'Validation error.'
assert len(resp.json['errors']) == 1
assert resp.json['errors'][0]['field'] == 'scheme'
assert resp.status_code == 200
assert resp.json['hits']['total'] == 0

params['scheme'] = 'doi'
resp = client.get(search_url, query_string=params)
assert resp.status_code == 400
assert resp.json['message'] == 'Validation error.'
assert len(resp.json['errors']) == 1
assert resp.json['errors'][0]['field'] == 'relation'
assert resp.status_code == 200
assert resp.json['hits']['total'] == 0


def test_invalid_search_parameters(client):
search_url = url_for('invenio_records_rest.relid_list')

params = {}
params['id'] = 'some-id'
resp = client.get(search_url, query_string=params)
assert resp.status_code == 200
assert resp.json['hits']['total'] == 0

params['relation'] = 'not-a-valid-value'
resp = client.get(search_url, query_string=params)
Expand Down

0 comments on commit b548c35

Please sign in to comment.