Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/tests/test_tasks.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from unittest.mock import patch | |||||
anlambert: Same remark as in D2398 and D2400, you should use `pytest-mock` | |||||
def test_loader(mocker, swh_app, celery_session_worker): | |||||
@patch('swh.loader.mercurial.loader.HgBundle20Loader.load') | mock_loader = mocker.patch( | ||||
def test_loader(mock_loader, swh_app, celery_session_worker): | 'swh.loader.mercurial.loader.HgBundle20Loader.load') | ||||
mock_loader.return_value = {'status': 'eventful'} | mock_loader.return_value = {'status': 'eventful'} | ||||
res = swh_app.send_task( | res = swh_app.send_task( | ||||
'swh.loader.mercurial.tasks.LoadMercurial', | 'swh.loader.mercurial.tasks.LoadMercurial', | ||||
kwargs=dict(origin_url='origin_url', directory='/some/repo', | kwargs={ | ||||
visit_date='now')) | 'url': 'origin_url', | ||||
'directory': '/some/repo', | |||||
'visit_date': 'now', | |||||
}) | |||||
assert res | assert res | ||||
Not Done Inline ActionsHow about using this instead ? res = swh_app.send_task( 'swh.loader.mercurial.tasks.LoadMercurial', kwargs={'url': 'origin_url', 'directory': '/some/repo', 'visit_date': 'now'}) anlambert: How about using this instead ?
```lang=python
res = swh_app.send_task(
'swh.loader. | |||||
Done Inline Actionsyup ardumont: yup | |||||
res.wait() | res.wait() | ||||
assert res.successful() | assert res.successful() | ||||
assert res.result == {'status': 'eventful'} | assert res.result == {'status': 'eventful'} | ||||
mock_loader.assert_called_once_with( | mock_loader.assert_called_once_with() | ||||
origin_url='origin_url', visit_date='now', directory='/some/repo') | |||||
@patch('swh.loader.mercurial.loader.HgArchiveBundle20Loader.load') | def test_archive_loader(mocker, swh_app, celery_session_worker): | ||||
def test_archive_loader(mock_loader, swh_app, celery_session_worker): | mock_loader = mocker.patch( | ||||
'swh.loader.mercurial.loader.HgArchiveBundle20Loader.load') | |||||
mock_loader.return_value = {'status': 'uneventful'} | mock_loader.return_value = {'status': 'uneventful'} | ||||
res = swh_app.send_task( | res = swh_app.send_task( | ||||
'swh.loader.mercurial.tasks.LoadArchiveMercurial', | 'swh.loader.mercurial.tasks.LoadArchiveMercurial', | ||||
('another_url', '/some/tar.tgz', 'now')) | kwargs={ | ||||
'url': 'another_url', | |||||
'archive_path': '/some/tar.tgz', | |||||
'visit_date': 'now', | |||||
}) | |||||
assert res | assert res | ||||
Not Done Inline Actionssame here anlambert: same here | |||||
res.wait() | res.wait() | ||||
assert res.successful() | assert res.successful() | ||||
assert res.result == {'status': 'uneventful'} | assert res.result == {'status': 'uneventful'} | ||||
mock_loader.assert_called_once_with( | mock_loader.assert_called_once_with() | ||||
origin_url='another_url', | |||||
archive_path='/some/tar.tgz', | |||||
visit_date='now') |
Same remark as in D2398 and D2400, you should use pytest-mock