Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 1,424 Lines • ▼ Show 20 Lines | def _generate_random_visits(self, nb_visits=100, start=0, end=7): | ||||
days = random.randint(0, 28) | days = random.randint(0, 28) | ||||
weeks = random.randint(start, end) | weeks = random.randint(start, end) | ||||
date_visit = today - timedelta( | date_visit = today - timedelta( | ||||
weeks=weeks, hours=hours, minutes=minutes, seconds=seconds, days=days | weeks=weeks, hours=hours, minutes=minutes, seconds=seconds, days=days | ||||
) | ) | ||||
visits.append(date_visit) | visits.append(date_visit) | ||||
return visits | return visits | ||||
def test_origin_visit_get_all(self, swh_storage): | |||||
origin = Origin.from_dict(data.origin) | |||||
swh_storage.origin_add_one(origin) | |||||
visits = swh_storage.origin_visit_add( | |||||
[ | |||||
OriginVisit( | |||||
origin=origin.url, date=data.date_visit1, type=data.type_visit1, | |||||
), | |||||
OriginVisit( | |||||
origin=origin.url, date=data.date_visit2, type=data.type_visit2, | |||||
), | |||||
OriginVisit( | |||||
origin=origin.url, date=data.date_visit2, type=data.type_visit2, | |||||
), | |||||
] | |||||
) | |||||
ov1, ov2, ov3 = [ | |||||
{**v.to_dict(), "status": "created", "snapshot": None, "metadata": None,} | |||||
for v in visits | |||||
] | |||||
all_visits = list(swh_storage.origin_visit_get(origin.url)) | |||||
assert all_visits == [ov1, ov2, ov3] | |||||
all_visits2 = list(swh_storage.origin_visit_get(origin.url, limit=2)) | |||||
assert all_visits2 == [ov1, ov2] | |||||
vlorentz: nit:
```
visits = swh_storage.origin_visit_add([visit1, visit2, visit3])
ov1, ov2, ov3 = [v. | |||||
Done Inline Actionsthanks ;) ardumont: thanks ;) | |||||
all_visits3 = list( | |||||
swh_storage.origin_visit_get(origin.url, last_visit=ov1["visit"], limit=1) | |||||
) | |||||
assert all_visits3 == [ov2] | |||||
def test_origin_visit_get__unknown_origin(self, swh_storage): | def test_origin_visit_get__unknown_origin(self, swh_storage): | ||||
assert [] == list(swh_storage.origin_visit_get("foo")) | assert [] == list(swh_storage.origin_visit_get("foo")) | ||||
def test_origin_visit_get_random(self, swh_storage): | def test_origin_visit_get_random(self, swh_storage): | ||||
swh_storage.origin_add(data.origins) | swh_storage.origin_add(data.origins) | ||||
# Add some random visits within the selection range | # Add some random visits within the selection range | ||||
visits = self._generate_random_visits() | visits = self._generate_random_visits() | ||||
visit_type = "git" | visit_type = "git" | ||||
▲ Show 20 Lines • Show All 2,475 Lines • Show Last 20 Lines |
nit:
then you can get rid of the list comprehensions below.