diff --git a/requirements-swh.txt b/requirements-swh.txt --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1,5 +1,5 @@ swh.core >= 0.0.36 swh.model >= 0.0.27 swh.storage >= 0.0.114 -swh.scheduler >= 0.0.19 +swh.scheduler >= 0.0.39 swh.loader.core >= 0.0.37 diff --git a/requirements-test.txt b/requirements-test.txt --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1 +1,2 @@ -pytest +pytest<4 +swh.scheduler[testing] diff --git a/swh/loader/mercurial/loader.py b/swh/loader/mercurial/loader.py --- a/swh/loader/mercurial/loader.py +++ b/swh/loader/mercurial/loader.py @@ -54,7 +54,7 @@ """Mercurial loader able to deal with remote or local repository. """ - CONFIG_BASE_FILENAME = 'loader/hg' + CONFIG_BASE_FILENAME = 'loader/mercurial' ADDITIONAL_CONFIG = { 'bundle_filename': ('str', 'HG20_none_bundle'), diff --git a/swh/loader/mercurial/tasks.py b/swh/loader/mercurial/tasks.py --- a/swh/loader/mercurial/tasks.py +++ b/swh/loader/mercurial/tasks.py @@ -3,41 +3,33 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from swh.scheduler.task import Task +from celery import current_app as app from .loader import HgBundle20Loader, HgArchiveBundle20Loader -class LoadMercurial(Task): +@app.task(name=__name__ + '.LoadMercurial') +def load_mercurial(origin_url, directory=None, visit_date=None): """Mercurial repository loading - """ - task_queue = 'swh_loader_mercurial' - - def run_task(self, *, origin_url, visit_date=None, directory=None): - """Import a mercurial tarball into swh. - - Args: see :func:`DepositLoader.load`. + Import a mercurial tarball into swh. - """ - loader = HgBundle20Loader() - loader.log = self.log - return loader.load(origin_url=origin_url, - directory=directory, - visit_date=visit_date) + Args: see :func:`DepositLoader.load`. + """ + loader = HgBundle20Loader() + return loader.load(origin_url=origin_url, + directory=directory, + visit_date=visit_date) -class LoadArchiveMercurial(Task): - task_queue = 'swh_loader_mercurial_archive' - - def run_task(self, *, origin_url, archive_path, visit_date): - """Import a mercurial tarball into swh. - Args: see :func:`DepositLoader.load`. +@app.task(name=__name__ + '.LoadArchiveMercurial') +def load_archive_mercurial(origin_url, archive_path, visit_date=None): + """Import a mercurial tarball into swh. - """ - loader = HgArchiveBundle20Loader() - loader.log = self.log - return loader.load(origin_url=origin_url, - archive_path=archive_path, - visit_date=visit_date) + Args: see :func:`DepositLoader.load`. + """ + loader = HgArchiveBundle20Loader() + return loader.load(origin_url=origin_url, + archive_path=archive_path, + visit_date=visit_date) diff --git a/swh/loader/mercurial/tests/conftest.py b/swh/loader/mercurial/tests/conftest.py new file mode 100644 --- /dev/null +++ b/swh/loader/mercurial/tests/conftest.py @@ -0,0 +1,10 @@ +import pytest + +from swh.scheduler.tests.conftest import * # noqa + + +@pytest.fixture(scope='session') +def celery_includes(): + return [ + 'swh.loader.mercurial.tasks', + ] diff --git a/swh/loader/mercurial/tests/test_tasks.py b/swh/loader/mercurial/tests/test_tasks.py --- a/swh/loader/mercurial/tests/test_tasks.py +++ b/swh/loader/mercurial/tests/test_tasks.py @@ -3,51 +3,39 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -import unittest from unittest.mock import patch -from swh.loader.mercurial.tasks import LoadMercurial, LoadArchiveMercurial +@patch('swh.loader.mercurial.loader.HgBundle20Loader.load') +def test_loader(mock_loader, swh_app, celery_session_worker): + mock_loader.return_value = {'status': 'eventful'} -class TestTasks(unittest.TestCase): - def test_check_task_name(self): - task = LoadMercurial() - self.assertEqual(task.task_queue, 'swh_loader_mercurial') + res = swh_app.send_task( + 'swh.loader.mercurial.tasks.LoadMercurial', + kwargs=dict(origin_url='origin_url', directory='/some/repo', + visit_date='now')) + assert res + res.wait() + assert res.successful() - @patch('swh.loader.mercurial.loader.HgBundle20Loader.load') - def test_task(self, mock_loader): - mock_loader.return_value = {'status': 'eventful'} - task = LoadMercurial() + assert res.result == {'status': 'eventful'} + mock_loader.assert_called_once_with( + origin_url='origin_url', visit_date='now', directory='/some/repo') - # given - actual_result = task.run_task( - origin_url='origin_url', visit_date='now', directory='/some/repo') - self.assertEqual(actual_result, {'status': 'eventful'}) +@patch('swh.loader.mercurial.loader.HgArchiveBundle20Loader.load') +def test_archive_loader(mock_loader, swh_app, celery_session_worker): + mock_loader.return_value = {'status': 'uneventful'} - mock_loader.assert_called_once_with( - origin_url='origin_url', visit_date='now', directory='/some/repo') + res = swh_app.send_task( + 'swh.loader.mercurial.tasks.LoadArchiveMercurial', + ('another_url', '/some/tar.tgz', 'now')) + assert res + res.wait() + assert res.successful() - -class TestTasks2(unittest.TestCase): - def test_check_task_name(self): - task = LoadArchiveMercurial() - self.assertEqual(task.task_queue, 'swh_loader_mercurial_archive') - - @patch('swh.loader.mercurial.loader.HgArchiveBundle20Loader.load') - def test_task(self, mock_loader): - mock_loader.return_value = {'status': 'uneventful'} - task = LoadArchiveMercurial() - - # given - actual_result = task.run_task( - origin_url='another_url', - archive_path='/some/tar.tgz', - visit_date='now') - - self.assertEqual(actual_result, {'status': 'uneventful'}) - - mock_loader.assert_called_once_with( - origin_url='another_url', - archive_path='/some/tar.tgz', - visit_date='now') + assert res.result == {'status': 'uneventful'} + mock_loader.assert_called_once_with( + origin_url='another_url', + archive_path='/some/tar.tgz', + visit_date='now')