Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/github/tests/test_tasks.py
Show All 20 Lines | def test_incremental(lister, swh_app, celery_session_worker): | ||||
lister.run.return_value = None | lister.run.return_value = None | ||||
res = swh_app.send_task( | res = swh_app.send_task( | ||||
'swh.lister.github.tasks.IncrementalGitHubLister') | 'swh.lister.github.tasks.IncrementalGitHubLister') | ||||
assert res | assert res | ||||
res.wait() | res.wait() | ||||
assert res.successful() | assert res.successful() | ||||
lister.assert_called_once_with(api_baseurl='https://api.github.com') | lister.assert_called_once_with() | ||||
lister.db_last_index.assert_called_once_with() | lister.db_last_index.assert_called_once_with() | ||||
lister.run.assert_called_once_with(min_bound=42, max_bound=None) | lister.run.assert_called_once_with(min_bound=42, max_bound=None) | ||||
@patch('swh.lister.github.tasks.GitHubLister') | @patch('swh.lister.github.tasks.GitHubLister') | ||||
def test_range(lister, swh_app, celery_session_worker): | def test_range(lister, swh_app, celery_session_worker): | ||||
# setup the mocked GitHubLister | # setup the mocked GitHubLister | ||||
lister.return_value = lister | lister.return_value = lister | ||||
lister.run.return_value = None | lister.run.return_value = None | ||||
res = swh_app.send_task( | res = swh_app.send_task( | ||||
'swh.lister.github.tasks.RangeGitHubLister', | 'swh.lister.github.tasks.RangeGitHubLister', | ||||
kwargs=dict(start=12, end=42)) | kwargs=dict(start=12, end=42)) | ||||
assert res | assert res | ||||
res.wait() | res.wait() | ||||
assert res.successful() | assert res.successful() | ||||
lister.assert_called_once_with(api_baseurl='https://api.github.com') | lister.assert_called_once_with() | ||||
lister.db_last_index.assert_not_called() | lister.db_last_index.assert_not_called() | ||||
lister.run.assert_called_once_with(min_bound=12, max_bound=42) | lister.run.assert_called_once_with(min_bound=12, max_bound=42) | ||||
@patch('swh.lister.github.tasks.GitHubLister') | @patch('swh.lister.github.tasks.GitHubLister') | ||||
def test_relister(lister, swh_app, celery_session_worker): | def test_relister(lister, swh_app, celery_session_worker): | ||||
# setup the mocked GitHubLister | # setup the mocked GitHubLister | ||||
lister.return_value = lister | lister.return_value = lister | ||||
Show All 13 Lines | def test_relister(lister, swh_app, celery_session_worker): | ||||
promise_id = res.result | promise_id = res.result | ||||
assert promise_id | assert promise_id | ||||
promise = GroupResult.restore(promise_id, app=swh_app) | promise = GroupResult.restore(promise_id, app=swh_app) | ||||
for i in range(5): | for i in range(5): | ||||
if promise.ready(): | if promise.ready(): | ||||
break | break | ||||
sleep(1) | sleep(1) | ||||
lister.assert_called_with(api_baseurl='https://api.github.com') | lister.assert_called_with() | ||||
# one by the FullGitHubRelister task | # one by the FullGitHubRelister task | ||||
# + 5 for the RangeGitHubLister subtasks | # + 5 for the RangeGitHubLister subtasks | ||||
assert lister.call_count == 6 | assert lister.call_count == 6 | ||||
lister.db_last_index.assert_not_called() | lister.db_last_index.assert_not_called() | ||||
lister.db_partition_indices.assert_called_once_with(10000) | lister.db_partition_indices.assert_called_once_with(10000) | ||||
# lister.run should have been called once per partition interval | # lister.run should have been called once per partition interval | ||||
for i in range(5): | for i in range(5): | ||||
# XXX inconsistent behavior: max_bound is INCLUDED here | # XXX inconsistent behavior: max_bound is INCLUDED here | ||||
assert (dict(min_bound=10*i, max_bound=10*i + 9),) \ | assert (dict(min_bound=10*i, max_bound=10*i + 9),) \ | ||||
in lister.run.call_args_list | in lister.run.call_args_list |