Changeset View
Changeset View
Standalone View
Standalone View
swh/web/ui/tests/test_service.py
Show First 20 Lines • Show All 345 Lines • ▼ Show 20 Lines | def stat_origin_visits(self, mock_backend): | ||||
# then | # then | ||||
self.assertEqual(expected_dates, | self.assertEqual(expected_dates, | ||||
list(actual_dates)) | list(actual_dates)) | ||||
mock_backend.stat_origin_visits.assert_called_once_with(6) | mock_backend.stat_origin_visits.assert_called_once_with(6) | ||||
@patch('swh.web.ui.service.backend') | @patch('swh.web.ui.service.backend') | ||||
@patch('swh.web.ui.service.hashutil') | |||||
@istest | |||||
def hash_and_search(self, mock_hashutil, mock_backend): | |||||
# given | |||||
bhash = hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f') | |||||
mock_hashutil.hashfile.return_value = {'sha1': bhash} | |||||
mock_backend.content_find = MagicMock(return_value={ | |||||
'sha1': bhash, | |||||
'sha1_git': bhash, | |||||
}) | |||||
# when | |||||
actual_content = service.hash_and_search('/some/path') | |||||
# then | |||||
self.assertEqual(actual_content, { | |||||
'sha1': '456caf10e9535160d90e874b45aa426de762f19f', | |||||
'sha1_git': '456caf10e9535160d90e874b45aa426de762f19f', | |||||
'found': True, | |||||
}) | |||||
mock_hashutil.hashfile.assert_called_once_with('/some/path') | |||||
mock_backend.content_find.assert_called_once_with('sha1', bhash) | |||||
@patch('swh.web.ui.service.hashutil') | |||||
@istest | |||||
def hash_and_search_not_found(self, mock_hashutil): | |||||
# given | |||||
bhash = hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f') | |||||
mock_hashutil.hashfile.return_value = {'sha1': bhash} | |||||
mock_hashutil.hash_to_hex = MagicMock( | |||||
return_value='456caf10e9535160d90e874b45aa426de762f19f') | |||||
self.storage.content_find = MagicMock(return_value=None) | |||||
# when | |||||
actual_content = service.hash_and_search('/some/path') | |||||
# then | |||||
self.assertEqual(actual_content, { | |||||
'sha1': '456caf10e9535160d90e874b45aa426de762f19f', | |||||
'found': False, | |||||
}) | |||||
mock_hashutil.hashfile.assert_called_once_with('/some/path') | |||||
self.storage.content_find.assert_called_once_with({'sha1': bhash}) | |||||
mock_hashutil.hash_to_hex.assert_called_once_with(bhash) | |||||
@patch('swh.web.ui.service.backend') | |||||
@istest | @istest | ||||
def lookup_origin(self, mock_backend): | def lookup_origin(self, mock_backend): | ||||
# given | # given | ||||
mock_backend.origin_get = MagicMock(return_value={ | mock_backend.origin_get = MagicMock(return_value={ | ||||
'id': 'origin-id', | 'id': 'origin-id', | ||||
'lister': 'uuid-lister', | 'lister': 'uuid-lister', | ||||
'project': 'uuid-project', | 'project': 'uuid-project', | ||||
'url': 'ftp://some/url/to/origin', | 'url': 'ftp://some/url/to/origin', | ||||
▲ Show 20 Lines • Show All 1,355 Lines • Show Last 20 Lines |