Skip to content

Commit

Permalink
Merge branch 'test-worker' of 'https://github.com/mghfdez/arthur.git'
Browse files Browse the repository at this point in the history
Merges chaoss#3
Closes chaoss#3
  • Loading branch information
sduenas committed Mar 29, 2017
2 parents 0f42282 + d7ecee5 commit 50a2b47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
18 changes: 5 additions & 13 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import unittest

from redis import StrictRedis
from fakeredis import FakeStrictRedis
from rq import pop_connection, push_connection


Expand All @@ -29,17 +29,9 @@
# to their authors.

def find_empty_redis_database():
"""Connect to a random Redis database.
Tries to connect a random Redis database (starting on 8) and
will use/connect it when no keys are stored in there.
"""
for db in range(8, 16):
conn = StrictRedis(db=db)
empty = len(conn.keys('*')) == 0
if empty:
return conn
assert False, "No empty Redis database found to run tests in."
"""Connect to a fake Redis database"""
conn = FakeStrictRedis()
return conn


class TestBaseRQ(unittest.TestCase):
Expand All @@ -54,7 +46,7 @@ def setUpClass(cls):
def tearDownClass(cls):
conn = pop_connection()
assert conn == cls.conn, \
"Wow, something really nasty happened to the Redis connection stack. Check your setup."
"Wow, something really nasty happened to the FakeRedis connection stack. Check your setup."

def setUp(self):
self.conn.flushdb()
Expand Down
9 changes: 7 additions & 2 deletions tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import sys
import unittest

import rq
import rq.worker

if not '..' in sys.path:
sys.path.insert(0, '..')
Expand All @@ -36,6 +36,11 @@
from tests import TestBaseRQ, mock_sum, mock_failure


class MockArthurWorker(rq.worker.SimpleWorker, ArthurWorker):
"""Unit tests for ArthurWorker class, avoids rq inheritance problems"""
pass


class TestArthurWorker(TestBaseRQ):
"""Unit tests for ArthurWorker class"""

Expand All @@ -46,7 +51,7 @@ def test_publish_finished_job_status(self):
pubsub.subscribe(CH_PUBSUB)

q = rq.Queue('foo')
w = ArthurWorker([q])
w = MockArthurWorker([q])

job_a = q.enqueue(mock_sum, a=2, b=3)
job_b = q.enqueue(mock_failure)
Expand Down

0 comments on commit 50a2b47

Please sign in to comment.