forked from iron-io/iron_mq_python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
65 lines (45 loc) · 1.63 KB
/
test.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
from iron_mq import *
import unittest
import time
class TestIronMQ(unittest.TestCase):
def setUp(self):
self.mq = IronMQ()
def test_postMessage(self):
q = self.mq.queue("test_queue")
old_size = q.size()
q.post("test message")
self.assertEqual(old_size, q.size() - 1)
def test_getMessage(self):
msg = "%s" % time.time()
q = self.mq.queue("test_queue")
q.post(msg)
message = q.get()
message = "%s" % message["messages"][0]["body"]
self.assertEqual(msg, message)
def test_deleteMessage(self):
q = self.mq.queue("test_queue")
size = q.size()
msg = q.post("test")
self.assertEqual(size, q.size() - 1)
q.delete(msg["ids"][0])
self.assertEqual(size, q.size())
def test_clearQueue(self):
q = self.mq.queue("test_queue")
q.post("%s" % time.time())
self.assertTrue(q.size() > 0)
q.clear()
self.assertEqual(q.size(), 0)
def test_deprecated(self):
self.assertEqual(self.mq.queues(), self.mq.getQueues())
name = 'test_queue'
q = self.mq.queue(name)
self.assertEqual('Cleared', self.mq.clearQueue(name)['msg'])
self.assertEqual(0, q.size())
info = self.mq.getQueueDetails(name)
self.assertEqual(q.info(), info)
msg_id = self.mq.postMessage(name, ['hello mq'])['ids'][0]
resp = self.mq.getMessage(name)
self.assertEqual(msg_id, resp['messages'][-1]['id'])
self.assertEqual('Deleted', self.mq.deleteMessage(name, msg_id)['msg'])
if __name__ == '__main__':
unittest.main()