-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
81 lines (48 loc) · 2.72 KB
/
tests.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#http://flask.pocoo.org/docs/0.10/testing/
#http://www.diveintopython3.net/unit-testing.html
#http://werkzeug.pocoo.org/docs/0.10/test/#testing-api
import unittest
from app import create_app
from app.users.models import Users
from app.posts.models import Posts
app = create_app('config')
class TestUsers(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
def test_list(self):
self.app = app.test_client()
rv = self.app.get('/users/')
assert "Users" in rv.data.decode('utf-8')
def test_01_add(self):
rv = self.app.post('/users/add', data=dict(name = 'test name', email = '[email protected]'), follow_redirects=True)
assert 'Add was successful' in rv.data.decode('utf-8')
def test_02_Update(self):
with app.app_context():
id = Users.query.first().id
rv = self.app.post('/users/update/{}'.format(id), data=dict(name = 'test name update', email = '[email protected]'), follow_redirects=True)
assert 'Update was successful' in rv.data.decode('utf-8')
def test_03_delete(self):
with app.app_context():
id = Users.query.first().id
rv = self.app.post('/users/delete/{}'.format(id), follow_redirects=True)
assert 'Delete was successful' in rv.data.decode('utf-8')
#Run for scafold.
def test_04_list(self):
self.app = app.test_client()
rv = self.app.get('/posts/')
assert "Posts" in rv.data.decode('utf-8')
def test_06_add(self):
rv = self.app.post('/posts/add', data=dict(name = 'test name', email = '[email protected]'), follow_redirects=True)
assert 'Add was successful' in rv.data.decode('utf-8')
def test_08_Update(self):
with app.app_context():
id = Posts.query.first().id
rv = self.app.post('/posts/update/{}'.format(id), data=dict(name = 'test name update', email = '[email protected]'), follow_redirects=True)
assert 'Update was successful' in rv.data.decode('utf-8')
def test_10_delete(self):
with app.app_context():
id = Posts.query.first().id
rv = self.app.post('/posts/delete/{}'.format(id), follow_redirects=True)
assert 'Delete was successful' in rv.data.decode('utf-8')
if __name__ == '__main__':
unittest.main()