Skip to content
Snippets Groups Projects
Commit fd6b50da authored by vlorentz's avatar vlorentz
Browse files

Fix error handling + add test.

parent 4913fd66
No related branches found
No related tags found
1 merge request!61Add api_origin_metadata_search.
......@@ -4,10 +4,9 @@
# See top-level LICENSE file for more information
from distutils.util import strtobool
from rest_framework import status
from rest_framework.response import Response
from swh.web.common import service
from swh.web.common.exc import BadInputExc
from swh.web.common.utils import (
reverse, get_origin_visits
)
......@@ -216,7 +215,7 @@ def api_origin_metadata_search(request):
if not fulltext:
content = '"fulltext" must be provided and non-empty.'
return Response(content, status=status.HTTP_400_BAD_REQUEST)
raise BadInputExc(content)
results = api_lookup(service.search_origin_metadata, fulltext, limit)
......
......@@ -289,3 +289,12 @@ class OriginApiTestCase(SWHWebTestCase, APITestCase):
self.assertEqual(rv.data, expected_data)
mock_idx_storage.origin_intrinsic_metadata_search_fulltext \
.assert_called_with(conjunction=['Jane Doe'], limit=50)
@patch('swh.web.common.service.idx_storage')
def test_api_origin_metadata_search_invalid(self, mock_idx_storage):
rv = self.client.get(
'/api/1/origin/metadata-search/?fulltext=Jane%20Doe')
# then
self.assertEqual(rv.status_code, 400, rv.content)
mock_idx_storage.assert_not_called()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment