Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/gitlab/tests/test_tasks.py
Show All 20 Lines | def test_incremental(lister, swh_app, celery_session_worker): | ||||
lister.get_pages_information.return_value = (None, 10, None) | lister.get_pages_information.return_value = (None, 10, None) | ||||
res = swh_app.send_task( | res = swh_app.send_task( | ||||
'swh.lister.gitlab.tasks.IncrementalGitLabLister') | 'swh.lister.gitlab.tasks.IncrementalGitLabLister') | ||||
assert res | assert res | ||||
res.wait() | res.wait() | ||||
assert res.successful() | assert res.successful() | ||||
lister.assert_called_once_with( | lister.assert_called_once_with(sort='desc') | ||||
api_baseurl='https://gitlab.com/api/v4', | |||||
instance=None, sort='desc', per_page=20) | |||||
lister.db_last_index.assert_not_called() | lister.db_last_index.assert_not_called() | ||||
lister.get_pages_information.assert_called_once_with() | lister.get_pages_information.assert_called_once_with() | ||||
lister.run.assert_called_once_with( | lister.run.assert_called_once_with( | ||||
min_bound=1, max_bound=10, check_existence=True) | min_bound=1, max_bound=10, check_existence=True) | ||||
@patch('swh.lister.gitlab.tasks.GitLabLister') | @patch('swh.lister.gitlab.tasks.GitLabLister') | ||||
def test_range(lister, swh_app, celery_session_worker): | def test_range(lister, swh_app, celery_session_worker): | ||||
# setup the mocked GitlabLister | # setup the mocked GitlabLister | ||||
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.gitlab.tasks.RangeGitLabLister', | 'swh.lister.gitlab.tasks.RangeGitLabLister', | ||||
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( | lister.assert_called_once_with() | ||||
api_baseurl='https://gitlab.com/api/v4', | |||||
instance=None, sort='asc', per_page=20) | |||||
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.gitlab.tasks.GitLabLister') | @patch('swh.lister.gitlab.tasks.GitLabLister') | ||||
def test_relister(lister, swh_app, celery_session_worker): | def test_relister(lister, swh_app, celery_session_worker): | ||||
# setup the mocked GitlabLister | # setup the mocked GitlabLister | ||||
lister.return_value = lister | lister.return_value = lister | ||||
Show All 14 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( | lister.assert_called_with() | ||||
api_baseurl='https://gitlab.com/api/v4', | |||||
instance=None, sort='asc', per_page=20) | |||||
# one by the FullGitlabRelister task | # one by the FullGitlabRelister task | ||||
# + 9 for the RangeGitlabLister subtasks | # + 9 for the RangeGitlabLister subtasks | ||||
assert lister.call_count == 10 | assert lister.call_count == 10 | ||||
lister.db_last_index.assert_not_called() | lister.db_last_index.assert_not_called() | ||||
lister.db_partition_indices.assert_not_called() | lister.db_partition_indices.assert_not_called() | ||||
lister.get_pages_information.assert_called_once_with() | lister.get_pages_information.assert_called_once_with() | ||||
Show All 13 Lines | def test_relister_instance(lister, swh_app, celery_session_worker): | ||||
lister.return_value = lister | lister.return_value = lister | ||||
lister.run.return_value = None | lister.run.return_value = None | ||||
lister.get_pages_information.return_value = (None, 85, None) | lister.get_pages_information.return_value = (None, 85, None) | ||||
lister.db_partition_indices.return_value = [ | lister.db_partition_indices.return_value = [ | ||||
(i, i+9) for i in range(0, 80, 10)] + [(80, 85)] | (i, i+9) for i in range(0, 80, 10)] + [(80, 85)] | ||||
res = swh_app.send_task( | res = swh_app.send_task( | ||||
'swh.lister.gitlab.tasks.FullGitLabRelister', | 'swh.lister.gitlab.tasks.FullGitLabRelister', | ||||
kwargs=dict(api_baseurl='https://0xacab.org/api/v4')) | kwargs=dict(url='https://0xacab.org/api/v4')) | ||||
assert res | assert res | ||||
res.wait() | res.wait() | ||||
assert res.successful() | assert res.successful() | ||||
# retrieve the GroupResult for this task and wait for all the subtasks | # retrieve the GroupResult for this task and wait for all the subtasks | ||||
# to complete | # to complete | ||||
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( | lister.assert_called_with(url='https://0xacab.org/api/v4') | ||||
api_baseurl='https://0xacab.org/api/v4', | |||||
instance=None, sort='asc', per_page=20) | |||||
# one by the FullGitlabRelister task | # one by the FullGitlabRelister task | ||||
# + 9 for the RangeGitlabLister subtasks | # + 9 for the RangeGitlabLister subtasks | ||||
assert lister.call_count == 10 | assert lister.call_count == 10 | ||||
lister.db_last_index.assert_not_called() | lister.db_last_index.assert_not_called() | ||||
lister.db_partition_indices.assert_not_called() | lister.db_partition_indices.assert_not_called() | ||||
lister.get_pages_information.assert_called_once_with() | lister.get_pages_information.assert_called_once_with() | ||||
# lister.run should have been called once per partition interval | # lister.run should have been called once per partition interval | ||||
for i in range(8): | for i in range(8): | ||||
# XXX inconsistent behavior: max_bound is EXCLUDED here | # XXX inconsistent behavior: max_bound is EXCLUDED here | ||||
assert (dict(min_bound=10*i, max_bound=10*i + 10),) \ | assert (dict(min_bound=10*i, max_bound=10*i + 10),) \ | ||||
in lister.run.call_args_list | in lister.run.call_args_list | ||||
assert (dict(min_bound=80, max_bound=85),) \ | assert (dict(min_bound=80, max_bound=85),) \ | ||||
in lister.run.call_args_list | in lister.run.call_args_list |