Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_origin.py
Show First 20 Lines • Show All 240 Lines • ▼ Show 20 Lines | def test_api_origin_not_found(self, mock_service): | ||||
self.assertEqual(rv.data, { | self.assertEqual(rv.data, { | ||||
'exception': 'NotFoundExc', | 'exception': 'NotFoundExc', | ||||
'reason': 'Origin with id 4321 not found.' | 'reason': 'Origin with id 4321 not found.' | ||||
}) | }) | ||||
mock_service.lookup_origin.assert_called_with({'id': '4321'}) | mock_service.lookup_origin.assert_called_with({'id': '4321'}) | ||||
@patch('swh.web.common.service.idx_storage') | @patch('swh.web.common.service.idx_storage') | ||||
def test_api_origin_metadata_search(self, mock_idx_storage): | @patch('swh.web.common.service.storage') | ||||
def test_api_origin_metadata_search(self, mock_storage, mock_idx_storage): | |||||
# given | # given | ||||
mock_storage.origin_get.return_value = { | |||||
'id': 54974445, 'type': 'git', 'url': '/dev/null'} | |||||
mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | ||||
.return_value = [{ | .side_effect = lambda conjunction, limit: [{ | ||||
'from_revision': | 'from_revision': | ||||
b'p&\xb7\xc1\xa2\xafVR\x1e\x95\x1c\x01\xed \xf2U\xfa\x05B8', | b'p&\xb7\xc1\xa2\xafVR\x1e\x95\x1c\x01\xed \xf2U\xfa\x05B8', | ||||
'metadata': {'author': 'Jane Doe'}, | 'metadata': {'author': 'Jane Doe'}, | ||||
'origin_id': 54974445, | 'origin_id': 54974445, | ||||
'tool': { | 'tool': { | ||||
'configuration': { | 'configuration': { | ||||
'context': ['NpmMapping', 'CodemetaMapping'], | 'context': ['NpmMapping', 'CodemetaMapping'], | ||||
'type': 'local' | 'type': 'local' | ||||
}, | }, | ||||
'id': 3, | 'id': 3, | ||||
'name': 'swh-metadata-detector', | 'name': 'swh-metadata-detector', | ||||
'version': '0.0.1' | 'version': '0.0.1' | ||||
} | } | ||||
}] | }] | ||||
# when | # when | ||||
rv = self.client.get( | rv = self.client.get( | ||||
'/api/1/origin/metadata-search/?fulltext=Jane%20Doe') | '/api/1/origin/metadata-search/?fulltext=Jane%20Doe') | ||||
# then | # then | ||||
self.assertEqual(rv.status_code, 200, rv.content) | self.assertEqual(rv.status_code, 200, rv.content) | ||||
self.assertEqual(rv['Content-Type'], 'application/json') | self.assertEqual(rv['Content-Type'], 'application/json') | ||||
expected_data = [{ | expected_data = [{ | ||||
'origin_id': 54974445, | 'id': 54974445, | ||||
'type': 'git', | |||||
'url': '/dev/null', | |||||
'metadata': { | |||||
'metadata': {'author': 'Jane Doe'}, | 'metadata': {'author': 'Jane Doe'}, | ||||
'from_revision': '7026b7c1a2af56521e951c01ed20f255fa054238', | 'from_revision': '7026b7c1a2af56521e951c01ed20f255fa054238', | ||||
'tool': { | 'tool': { | ||||
'configuration': { | 'configuration': { | ||||
'context': ['NpmMapping', 'CodemetaMapping'], | 'context': ['NpmMapping', 'CodemetaMapping'], | ||||
'type': 'local' | 'type': 'local' | ||||
}, | }, | ||||
'id': 3, | 'id': 3, | ||||
'name': 'swh-metadata-detector', | 'name': 'swh-metadata-detector', | ||||
'version': '0.0.1', | 'version': '0.0.1', | ||||
} | } | ||||
} | |||||
}] | }] | ||||
self.assertEqual(rv.data, expected_data) | self.assertEqual(rv.data, expected_data) | ||||
mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | ||||
.assert_called_with(conjunction=['Jane Doe'], limit=70) | .assert_called_with(conjunction=['Jane Doe'], limit=70) | ||||
@patch('swh.web.common.service.idx_storage') | @patch('swh.web.common.service.idx_storage') | ||||
def test_api_origin_metadata_search_limit(self, mock_idx_storage): | @patch('swh.web.common.service.storage') | ||||
def test_api_origin_metadata_search_limit(self, mock_storage, | |||||
mock_idx_storage): | |||||
# given | # given | ||||
mock_storage.origin_get.return_value = { | |||||
'id': 54974445, 'type': 'git', 'url': '/dev/null'} | |||||
mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | ||||
.return_value = [{ | .side_effect = lambda conjunction, limit: [{ | ||||
'from_revision': | 'from_revision': | ||||
b'p&\xb7\xc1\xa2\xafVR\x1e\x95\x1c\x01\xed \xf2U\xfa\x05B8', | b'p&\xb7\xc1\xa2\xafVR\x1e\x95\x1c\x01\xed \xf2U\xfa\x05B8', | ||||
'metadata': {'author': 'Jane Doe'}, | 'metadata': {'author': 'Jane Doe'}, | ||||
'origin_id': 54974445, | 'origin_id': 54974445, | ||||
'tool': { | 'tool': { | ||||
'configuration': { | 'configuration': { | ||||
'context': ['NpmMapping', 'CodemetaMapping'], | 'context': ['NpmMapping', 'CodemetaMapping'], | ||||
'type': 'local' | 'type': 'local' | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |