Skip to content

Commit

Permalink
Update job tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Dec 26, 2019
1 parent 40bb256 commit 0547d3d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ckan/tests/helpers.py
Expand Up @@ -28,6 +28,7 @@

import webtest
import nose.tools
import pytest
import mock
import rq
import six
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions ckan/tests/lib/test_jobs.py
Expand Up @@ -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()
Expand Down
14 changes: 13 additions & 1 deletion ckan/tests/pytest_ckan/fixtures.py
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit 0547d3d

Please sign in to comment.