-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestapp.py
43 lines (29 loc) · 1.09 KB
/
testapp.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
# -*- coding: utf-8 -*-
# @time: 2019-05-11 15:23
# @Author : zpy
# @Email : zpy94254@gmail.com
# @file: testapp.py
import requests
burl = 'http://localhost:5000/'
import unittest
from flask_testing import TestCase
class ApiTest(unittest.TestCase):
def test_todopost(self):
resp = requests.post(f'{burl}todo', data={'user': 'test','data': 'test'})
assert resp.status_code == 201
def test_todoget(self):
resp = requests.get(f'{burl}todo?user=test&type=svip')
assert resp.status_code == 200
assert resp.status_code in (200, 404)
def test_todoput(self):
ndata = 'test'
_id = requests.get(f'{burl}todo?user=test&type=svip').json()[0]['_id']
resp = requests.put(f'{burl}todo/{_id}', data={'data': ndata})
assert resp.status_code == 200
assert resp.json()['1'] == ndata
def test_tododelete(self):
_id = requests.get(f'{burl}todo?user=test&type=svip').json()[0]['_id']
resp = requests.delete(f'{burl}todo/{_id}')
assert resp.status_code == 204
if __name__ == '__main__':
unittest.main()