-
Notifications
You must be signed in to change notification settings - Fork 0
/
application_test.py
62 lines (42 loc) · 1.78 KB
/
application_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
import json
from application import app
import pytest
class TestClass():
def setup_class(self):
app.config['TESTING'] = True
self.app = app.test_client()
def teardown_class(self):
pass
#test case: / endpoint
def test_hello(self):
response = self.app.get('/')
assert response.status_code == 200
assert response.data == b'Hello!!!'
assert response.mimetype == 'text/html'
#test case: /add endpoint (valid input)
def test_add1(self):
response = self.app.get('/add?op1=3&op2=4')
if (not response.is_json):
pytest.fail("Response is not json object!")
j = response.get_json() #j is dict type
expected_output = {"operand 1":3, "operand 2":4, "sum":7}
assert response.status_code == 200
assert response.mimetype == 'application/json'
assert j == expected_output
#test case: /add endpoint (missing operand)
def test_add2(self):
response = self.app.get('/add?op1=3')
assert response.status_code == 400
assert response.is_json
assert response.mimetype == 'application/json'
j = response.get_json() #j is dict type
assert j == {'error': 'missing parameter(s)'}
def test_mul1(self):
http_body = json.dumps({"op1":3,"op2":5})
response = self.app.post('/mul',
data=http_body,
content_type='application/json')
assert response.status_code == 200
assert response.is_json
j = response.get_json() #j is dict type
assert j == {'mul': 15}