-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathtest.py
34 lines (24 loc) · 872 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
33
34
import unittest
import app
import requests
import json
import sys
class TestFlaskApiUsingRequests(unittest.TestCase):
def test_hello_world(self):
response = requests.get('http://localhost:5000/my-resource/0')
self.assertEqual(response.json(), {'hello': 'world'})
def test_post(self):
response = requests.post('http://localhost:5000/my-resource/0')
self.assertEqual(response.status_code, 403)
class TestFlaskApi(unittest.TestCase):
def setUp(self):
self.app = app.app.test_client()
def test_hello_world(self):
response = self.app.get('/my-resource/0')
self.assertEqual(json.loads(response.get_data().decode(
sys.getdefaultencoding())), {'hello': 'world'})
def test_post(self):
response = self.app.post('/my-resource/0')
self.assertEqual(response.status_code, 403)
if __name__ == "__main__":
unittest.main()