-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rocksms.py
84 lines (68 loc) · 2.2 KB
/
test_rocksms.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
#! usr/bin/python
# Copyright 2017 Michael Neeley
# This script will run unit tests on the rocksms app suite
import logging
import unittest
from xml.etree import ElementTree as ET
from rocksms import app
# disable logging
#TODO: turn off logging for file but set console to debug
logging.disable(logging.WARNING)
class TwiMLTest(unittest.TestCase):
def setUp(self):
self.client = app.test_client()
def assertTwiML(self, response):
self.assertEquals(response.status, "200 OK")
x = ET.fromstring(response.data)
self.assertEquals(x.tag, "Response", "Did not get back a TwiML Response tag.")
def call(self, url = "/voice", from_ = "+15556667777",
digits = None, extra_params = None):
"""
Simulates Twilio Voice request to Flask test client.
"""
# Set some common parameters for messages received by Twilio.
params = {
"CallSid": "CAtesting",
"AccountSid": "ACxxxxxxxxxxxxx",
"To": "+15551234567",
"From": from_,
"CallStatus": "ringing",
"Direction": "inbound",
"FromCity": "BROOKLYN",
"FromState": "NY",
"FromCountry": "US",
"FromZip": "55555"}
# Add simulated DTMF input.
if digits:
params["Digits"] = digits
# Add extra params not defined by default.
if extra_params:
params = dict(params.items() + extra_params.items())
# Return the app's response.
return self.client.post(url, data = params)
def message(self, body, url = "/sms", from_ = "+15556667777", extra_params = None):
"""
Simulates Twilio Message request to Flask test client.
"""
# Set some common parameters for messages received by Twilio.
params = {
"MessageSid": "SMtesting",
"AccountSid": "ACxxxxxxxxxxxxx",
"To": "+15551234567",
"From": from_,
"Body": body,
"NumMedia": 0,
"FromCity": "BROOKLYN",
"FromState": "NY",
"FromCountry": "US",
"FromZip": "55555"}
# Add extra params not defined by default.
if extra_params:
params = dict(params.items() + extra_params.items())
# Return the app's response.
return self.client.post(url, data = params)
class ContactsSearchTest(TwiMLTest):
def test_inactiveEmail(self):
body = "John Doe"
response = self.message(body)
self.assertTwiML(response)