aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_views.py
blob: da0d94b5105a1af197be0633e5705f7685557c36 (plain)
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
data2check_visitors = {
	"/index": {
	"code": 200, "data": b"Nice Tagline"
	},
	"/": {
	"code": 200, "data": b"Nice Tagline"
	},
	"/ContactUs":{
	"code": 200, "data": b"send us a message."
	},
	"/doesnotexists":{
	"code": 404, "data": b"Page Not Found"
	},
	"/logout":{
	"code": 200, "data": b"You have been logged out."
	},
	"/dashboard":{
	"code":401,"data":b"You need to be logged in to access this resource"
	},
	"/signup":{
	"code":200,"data":b"Register your account."
	},
	"/signin":{
	"code":200,"data":b"Sign in to your account."
	},
	"/Simulate500":{
	"code":500,"data":b"Server Could Not Process This."
	},
	"/admin/user/":{
	"code":403,"data":b"Forbidden"
	}
}

def test_visitors(app, client):
	for page in data2check_visitors:
		res = client.get(page)
		print("Testing %s",page)
		assert res.status_code == data2check_visitors[page]["code"]
		assert data2check_visitors[page]["data"] in res.data 

def test_user_auth_flow(app, client):
	res = client.post("/signup",data=dict(
		email="test@example.com",
		first_name="John",
		password="testpassword",
		), follow_redirects=True)

	assert res.status_code == 200
	assert b"Hi John" in res.data
	
	res = client.get("/logout", follow_redirects=True)
	assert res.status_code == 200
	assert b"You have been logged out." in res.data

	res = client.post("/signin",data=dict(
		email="test@example.com",
		password="testpassword"),
		follow_redirects=True)
	assert res.status_code == 200
	assert b"Hi John" in res.data

	res = client.get("/logout")
	res = client.post("/signin",data=dict(
		email="testtest@example.com",
		password="123456"),follow_redirects=True)
	assert res.status_code == 200
	assert b"Incorrect Email" in res.data
	res = client.post("/signin",data=dict(
		email="test@example.com",
		password="incorrectpassword"),
		follow_redirects = True)
	assert res.status_code == 200
	assert b"Incorrect Password" in res.data	

	res = client.post("/signup",data=dict(
		email="test@example.com",
		first_name="John",
		password="testpassword",
		), follow_redirects=True)
	assert res.status_code == 200
	assert b"Oops! An account with that email already exists" in res.data