Changeset View
Changeset View
Standalone View
Standalone View
swh/search/tests/test_journal_client.py
Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | def test_journal_client_origin_from_journal(): | ||||
search_mock.reset_mock() | search_mock.reset_mock() | ||||
worker_fn({"origin": [{"url": "http://foobar.baz"}, {"url": "http://barbaz.qux"},]}) | worker_fn({"origin": [{"url": "http://foobar.baz"}, {"url": "http://barbaz.qux"},]}) | ||||
search_mock.origin_update.assert_called_once_with( | search_mock.origin_update.assert_called_once_with( | ||||
[{"url": "http://foobar.baz"}, {"url": "http://barbaz.qux"},] | [{"url": "http://foobar.baz"}, {"url": "http://barbaz.qux"},] | ||||
) | ) | ||||
def test_journal_client_origin_visit_from_journal(): | |||||
search_mock = MagicMock() | |||||
worker_fn = functools.partial(process_journal_objects, search=search_mock,) | |||||
worker_fn({"origin_visit": [{"origin": "http://foobar.baz", "type": "git"},]}) | |||||
search_mock.origin_update.assert_called_once_with( | |||||
[{"url": "http://foobar.baz", "visit_types": ["git"]},] | |||||
) | |||||
def test_journal_client_origin_visit_status_from_journal(storage): | def test_journal_client_origin_visit_status_from_journal(storage): | ||||
search_mock = MagicMock() | search_mock = MagicMock() | ||||
worker_fn = functools.partial( | worker_fn = functools.partial( | ||||
process_journal_objects, search=search_mock, storage=storage | process_journal_objects, search=search_mock, storage=storage | ||||
) | ) | ||||
current_datetime = datetime.now(tz=timezone.utc) | current_datetime = datetime.now(tz=timezone.utc) | ||||
worker_fn( | worker_fn( | ||||
{ | { | ||||
"origin_visit_status": [ | "origin_visit_status": [ | ||||
{ | { | ||||
"origin": "http://foobar.baz", | "origin": "http://foobar.baz", | ||||
"status": "full", | "status": "full", | ||||
"type": "git", | |||||
"visit": 5, | "visit": 5, | ||||
"date": current_datetime, | "date": current_datetime, | ||||
"snapshot": SNAPSHOTS[0].id, | "snapshot": SNAPSHOTS[0].id, | ||||
} # full visits ok | } # full visits ok | ||||
] | ] | ||||
} | } | ||||
) | ) | ||||
search_mock.origin_update.assert_called_once_with( | search_mock.origin_update.assert_called_once_with( | ||||
[ | [ | ||||
{ | { | ||||
"url": "http://foobar.baz", | "url": "http://foobar.baz", | ||||
"visit_types": ["git"], | |||||
"has_visits": True, | "has_visits": True, | ||||
"nb_visits": 5, | "nb_visits": 5, | ||||
"snapshot_id": SNAPSHOTS[0].id.hex(), | "snapshot_id": SNAPSHOTS[0].id.hex(), | ||||
"last_visit_date": current_datetime.isoformat(), | "last_visit_date": current_datetime.isoformat(), | ||||
"last_eventful_visit_date": current_datetime.isoformat(), | "last_eventful_visit_date": current_datetime.isoformat(), | ||||
"last_revision_date": "2009-02-14T01:31:33+02:00", | "last_revision_date": "2009-02-14T01:31:33+02:00", | ||||
"last_release_date": "2009-02-14T01:31:34+02:00", | "last_release_date": "2009-02-14T01:31:34+02:00", | ||||
}, | }, | ||||
] | ] | ||||
) | ) | ||||
search_mock.reset_mock() | search_mock.reset_mock() | ||||
# non-full visits are filtered out | # non-full visits only set the visit_types attribute | ||||
worker_fn( | worker_fn( | ||||
{ | { | ||||
"origin_visit_status": [ | "origin_visit_status": [ | ||||
{ | { | ||||
"origin": "http://foobar.baz", | "origin": "http://foobar.baz", | ||||
"type": "git", | |||||
"status": "partial", | "status": "partial", | ||||
"visit": 5, | "visit": 5, | ||||
"date": current_datetime, | "date": current_datetime, | ||||
} | } | ||||
] | ] | ||||
} | } | ||||
) | ) | ||||
search_mock.origin_update.assert_not_called() | search_mock.origin_update.assert_called_once_with( | ||||
[{"url": "http://foobar.baz", "visit_types": ["git"]}] | |||||
) | |||||
def test_journal_client_origin_metadata_from_journal(): | def test_journal_client_origin_metadata_from_journal(): | ||||
search_mock = MagicMock() | search_mock = MagicMock() | ||||
worker_fn = functools.partial(process_journal_objects, search=search_mock,) | worker_fn = functools.partial(process_journal_objects, search=search_mock,) | ||||
worker_fn( | worker_fn( | ||||
Show All 32 Lines |