-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
191 lines (142 loc) · 6.28 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import unittest
from server import app
from model import db, example_data, connect_to_db
import json
class HikeTests(unittest.TestCase):
"""Tests for my Hike site."""
def setUp(self):
self.client = app.test_client()
app.config['TESTING'] = True
def test_homepage(self):
"""Test Homepage"""
result = self.client.get("/")
self.assertIn("nearby Trails", result.data)
def test_no_signin_yet(self):
"""Test Homepage before Sign In"""
result = self.client.get("/")
self.assertIn("SignIn", result.data)
self.assertNotIn("Logout", result.data)
def test_signin_yet(self):
"""Test Sign In Page"""
result = self.client.get("/SignIn")
self.assertIn("SignIn", result.data)
self.assertNotIn("Logout", result.data)
def test_no_signup_yet(self):
"""Test Sign Up page"""
result = self.client.get("/SignUp")
self.assertIn("SignUp", result.data)
self.assertNotIn("Logout", result.data)
class HikeTestsDatabase(unittest.TestCase):
"""Flask tests that use the database."""
def setUp(self):
"""Stuff to do before every test."""
self.client = app.test_client()
app.config['TESTING'] = True
app.config['SECRET_KEY'] = 'key'
# Connect to test database (uncomment when testing database)
connect_to_db(app, "testdb")
with self.client as c:
with c.session_transaction() as sess:
sess['id'] = 1
# Create tables and add sample data (uncomment when testing database)
db.create_all()
example_data()
def tearDown(self):
"""Do at end of every test."""
# (uncomment when testing database)
db.session.close()
db.drop_all()
def test_search(self):
"""Test Search Page"""
result = self.client.get("/search")
self.assertIn("Enter", result.data)
self.assertNotIn("Signed In", result.data)
def test_user_profile(self):
"""Test User Profile"""
#FIXME: test that the user page displays the user from example_data()
result = self.client.get("/users/1")
self.assertIn("Test", result.data)
self.assertNotIn("Test3", result.data)
def test_signin(self):
"""Test Sign In """
result = self.client.post("/SignIn",
data={"email": "fun@hb.com",
"password": "1234"},
follow_redirects=True)
self.assertIn("Hike List", result.data)
self.assertIn("Test", result.data)
def test_signup(self):
"""Test Sign Up"""
result = self.client.post("/SignUp",
data={"name": "unittest",
"email": "unittest@hb.com",
"zip": "11111",
"password": "1234"
},
follow_redirects=True)
self.assertIn("Registered successfully", result.data)
self.assertIn("Search", result.data)
def test_search_zipcode(self):
"""Test Search by Zipcode"""
result = self.client.post("/search",
data={"zipcode": "94102"
},
follow_redirects=True)
self.assertIn("Land", result.data)
self.assertIn("URL", result.data)
def test_search_location(self):
"""Test Search by Location"""
result = self.client.post("/search",
data={"location": "Fremont"
},
follow_redirects=True)
self.assertIn("Mission", result.data)
self.assertIn("URL", result.data)
def test_get_trail_info(self):
"""Test Trail Info"""
result = self.client.post("/get-trails-info",
data={"trail_id": "1",
"date": "2018-02-24",
"user_id": "1",
"name": "name",
"url": "url",
"length": "2.5",
"rating": "1.5"},
follow_redirects=True)
result_json_data = json.loads(result.data)
self.assertEqual(result_json_data['trail_id'],"1")
def test_get_comment_info(self):
"""Test commenting"""
result = self.client.post("/add-trails-comment",
data={"trail_id": "1",
"comments": "abcd",
"hike_id": "1"},
follow_redirects=True)
result_json_data = json.loads(result.data)
self.assertEqual(result_json_data['trail_id'],"1")
def test_get_rating_info(self):
"""Test Rating"""
result = self.client.post("/add-rating",
data={"hike_id": "1",
"u_rating": "2.5"
},
follow_redirects=True)
result_json_data = json.loads(result.data)
self.assertEqual(result_json_data['hike_id'],"1")
def test_send_email(self):
"""Test Recommend"""
#TODO - Need to make sure email is being sent as well,
result = self.client.post("/send-email",
data={"trail_name": "test trail",
"trail_url": "test trail",
"hike_id": "1",
"trail_length": "test trail",
"T_email": "niravtrivedi03@gmail.com",
"F_email": "niravtrivedi03@gmail.com",
"message": "recommending ",
"user_name": "user_name"},
follow_redirects=True)
result_json_data = json.loads(result.data)
self.assertEqual(result_json_data['trail_name'],"test trail")
if __name__ == "__main__":
unittest.main()