-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
68 lines (54 loc) · 2.62 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
import unittest
from beckton import app, db
from mongoengine import connect
import os
class Tests(unittest.TestCase):
def _drop_database(self):
mongo_settings = app.config['MONGODB_SETTINGS']
db = connect(mongo_settings['DB'])
db.drop_database(mongo_settings['DB'])
def setUp(self):
self.app = app.test_client()
self._drop_database()
def tearDown(self):
self._drop_database()
def test_alive(self):
rv = self.app.get('/')
assert rv.status == '200 OK'
def test_commit_invalid(self):
rv = self.app.post('/', data={})
assert rv.status == '200 OK'
assert "You need to enter your name" in rv.data
assert "You need to enter a valid mobile phone number" in rv.data
assert "You need to agree" in rv.data
#test name
rv = self.app.post('/', data={"name": "William Shu"})
assert rv.status == '200 OK'
assert "You need to enter your name" not in rv.data
assert "You need to enter a valid mobile phone number" in rv.data
assert "You need to agree" in rv.data
#test phone
rv = self.app.post('/', data={"mobile_number": "07877666555"})
assert rv.status == '200 OK'
assert "You need to enter your name" in rv.data
assert "You need to enter a valid mobile phone number" not in rv.data
assert "You need to agree" in rv.data
#test agreed
rv = self.app.post('/', data={"agree": 1})
assert rv.status == '200 OK'
assert "You need to enter your name" in rv.data
assert "You need to enter a valid mobile phone number" in rv.data
assert "You need to agree" not in rv.data
def test_commit_valid(self):
rv = self.app.post('/', data= {"name": "Greg Orlowski", "mobile_number": "07877666555", "agree": 1}, follow_redirects=True)
assert rv.status == '200 OK'
assert "You are the first person to agree. The target is %d people" % app.config['BECKTON_TARGET'] in rv.data
def test_commit_cannot_signup_twice(self):
rv = self.app.post('/', data= {"name": "Greg Orlowski", "mobile_number": "07877666555", "agree": 1}, follow_redirects=True)
assert rv.status == '200 OK'
assert "You are the first person to agree. The target is %d people" % app.config['BECKTON_TARGET'] in rv.data
rv = self.app.post('/', data= {"name": "Greg Orlowski", "mobile_number": "07877666555", "agree": 1}, follow_redirects=True)
assert rv.status == '200 OK'
assert "Someone has already signed up with that phone number" in rv.data
if __name__ == '__main__':
unittest.main()