forked from boyuan12/Bit.ly-Clone
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
51 lines (38 loc) · 1.52 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
1. Register, Login
2. Shorten the URL
3. API
"""
import unittest
from app import app # importing app variable from app.py
class BasicTestCase(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
def register(self, email, password, confirmation):
return self.app.post("/register", data=dict(email=email, password=password, confirmation=confirmation))
def test_register(self):
# register without password
rv = self.register("[email protected]", "", "abc")
assert b"please fill out all fields" in rv.data
# register without username
rv = self.register("", "hi", "abc")
assert b"please fill out all fields" in rv.data
# register without confirmation
rv = self.register("[email protected]", "hi", "")
assert b"please fill out all fields" in rv.data
# register wrong confirmation
rv = self.register("[email protected]", "hi", "abc")
assert b"password confirmation doesn't match password" in rv.data
# register with existing credentials
rv = self.register("[email protected]", "hi", "hi")
print(rv.data)
assert b"user already registered" in rv.data
# register success
rv = self.register("[email protected]", "hi", "hi")
print(rv.data)
assert b"registered successfully!" in rv.data
def test_api(self):
rv = self.app.get("/api?custom=hello")
assert str(200) in str(rv.get_json()["code"])
if __name__ == "__main__":
unittest.main()