-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
40 lines (33 loc) · 1.48 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
import unittest
from app import app
from config import MY_NR
class TestCase(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
self.app = app.test_client()
def test_new_post(self):
response = self.app.post('/new', data={'From': MY_NR})
expected = (b'<?xml version="1.0" encoding="UTF-8"?>'
b'<Response>'
b'<Say>Hi!</Say>'
b'<Gather action="/handle-key" method="POST" numDigits="1">'
b'<Say>To record a post, press 1.</Say>'
b'</Gather>'
b'</Response>')
self.assertEqual(expected, response.data)
def test_handle_key(self):
response = self.app.post('/handle-key', data={'Digits': '1'})
expected = (b'<?xml version="1.0" encoding="UTF-8"?>'
b'<Response>'
b'<Say>Record your post after the tone.</Say>'
b'<Record action="/handle-recording" maxLength="30" />'
b'</Response>')
self.assertEqual(expected, response.data)
def test_handle_recording(self):
response = self.app.post('/handle-recording', data={'RecordingUrl': 'something-random'})
expected = (b'<?xml version="1.0" encoding="UTF-8"?>'
b'<Response><Say>Your post is now live! Goodbye</Say>'
b'</Response>')
self.assertEqual(expected, response.data)
if __name__ == '__main__':
unittest.main()