-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-test.py
50 lines (38 loc) · 1.5 KB
/
app-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
import unittest
import app
import json
class SmsTestCase(unittest.TestCase):
def setUp(self):
self.app = app.app.test_client();
app.testing = True
# Perform test using application/x-www-form-urlencoded.
def test_can_send_form_encoded(self):
response = self.app.post('/sms/send', data=dict(
phone=['60145127982'],
message='hello from test 1',
username=app.app.config['ISMS_USERNAME'],
password=app.app.config['ISMS_PASSWORD'],
))
data = json.loads(response.get_data())
self.assertEqual('2000', data.get('code'))
# Perform test using application/json.
def test_can_send_application_json(self):
response = self.app.post('/sms/send', data=json.dumps(dict(
phone=['60145127982'],
message='hello from test 2',
username=app.app.config['ISMS_USERNAME'],
password=app.app.config['ISMS_PASSWORD']
)), content_type='application/json')
data = json.loads(response.get_data())
self.assertEqual('2000', data.get('code'))
# Perform test for checking credit balance.
def test_can_check_for_credit_balance(self):
response = self.app.post('/sms/check-balance', data=dict(
username=app.app.config['ISMS_USERNAME'],
password=app.app.config['ISMS_PASSWORD']
))
data = json.loads(response.get_data())
self.assertEqual(float, type(float(data.get('message'))))
self.assertEqual('2000', data.get('code'))
if __name__ == '__main__':
unittest.main()