-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
291 lines (181 loc) · 12.4 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
# -*- coding: utf-8 -*-
import unittest
import hop.tags as hop
class TagsTests(unittest.TestCase):
def test_a_tag(self):
html = u'<a href="http://balor.pl" title="http://balor.pl">http://balor.pl</a>'
self.assertEqual(hop.a(u'http://balor.pl'), html)
html = u'<a href="http://balor.pl" title="http://balor.pl">http://balor.pl</a>'
self.assertEqual(hop.a(u' http://balor.pl \n\n\n\t'), html)
html = u'<a href="http://balor.pl" title="balor website">balor website</a>'
self.assertEqual(hop.a(u'http://balor.pl', u'balor website'), html)
html = u'<a href="http://balor.pl" title="balor website">http://balor.pl</a>'
self.assertEqual(hop.a(u'http://balor.pl', title=u'balor website'), html)
html = u'<a title="balor website" style="color:red;" href="http://balor.pl" id="ganja" class="myLink">BALOR</a>'
self.assertEqual(hop.a(u'http://balor.pl', u'BALOR', u'balor website', _class=u'myLink', id=u'ganja', style=u'color:red;'), html)
html = u'<a href="http://balor.pl" title="http://balor.pl">http://balor.pl</a>'
self.assertEqual(hop.a(u'balor.pl', validate_url=True), html)
def test_email_alias(self):
html = u'<a href="mailto:[email protected]" title="Mail to [email protected]">[email protected]</a>'
self.assertEqual(hop.email(u'[email protected]'), html)
def test_img_tag(self):
html = u'<img src="http://balor.pl/picture.png" alt="" />'
self.assertEqual(hop.img(u'http://balor.pl/picture.png'), html)
html = u'<img src="http://balor.pl/picture.png" alt="" />'
self.assertEqual(hop.img(u'\t http://balor.pl/picture.png '), html)
html = u'<img src="/picture.png" alt="My picture" />'
self.assertEqual(hop.img(u'/picture.png', alt=u'My picture'), html)
html = u'<img src="/picture.png" alt="My picture" class="thePicture" />'
self.assertEqual(hop.img(u'/picture.png', alt=u'My picture', _class=u'thePicture'), html)
def test_script_tag(self):
html = u'<script src="/jquery.js" type="text/javascript"></script>'
self.assertEqual(hop.script(u'/jquery.js'), html)
html = u'<script src="http://balor.pl/jquery.js" type="text/javascript"></script>'
self.assertEqual(hop.script(u'http://balor.pl/jquery.js', validate_url=True), html)
html = u'<script src="http://balor.pl/jquery.js" type="text/javascript"></script>'
self.assertEqual(hop.script(u'balor.pl/jquery.js', validate_url=True), html)
def test_style_tag(self):
html = u'<link href="http://balor.pl/my.css" type="text/css" rel="stylesheet" />'
self.assertEqual(hop.style(u'http://balor.pl/my.css'), html)
def test_meta_charser_tag(self):
html = u'<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />'
self.assertEqual(hop.charset(), html)
def test_title_tag(self):
html = u'<title>Balors cave</title>'
self.assertEqual(hop.title(u'Balors cave'), html)
def test_comment_tag(self):
html = u'<!-- rage age -->'
self.assertEqual(hop.comment(u'rage age'), html)
def test_button_tag(self):
html = u'<button type="button"></button>'
self.assertEqual(hop.button(), html)
html = u'<button type="button">Click Me!</button>'
self.assertEqual(hop.button(u'Click Me!'), html)
def test_list_tag(self):
data = [
u'Apple',
u'Microsoft',
u'Oracle',
u'VMWare',
]
html = u'<ul><li>Apple</li><li>Microsoft</li><li>Oracle</li><li>VMWare</li></ul>'
self.assertEqual(hop.ul(data), html)
html = u'<ol><li>Apple</li><li>Microsoft</li><li>Oracle</li><li>VMWare</li></ol>'
self.assertEqual(hop.ol(data), html)
def test_form_tag(self):
html = u'<form action="#" accept-charset="utf-8" method="post">'
self.assertEqual(hop.form(), html)
html = u'<form action="/trolling/hard.php" accept-charset="utf-8" method="post" enctype="multipart/form-data">'
self.assertEqual(hop.form(u'/trolling/hard.php', multipart=True), html)
html = u'<form action="http://balor.pl/process/form" accept-charset="utf-8" class="EineKleineForm" method="get">'
self.assertEqual(hop.form(u'http://balor.pl/process/form', u'get', _class=u'EineKleineForm'), html)
def test_end_form_tag(self):
html = u'</form>'
self.assertEqual(hop.end_form(), html)
def test_textarea_tag(self):
html = u'<textarea name="ta" id="ta">This is content</textarea>'
self.assertEqual(hop.textarea(u'ta', u'This is content'), html)
html = u'<textarea class="beauty" name="my_textarea" id="my_textarea">Content</textarea>'
self.assertEqual(hop.textarea(u'my_textarea', u'Content', _class=u'beauty'), html)
def test_select_tag(self):
data = [
u'Apple',
u'Microsoft',
u'Oracle',
u'VMWare',
]
html = u'<select name="my_select" id="my_select"><option selected="selected" value="Apple">Apple</option><option value="Microsoft">Microsoft</option><option value="Oracle">Oracle</option><option value="VMWare">VMWare</option></select>'
self.assertEqual(hop.select(u'my_select', data), html)
data = [
(1, u'Apple'),
(2, u'Microsoft'),
(3, u'Oracle'),
(4, u'VMWare'),
]
html = u'<select name="my_select" id="my_select"><option selected="selected" value="1">Apple</option><option value="2">Microsoft</option><option value="3">Oracle</option><option value="4">VMWare</option></select>'
self.assertEqual(hop.select(u'my_select', data), html)
data = [
(1, u'Apple'),
(2, u'Microsoft'),
(3, u'Oracle'),
(4, u'VMWare'),
]
html = u'<select class="my_selector" name="tech_companies" id="tech_companies"><option value="1">Apple</option><option value="2">Microsoft</option><option selected="selected" value="3">Oracle</option><option value="4">VMWare</option></select>'
self.assertEqual(hop.select(u'tech_companies', data, 3, _class=u'my_selector'), html)
data = [
(1, u'Apple'),
(2, u'Microsoft'),
(3, u'Oracle'),
(4, u'VMWare'),
]
html = u'<label for="tech_companies">tech_companies</label><select class="my_selector" id="tech_companies" name="tech_companies"><option value="1">Apple</option><option value="2">Microsoft</option><option selected="selected" value="3">Oracle</option><option value="4">VMWare</option></select>'
self.assertEqual(hop.select(u'tech_companies', data, 3, _class=u'my_selector', label=True), html)
def test_input_field_tag(self):
html = u'<input type="text" value="" />'
self.assertEqual(hop.input_field(u'text'), html)
html = u'<input checked="checked" name="omni_auth" value="true" class="checkers" type="checkbox" id="omni_auth" />'
self.assertEqual(hop.input_field(u'checkbox', u'omni_auth', u'true', checked=True, _class=u'checkers'), html)
html = u'<div style="display:none;"><input type="hidden" name="nightmare" value="1" id="nightmare" /></div>'
self.assertEqual(hop.input_field(u'hidden', u'nightmare', u'1'), html)
html = u'<label for="nightmare">nightmare</label><input type="text" id="nightmare" value="" name="nightmare" />'
self.assertEqual(hop.input_field(u'text', u'nightmare', label=True), html)
html = u'<label for="nightmare">The low night mare:</label><input type="text" id="nightmare" value="" name="nightmare" />'
self.assertEqual(hop.input_field(u'text', u'nightmare', label=u'The low night mare:'), html)
def test_text_field_tag(self):
html = u'<input type="text" name="movie" value="nothing hill" id="movie" />'
self.assertEqual(hop.text(u'movie', u'nothing hill'), html)
html = u'<input style="color: red;" type="text" name="movie" value="nothing hill" id="movie" />'
self.assertEqual(hop.text(u'movie', u'nothing hill', style='color: red;'), html)
def test_password_field_tag(self):
html = u'<input type="password" name="movie" value="" id="movie" />'
self.assertEqual(hop.password(u'movie'), html)
html = u'<input style="color: red;" type="password" name="movie" value="" id="movie" />'
self.assertEqual(hop.password(u'movie', style='color: red;'), html)
def test_file_field_tag(self):
html = u'<input class="file_input" type="file" name="myfile" value="" id="myfile" />'
self.assertEqual(hop.file(u'myfile', _class=u'file_input'), html)
def test_hidden_field_tag(self):
html = u'<label for="secret">My secret is somewhere here...</label><div style="display:none;"><input type="hidden" id="secret" value="" name="secret" /></div>'
self.assertEqual(hop.hidden(u'secret', label=u'My secret is somewhere here...'), html)
def test_checkbox_field_tag(self):
html = u'<input type="checkbox" name="remember_me" value="true" id="remember_me" />'
self.assertEqual(hop.checkbox(u'remember_me'), html)
html = u'<input type="checkbox" checked="checked" name="remember_me" value="true" id="remember_me" />'
self.assertEqual(hop.checkbox(u'remember_me', checked=True), html)
html = u'<input type="checkbox" checked="checked" name="remember_me" value="please_yeah" id="remember_me" />'
self.assertEqual(hop.checkbox(u'remember_me', u'please_yeah', checked=True), html)
def test_radio_field_tag(self):
html = u'<input type="radio" name="use_power" value="" id="use_power" />'
self.assertEqual(hop.radio(u'use_power'), html)
html = u'<label for="use_power">use_power</label><input type="radio" id="use_power" value="1" name="use_power" />'
self.assertEqual(hop.radio(u'use_power', 1, label=True), html)
html = u'<label for="use_power">use_power</label><input checked="checked" type="radio" name="use_power" value="1" id="use_power" />'
self.assertEqual(hop.radio(u'use_power', 1, True, label=True), html)
html = u'<label><input type="radio" name="use_power" value="1" id="use_power" />1</label><label><input type="radio" name="use_power" value="2" id="use_power" />2</label><label><input type="radio" checked="checked" name="use_power" value="3" id="use_power" />3</label>'
self.assertEqual(hop.radio_list(u'use_power', [1,2,3], 3), html)
html = u'<label><input type="radio" name="fav_movie" value="one" id="fav_movie" />Matrix</label><label><input type="radio" name="fav_movie" value="two" id="fav_movie" />Star Wars</label><label><input type="radio" name="fav_movie" value="three" id="fav_movie" />Pulp Fiction</label>'
self.assertEqual(hop.radio_list(u'fav_movie', [
[u'one', u'Matrix'],
[u'two', u'Star Wars'],
[u'three', u'Pulp Fiction'],
], 2), html)
def test_submit_field_tag(self):
html = u'<input type="submit" name="Log me in" value="Log me in" id="Log me in" />'
self.assertEqual(hop.submit(u'Log me in'), html)
html = u'<input type="submit" value="" />'
self.assertEqual(hop.submit(), html)
def test_table(self):
headers = [u'corp', u'market share', u'flaship product']
cells = [
[u'Microsoft', u'80%', u'Microsoft Windows'],
[u'Apple', u'12%', u'iPhone'],
[u'Oracle', u'63%', u'Oracle db'],
]
html = u'<table><tr><th>corp</th><th>market share</th><th>flaship product</th></tr><tr><td>Microsoft</td><td>80%</td><td>Microsoft Windows</td></tr><tr><td>Apple</td><td>12%</td><td>iPhone</td></tr><tr><td>Oracle</td><td>63%</td><td>Oracle db</td></tr></table>'
self.assertEqual(hop.table(cells, headers), html)
html = u'<table><tr><th>corp</th></tr><tr><td>Microsoft</td></tr><tr><td>Apple</td></tr><tr><td>Oracle</td></tr></table>'
self.assertEqual(hop.fixed_col_table(cells, 1, headers), html)
html = u'<table><tr><th>corp</th><th>market share</th><th>flaship product</th><th> </th><th> </th><th> </th></tr><tr><td>Microsoft</td><td>80%</td><td>Microsoft Windows</td><td> </td><td> </td><td> </td></tr><tr><td>Apple</td><td>12%</td><td>iPhone</td><td> </td><td> </td><td> </td></tr></table>'
self.assertEqual(hop.fixed_col_table(cells[:2], 6, headers), html)
if __name__ == '__main__':
unittest.main()