-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
32 lines (25 loc) · 926 Bytes
/
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
import app
import unittest
import requests
import json
import sys
class TestApp(unittest.TestCase):
def setUp(self):
self.app = app.app.test_client()
def test_post(self):
response = self.app.post('/')
self.assertEqual(response.data, "POST Request")
def test_get_with_right_header(self):
headers = {'Accept': 'application/json'}
response = self.app.get('/', headers=headers)
self.assertEqual(response.data, '{"message": "Good morning"}')
def test_get_with_wrong_header(self):
headers = {'Accept': 'xxx'}
response = self.app.get('/', headers=headers)
self.assertEqual(response.data, 'Accept header not set to application/json')
def test_get_without_Accept_header(self):
headers = None
response = self.app.get('/', headers=headers)
self.assertEqual(response.data, '<p>Hello, World</p>')
if __name__ == "__main__":
unittest.main()