Add tests for npm tasks
This commit is contained in:
parent
264e9ea574
commit
f63b8326c5
3 changed files with 57 additions and 0 deletions
1
swh/lister/npm/tests/conftest.py
Normal file
1
swh/lister/npm/tests/conftest.py
Normal file
|
@ -0,0 +1 @@
|
|||
from swh.lister.core.tests.conftest import * # noqa
|
55
swh/lister/npm/tests/test_tasks.py
Normal file
55
swh/lister/npm/tests/test_tasks.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
from contextlib import contextmanager
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
@contextmanager
|
||||
def mock_save(lister):
|
||||
yield
|
||||
|
||||
|
||||
def test_ping(swh_app, celery_session_worker):
|
||||
res = swh_app.send_task(
|
||||
'swh.lister.npm.tasks.ping')
|
||||
assert res
|
||||
res.wait()
|
||||
assert res.successful()
|
||||
assert res.result == 'OK'
|
||||
|
||||
|
||||
@patch('swh.lister.npm.tasks.save_registry_state')
|
||||
@patch('swh.lister.npm.tasks.NpmLister')
|
||||
def test_lister(lister, save, swh_app, celery_session_worker):
|
||||
# setup the mocked NpmLister
|
||||
lister.return_value = lister
|
||||
lister.run.return_value = None
|
||||
save.side_effect = mock_save
|
||||
|
||||
res = swh_app.send_task('swh.lister.npm.tasks.NpmListerTask')
|
||||
assert res
|
||||
res.wait()
|
||||
assert res.successful()
|
||||
|
||||
lister.assert_called_once_with()
|
||||
lister.run.assert_called_once_with()
|
||||
|
||||
|
||||
@patch('swh.lister.npm.tasks.save_registry_state')
|
||||
@patch('swh.lister.npm.tasks.get_last_update_seq')
|
||||
@patch('swh.lister.npm.tasks.NpmIncrementalLister')
|
||||
def test_incremental(lister, seq, save, swh_app, celery_session_worker):
|
||||
# setup the mocked NpmLister
|
||||
lister.return_value = lister
|
||||
lister.run.return_value = None
|
||||
lister.request_headers.return_value = []
|
||||
seq.return_value = 42
|
||||
save.side_effect = mock_save
|
||||
|
||||
res = swh_app.send_task(
|
||||
'swh.lister.npm.tasks.NpmIncrementalListerTask')
|
||||
assert res
|
||||
res.wait()
|
||||
assert res.successful()
|
||||
|
||||
lister.assert_called_once_with()
|
||||
seq.assert_called_once_with(lister)
|
||||
lister.run.assert_called_once_with(min_bound=42)
|
Loading…
Add table
Add a link
Reference in a new issue