-
Notifications
You must be signed in to change notification settings - Fork 175
/
index.txt
588 lines (586 loc) · 13.4 KB
/
index.txt
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
Index
A
acceptance test (see functional tests/testing
(FT))
acceptance tests, 397
aesthetics (see layout and style)
agile movement in software development, 79
Ajax, 249, 269
ALLOWED_HOSTS, 151
Anderson, Ross, 51
Ansible, 166, 423–426
architectural solutions to test problems, 402
assertion messages, 264
AssertionError, 14, 44, 55
assertRegex, 83
assertTemplateUsed, 88
assertTrue function, 44
asynchronous JavaScript, 272–275
authentication
backend, 285–293
customising, 245–247, 277
in Django, 282
login view, 281–284
minimum custom user model, 295–299
mocking (see mocks/mocking)
Mozilla Persona, 242
pre-authentication, 303–306
testing logout, 300
testing view, 278
tests as documentation, 297
automation, in deployment, 132, 157–166
(see also deployment)
automation, in provisioning, 166
B
Bash, 141
Behavior-Driven Development (BDD) tools,
428
Bernhardt, Gary, 399, 404
best practices in testing, 397
Big Design Up Front, 79
black box test (see functional tests/testing (FT))
Boolean comparisons, 290
Bootstrap, 116–125
jumbotron, 123
large inputs, 124
rows and columns in, 120
table styling, 124
boundaries, 403
browsers, 428
browsers, headless, 372
C
caching, 429
capture group, 101
CI server (see continuous integration (CI))
class-based generic views, 413–421
class-based views, 413
clean architecture, 404
code smell, 193, 302
collectstatic, 126–128
comments, 13, 84
commits, 16, 22, 27, 108
configuration management tools, 167
(see also Fabric)
context managers, 177
continuous integration (CI), 365–385, cdvii
adding required plugins, 368
best practices, 385
configuring Jenkins, 367
debugging with screenshots, 374–378
first build, 371
installing Jenkins, 365
JavaScript tests, 381–384
project setup, 369
Selenium race conditions, 378–381
for staging server test automation, 384
virtual display setup, 372–374
contracts, implicit, 355
cookies, 282, 304
Cross-Site Request Forgery (CSRF) error, 51
CSS (Cascading Style Sheets) framework, 114,
116
(see also Bootstrap)
where Bootstrap won’t work, 124
cutting corners, cdvii
D
data migrations, 432–435
database deployment issues, 132
database location, 141
De-spiking, 251, 285–293
debugging, 19, 50, 249
Ajax, 249
Django debug screen, 146
improving error messages, 55
in continuous integration, 374–378
in JavaScript, 262
staging for, 306–310
switching DEBUG to false, 151
screenshots, for debugging, 374–378
dependencies, and deployment, 132
deployment, 411
adjusting database location, 141
automating, 153–155, 157–166
dependencies and, 132
deploying to live, 163
further reading on, 166
key points, 155
to live, 225
migrate, 147
Nginx, 144–147
overview, 153
production-ready, 148–152
vs. provisioning, 140
sample script, 158–161
saving progress, 156
staging, 225, 431
virtualenvs, 142–144
deployment testing, 131–156
danger areas, 132
domain name for, 135
manual provisioning for hosting, 136–140
overview, 133
design (see layout and style)
Django, 4
admin site, 428
apps in, 20
authentication in, 245–247, 282
class-based views, 413–421
(see also class-based views)
collectstatic, 126–128
custom user model, 295–299
debugging screen, 146, 151
field types, 61
foreign key relationship, 97
forms in (see forms)
FormView, 414functional tests (FT) in (see functional tests/
testing (FT))
and Gunicorn, 148
LiveServerTestCase, 75
management commands, 311–314, 320
migrations, 60–62, 69–71, 225
model adjustment in, 95
model-layer validation, 175–187
Model-View-Controller (MVC), 22
notifications, 427
Object-Relational Mapper (ORM), 58–62
POST requests (see POST requests)
as PythonAnywhere app, 410
running, 6
static files in, 121
static live server case, 122
template inheritance, 118–119
templates, 67–68, 88
test class in, 91
test client, 86, 91
test fixtures, 304
unit testing in, 21
URLs in, 22–27, 86, 92, 94, 100, 104, 106
validation quirk, 178
view functions in, 22, 87, 92, 103–106, 326
and virtualenvs, 142–144
Django-BrowserID, 243
documentation, tests as, 297
domain configuration, 139
domain names, 135
Don’t Test Constants rule, 38
double-loop TDD, 45, 323
DRY (don’t repeat yourself), 57, 396
duplicates, eliminating, 56, 211–221
E
encryption, 430
end-to-end test (see functional tests/testing
(FT))
error messages, 429
error pages, 428
exception handling, 293
expected failure, 14, 17
explicit waits, 254
exploratory coding, 195, 242
(see also spiking)
F
Fabric, 166, 314, 426
configuration, 163
installing, 157
sample deployment script, 158–161
Fake XMLHttpRequest, 269
Fixtures Div, 231–233
foreign key relationship, 97
forms
advanced, 211–223
autogeneration, 195
customising form field input, 194
experimenting with, 194
find and replace in, 201
ModelForm, 195
save methods, 208
simple, 193–210
thin views, 210
tips for, 210
using in views, 198–207
validation testing and customising, 196
Fuctional Core, Imperative Shell architecture,
404
functional tests/testing (FT), 5, 397
automation of (see continuous integration
(CI))
blank items, 169–175
cleanup, 75–78, 94, 387
de-duplication, 320
defining, 11
for de-spiking, 251
and developer stupidity, 213
for duplicate items, 211–221
for evaluating third-party systems, 253
isolation in, 75–78, 109
in JavaScript, 234–236
for layout and style, 113–116, 149, 173
multiple users, 387, 393–396
pros and cons, 363
in provisioning, 139
running unit tests only, 78
safeguards with, 317
splitting, 171
for staging sites, 132, 133
unittest model, 11–17
vs. unit tests, 20, 303
in views, 223
Index
|
441G
generator expression, 37
GET requests, 198, 205
get_user, 292, 293
Git
repository setup, 7–10
reset --hard, 116
tags, 166, 226
global variables, 230
greedy regular expressions, 104
Gunicorn, 148–155, 165, 307, 425
H
headless browsers, 372
helper functions/methods, 57, 172, 175, 206,
228, 350, 390–393
hexagonal architecture, 404
hosting options, 136
hosting, manual provisioning, 136–140
I
Idempotency, 167
implicit waits, 16
in-memory model objects, 352
integrated tests, 351–363, 403
vs. integration test, 342
vs. isolated tests, 362, 397
pros and cons, 363
vs. unit tests, 59
integration tests, 342, 397
integrity errors, 217
isolated tests, 337, 403
(see also test isolation)
vs. integrated tests, 362, 397
problems with, 400
pros and cons, 363
J
JavaScript, 227
de-spiking in, 251
debug console, 262
functional test (FT) building in, 234–236
jQuery and Fixtures Div, 231–233
linters, 230
MVC frameworks, 429
onload boilerplate and namespacing, 236
QUnit, 229
442
| Index
running tests in continuous integration,
381–384
spiking with, 242–256
(see also spiking)
in TDD Cycle, 236
test runner setup, 228
testing notes, 237
Jenkins Security, 365–384
(see also continuous integration (CI))
adding required plugins, 368
configuring, 367
installing, 365
jQuery, 231–233, 236, 237
JSON fixtures, 304, 320
jumbotron, 123
L
large inputs, 124
layout and style, 113–128
Bootstrap for (see Bootstrap)
functional tests (FT) for, 173
large inputs, 124
overview, 128
rows and columns, 120
static files, 121, 126–128
table styling, 124
using a CSS framework for, 116
(see also Bootstrap)
using our own CSS in, 124
what to functionally test for, 113
list comprehension, 37
LiveServerTestCase, 75
log messages, 320
logging, 307, 320
logging configuration, 318–320
M
manage, 6
Meta, 196
meta-comments, 84
migrate, 147
migrations, 60–62, 69–71, 225, 226
(see also data migrations)
database, 431–435
deleting, 97
testing, 431–435
minimum viable application, 11–14, 79
mocking library, 265MockMyID, 252
mocks/mocking
in Boolean comparisons, 290
callbacks, 272–275
checking call arguments, 268
Django ORM, 292, 302
implicit contracts, 355
in JavaScript, 241, 258–275
initialize function test, 259–264
Internet requests, 285–295
for isolation, 338–341
mock library, 302
Mock side_effects, 339
namespacing, 258
in Outside-In TDD, 331
in Python, 278–284
risks, 354
sinon.js, 265
testing Django login, 284
model adjustments, 95–99
model-layer validation, 175–187
changes to test, 216
enforcing, 186
errors in View, 178–182
integrity errors, 217
POST requests, 183–187
preventing duplicates, 212
refactoring, 175, 184–186
unit testing, 177–178
at views level, 218
Model-View-Controller (MVC), 22, 429
ModelForm, 195
Mozilla Persona, 242
MVC frameworks, 22, 429
N
namespacing, 236, 258
Nginx, 138, 144–147, 149, 165, 424
nonroot user creation, 137
notifications, 427
O
ORM (Object-Relational Mapper), 58–62
ORM code, 347–350, 363
Outside-In TDD, 323–335
advantages, 323
controller layer, 326
defined, 335
vs. Inside-Out, 323
model layer, 330–333
pitfalls, 335
presentation layer, 325
template hierarchy, 327–329
views layer, 326–330, 333
P
PaaS (Platform-as-a-Service), 136
Page pattern, 390–393, 396
parameters, capture group, 101
patch decorator, 279, 290, 302
patching, 287
payment systems, testing for, 253
performance testing, 429
Persona, 242, 252, 308–310, 429
PhantomJS, 381–384, 428
Platform-as-a-Service (PaaS), 136
POST requests, 203
processing, 52, 183–187
redirect after, 65
saving to database, 62–65
sending, 49–52, 90
Postgres, 427
private key authentication, 137
programming by wishful thinking, 328, 335
(see also Outside-In TDD)
property Decorator, 334
provisioning, 136–140
with Ansible, 423–426
automation in, 166
functional tests (FT) in, 139
overview, 153
vs. deployment, 140
pure unit tests (see isolated tests)
py.test, 430
Python
adding to Jenkins, 369
PythonAnywhere, 136, 409
Q
QuerySet, 59, 214–216
QUnit, 229, 237, 264, 269
R
race conditions, 374, 389
Red, Green, Refactor, 56, 87, 170
Index
|
443redirects, 65, 188
redundant code, 359
refactoring
at application level, 183–186
Red, Green, Refactor, 56, 87, 170
removing hard-coded URLs, 187
and test isolation, 341, 362
tips, 190
unit tests, 175
with templates, 38–42
Refactoring Cat, 42, 109
relative import, 161, 173
render to string, 54
REST (Representational Site Transfer), 80
S
screenshots, 411
scripts, automated, 132
secret key, 160
Security Engineering (Anderson), 51
security tests, 429
sed (stream editor), 165
Selenium, 4
and JavaScript, 237
best practices, 385
in continuous integration, 378–381
in continuous integration, 372
race conditions, 389
race conditions in, 378–381
upgrading, 84
for user interaction testing, 35–38
wait patterns, 16, 254, 387, 389
waits in, 379–381, 385
server configuration, 155
server options, 137
servers, 136–140
(see also staging server)
session key, 304
sessions, 282
Shining Panda, 369
sinon.js, 265, 269, 272
skips, 170
spiking, 242–256, 275
browser-ID protocol, 244
de-spiking, 251
frontend and JavaScript code, 243
logging, 250
server-side authentication, 245–247
with JavaScript, 242
444
|
Index
SQLite, 427
staging server
creating sessions, 311
debugging in, 306–310
pre-creating a session, 303–306
test automation with CI, 384
test database on, 311–317
staging sites, 132, 133, 135
static directories, 126–128
static files, 114, 121, 132, 149
static folder, site-wide, 256
static live server case, 122
string representation, 215
string substitutions, 101
style (see layout and style)
superlists, 6, 8, 20, 108
superusers, 70
system boundaries, 403
system tests, 397
T
table styling, 124
template inheritance, 118–119
template inheritance hierarchy, 327
template tag, 51
templates
for refactoring, 38–42
Python variables in, 53–56
rendering items in, 67–68
separate, 88
test fixtures, 304, 320
test isolation, 109, 337–363
cleanup after, 359–361
collaborators, 343–345
complexity in, 362
forms layer, 347–350
full isolation, 342
interactions between layers, 355
isolated vs. integrated tests, 362
mocks/mocking for, 338–341
models layer, 351–353
ORM code, 347–350, 363
refactoring in, 341, 362
views layer, 337, 338–346, 353
test methods, 15
test organisation, 190
test skips, 170
test types, 363, 397test-driven development (TDD)
advanced considerations in, 397–405
double-loop, 45, 323
further reading on, 405
Inside-Out, 323
iterating towards new design, 84
Java testing in, 236
new design implementation with, 81–84
Outside-In, 323–335
(see also Outside-In TDD)
process flowchart, 81
process recap, 45–47
trivialities of, 33–35
TestCase, in Django, 21
testing best practices, 397
Testing Goat, 3, 108, 109, cdvii
tests, as documentation, 297
thin views, 210
time.sleep, 50
tracebacks, 24, 54
triangulation, 56
U
Ubuntu, 137
unit tests
architectural solutions for, 402
context manager, 177
desired features of, 401
in Django, 21
for simple home page, 19–31
vs. functional tests, 303
vs. functional tests (FT), 20
vs. integrated tests, 59
pros and cons of, 398–401
refactoring, 175
unit-test/code cycle, 29–31
unittest, 134
unittest model, 11–17
Unix sockets, 150
Upstart, 151
URLs
capturing parameters in, 101
distinct, 100
in Django, 22–27, 86, 92, 94, 100, 104, 106
pointing forms to, 94
urls.py, 25–27
user authentication, 241
user creation, 291
user input, saving, 49–72
user interaction testing, 35–38
user stories, 17, 170
V
Vagrant, 426
validation, 169
(see also functional tests/testing (FT))
blank items, 169–175
model-layer, 175–187
(see also model-layer validation)
VCS (version control system), 7–10
view functions, in Django, 22, 87, 92, 103–106
views layer, 337, 338–346, 353
model validation errors in, 178–182
views, what to test in, 223
virtual displays, 372
Virtualbox, 426
virtualenvs, 132, 142–144
W
waits, 16, 254, 379–381, 385, 387, 389
warnings, 15
watch function, 265
websockets, 429
widgets, 194, 196
X
Xvfb, 369, 373, 410
Y
YAGNI, 80
Index
|
445