Changeset View
Changeset View
Standalone View
Standalone View
swh/web/ui/tests/test_service.py
Show First 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | def stat_counters(self, mock_backend): | ||||
# then | # then | ||||
expected_stats = input_stats | expected_stats = input_stats | ||||
self.assertEqual(actual_stats, expected_stats) | self.assertEqual(actual_stats, expected_stats) | ||||
mock_backend.stat_counters.assert_called_with() | mock_backend.stat_counters.assert_called_with() | ||||
@patch('swh.web.ui.service.backend') | @patch('swh.web.ui.service.backend') | ||||
@istest | |||||
def stat_origin_visits(self, mock_backend): | |||||
# given | |||||
stub_result = [ | |||||
{ | |||||
'date': datetime.datetime( | |||||
2015, 1, 1, 22, 0, 0, | |||||
tzinfo=datetime.timezone.utc), | |||||
'origin': 1, | |||||
'visit': 1 | |||||
}, | |||||
{ | |||||
'date': datetime.datetime( | |||||
2013, 7, 1, 20, 0, 0, | |||||
tzinfo=datetime.timezone.utc), | |||||
'origin': 1, | |||||
'visit': 2 | |||||
}, | |||||
{ | |||||
'date': datetime.datetime( | |||||
2015, 1, 1, 21, 0, 0, | |||||
tzinfo=datetime.timezone.utc), | |||||
'origin': 1, | |||||
'visit': 3 | |||||
} | |||||
] | |||||
mock_backend.stat_origin_visits.return_value = stub_result | |||||
# when | |||||
expected_dates = [ | |||||
{ | |||||
'date': datetime.datetime( | |||||
2015, 1, 1, 22, 0, 0, | |||||
tzinfo=datetime.timezone.utc).timestamp(), | |||||
'origin': 1, | |||||
'visit': 1 | |||||
}, | |||||
{ | |||||
'date': datetime.datetime( | |||||
2013, 7, 1, 20, 0, 0, | |||||
tzinfo=datetime.timezone.utc).timestamp(), | |||||
'origin': 1, | |||||
'visit': 2 | |||||
}, | |||||
{ | |||||
'date': datetime.datetime( | |||||
2015, 1, 1, 21, 0, 0, | |||||
tzinfo=datetime.timezone.utc).timestamp(), | |||||
'origin': 1, | |||||
'visit': 3 | |||||
} | |||||
] | |||||
actual_dates = service.stat_origin_visits(6) | |||||
# then | |||||
self.assertEqual(expected_dates, | |||||
list(actual_dates)) | |||||
mock_backend.stat_origin_visits.assert_called_once_with(6) | |||||
@patch('swh.web.ui.service.backend') | |||||
@patch('swh.web.ui.service.hashutil') | @patch('swh.web.ui.service.hashutil') | ||||
@istest | @istest | ||||
def hash_and_search(self, mock_hashutil, mock_backend): | def hash_and_search(self, mock_hashutil, mock_backend): | ||||
# given | # given | ||||
bhash = hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f') | bhash = hex_to_hash('456caf10e9535160d90e874b45aa426de762f19f') | ||||
mock_hashutil.hashfile.return_value = {'sha1': bhash} | mock_hashutil.hashfile.return_value = {'sha1': bhash} | ||||
mock_backend.content_find = MagicMock(return_value={ | mock_backend.content_find = MagicMock(return_value={ | ||||
'sha1': bhash, | 'sha1': bhash, | ||||
▲ Show 20 Lines • Show All 1,772 Lines • Show Last 20 Lines |