-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·278 lines (253 loc) · 10.5 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
#!/usr/bin/env python3
'''
File: tests.py
Authors:
2015-03-17 - C.Shaw <shaw.colin@gmail.com>
Description:
Test suite for angryhos.com, makes use of selenium to drive
testing procedures.
'''
import os
import shutil
from datetime import datetime
from pytz import utc
import unittest
from app import db, bc
import app.model
from app.model import User, Role
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
def recreateDatabase():
"""
Function to recreate database tables, make a user for testing,
and create application roles.
"""
print("Dropping and recreating database tables.")
db.drop_all()
db.create_all()
print("Cleansing user uploads folder.")
shutil.rmtree('app/static/uploads/1/')
os.mkdir('app/static/uploads/1')
os.chmod('app/static/uploads/1', mode=0o777)
print("Creating application roles and first user.")
user = User(password=bc.generate_password_hash('la73ralu5', rounds=12),
user_name='cshaw')
from app.roles import active_role, admin_role, verified_role
db.session.add(admin_role)
db.session.add(active_role)
db.session.add(verified_role)
db.session.flush()
user.roles.append(admin_role)
user.roles.append(active_role)
user.roles.append(verified_role)
db.session.add(user)
db.session.commit()
recreateDatabase()
class TestAngryHos(unittest.TestCase):
"""
Test case for angryhos.com
"""
def setUp(self):
"""
Resets everything and prepares test driver.
"""
# Prepares driver for browser automation.
self.firefox = webdriver.Firefox()
def test_logInOut(self):
"""
Tests for confirming user functionality:
signing in
create post without title
creat post without picture
creat post with picture
creat post with multiple pictures
creat post with too many pictures
add picture to post
"""
ff = self.firefox
# User login.
ff.get("localhost:8080/index")
ff.find_element_by_id('login').click()
input = ff.find_element_by_id('user_name')
input.send_keys("cshaw")
input = ff.find_element_by_id('password')
input.send_keys("la73ralu5")
input.submit()
success_alert = ff.find_element_by_class_name(
'alert-success')
# User logout.
ff.find_element_by_id('logout').click()
success_alert = ff.find_element_by_class_name(
'alert-success')
def test_postActions(self):
"""
docstring for test_postActions
"""
ff = self.firefox
# User login.
ff.get("localhost:8080/index")
ff.find_element_by_id('login').click()
input = ff.find_element_by_id('user_name')
input.send_keys("cshaw")
input = ff.find_element_by_id('password')
input.send_keys("la73ralu5")
input.submit()
success_alert = ff.find_element_by_class_name(
'alert-success')
# Create post without title.
ff.find_element_by_id('create-post').click()
input = ff.find_element_by_id('title')
input.submit()
ff.find_element_by_class_name('alert-warning')
# Create post without picture
input = ff.find_element_by_id('title')
input.send_keys('Title 1')
input = ff.find_element_by_id('subtitle')
input.send_keys('Subtitle 1')
input = ff.find_element_by_id('body')
body = \
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
"""
input.send_keys(body)
input.submit()
ff.find_element_by_class_name('alert-success')
# Create post with one picture.
ff.find_element_by_id('create-post').click()
input = ff.find_element_by_id('pics')
input.send_keys(
'/home/colin/Pictures/1240565_406439336124583_1778167961_n.jpg')
input = ff.find_element_by_id('title')
input.send_keys('Title 2')
input = ff.find_element_by_id('subtitle')
input.send_keys('Subtitle 2')
input = ff.find_element_by_id('body')
body = \
"""
Sed ut perspiciatis unde omnis iste natus error sit voluptatem
accusantium doloremque laudantium, totam rem aperiam, eaque
ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem
quia voluptas sit aspernatur aut odit aut fugit, sed quia
consequuntur magni dolores eos qui ratione voluptatem sequi
nesciunt. Neque porro quisquam est, qui dolorem ipsum quia
dolor sit amet, consectetur, adipisci velit, sed quia non
numquam eius modi tempora incidunt ut labore et dolore magnam
aliquam quaerat voluptatem. Ut enim ad minima veniam, quis
nostrum exercitationem ullam corporis suscipit laboriosam,
nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
iure reprehenderit qui in ea voluptate velit esse quam nihil
molestiae consequatur, vel illum qui dolorem eum fugiat quo
voluptas nulla pariatur?
"""
input.send_keys(body)
input.submit()
ff.find_element_by_class_name('alert-success')
# Add second picture to post.
ff.get('localhost:8080/edit/2')
input = ff.find_element_by_id('pics')
input.send_keys('/home/colin/Pictures/2014-12-02-123635.jpg')
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
# Add third picture to post and change picture ordering.
# Picture is a duplicate to test renaming.
ff.get('localhost:8080/edit/2')
input = ff.find_element_by_id('pics')
input.send_keys('/home/colin/Pictures/2014-12-02-123635.jpg')
ff.find_element_by_class_name('down').click()
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
# Add fourth picture to post, rename picture.
ff.get('localhost:8080/edit/2')
input = ff.find_element_by_id('pics')
input.send_keys(
'/home/colin/Pictures/45e2ea709e55687d60bcb6008efb6081.jpg')
title = ff.find_element_by_id('pic_forms-2-title')
title.clear()
title.send_keys("ticket2")
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
# Add fifth picture to post, rename pictures, and change
# picture ordering, and change cover choice.
ff.get('localhost:8080/edit/2')
ff.find_element_by_id('pics').send_keys(
'/home/colin/Pictures/'
'811-Get_money_fuck_bitches_smoke_trees.jpg')
titles = ff.find_elements_by_class_name('title')
names = ["ticket 1", "twins", "ticket 2", "dino", "wisdom"]
for title, name in zip(titles, names):
title.clear()
title.send_keys(name)
ups = ff.find_elements_by_class_name('up')
downs = ff.find_elements_by_class_name('down')
ups[3].click()
ups[3].click()
ups[3].click()
downs[1].click()
downs[2].click()
ups[4].click()
ff.find_element_by_name('choice').click()
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
# Add three more pictures, delete one, rename some,
# change ordering again, and change cover choice again.
files = ['dafsdfasf.jpeg', 'images.jpeg',
'Ger-ma-bethi-ho-bag-to-side-per-rakh-do.jpg']
names = ['nympho', 'mean girl', 'durrrr']
for file in files:
ff.get('localhost:8080/edit/2')
ff.find_element_by_id('pics').send_keys(
'/home/colin/Pictures/' + file)
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
ff.get('localhost:8080/edit/2')
ff.find_element_by_id('pic_forms-4-delete').click()
titles = ff.find_elements_by_class_name('title')
for i in range(3):
titles[len(titles) - 1 - i].clear()
titles[len(titles) - 1 - i].send_keys(names[i])
ups = ff.find_elements_by_class_name('up')
downs = ff.find_elements_by_class_name('down')
ups[4].click()
ups[4].click()
ups[4].click()
downs[3].click()
downs[3].click()
ff.find_element_by_id('pics').send_keys(
'/home/colin/Pictures/resized_ap_gqhunter.jpg')
ff.find_elements_by_name('choice')[4].click()
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
# Add one picture.
ff.get('localhost:8080/edit/2')
ff.find_element_by_id('pics').send_keys(
'/home/colin/Pictures/windows.png')
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-warning')
# Add comment.
ff.get('localhost:8080/view/2')
ff.find_element_by_id('body').send_keys('This is one fine post. rekt.')
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
# Reply to previous comment.
# Changed to click the internal icon and not the link itself.
ff.find_element_by_class_name('fa-reply').click()
ff.find_element_by_id('body').send_keys('10/10 would read again.')
ff.find_element_by_id('submit').submit()
ff.find_element_by_class_name('alert-success')
def tearDown(self):
"""
Close driver connection and clean up.
"""
self.firefox.quit()
if __name__ == '__main__':
unittest.main()