-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
352 lines (264 loc) · 14.3 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
"""Tests for safework server.py"""
import sqlalchemy
import server
import bcrypt
from server import app
from flask import session
import unittest
from model import connect_to_db, db, example_data
from model import Forum, Post, User, Incident, Police, Source
import requests
from flask import (Flask, render_template, redirect, request, flash,
session, copy_current_request_context, jsonify)
from flask_debugtoolbar import DebugToolbarExtension
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import (update, desc)
import flask_testing
#######################################################33
# class safeworkIntegrationTestCase(unittest.TestCase):
# """Integration tests for flask server for safework app."""
# def setUp(self):
# print("setUp ran")
# self.client = server.app.test_client()
# server.app.config['TESTING'] = True
# def tearDown(self):
# """Do at end of every test."""
# print("tearDown ran")
# def test_homepage(self):
# result = self.client.get('/')
# self.assertIn('created by and for sex workers'.encode(), result.data)
# def test_map_page(self):
# result = self.client.get('/map')
# self.assertIn('<input id="PointscheckBox" type="checkbox" checked>'.encode(), result.data)
# # def test_incidents(self):
# # result = self.client.get('/incidents.json')
# # self.assertIn('incidents', result.data)
# def test_reg_page(self):
# result = self.client.get('/register')
# self.assertIn('Feel free to use any name, real or fake!'.encode(), result.data)
# def test_login_page(self):
# result = self.client.get('/login')
# self.assertIn("Don't have an account?".encode(), result.data)
# def test_resources_page(self):
# result = self.client.get('/resources')
# self.assertIn("St. James Infirmiry".encode(), result.data)
# def test_contact_page(self):
# result = self.client.get('/contact')
# self.assertIn("E-mail [email protected] with any comments!".encode(), result.data)
######################################################
# class safeworkTestsDatabase(unittest.TestCase):
# """Flask tests that use the database."""
# # db = SQLAlchemy()
# # db.app = app
# # app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///testdb'
# def setUp(self):
# """Stuff to do before every test."""
# app.config['TESTING'] = True
# app.config['SECRET_KEY'] = 'ABC'
# self.client = app.test_client()
# with self.client as c:
# with c.session_transaction() as sess:
# sess['current_user'] = "[email protected]"
# # Connect to test database
# connect_to_db(app, "postgresql:///testdb")
# # Create tables and add sample data
# db.drop_all()
# db.create_all()
# example_data()
# # def test_registration(self):
# # """Testing Registration"""
# # result = self.client.post("/register",
# # data={"email_input": "[email protected]", "password": "Testing123", "username": "Developer", "user_type": "other", "2nd": "support", "fname": "Happy", "lname": "Dopey", "about_me": "Doc"},
# # follow_redirects=True)
# # self.assertIn("While you may enter the discussion forums if you are not a sex worker", result.data)
# # result = self.client.post('/login',
# # data={"email_input": "[email protected]", "pw_input": "Testing123"},
# # follow_redirects=True)
# # self.assertIn('You were successfully logged in', result.data)
# def test_login_failure(self):
# """Test login page."""
# result = self.client.post("/login",
# data={"email_input": "[email protected]".encode(), "pw_input": "Tawdafawvcing".encode()},
# follow_redirects=True)
# self.assertIn("Your e-mail or password was incorrect!".encode(), result.data)
# def test_login_failure2(self):
# """Test login page."""
# result = self.client.post("/login",
# data={"email_input": "[email protected]", "pw_input": "Tawdafawvcing"},
# follow_redirects=True)
# self.assertIn("There is no record of your e-mail address".encode(), result.data)
# def test_login_success(self):
# """Test login page."""
# result = self.client.post("/login",
# data={"email_input": "[email protected]", "pw_input": "Testing"},
# follow_redirects=True)
# self.assertIn("You were successfully logged in".encode(), result.data)
# def tearDown(self):
# """Do at end of every test."""
# db.session.close()
# ##############################################################
# class FlaskTestsLoggedIn(unittest.TestCase):
# """Flask tests with user logged in to session."""
# def setUp(self):
# """Stuff to do before every test."""
# app.config['TESTING'] = True
# app.config['SECRET_KEY'] = 'ABC'
# self.client = app.test_client()
# with self.client as c:
# with c.session_transaction() as sess:
# sess['current_user'] = "[email protected]"
# # Connect to test database
# connect_to_db(app, "postgresql:///testdb")
# # Create tables and add sample data
# db.drop_all()
# db.create_all()
# example_data()
# def test_forums(self):
# result = self.client.get('/forums')
# self.assertIn('Example Forum Name For Testing', str(result.data))
# def test_add_post(self):
# result = self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing9876543"},
# follow_redirects=True)
# self.assertIn("Test Post Content for Testing9876543", str(result.data))
# self.assertIn("Central Forum for all Cam Models to discuss Strategies", str(result.data))
# def test_add_child_post(self):
# self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing9876543"},
# follow_redirects=True)
# p_post = Post.query.filter_by(content="Test Post Content for Testing9876543").one()
# result = self.client.post('/forums/child/' + str(p_post.post_id),
# data={"child_content": "Test Post Content for Testing ABC 876", "parent_post_id": p_post.post_id},
# follow_redirects=True)
# self.assertIn("Test Post Content for Testing ABC 876", str(result.data))
# def test_edit_post(self):
# result = self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing9876543"},
# follow_redirects=True)
# result = self.client.post('/forums/edit/3',
# data={"child_content": "Edited Post12345 for Testing"},
# follow_redirects=True)
# self.assertIn("Edited Post12345 for Testing", str(result.data))
# def test_delete_post(self):
# result = self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing9876543"},
# follow_redirects=True)
# result = self.client.post('/forums/delete/3',
# data={"delete_check": "Yes"},
# follow_redirects=True)
# self.assertNotIn("Edited Post12345 for Testing", str(result.data))
# def test_like_post(self):
# result = self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing9876543"},
# follow_redirects=True)
# result = self.client.get('/forums/like/3',
# follow_redirects=True)
# self.assertIn('<a href="/forums/like/3">Like</a>(1)', str(result.data))
# def test_dislike_post(self):
# self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing9876543"},
# follow_redirects=True)
# result = self.client.get('/forums/dislike/3',
# follow_redirects=True)
# self.assertIn('<a href="/forums/dislike/3">Dislike</a>(1)', str(result.data))
# def test_flag_post(self):
# self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing9876543"},
# follow_redirects=True)
# result = self.client.post('/forums/flag/3',
# data={'flag_rad': 'trolling'},
# follow_redirects=True)
# self.assertIn('Your report has been submitted!', str(result.data))
# def test_date_order(self):
# """Tests that the page load, but doesn't test the actual post order (yet)"""
# self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing12412424"},
# follow_redirects=True)
# result = self.client.get('/forums/order_by_date/1/1',
# follow_redirects=True)
# self.assertIn("Test Post Content for Testing12412424", str(result.data))
# def test_pop_order(self):
# """Tests that the page load, but doesn't test the actual post order (yet)"""
# self.client.post('/forums/parent/1/1',
# data={"content": "Test Post Content for Testing090980987"},
# follow_redirects=True)
# result = self.client.get('/forums/order_by_pop/1/1',
# follow_redirects=True)
# self.assertIn("Test Post Content for Testing090980987", str(result.data))
# def test_logout(self):
# result = self.client.get('/logout',
# follow_redirects=True)
# self.assertIn('Bye! You have been succesfully logged out!', str(result.data))
# def tearDown(self):
# """Do at end of every test."""
# db.session.close()
#########################################################
# class FlaskTestsSafeWalk(unittest.TestCase):
# """Flask tests with user logged in to session."""
# def setUp(self):
# """Stuff to do before every test."""
# app.config['TESTING'] = True
# app.config['SECRET_KEY'] = 'ABC'
# self.client = app.test_client()
# with self.client as c:
# with c.session_transaction() as sess:
# sess['current_user'] = "[email protected]"
# # Connect to test database
# connect_to_db(app, "postgresql:///testdb")
# # Create tables and add sample data
# db.drop_all()
# db.create_all()
# example_data()
# def test_sw_main(self):
# """Tests that the main Safewalk Page Loads."""
# result = self.client.get('/sw_main')
# self.assertIn('Press this Button to Generate a New Code.', str(result.data))
# def test_sw_gettingstarted(self):
# """Tests that the Safewalk Getting Started Page Loads."""
# result = self.client.get('/sw_getting_started')
# self.assertIn('A scheduled alert-set allows you to pre-set alerts(/check-in requirements) by time.', str(result.data))
# def test_rec_alerts(self):
# """Tests that the recurring alerts page loads."""
# result = self.client.get('/rec_alerts')
# self.assertIn('How often would you like to require checking in with the app?', str(result.data))
# def test_sched_alerts(self):
# """Test that the scheduled alerts page loads."""
# result = self.client.get('/sched_alerts')
# self.assertIn('What would you like to name this alert set?', str(result.data))
# def test_contacts(self):
# """Tests that the contact page loads."""
# result = self.client.get('/contacts')
# self.assertIn('Custom Message For Contact', str(result.data))
# def test_edit_rec(self):
# """Tests that the edit recurring set page loads."""
# result = self.client.get('/edit_recset/2')
# self.assertIn('How often would you like to require checking in with the app?', str(result.data))
# def test_edit_sched(self):
# """Tests that the edit scheduled set page loads."""
# result = self.client.get('/edit_schedset/1')
# self.assertIn('Where are you going and/or what are you doing that you might need this alert?', str(result.data))
# def test_check_ins(self):
# """Tests that the check-in page loads."""
# result = self.client.get('/check_ins')
# self.assertIn('Include a short message about where you are, if you are safe, and/or what your plans are:', str(result.data))
# def test_pass_page(self):
# """Tests that the password Change page loads."""
# result = self.client.get('/pass_page')
# self.assertIn('Change Password', str(result.data))
# def test_reset_page(self):
# """Tests that the password reset page loads."""
# result = self.client.get('/pass_reset_page')
# self.assertIn('Change/Reset Password', str(result.data))
# def test_add_contact(self):
# """Test login page."""
# result = self.client.post("/contacts",
# data={"email": "[email protected]", "name": "AmazingTester123", "c_type": "family"},
# follow_redirects=True)
# self.assertIn("AmazingTester123", str(result.data))
# def tearDown(self):
# """Do at end of every test."""
# db.session.close()
# ##########################################################
# if __name__ == '__main__':
# # If called like a script, run our tests
# unittest.main()