diff --git a/swh/web/ui/backend.py b/swh/web/ui/backend.py --- a/swh/web/ui/backend.py +++ b/swh/web/ui/backend.py @@ -80,17 +80,18 @@ return res[0] -def origin_get(origin_id): - """Return information about the origin with id origin_id. +def origin_get(origin): + """Return information about the origin matching dict origin. Args: - origin_id: origin's identifier + origin: origin's dict with keys either 'id' or + ('type' AND 'url') Returns: Origin information as dict. """ - return main.storage().origin_get({'id': origin_id}) + return main.storage().origin_get(origin) def person_get(person_id): diff --git a/swh/web/ui/service.py b/swh/web/ui/service.py --- a/swh/web/ui/service.py +++ b/swh/web/ui/service.py @@ -73,17 +73,18 @@ return converters.from_origin(origin) -def lookup_origin(origin_id): - """Return information about the origin with id origin_id. +def lookup_origin(origin): + """Return information about the origin matching dict origin. Args: - origin_id as string + origin: origin's dict with keys either 'id' or + ('type' AND 'url') Returns: origin information as dict. """ - return backend.origin_get(origin_id) + return backend.origin_get(origin) def lookup_person(person_id): diff --git a/swh/web/ui/tests/test_backend.py b/swh/web/ui/tests/test_backend.py --- a/swh/web/ui/tests/test_backend.py +++ b/swh/web/ui/tests/test_backend.py @@ -174,7 +174,7 @@ self.storage.content_missing_per_sha1.assert_called_with(sha1s_bin) @istest - def origin_get(self): + def origin_get_by_id(self): # given self.storage.origin_get = MagicMock(return_value={ 'id': 'origin-id', @@ -184,7 +184,7 @@ 'type': 'ftp'}) # when - actual_origin = backend.origin_get('origin-id') + actual_origin = backend.origin_get({'id': 'origin-id'}) # then self.assertEqual(actual_origin, {'id': 'origin-id', @@ -196,6 +196,31 @@ self.storage.origin_get.assert_called_with({'id': 'origin-id'}) @istest + def origin_get_by_type_url(self): + # given + self.storage.origin_get = MagicMock(return_value={ + 'id': 'origin-id', + 'lister': 'uuid-lister', + 'project': 'uuid-project', + 'url': 'ftp://some/url/to/origin', + 'type': 'ftp'}) + + # when + actual_origin = backend.origin_get({'type': 'ftp', + 'url': 'ftp://some/url/to/origin'}) + + # then + self.assertEqual(actual_origin, {'id': 'origin-id', + 'lister': 'uuid-lister', + 'project': 'uuid-project', + 'url': 'ftp://some/url/to/origin', + 'type': 'ftp'}) + + self.storage.origin_get.assert_called_with( + {'type': 'ftp', + 'url': 'ftp://some/url/to/origin'}) + + @istest def person_get(self): # given self.storage.person_get = MagicMock(return_value=[{ diff --git a/swh/web/ui/tests/test_service.py b/swh/web/ui/tests/test_service.py --- a/swh/web/ui/tests/test_service.py +++ b/swh/web/ui/tests/test_service.py @@ -362,7 +362,7 @@ 'type': 'ftp'}) # when - actual_origin = service.lookup_origin('origin-id') + actual_origin = service.lookup_origin({'id': 'origin-id'}) # then self.assertEqual(actual_origin, {'id': 'origin-id', @@ -371,7 +371,7 @@ 'url': 'ftp://some/url/to/origin', 'type': 'ftp'}) - mock_backend.origin_get.assert_called_with('origin-id') + mock_backend.origin_get.assert_called_with({'id': 'origin-id'}) @patch('swh.web.ui.service.backend') @istest