From 33ec762bd41324da66521aa5a6a12eabf620bdc4 Mon Sep 17 00:00:00 2001 From: David Douard Date: Tue, 8 Jan 2019 10:11:28 +0100 Subject: [PATCH] Add tests for debian tasks --- swh/lister/core/tests/conftest.py | 1 + swh/lister/debian/tests/__init__.py | 0 swh/lister/debian/tests/conftest.py | 1 + swh/lister/debian/tests/test_tasks.py | 29 +++++++++++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 swh/lister/debian/tests/__init__.py create mode 100644 swh/lister/debian/tests/conftest.py create mode 100644 swh/lister/debian/tests/test_tasks.py diff --git a/swh/lister/core/tests/conftest.py b/swh/lister/core/tests/conftest.py index 07ef181..f4a0e99 100644 --- a/swh/lister/core/tests/conftest.py +++ b/swh/lister/core/tests/conftest.py @@ -10,6 +10,7 @@ def celery_enable_logging(): def celery_includes(): return [ 'swh.lister.bitbucket.tasks', + 'swh.lister.debian.tasks', 'swh.lister.github.tasks', ] diff --git a/swh/lister/debian/tests/__init__.py b/swh/lister/debian/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/lister/debian/tests/conftest.py b/swh/lister/debian/tests/conftest.py new file mode 100644 index 0000000..507fef9 --- /dev/null +++ b/swh/lister/debian/tests/conftest.py @@ -0,0 +1 @@ +from swh.lister.core.tests.conftest import * # noqa diff --git a/swh/lister/debian/tests/test_tasks.py b/swh/lister/debian/tests/test_tasks.py new file mode 100644 index 0000000..bd1d0b4 --- /dev/null +++ b/swh/lister/debian/tests/test_tasks.py @@ -0,0 +1,29 @@ +from time import sleep +from celery.result import GroupResult + +from unittest.mock import patch + + +def test_ping(swh_app, celery_session_worker): + res = swh_app.send_task( + 'swh.lister.debian.tasks.ping') + assert res + res.wait() + assert res.successful() + assert res.result == 'OK' + + +@patch('swh.lister.debian.tasks.DebianLister') +def test_lister(lister, swh_app, celery_session_worker): + # setup the mocked DebianLister + lister.return_value = lister + lister.run.return_value = None + + res = swh_app.send_task( + 'swh.lister.debian.tasks.DebianListerTask', ('stretch',)) + assert res + res.wait() + assert res.successful() + + lister.assert_called_once_with() + lister.run.assert_called_once_with('stretch')