Changeset View
Changeset View
Standalone View
Standalone View
swh/web/ui/tests/test_service.py
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | def lookup_hash_exist(self, mock_backend): | ||||
mock_backend.content_find.assert_called_with( | mock_backend.content_find.assert_called_with( | ||||
'sha1', | 'sha1', | ||||
hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f'), | hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f'), | ||||
) | ) | ||||
@patch('swh.web.ui.service.backend') | @patch('swh.web.ui.service.backend') | ||||
@istest | @istest | ||||
def search_hash_does_not_exist(self, mock_backend): | |||||
# given | |||||
mock_backend.content_find = MagicMock(return_value=None) | |||||
# when | |||||
actual_lookup = service.search_hash( | |||||
'sha1_git:123caf10e9535160d90e874b45aa426de762f19f') | |||||
# then | |||||
self.assertEquals({'found': False}, actual_lookup) | |||||
# check the function has been called with parameters | |||||
mock_backend.content_find.assert_called_with( | |||||
'sha1_git', | |||||
hex_to_hash('123caf10e9535160d90e874b45aa426de762f19f')) | |||||
@patch('swh.web.ui.service.backend') | |||||
@istest | |||||
def search_hash_exist(self, mock_backend): | |||||
# given | |||||
stub_content = { | |||||
'sha1': hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f') | |||||
} | |||||
mock_backend.content_find = MagicMock(return_value=stub_content) | |||||
# when | |||||
actual_lookup = service.search_hash( | |||||
'sha1:456caf10e9535160d90e874b45aa426de762f19f') | |||||
# then | |||||
self.assertEquals({'found': True}, actual_lookup) | |||||
mock_backend.content_find.assert_called_with( | |||||
'sha1', | |||||
hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f'), | |||||
) | |||||
@patch('swh.web.ui.service.backend') | |||||
@istest | |||||
def lookup_hash_origin(self, mock_backend): | def lookup_hash_origin(self, mock_backend): | ||||
# given | # given | ||||
mock_backend.content_find_occurrence = MagicMock(return_value={ | mock_backend.content_find_occurrence = MagicMock(return_value={ | ||||
'origin_type': 'sftp', | 'origin_type': 'sftp', | ||||
'origin_url': 'sftp://ftp.gnu.org/gnu/octave', | 'origin_url': 'sftp://ftp.gnu.org/gnu/octave', | ||||
'branch': 'octavio-3.4.0.tar.gz', | 'branch': 'octavio-3.4.0.tar.gz', | ||||
'revision': b'\xb0L\xaf\x10\xe9SQ`\xd9\x0e\x87KE\xaaBm\xe7b\xf1\x9f', # noqa | 'revision': b'\xb0L\xaf\x10\xe9SQ`\xd9\x0e\x87KE\xaaBm\xe7b\xf1\x9f', # noqa | ||||
'path': b'octavio-3.4.0/doc/interpreter/octave.html/doc_002dS_005fISREG.html' # noqa | 'path': b'octavio-3.4.0/doc/interpreter/octave.html/doc_002dS_005fISREG.html' # noqa | ||||
▲ Show 20 Lines • Show All 1,676 Lines • Show Last 20 Lines |