Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_origin.py
Show First 20 Lines • Show All 320 Lines • ▼ Show 20 Lines | def test_api_origin_metadata_search_limit(self, origin): | ||||
rv = self.client.get(url) | rv = self.client.get(url) | ||||
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') | ||||
self.assertEqual(len(rv.data), 1) | self.assertEqual(len(rv.data), 1) | ||||
mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | mock_idx_storage.origin_intrinsic_metadata_search_fulltext \ | ||||
.assert_called_with(conjunction=['Jane Doe'], limit=100) | .assert_called_with(conjunction=['Jane Doe'], limit=100) | ||||
@given(origin()) | |||||
def test_api_origin_intrinsic_metadata_get(self, origin): | |||||
with patch('swh.web.common.service.idx_storage') as mock_idx_storage: | |||||
mock_idx_storage.origin_intrinsic_metadata_get \ | |||||
twitu: Test case is failing here, citing an `Attribute error` here. I need multiple context managers… | |||||
.side_effect = lambda origin_ids: [{ | |||||
'from_revision': ( | |||||
b'p&\xb7\xc1\xa2\xafVR\x1e\x95\x1c\x01\xed ' | |||||
b'\xf2U\xfa\x05B8'), | |||||
'metadata': {'author': 'Jane Doe'}, | |||||
'id': origin['id'], | |||||
'tool': { | |||||
'configuration': { | |||||
'context': ['NpmMapping', 'CodemetaMapping'], | |||||
'type': 'local' | |||||
}, | |||||
'id': 3, | |||||
'name': 'swh-metadata-detector', | |||||
'version': '0.0.1' | |||||
} | |||||
}] | |||||
url = reverse('api-origin-intrinsic-metadata-get', | |||||
url_args={'origin_type': origin['type'], | |||||
'origin_url': origin['url']}) | |||||
rv = self.client.get(url) | |||||
mock_idx_storage.origin_intrinsic_metadata_get \ | |||||
.assert_called_once_with([origin['id']]) | |||||
self.assertEqual(rv.status_code, 200, rv.content) | |||||
self.assertEqual(rv['Content-Type'], 'application/json') | |||||
expected_data = {'author': 'Jane Doe'} | |||||
self.assertEqual(rv.data, expected_data) | |||||
@patch('swh.web.common.service.idx_storage') | @patch('swh.web.common.service.idx_storage') | ||||
def test_api_origin_metadata_search_invalid(self, mock_idx_storage): | def test_api_origin_metadata_search_invalid(self, mock_idx_storage): | ||||
url = reverse('api-1-origin-metadata-search') | url = reverse('api-1-origin-metadata-search') | ||||
rv = self.client.get(url) | rv = self.client.get(url) | ||||
self.assertEqual(rv.status_code, 400, rv.content) | self.assertEqual(rv.status_code, 400, rv.content) | ||||
mock_idx_storage.assert_not_called() | mock_idx_storage.assert_not_called() | ||||
Show All 39 Lines |
Test case is failing here, citing an Attribute error here. I need multiple context managers because to test the api I need to mock both storage and index-storage. I am not sure why I am unable to mock storage, any suggestions?