Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 1,658 Lines • ▼ Show 20 Lines | |||||
def test_origin_visit_upsert_new(self): | def test_origin_visit_upsert_new(self): | ||||
# given | # given | ||||
self.assertIsNone(self.storage.origin_get([self.origin2])[0]) | self.assertIsNone(self.storage.origin_get([self.origin2])[0]) | ||||
origin_id = self.storage.origin_add_one(self.origin2) | origin_id = self.storage.origin_add_one(self.origin2) | ||||
self.assertIsNotNone(origin_id) | self.assertIsNotNone(origin_id) | ||||
# when | # when | ||||
self.storage.origin_visit_upsert([{ | self.storage.origin_visit_upsert([ | ||||
{ | |||||
'origin': origin_id, | 'origin': origin_id, | ||||
'date': self.date_visit2, | 'date': self.date_visit2, | ||||
'visit': 123, | 'visit': 123, | ||||
'status': 'full', | 'status': 'full', | ||||
'metadata': None, | 'metadata': None, | ||||
'snapshot': None, | 'snapshot': None, | ||||
}]) | }, | ||||
{ | |||||
'origin': origin_id, | |||||
douardda: for this kind of test, I prefer to be able to read the input data litterally. Otherwise the… | |||||
Done Inline ActionsWhat if I add a comment instead? vlorentz: What if I add a comment instead? | |||||
Done Inline ActionsI prefer a literal string, but I would accept your diff with a comment. As you prefer. douardda: I prefer a literal string, but I would accept your diff with a comment. As you prefer. | |||||
'date': '2018-01-01 23:00:00+00', | |||||
'visit': 1234, | |||||
'status': 'full', | |||||
'metadata': None, | |||||
'snapshot': None, | |||||
}, | |||||
]) | |||||
# then | # then | ||||
actual_origin_visits = list(self.storage.origin_visit_get(origin_id)) | actual_origin_visits = list(self.storage.origin_visit_get(origin_id)) | ||||
self.assertEqual(actual_origin_visits, | self.assertEqual(actual_origin_visits, [ | ||||
[{ | { | ||||
'origin': origin_id, | 'origin': origin_id, | ||||
'date': self.date_visit2, | 'date': self.date_visit2, | ||||
'visit': 123, | 'visit': 123, | ||||
'status': 'full', | 'status': 'full', | ||||
'metadata': None, | 'metadata': None, | ||||
'snapshot': None, | 'snapshot': None, | ||||
}]) | }, | ||||
{ | |||||
'origin': origin_id, | |||||
'date': self.date_visit3, | |||||
'visit': 1234, | |||||
'status': 'full', | |||||
'metadata': None, | |||||
'snapshot': None, | |||||
}, | |||||
]) | |||||
expected_origin = self.origin2.copy() | expected_origin = self.origin2.copy() | ||||
data = { | data1 = { | ||||
'origin': expected_origin, | 'origin': expected_origin, | ||||
'date': self.date_visit2, | 'date': self.date_visit2, | ||||
'visit': 123, | 'visit': 123, | ||||
'status': 'full', | 'status': 'full', | ||||
'metadata': None, | 'metadata': None, | ||||
'snapshot': None, | 'snapshot': None, | ||||
} | } | ||||
data2 = { | |||||
'origin': expected_origin, | |||||
'date': self.date_visit3, | |||||
'visit': 1234, | |||||
'status': 'full', | |||||
'metadata': None, | |||||
'snapshot': None, | |||||
} | |||||
self.assertEqual(list(self.journal_writer.objects), | self.assertEqual(list(self.journal_writer.objects), | ||||
[('origin', expected_origin), | [('origin', expected_origin), | ||||
('origin_visit', data)]) | ('origin_visit', data1), | ||||
('origin_visit', data2)]) | |||||
def test_origin_visit_upsert_existing(self): | def test_origin_visit_upsert_existing(self): | ||||
# given | # given | ||||
self.assertIsNone(self.storage.origin_get([self.origin2])[0]) | self.assertIsNone(self.storage.origin_get([self.origin2])[0]) | ||||
origin_id = self.storage.origin_add_one(self.origin2) | origin_id = self.storage.origin_add_one(self.origin2) | ||||
self.assertIsNotNone(origin_id) | self.assertIsNotNone(origin_id) | ||||
▲ Show 20 Lines • Show All 1,699 Lines • Show Last 20 Lines |
for this kind of test, I prefer to be able to read the input data litterally. Otherwise the reader need to pay way much more attention to get what self.date_visit is (what type) and pay extra attention to the presence of the str() call.
It's much easier to read as: