-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamples.py
37 lines (28 loc) · 891 Bytes
/
examples.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
import awstestutils
import unittest
import json
class ObjectUnderTest:
def __init__(self, sqs_queue):
self.queue = sqs_queue
self.data = {}
def do_something(self):
self.data.update({
'some': 'value',
'other': 123,
})
def send_results_to_backend(self):
payload = json.dumps(self.data)
self.queue.send_message(MessageBody=payload)
class TestCase(unittest.TestCase):
def test_it(self):
with awstestutils.LiveTestQueue() as queue:
o = ObjectUnderTest(sqs_queue=queue)
o.do_something()
data = o.data
o.send_results_to_backend()
msgs = queue.receive_messages()
self.assertEqual(len(msgs), 1)
expected = json.dumps(data)
self.assertEqual(msgs[0].body, expected)
if __name__ == '__main__':
unittest.main()