From 0547d3d8e26a76793355bb97ef13ec05266dc19e Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Thu, 26 Dec 2019 14:18:48 +0200 Subject: [PATCH] Update job tests --- ckan/tests/helpers.py | 2 ++ ckan/tests/lib/test_jobs.py | 8 ++++---- ckan/tests/pytest_ckan/fixtures.py | 14 +++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ckan/tests/helpers.py b/ckan/tests/helpers.py index af1d76ee834..c3d5bee7199 100644 --- a/ckan/tests/helpers.py +++ b/ckan/tests/helpers.py @@ -28,6 +28,7 @@ import webtest import nose.tools +import pytest import mock import rq import six @@ -296,6 +297,7 @@ def teardown_class(cls): config.update(cls._original_config) +@pytest.mark.usefixtures("with_test_worker") class RQTestBase(object): """ Base class for tests of RQ functionality. diff --git a/ckan/tests/lib/test_jobs.py b/ckan/tests/lib/test_jobs.py index c091691a4bb..59bf35272c0 100644 --- a/ckan/tests/lib/test_jobs.py +++ b/ckan/tests/lib/test_jobs.py @@ -71,10 +71,10 @@ def test_enqueue_queue(self): self.enqueue(queue=u"my_queue") all_jobs = self.all_jobs() assert len(all_jobs) == 2 - assert all_jobs[0].origin == jobs.add_queue_name_prefix( - jobs.DEFAULT_QUEUE_NAME - ) - assert all_jobs[1].origin == jobs.add_queue_name_prefix(u"my_queue") + assert sorted(job.origin for job in all_jobs) == sorted([ + jobs.add_queue_name_prefix(jobs.DEFAULT_QUEUE_NAME), + jobs.add_queue_name_prefix(u"my_queue") + ]) def test_enqueue_timeout(self): self.enqueue() diff --git a/ckan/tests/pytest_ckan/fixtures.py b/ckan/tests/pytest_ckan/fixtures.py index a215ebb904b..22446866f57 100644 --- a/ckan/tests/pytest_ckan/fixtures.py +++ b/ckan/tests/pytest_ckan/fixtures.py @@ -35,7 +35,7 @@ import ckan.tests.helpers as test_helpers import ckan.plugins import ckan.lib.search as search - +import rq from ckan.common import config @@ -237,6 +237,18 @@ def clear_smtp_messages(self): @pytest.fixture def mail_server(monkeypatch): + """Catch all outcome mails. + """ bag = FakeSMTP() monkeypatch.setattr(smtplib, 'SMTP', bag) yield bag + + +@pytest.fixture +def with_test_worker(monkeypatch): + """Worker that doesn't create forks. + """ + if six.PY3: + monkeypatch.setattr(rq.Worker, 'main_work_horse', rq.SimpleWorker.main_work_horse) + monkeypatch.setattr(rq.Worker, 'execute_job', rq.SimpleWorker.execute_job) + yield