diff --git a/asclepias_broker/search/query.py b/asclepias_broker/search/query.py index db87841..9fec39f 100644 --- a/asclepias_broker/search/query.py +++ b/asclepias_broker/search/query.py @@ -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(): diff --git a/tests/api/test_relationships.py b/tests/api/test_relationships.py index c20adf7..36c4af2 100644 --- a/tests/api/test_relationships.py +++ b/tests/api/test_relationships.py @@ -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)