-
Notifications
You must be signed in to change notification settings - Fork 51
/
tests.py
112 lines (84 loc) · 2.32 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import unittest
import redis
from mock import patch
from retask import Task
from retask import Queue
class ConnectTest(unittest.TestCase):
"""
Test the connect method
"""
def runTest(self):
queue = Queue('testqueue')
self.assertTrue(queue.connect())
class LengthTest(unittest.TestCase):
"""
Tests the length method of the Queue
"""
@patch('redis.Redis')
def runTest(self, mock_redis):
m = mock_redis.return_value
m.llen.return_value = 2
queue = Queue('testqueue')
queue.connect()
self.assertEqual(queue.length, 2)
class SetTest(unittest.TestCase):
"""
Sets a task in the Queue
"""
def runTest(self):
queue = Queue('testqueue')
queue.connect()
t = Task({'name':'kushal'})
self.assertTrue(queue.enqueue(t))
def tearDown(self):
rdb = redis.Redis()
rdb.delete('retaskqueue-testqueue')
class GetTest(unittest.TestCase):
"""
Gets a task in the Queue
"""
def setUp(self):
queue = Queue('testqueue')
queue.connect()
t = Task({'name':'kushal'})
queue.enqueue(t)
def runTest(self):
queue = Queue('testqueue')
queue.connect()
task = queue.dequeue()
i = task.data
self.assertEqual(task.data['name'], 'kushal')
class GetQueueNamesTest(unittest.TestCase):
"""
Gets a task in the Queue
"""
def setUp(self):
queue = Queue('lambda')
queue.connect()
t = Task({'name':'kushal'})
queue.enqueue(t)
def runTest(self):
queue = Queue('lambda')
queue.connect()
results = queue.names()
self.assertEqual(results[0], 'lambda')
def tearDown(self):
rdb = redis.Redis()
rdb.delete('retaskqueue-lambda')
class FindObjQueueTest(unittest.TestCase):
"""
Finds the index of the given object in the Queue
"""
def setUp(self):
self.queue = Queue('findTest')
self.queue.connect()
t = Task({'name': 'mytask'})
self.queue.enqueue(t)
def runTest(self):
task_idx = self.queue.find('mytask')
self.assertEqual(task_idx, 0)
def tearDown(self):
rdb = redis.Redis()
rdb.delete('retaskqueue-findTest')
if __name__ == '__main__':
unittest.main()