arthexis 0.1.13__py3-none-any.whl → 0.1.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of arthexis might be problematic. Click here for more details.
- {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/METADATA +222 -221
- arthexis-0.1.14.dist-info/RECORD +109 -0
- {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/licenses/LICENSE +674 -674
- config/__init__.py +5 -5
- config/active_app.py +15 -15
- config/asgi.py +43 -43
- config/auth_app.py +7 -7
- config/celery.py +32 -32
- config/context_processors.py +67 -69
- config/horologia_app.py +7 -7
- config/loadenv.py +11 -11
- config/logging.py +59 -48
- config/middleware.py +25 -25
- config/offline.py +49 -49
- config/settings.py +691 -682
- config/settings_helpers.py +109 -109
- config/urls.py +171 -166
- config/wsgi.py +17 -17
- core/admin.py +3771 -2809
- core/admin_history.py +50 -50
- core/admindocs.py +151 -151
- core/apps.py +356 -272
- core/auto_upgrade.py +57 -57
- core/backends.py +265 -236
- core/changelog.py +342 -0
- core/entity.py +133 -133
- core/environment.py +61 -61
- core/fields.py +168 -168
- core/form_fields.py +75 -75
- core/github_helper.py +188 -25
- core/github_issues.py +178 -172
- core/github_repos.py +72 -0
- core/lcd_screen.py +78 -78
- core/liveupdate.py +25 -25
- core/log_paths.py +100 -100
- core/mailer.py +85 -85
- core/middleware.py +91 -91
- core/models.py +3609 -2795
- core/notifications.py +105 -105
- core/public_wifi.py +267 -227
- core/reference_utils.py +108 -108
- core/release.py +721 -368
- core/rfid_import_export.py +113 -0
- core/sigil_builder.py +149 -149
- core/sigil_context.py +20 -20
- core/sigil_resolver.py +315 -315
- core/system.py +752 -493
- core/tasks.py +408 -394
- core/temp_passwords.py +181 -181
- core/test_system_info.py +186 -139
- core/tests.py +2095 -1521
- core/tests_liveupdate.py +17 -17
- core/urls.py +11 -11
- core/user_data.py +641 -633
- core/views.py +2175 -1417
- core/widgets.py +213 -94
- core/workgroup_urls.py +17 -17
- core/workgroup_views.py +94 -94
- nodes/admin.py +1720 -1161
- nodes/apps.py +87 -85
- nodes/backends.py +160 -160
- nodes/dns.py +203 -203
- nodes/feature_checks.py +133 -133
- nodes/lcd.py +165 -165
- nodes/models.py +1737 -1597
- nodes/reports.py +411 -411
- nodes/rfid_sync.py +195 -0
- nodes/signals.py +18 -0
- nodes/tasks.py +46 -46
- nodes/tests.py +3810 -3116
- nodes/urls.py +15 -14
- nodes/utils.py +121 -105
- nodes/views.py +683 -619
- ocpp/admin.py +948 -948
- ocpp/apps.py +25 -25
- ocpp/consumers.py +1565 -1459
- ocpp/evcs.py +844 -844
- ocpp/evcs_discovery.py +158 -158
- ocpp/models.py +917 -917
- ocpp/reference_utils.py +42 -42
- ocpp/routing.py +11 -11
- ocpp/simulator.py +745 -745
- ocpp/status_display.py +26 -26
- ocpp/store.py +601 -541
- ocpp/tasks.py +31 -31
- ocpp/test_export_import.py +130 -130
- ocpp/test_rfid.py +913 -702
- ocpp/tests.py +4445 -4094
- ocpp/transactions_io.py +189 -189
- ocpp/urls.py +50 -50
- ocpp/views.py +1479 -1251
- pages/admin.py +708 -539
- pages/apps.py +10 -10
- pages/checks.py +40 -40
- pages/context_processors.py +127 -119
- pages/defaults.py +13 -13
- pages/forms.py +198 -198
- pages/middleware.py +205 -153
- pages/models.py +607 -426
- pages/tests.py +2612 -2200
- pages/urls.py +25 -25
- pages/utils.py +12 -12
- pages/views.py +1165 -1128
- arthexis-0.1.13.dist-info/RECORD +0 -105
- nodes/actions.py +0 -70
- {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/WHEEL +0 -0
- {arthexis-0.1.13.dist-info → arthexis-0.1.14.dist-info}/top_level.txt +0 -0
pages/tests.py
CHANGED
|
@@ -1,2200 +1,2612 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
|
4
|
-
|
|
5
|
-
import django
|
|
6
|
-
|
|
7
|
-
django.setup()
|
|
8
|
-
|
|
9
|
-
from django.test import Client, RequestFactory, TestCase, override_settings
|
|
10
|
-
from django.urls import reverse
|
|
11
|
-
from django.templatetags.static import static
|
|
12
|
-
from urllib.parse import quote
|
|
13
|
-
from django.contrib.auth import get_user_model
|
|
14
|
-
from django.contrib.sites.models import Site
|
|
15
|
-
from django.contrib import admin
|
|
16
|
-
from django.contrib.messages.storage.fallback import FallbackStorage
|
|
17
|
-
from django.core.exceptions import DisallowedHost
|
|
18
|
-
import socket
|
|
19
|
-
from pages.models import (
|
|
20
|
-
Application,
|
|
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
|
-
from
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
import
|
|
63
|
-
from django.
|
|
64
|
-
from
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
from core
|
|
78
|
-
import
|
|
79
|
-
|
|
80
|
-
from
|
|
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
|
-
resp = self.client.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def
|
|
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
|
-
self.assertRedirects(resp, "
|
|
177
|
-
|
|
178
|
-
def
|
|
179
|
-
resp = self.client.post(
|
|
180
|
-
reverse("pages:login") + "?next=/nodes/list/",
|
|
181
|
-
{"username": "
|
|
182
|
-
)
|
|
183
|
-
self.assertRedirects(resp, "/nodes/list/")
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
self.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
resp = self.client.get(reverse("pages:login"))
|
|
197
|
-
self.
|
|
198
|
-
self.
|
|
199
|
-
|
|
200
|
-
@override_settings(
|
|
201
|
-
def
|
|
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
|
-
self.
|
|
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
|
-
self.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
self.
|
|
349
|
-
self.
|
|
350
|
-
|
|
351
|
-
def
|
|
352
|
-
self.client.post(reverse("pages:authenticator-setup"), {"action": "generate"})
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
self.
|
|
360
|
-
device.
|
|
361
|
-
self.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
)
|
|
374
|
-
self.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
self.user
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
self.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
)
|
|
404
|
-
self.
|
|
405
|
-
|
|
406
|
-
def
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
self.assertEqual(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
self.
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
self.
|
|
418
|
-
self.
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
self.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
)
|
|
437
|
-
self.
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
self.
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
)
|
|
448
|
-
self.assertEqual(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
self.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
self.assertEqual(
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
)
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
self.assertEqual(
|
|
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
|
-
self.
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
self.
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
resp = self.client.get(reverse("pages:index"))
|
|
538
|
-
self.assertContains(resp, '<a class="navbar-brand" href="/">
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
self.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
self.client
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
def
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
self.
|
|
591
|
-
self.
|
|
592
|
-
self.
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
self.
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
self.
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
)
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
)
|
|
626
|
-
|
|
627
|
-
self.
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
self.
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
)
|
|
641
|
-
self.
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
self.
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
self.
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
)
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
self.
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
resp = self.client.get(
|
|
702
|
-
self.
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
)
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
self.
|
|
715
|
-
self.
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
)
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
)
|
|
728
|
-
|
|
729
|
-
self.
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
User = get_user_model()
|
|
738
|
-
|
|
739
|
-
username="
|
|
740
|
-
)
|
|
741
|
-
self.client.
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
self.
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
self.
|
|
774
|
-
self.
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
)
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
self.
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
self.
|
|
838
|
-
|
|
839
|
-
)
|
|
840
|
-
self.client.
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
)
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
)
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
)
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
self.
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
self.
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
self.
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
)
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
)
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
)
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
self.
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
self.
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
self.
|
|
989
|
-
self.
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
),
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
self.
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
)
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
)
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
)
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
),
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
),
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
)
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
self.
|
|
1148
|
-
self.assertContains(resp, "
|
|
1149
|
-
self.
|
|
1150
|
-
|
|
1151
|
-
def
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
)
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
self.
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
)
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
self.
|
|
1224
|
-
self.
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
defaults={"
|
|
1234
|
-
)
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
)
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
self.
|
|
1246
|
-
|
|
1247
|
-
self.
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
self.
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
self.
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
"
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
self.
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
)
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
self.
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
def
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
self.
|
|
1414
|
-
|
|
1415
|
-
self.
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
def
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
self.client
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
)
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
self.
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
)
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
)
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
class
|
|
1555
|
-
def setUp(self):
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
)
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
)
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
)
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
)
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
)
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
)
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
self.
|
|
1709
|
-
self.
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
def
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
)
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
self.assertEqual(
|
|
1904
|
-
self.
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
self.
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
self.
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
self.
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
)
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
self.
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
self.
|
|
1986
|
-
self.
|
|
1987
|
-
self.
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
},
|
|
2030
|
-
)
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
)
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
)
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
self.
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
self.
|
|
2089
|
-
|
|
2090
|
-
)
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
self.
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
self.
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
|
4
|
+
|
|
5
|
+
import django
|
|
6
|
+
|
|
7
|
+
django.setup()
|
|
8
|
+
|
|
9
|
+
from django.test import Client, RequestFactory, TestCase, SimpleTestCase, override_settings
|
|
10
|
+
from django.urls import reverse
|
|
11
|
+
from django.templatetags.static import static
|
|
12
|
+
from urllib.parse import quote
|
|
13
|
+
from django.contrib.auth import get_user_model
|
|
14
|
+
from django.contrib.sites.models import Site
|
|
15
|
+
from django.contrib import admin
|
|
16
|
+
from django.contrib.messages.storage.fallback import FallbackStorage
|
|
17
|
+
from django.core.exceptions import DisallowedHost
|
|
18
|
+
import socket
|
|
19
|
+
from pages.models import (
|
|
20
|
+
Application,
|
|
21
|
+
Landing,
|
|
22
|
+
Module,
|
|
23
|
+
RoleLanding,
|
|
24
|
+
SiteBadge,
|
|
25
|
+
Favorite,
|
|
26
|
+
ViewHistory,
|
|
27
|
+
LandingLead,
|
|
28
|
+
UserManual,
|
|
29
|
+
UserStory,
|
|
30
|
+
)
|
|
31
|
+
from pages.admin import (
|
|
32
|
+
ApplicationAdmin,
|
|
33
|
+
UserManualAdmin,
|
|
34
|
+
UserStoryAdmin,
|
|
35
|
+
ViewHistoryAdmin,
|
|
36
|
+
log_viewer,
|
|
37
|
+
)
|
|
38
|
+
from pages.screenshot_specs import (
|
|
39
|
+
ScreenshotSpec,
|
|
40
|
+
ScreenshotSpecRunner,
|
|
41
|
+
ScreenshotUnavailable,
|
|
42
|
+
registry,
|
|
43
|
+
)
|
|
44
|
+
from django.apps import apps as django_apps
|
|
45
|
+
from core import mailer
|
|
46
|
+
from core.admin import ProfileAdminMixin
|
|
47
|
+
from core.models import (
|
|
48
|
+
AdminHistory,
|
|
49
|
+
InviteLead,
|
|
50
|
+
Package,
|
|
51
|
+
Reference,
|
|
52
|
+
RFID,
|
|
53
|
+
ReleaseManager,
|
|
54
|
+
SecurityGroup,
|
|
55
|
+
Todo,
|
|
56
|
+
TOTPDeviceSettings,
|
|
57
|
+
)
|
|
58
|
+
from django.core.files.uploadedfile import SimpleUploadedFile
|
|
59
|
+
import base64
|
|
60
|
+
import tempfile
|
|
61
|
+
import shutil
|
|
62
|
+
from io import StringIO
|
|
63
|
+
from django.conf import settings
|
|
64
|
+
from pathlib import Path
|
|
65
|
+
from unittest.mock import MagicMock, Mock, patch
|
|
66
|
+
from types import SimpleNamespace
|
|
67
|
+
from django.core.management import call_command
|
|
68
|
+
import re
|
|
69
|
+
from django.contrib.contenttypes.models import ContentType
|
|
70
|
+
from datetime import (
|
|
71
|
+
date,
|
|
72
|
+
datetime,
|
|
73
|
+
time as datetime_time,
|
|
74
|
+
timedelta,
|
|
75
|
+
timezone as datetime_timezone,
|
|
76
|
+
)
|
|
77
|
+
from django.core import mail
|
|
78
|
+
from django.utils import timezone
|
|
79
|
+
from django.utils.text import slugify
|
|
80
|
+
from django.utils.translation import gettext
|
|
81
|
+
from django_otp import DEVICE_ID_SESSION_KEY
|
|
82
|
+
from django_otp.oath import TOTP
|
|
83
|
+
from django_otp.plugins.otp_totp.models import TOTPDevice
|
|
84
|
+
from core.backends import TOTP_DEVICE_NAME
|
|
85
|
+
import time
|
|
86
|
+
|
|
87
|
+
from nodes.models import (
|
|
88
|
+
EmailOutbox,
|
|
89
|
+
Node,
|
|
90
|
+
ContentSample,
|
|
91
|
+
NodeRole,
|
|
92
|
+
NodeFeature,
|
|
93
|
+
NodeFeatureAssignment,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class LoginViewTests(TestCase):
|
|
98
|
+
def setUp(self):
|
|
99
|
+
self.client = Client()
|
|
100
|
+
User = get_user_model()
|
|
101
|
+
self.staff = User.objects.create_user(
|
|
102
|
+
username="staff", password="pwd", is_staff=True
|
|
103
|
+
)
|
|
104
|
+
self.user = User.objects.create_user(username="user", password="pwd")
|
|
105
|
+
Site.objects.update_or_create(id=1, defaults={"name": "Terminal"})
|
|
106
|
+
|
|
107
|
+
def test_login_link_in_navbar(self):
|
|
108
|
+
resp = self.client.get(reverse("pages:index"))
|
|
109
|
+
self.assertContains(resp, 'href="/login/"')
|
|
110
|
+
|
|
111
|
+
def test_login_page_shows_authenticator_toggle(self):
|
|
112
|
+
resp = self.client.get(reverse("pages:login"))
|
|
113
|
+
self.assertContains(resp, "Use Authenticator app")
|
|
114
|
+
|
|
115
|
+
def test_cp_simulator_redirect_shows_restricted_message(self):
|
|
116
|
+
simulator_path = reverse("cp-simulator")
|
|
117
|
+
resp = self.client.get(f"{reverse('pages:login')}?next={simulator_path}")
|
|
118
|
+
self.assertContains(
|
|
119
|
+
resp,
|
|
120
|
+
"This page is reserved for members only. Please log in to continue.",
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def test_staff_login_redirects_admin(self):
|
|
124
|
+
resp = self.client.post(
|
|
125
|
+
reverse("pages:login"),
|
|
126
|
+
{"username": "staff", "password": "pwd"},
|
|
127
|
+
)
|
|
128
|
+
self.assertRedirects(resp, reverse("admin:index"))
|
|
129
|
+
|
|
130
|
+
def test_login_with_authenticator_code(self):
|
|
131
|
+
device = TOTPDevice.objects.create(
|
|
132
|
+
user=self.staff,
|
|
133
|
+
name=TOTP_DEVICE_NAME,
|
|
134
|
+
confirmed=True,
|
|
135
|
+
)
|
|
136
|
+
totp = TOTP(device.bin_key, device.step, device.t0, device.digits, device.drift)
|
|
137
|
+
totp.time = time.time()
|
|
138
|
+
token = f"{totp.token():0{device.digits}d}"
|
|
139
|
+
|
|
140
|
+
resp = self.client.post(
|
|
141
|
+
reverse("pages:login"),
|
|
142
|
+
{
|
|
143
|
+
"username": "staff",
|
|
144
|
+
"auth_method": "otp",
|
|
145
|
+
"otp_token": token,
|
|
146
|
+
},
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
self.assertRedirects(resp, reverse("admin:index"))
|
|
150
|
+
session = self.client.session
|
|
151
|
+
self.assertIn(DEVICE_ID_SESSION_KEY, session)
|
|
152
|
+
self.assertEqual(session[DEVICE_ID_SESSION_KEY], device.persistent_id)
|
|
153
|
+
|
|
154
|
+
def test_login_with_invalid_authenticator_code(self):
|
|
155
|
+
TOTPDevice.objects.create(
|
|
156
|
+
user=self.staff,
|
|
157
|
+
name=TOTP_DEVICE_NAME,
|
|
158
|
+
confirmed=True,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
resp = self.client.post(
|
|
162
|
+
reverse("pages:login"),
|
|
163
|
+
{
|
|
164
|
+
"username": "staff",
|
|
165
|
+
"auth_method": "otp",
|
|
166
|
+
"otp_token": "000000",
|
|
167
|
+
},
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
self.assertEqual(resp.status_code, 200)
|
|
171
|
+
self.assertContains(resp, "authenticator code is invalid", status_code=200)
|
|
172
|
+
|
|
173
|
+
def test_already_logged_in_staff_redirects(self):
|
|
174
|
+
self.client.force_login(self.staff)
|
|
175
|
+
resp = self.client.get(reverse("pages:login"))
|
|
176
|
+
self.assertRedirects(resp, reverse("admin:index"))
|
|
177
|
+
|
|
178
|
+
def test_regular_user_redirects_next(self):
|
|
179
|
+
resp = self.client.post(
|
|
180
|
+
reverse("pages:login") + "?next=/nodes/list/",
|
|
181
|
+
{"username": "user", "password": "pwd"},
|
|
182
|
+
)
|
|
183
|
+
self.assertRedirects(resp, "/nodes/list/")
|
|
184
|
+
|
|
185
|
+
def test_staff_redirects_next_when_specified(self):
|
|
186
|
+
resp = self.client.post(
|
|
187
|
+
reverse("pages:login") + "?next=/nodes/list/",
|
|
188
|
+
{"username": "staff", "password": "pwd"},
|
|
189
|
+
)
|
|
190
|
+
self.assertRedirects(resp, "/nodes/list/")
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
@override_settings(EMAIL_BACKEND="django.core.mail.backends.dummy.EmailBackend")
|
|
195
|
+
def test_login_page_hides_request_link_without_email_backend(self):
|
|
196
|
+
resp = self.client.get(reverse("pages:login"))
|
|
197
|
+
self.assertFalse(resp.context["can_request_invite"])
|
|
198
|
+
self.assertNotContains(resp, reverse("pages:request-invite"))
|
|
199
|
+
|
|
200
|
+
@override_settings(EMAIL_BACKEND="django.core.mail.backends.dummy.EmailBackend")
|
|
201
|
+
def test_login_page_shows_request_link_when_outbox_configured(self):
|
|
202
|
+
EmailOutbox.objects.create(host="smtp.example.com")
|
|
203
|
+
resp = self.client.get(reverse("pages:login"))
|
|
204
|
+
self.assertTrue(resp.context["can_request_invite"])
|
|
205
|
+
self.assertContains(resp, reverse("pages:request-invite"))
|
|
206
|
+
|
|
207
|
+
@override_settings(ALLOWED_HOSTS=["gway-qk32000"])
|
|
208
|
+
def test_login_allows_forwarded_https_origin(self):
|
|
209
|
+
secure_client = Client(enforce_csrf_checks=True)
|
|
210
|
+
login_url = reverse("pages:login")
|
|
211
|
+
response = secure_client.get(login_url, HTTP_HOST="gway-qk32000")
|
|
212
|
+
csrf_cookie = response.cookies["csrftoken"].value
|
|
213
|
+
submit = secure_client.post(
|
|
214
|
+
login_url,
|
|
215
|
+
{
|
|
216
|
+
"username": "staff",
|
|
217
|
+
"password": "pwd",
|
|
218
|
+
"csrfmiddlewaretoken": csrf_cookie,
|
|
219
|
+
},
|
|
220
|
+
HTTP_HOST="gway-qk32000",
|
|
221
|
+
HTTP_ORIGIN="https://gway-qk32000",
|
|
222
|
+
HTTP_X_FORWARDED_PROTO="https",
|
|
223
|
+
HTTP_REFERER="https://gway-qk32000/login/",
|
|
224
|
+
)
|
|
225
|
+
self.assertRedirects(submit, reverse("admin:index"))
|
|
226
|
+
|
|
227
|
+
@override_settings(ALLOWED_HOSTS=["10.42.0.0/16", "gway-qk32000"])
|
|
228
|
+
def test_login_allows_forwarded_origin_with_private_host_header(self):
|
|
229
|
+
secure_client = Client(enforce_csrf_checks=True)
|
|
230
|
+
login_url = reverse("pages:login")
|
|
231
|
+
response = secure_client.get(login_url, HTTP_HOST="10.42.0.2")
|
|
232
|
+
csrf_cookie = response.cookies["csrftoken"].value
|
|
233
|
+
submit = secure_client.post(
|
|
234
|
+
login_url,
|
|
235
|
+
{
|
|
236
|
+
"username": "staff",
|
|
237
|
+
"password": "pwd",
|
|
238
|
+
"csrfmiddlewaretoken": csrf_cookie,
|
|
239
|
+
},
|
|
240
|
+
HTTP_HOST="10.42.0.2",
|
|
241
|
+
HTTP_ORIGIN="https://gway-qk32000",
|
|
242
|
+
HTTP_X_FORWARDED_PROTO="https",
|
|
243
|
+
HTTP_X_FORWARDED_HOST="gway-qk32000",
|
|
244
|
+
HTTP_REFERER="https://gway-qk32000/login/",
|
|
245
|
+
)
|
|
246
|
+
self.assertRedirects(submit, reverse("admin:index"))
|
|
247
|
+
|
|
248
|
+
@override_settings(ALLOWED_HOSTS=["10.42.0.0/16", "gway-qk32000"])
|
|
249
|
+
def test_login_allows_forwarded_header_host_and_proto(self):
|
|
250
|
+
secure_client = Client(enforce_csrf_checks=True)
|
|
251
|
+
login_url = reverse("pages:login")
|
|
252
|
+
response = secure_client.get(login_url, HTTP_HOST="10.42.0.2")
|
|
253
|
+
csrf_cookie = response.cookies["csrftoken"].value
|
|
254
|
+
submit = secure_client.post(
|
|
255
|
+
login_url,
|
|
256
|
+
{
|
|
257
|
+
"username": "staff",
|
|
258
|
+
"password": "pwd",
|
|
259
|
+
"csrfmiddlewaretoken": csrf_cookie,
|
|
260
|
+
},
|
|
261
|
+
HTTP_HOST="10.42.0.2",
|
|
262
|
+
HTTP_ORIGIN="https://gway-qk32000",
|
|
263
|
+
HTTP_FORWARDED="proto=https;host=gway-qk32000",
|
|
264
|
+
HTTP_REFERER="https://gway-qk32000/login/",
|
|
265
|
+
)
|
|
266
|
+
self.assertRedirects(submit, reverse("admin:index"))
|
|
267
|
+
|
|
268
|
+
@override_settings(ALLOWED_HOSTS=["10.42.0.0/16", "gway-qk32000"])
|
|
269
|
+
def test_login_allows_forwarded_referer_without_origin(self):
|
|
270
|
+
secure_client = Client(enforce_csrf_checks=True)
|
|
271
|
+
login_url = reverse("pages:login")
|
|
272
|
+
response = secure_client.get(login_url, HTTP_HOST="10.42.0.2")
|
|
273
|
+
csrf_cookie = response.cookies["csrftoken"].value
|
|
274
|
+
submit = secure_client.post(
|
|
275
|
+
login_url,
|
|
276
|
+
{
|
|
277
|
+
"username": "staff",
|
|
278
|
+
"password": "pwd",
|
|
279
|
+
"csrfmiddlewaretoken": csrf_cookie,
|
|
280
|
+
},
|
|
281
|
+
HTTP_HOST="10.42.0.2",
|
|
282
|
+
HTTP_X_FORWARDED_PROTO="https",
|
|
283
|
+
HTTP_X_FORWARDED_HOST="gway-qk32000",
|
|
284
|
+
HTTP_REFERER="https://gway-qk32000/login/",
|
|
285
|
+
)
|
|
286
|
+
self.assertRedirects(submit, reverse("admin:index"))
|
|
287
|
+
|
|
288
|
+
@override_settings(ALLOWED_HOSTS=["gway-qk32000"])
|
|
289
|
+
def test_login_allows_forwarded_origin_with_explicit_port(self):
|
|
290
|
+
secure_client = Client(enforce_csrf_checks=True)
|
|
291
|
+
login_url = reverse("pages:login")
|
|
292
|
+
response = secure_client.get(login_url, HTTP_HOST="gway-qk32000")
|
|
293
|
+
csrf_cookie = response.cookies["csrftoken"].value
|
|
294
|
+
submit = secure_client.post(
|
|
295
|
+
login_url,
|
|
296
|
+
{
|
|
297
|
+
"username": "staff",
|
|
298
|
+
"password": "pwd",
|
|
299
|
+
"csrfmiddlewaretoken": csrf_cookie,
|
|
300
|
+
},
|
|
301
|
+
HTTP_HOST="gway-qk32000",
|
|
302
|
+
HTTP_ORIGIN="https://gway-qk32000:4443",
|
|
303
|
+
HTTP_X_FORWARDED_PROTO="https",
|
|
304
|
+
HTTP_X_FORWARDED_HOST="gway-qk32000:4443",
|
|
305
|
+
HTTP_REFERER="https://gway-qk32000:4443/login/",
|
|
306
|
+
)
|
|
307
|
+
self.assertRedirects(submit, reverse("admin:index"))
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class AuthenticatorSetupTests(TestCase):
|
|
311
|
+
def setUp(self):
|
|
312
|
+
self.client = Client()
|
|
313
|
+
User = get_user_model()
|
|
314
|
+
self.staff = User.objects.create_user(
|
|
315
|
+
username="staffer", password="pwd", is_staff=True
|
|
316
|
+
)
|
|
317
|
+
Site.objects.update_or_create(id=1, defaults={"name": "Terminal"})
|
|
318
|
+
self.client.force_login(self.staff)
|
|
319
|
+
|
|
320
|
+
def _current_token(self, device):
|
|
321
|
+
totp = TOTP(device.bin_key, device.step, device.t0, device.digits, device.drift)
|
|
322
|
+
totp.time = time.time()
|
|
323
|
+
return f"{totp.token():0{device.digits}d}"
|
|
324
|
+
|
|
325
|
+
def test_generate_creates_pending_device(self):
|
|
326
|
+
resp = self.client.post(
|
|
327
|
+
reverse("pages:authenticator-setup"), {"action": "generate"}
|
|
328
|
+
)
|
|
329
|
+
self.assertRedirects(resp, reverse("pages:authenticator-setup"))
|
|
330
|
+
device = TOTPDevice.objects.get(user=self.staff)
|
|
331
|
+
self.assertFalse(device.confirmed)
|
|
332
|
+
self.assertEqual(device.name, TOTP_DEVICE_NAME)
|
|
333
|
+
|
|
334
|
+
def test_device_config_url_includes_issuer_prefix(self):
|
|
335
|
+
self.client.post(reverse("pages:authenticator-setup"), {"action": "generate"})
|
|
336
|
+
device = TOTPDevice.objects.get(user=self.staff)
|
|
337
|
+
config_url = device.config_url
|
|
338
|
+
label = quote(f"{settings.OTP_TOTP_ISSUER}:{self.staff.username}")
|
|
339
|
+
self.assertIn(label, config_url)
|
|
340
|
+
self.assertIn(f"issuer={quote(settings.OTP_TOTP_ISSUER)}", config_url)
|
|
341
|
+
|
|
342
|
+
def test_device_config_url_uses_custom_issuer_when_available(self):
|
|
343
|
+
self.client.post(reverse("pages:authenticator-setup"), {"action": "generate"})
|
|
344
|
+
device = TOTPDevice.objects.get(user=self.staff)
|
|
345
|
+
TOTPDeviceSettings.objects.create(device=device, issuer="Custom Co")
|
|
346
|
+
config_url = device.config_url
|
|
347
|
+
quoted_issuer = quote("Custom Co")
|
|
348
|
+
self.assertIn(quoted_issuer, config_url)
|
|
349
|
+
self.assertIn(f"issuer={quoted_issuer}", config_url)
|
|
350
|
+
|
|
351
|
+
def test_pending_device_context_includes_qr(self):
|
|
352
|
+
self.client.post(reverse("pages:authenticator-setup"), {"action": "generate"})
|
|
353
|
+
resp = self.client.get(reverse("pages:authenticator-setup"))
|
|
354
|
+
self.assertEqual(resp.status_code, 200)
|
|
355
|
+
self.assertTrue(resp.context["qr_data_uri"].startswith("data:image/png;base64,"))
|
|
356
|
+
self.assertTrue(resp.context["manual_key"])
|
|
357
|
+
|
|
358
|
+
def test_confirm_pending_device(self):
|
|
359
|
+
self.client.post(reverse("pages:authenticator-setup"), {"action": "generate"})
|
|
360
|
+
device = TOTPDevice.objects.get(user=self.staff)
|
|
361
|
+
token = self._current_token(device)
|
|
362
|
+
resp = self.client.post(
|
|
363
|
+
reverse("pages:authenticator-setup"),
|
|
364
|
+
{"action": "confirm", "token": token},
|
|
365
|
+
)
|
|
366
|
+
self.assertRedirects(resp, reverse("pages:authenticator-setup"))
|
|
367
|
+
device.refresh_from_db()
|
|
368
|
+
self.assertTrue(device.confirmed)
|
|
369
|
+
|
|
370
|
+
def test_remove_device(self):
|
|
371
|
+
self.client.post(reverse("pages:authenticator-setup"), {"action": "generate"})
|
|
372
|
+
device = TOTPDevice.objects.get(user=self.staff)
|
|
373
|
+
token = self._current_token(device)
|
|
374
|
+
self.client.post(
|
|
375
|
+
reverse("pages:authenticator-setup"),
|
|
376
|
+
{"action": "confirm", "token": token},
|
|
377
|
+
)
|
|
378
|
+
resp = self.client.post(
|
|
379
|
+
reverse("pages:authenticator-setup"), {"action": "remove"}
|
|
380
|
+
)
|
|
381
|
+
self.assertRedirects(resp, reverse("pages:authenticator-setup"))
|
|
382
|
+
self.assertFalse(TOTPDevice.objects.filter(user=self.staff).exists())
|
|
383
|
+
|
|
384
|
+
@override_settings(EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend")
|
|
385
|
+
class InvitationTests(TestCase):
|
|
386
|
+
def setUp(self):
|
|
387
|
+
self.client = Client()
|
|
388
|
+
User = get_user_model()
|
|
389
|
+
self.user = User.objects.create_user(
|
|
390
|
+
username="invited",
|
|
391
|
+
email="invite@example.com",
|
|
392
|
+
is_active=False,
|
|
393
|
+
)
|
|
394
|
+
self.user.set_unusable_password()
|
|
395
|
+
self.user.save()
|
|
396
|
+
Site.objects.update_or_create(id=1, defaults={"name": "Terminal"})
|
|
397
|
+
|
|
398
|
+
def test_login_page_has_request_link(self):
|
|
399
|
+
resp = self.client.get(reverse("pages:login"))
|
|
400
|
+
self.assertContains(resp, reverse("pages:request-invite"))
|
|
401
|
+
|
|
402
|
+
def test_request_invite_sets_csrf_cookie(self):
|
|
403
|
+
resp = self.client.get(reverse("pages:request-invite"))
|
|
404
|
+
self.assertIn("csrftoken", resp.cookies)
|
|
405
|
+
|
|
406
|
+
def test_request_invite_allows_post_without_csrf(self):
|
|
407
|
+
client = Client(enforce_csrf_checks=True)
|
|
408
|
+
resp = client.post(
|
|
409
|
+
reverse("pages:request-invite"), {"email": "invite@example.com"}
|
|
410
|
+
)
|
|
411
|
+
self.assertEqual(resp.status_code, 200)
|
|
412
|
+
|
|
413
|
+
def test_invitation_flow(self):
|
|
414
|
+
resp = self.client.post(
|
|
415
|
+
reverse("pages:request-invite"), {"email": "invite@example.com"}
|
|
416
|
+
)
|
|
417
|
+
self.assertEqual(resp.status_code, 200)
|
|
418
|
+
self.assertEqual(len(mail.outbox), 1)
|
|
419
|
+
link = re.search(r"http://testserver[\S]+", mail.outbox[0].body).group(0)
|
|
420
|
+
resp = self.client.get(link)
|
|
421
|
+
self.assertEqual(resp.status_code, 200)
|
|
422
|
+
resp = self.client.post(link)
|
|
423
|
+
self.user.refresh_from_db()
|
|
424
|
+
self.assertTrue(self.user.is_active)
|
|
425
|
+
self.assertIn("_auth_user_id", self.client.session)
|
|
426
|
+
|
|
427
|
+
def test_request_invite_handles_email_errors(self):
|
|
428
|
+
with patch("pages.views.mailer.send", side_effect=Exception("fail")):
|
|
429
|
+
resp = self.client.post(
|
|
430
|
+
reverse("pages:request-invite"), {"email": "invite@example.com"}
|
|
431
|
+
)
|
|
432
|
+
self.assertEqual(resp.status_code, 200)
|
|
433
|
+
self.assertContains(resp, "If the email exists, an invitation has been sent.")
|
|
434
|
+
lead = InviteLead.objects.get()
|
|
435
|
+
self.assertIsNone(lead.sent_on)
|
|
436
|
+
self.assertIn("fail", lead.error)
|
|
437
|
+
self.assertIn("email service", lead.error)
|
|
438
|
+
self.assertEqual(len(mail.outbox), 0)
|
|
439
|
+
|
|
440
|
+
def test_request_invite_records_send_time(self):
|
|
441
|
+
resp = self.client.post(
|
|
442
|
+
reverse("pages:request-invite"), {"email": "invite@example.com"}
|
|
443
|
+
)
|
|
444
|
+
self.assertEqual(resp.status_code, 200)
|
|
445
|
+
lead = InviteLead.objects.get()
|
|
446
|
+
self.assertIsNotNone(lead.sent_on)
|
|
447
|
+
self.assertEqual(lead.error, "")
|
|
448
|
+
self.assertEqual(len(mail.outbox), 1)
|
|
449
|
+
|
|
450
|
+
def test_request_invite_creates_lead_with_comment(self):
|
|
451
|
+
resp = self.client.post(
|
|
452
|
+
reverse("pages:request-invite"),
|
|
453
|
+
{"email": "new@example.com", "comment": "Hello"},
|
|
454
|
+
)
|
|
455
|
+
self.assertEqual(resp.status_code, 200)
|
|
456
|
+
lead = InviteLead.objects.get()
|
|
457
|
+
self.assertEqual(lead.email, "new@example.com")
|
|
458
|
+
self.assertEqual(lead.comment, "Hello")
|
|
459
|
+
self.assertIsNone(lead.sent_on)
|
|
460
|
+
self.assertEqual(lead.error, "")
|
|
461
|
+
self.assertEqual(lead.mac_address, "")
|
|
462
|
+
self.assertEqual(len(mail.outbox), 0)
|
|
463
|
+
|
|
464
|
+
def test_request_invite_falls_back_to_send_mail(self):
|
|
465
|
+
node = Node.objects.create(
|
|
466
|
+
hostname="local", address="127.0.0.1", mac_address="00:11:22:33:44:55"
|
|
467
|
+
)
|
|
468
|
+
with (
|
|
469
|
+
patch("pages.views.Node.get_local", return_value=node),
|
|
470
|
+
patch.object(
|
|
471
|
+
node, "send_mail", side_effect=Exception("node fail")
|
|
472
|
+
) as node_send,
|
|
473
|
+
patch("pages.views.mailer.send", wraps=mailer.send) as fallback,
|
|
474
|
+
):
|
|
475
|
+
resp = self.client.post(
|
|
476
|
+
reverse("pages:request-invite"), {"email": "invite@example.com"}
|
|
477
|
+
)
|
|
478
|
+
self.assertEqual(resp.status_code, 200)
|
|
479
|
+
lead = InviteLead.objects.get()
|
|
480
|
+
self.assertIsNotNone(lead.sent_on)
|
|
481
|
+
self.assertIn("node fail", lead.error)
|
|
482
|
+
self.assertIn("default mail backend", lead.error)
|
|
483
|
+
self.assertTrue(node_send.called)
|
|
484
|
+
self.assertTrue(fallback.called)
|
|
485
|
+
self.assertEqual(len(mail.outbox), 1)
|
|
486
|
+
|
|
487
|
+
@patch(
|
|
488
|
+
"pages.views.public_wifi.resolve_mac_address",
|
|
489
|
+
return_value="aa:bb:cc:dd:ee:ff",
|
|
490
|
+
)
|
|
491
|
+
def test_request_invite_records_mac_address(self, mock_resolve):
|
|
492
|
+
resp = self.client.post(
|
|
493
|
+
reverse("pages:request-invite"), {"email": "invite@example.com"}
|
|
494
|
+
)
|
|
495
|
+
self.assertEqual(resp.status_code, 200)
|
|
496
|
+
lead = InviteLead.objects.get()
|
|
497
|
+
self.assertEqual(lead.mac_address, "aa:bb:cc:dd:ee:ff")
|
|
498
|
+
|
|
499
|
+
@patch("pages.views.public_wifi.grant_public_access")
|
|
500
|
+
@patch(
|
|
501
|
+
"pages.views.public_wifi.resolve_mac_address",
|
|
502
|
+
return_value="aa:bb:cc:dd:ee:ff",
|
|
503
|
+
)
|
|
504
|
+
def test_invitation_login_grants_public_wifi_access(self, mock_resolve, mock_grant):
|
|
505
|
+
control_role, _ = NodeRole.objects.get_or_create(name="Control")
|
|
506
|
+
feature = NodeFeature.objects.create(slug="ap-router", display="AP Router")
|
|
507
|
+
feature.roles.add(control_role)
|
|
508
|
+
node = Node.objects.create(
|
|
509
|
+
hostname="control",
|
|
510
|
+
address="127.0.0.1",
|
|
511
|
+
mac_address=Node.get_current_mac(),
|
|
512
|
+
role=control_role,
|
|
513
|
+
)
|
|
514
|
+
NodeFeatureAssignment.objects.create(node=node, feature=feature)
|
|
515
|
+
with patch("pages.views.Node.get_local", return_value=node):
|
|
516
|
+
resp = self.client.post(
|
|
517
|
+
reverse("pages:request-invite"), {"email": "invite@example.com"}
|
|
518
|
+
)
|
|
519
|
+
self.assertEqual(resp.status_code, 200)
|
|
520
|
+
link = re.search(r"http://testserver[\S]+", mail.outbox[0].body).group(0)
|
|
521
|
+
with patch("pages.views.Node.get_local", return_value=node):
|
|
522
|
+
resp = self.client.post(link)
|
|
523
|
+
self.assertEqual(resp.status_code, 302)
|
|
524
|
+
self.user.refresh_from_db()
|
|
525
|
+
self.assertTrue(self.user.is_active)
|
|
526
|
+
mock_grant.assert_called_once_with(self.user, "aa:bb:cc:dd:ee:ff")
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
class NavbarBrandTests(TestCase):
|
|
530
|
+
def setUp(self):
|
|
531
|
+
self.client = Client()
|
|
532
|
+
Site.objects.update_or_create(
|
|
533
|
+
id=1, defaults={"name": "Terminal", "domain": "testserver"}
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
def test_site_name_displayed_when_known(self):
|
|
537
|
+
resp = self.client.get(reverse("pages:index"))
|
|
538
|
+
self.assertContains(resp, '<a class="navbar-brand" href="/">Terminal</a>')
|
|
539
|
+
|
|
540
|
+
def test_default_brand_when_unknown(self):
|
|
541
|
+
Site.objects.filter(id=1).update(domain="example.com")
|
|
542
|
+
resp = self.client.get(reverse("pages:index"))
|
|
543
|
+
self.assertContains(resp, '<a class="navbar-brand" href="/">Arthexis</a>')
|
|
544
|
+
|
|
545
|
+
@override_settings(ALLOWED_HOSTS=["127.0.0.1", "testserver"])
|
|
546
|
+
def test_brand_uses_role_name_when_site_name_blank(self):
|
|
547
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
548
|
+
Node.objects.update_or_create(
|
|
549
|
+
mac_address=Node.get_current_mac(),
|
|
550
|
+
defaults={
|
|
551
|
+
"hostname": "localhost",
|
|
552
|
+
"address": "127.0.0.1",
|
|
553
|
+
"role": role,
|
|
554
|
+
},
|
|
555
|
+
)
|
|
556
|
+
Site.objects.filter(id=1).update(name="", domain="127.0.0.1")
|
|
557
|
+
resp = self.client.get(reverse("pages:index"), HTTP_HOST="127.0.0.1")
|
|
558
|
+
self.assertEqual(resp.context["badge_site_name"], "Terminal")
|
|
559
|
+
self.assertContains(resp, '<a class="navbar-brand" href="/">Terminal</a>')
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
class AdminBadgesTests(TestCase):
|
|
563
|
+
def setUp(self):
|
|
564
|
+
self.client = Client()
|
|
565
|
+
User = get_user_model()
|
|
566
|
+
self.admin = User.objects.create_superuser(
|
|
567
|
+
username="badge-admin", password="pwd", email="admin@example.com"
|
|
568
|
+
)
|
|
569
|
+
self.client.force_login(self.admin)
|
|
570
|
+
Site.objects.update_or_create(
|
|
571
|
+
id=1, defaults={"name": "test", "domain": "testserver"}
|
|
572
|
+
)
|
|
573
|
+
from nodes.models import Node
|
|
574
|
+
|
|
575
|
+
self.node_hostname = "otherhost"
|
|
576
|
+
self.node = Node.objects.create(
|
|
577
|
+
hostname=self.node_hostname,
|
|
578
|
+
address=socket.gethostbyname(socket.gethostname()),
|
|
579
|
+
)
|
|
580
|
+
|
|
581
|
+
def test_badges_show_site_and_node(self):
|
|
582
|
+
resp = self.client.get(reverse("admin:index"))
|
|
583
|
+
self.assertContains(resp, "SITE: test")
|
|
584
|
+
self.assertContains(resp, f"NODE: {self.node_hostname}")
|
|
585
|
+
|
|
586
|
+
def test_badges_show_node_role(self):
|
|
587
|
+
from nodes.models import NodeRole
|
|
588
|
+
|
|
589
|
+
role = NodeRole.objects.create(name="Dev")
|
|
590
|
+
self.node.role = role
|
|
591
|
+
self.node.save()
|
|
592
|
+
resp = self.client.get(reverse("admin:index"))
|
|
593
|
+
role_list = reverse("admin:nodes_noderole_changelist")
|
|
594
|
+
role_change = reverse("admin:nodes_noderole_change", args=[role.pk])
|
|
595
|
+
self.assertContains(resp, "ROLE: Dev")
|
|
596
|
+
self.assertContains(resp, f'href="{role_list}"')
|
|
597
|
+
self.assertContains(resp, f'href="{role_change}"')
|
|
598
|
+
|
|
599
|
+
def test_badges_warn_when_node_missing(self):
|
|
600
|
+
from nodes.models import Node
|
|
601
|
+
|
|
602
|
+
Node.objects.all().delete()
|
|
603
|
+
resp = self.client.get(reverse("admin:index"))
|
|
604
|
+
self.assertContains(resp, "NODE: Unknown")
|
|
605
|
+
self.assertContains(resp, "badge-unknown")
|
|
606
|
+
self.assertContains(resp, "#6c757d")
|
|
607
|
+
|
|
608
|
+
def test_badges_link_to_admin(self):
|
|
609
|
+
resp = self.client.get(reverse("admin:index"))
|
|
610
|
+
site_list = reverse("admin:pages_siteproxy_changelist")
|
|
611
|
+
site_change = reverse("admin:pages_siteproxy_change", args=[1])
|
|
612
|
+
node_list = reverse("admin:nodes_node_changelist")
|
|
613
|
+
node_change = reverse("admin:nodes_node_change", args=[self.node.pk])
|
|
614
|
+
self.assertContains(resp, f'href="{site_list}"')
|
|
615
|
+
self.assertContains(resp, f'href="{site_change}"')
|
|
616
|
+
self.assertContains(resp, f'href="{node_list}"')
|
|
617
|
+
self.assertContains(resp, f'href="{node_change}"')
|
|
618
|
+
|
|
619
|
+
def test_badge_colors_use_standard_palette(self):
|
|
620
|
+
site = Site.objects.get(pk=1)
|
|
621
|
+
badge, _ = SiteBadge.objects.get_or_create(site=site)
|
|
622
|
+
badge.badge_color = "#ff0000"
|
|
623
|
+
badge.save(update_fields=["badge_color"])
|
|
624
|
+
self.node.badge_color = "#123456"
|
|
625
|
+
self.node.save(update_fields=["badge_color"])
|
|
626
|
+
|
|
627
|
+
resp = self.client.get(reverse("admin:index"))
|
|
628
|
+
|
|
629
|
+
self.assertNotContains(resp, "#ff0000")
|
|
630
|
+
self.assertNotContains(resp, "#123456")
|
|
631
|
+
self.assertContains(resp, 'style="background-color: #28a745;"', 2)
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
class AdminDashboardAppListTests(TestCase):
|
|
635
|
+
def setUp(self):
|
|
636
|
+
self.client = Client()
|
|
637
|
+
User = get_user_model()
|
|
638
|
+
self.admin = User.objects.create_superuser(
|
|
639
|
+
username="dashboard_admin", password="pwd", email="admin@example.com"
|
|
640
|
+
)
|
|
641
|
+
self.client.force_login(self.admin)
|
|
642
|
+
Site.objects.update_or_create(
|
|
643
|
+
id=1, defaults={"name": "test", "domain": "testserver"}
|
|
644
|
+
)
|
|
645
|
+
self.locks_dir = Path(settings.BASE_DIR) / "locks"
|
|
646
|
+
self.locks_dir.mkdir(parents=True, exist_ok=True)
|
|
647
|
+
self.celery_lock = self.locks_dir / "celery.lck"
|
|
648
|
+
if self.celery_lock.exists():
|
|
649
|
+
self.celery_lock.unlink()
|
|
650
|
+
self.addCleanup(self._remove_celery_lock)
|
|
651
|
+
self.node, _ = Node.objects.update_or_create(
|
|
652
|
+
mac_address=Node.get_current_mac(),
|
|
653
|
+
defaults={
|
|
654
|
+
"hostname": socket.gethostname(),
|
|
655
|
+
"address": socket.gethostbyname(socket.gethostname()),
|
|
656
|
+
"base_path": settings.BASE_DIR,
|
|
657
|
+
"port": 8000,
|
|
658
|
+
},
|
|
659
|
+
)
|
|
660
|
+
self.node.features.clear()
|
|
661
|
+
|
|
662
|
+
def _remove_celery_lock(self):
|
|
663
|
+
try:
|
|
664
|
+
self.celery_lock.unlink()
|
|
665
|
+
except FileNotFoundError:
|
|
666
|
+
pass
|
|
667
|
+
|
|
668
|
+
def test_horologia_hidden_without_celery_feature(self):
|
|
669
|
+
resp = self.client.get(reverse("admin:index"))
|
|
670
|
+
self.assertNotContains(resp, "5. Horologia MODELS")
|
|
671
|
+
|
|
672
|
+
def test_horologia_visible_with_celery_feature(self):
|
|
673
|
+
feature = NodeFeature.objects.create(slug="celery-queue", display="Celery Queue")
|
|
674
|
+
NodeFeatureAssignment.objects.create(node=self.node, feature=feature)
|
|
675
|
+
resp = self.client.get(reverse("admin:index"))
|
|
676
|
+
self.assertContains(resp, "5. Horologia MODELS")
|
|
677
|
+
|
|
678
|
+
def test_horologia_visible_with_celery_lock(self):
|
|
679
|
+
self.celery_lock.write_text("")
|
|
680
|
+
resp = self.client.get(reverse("admin:index"))
|
|
681
|
+
self.assertContains(resp, "5. Horologia MODELS")
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
class AdminSidebarTests(TestCase):
|
|
685
|
+
def setUp(self):
|
|
686
|
+
self.client = Client()
|
|
687
|
+
User = get_user_model()
|
|
688
|
+
self.admin = User.objects.create_superuser(
|
|
689
|
+
username="sidebar_admin", password="pwd", email="admin@example.com"
|
|
690
|
+
)
|
|
691
|
+
self.client.force_login(self.admin)
|
|
692
|
+
Site.objects.update_or_create(
|
|
693
|
+
id=1, defaults={"name": "test", "domain": "testserver"}
|
|
694
|
+
)
|
|
695
|
+
from nodes.models import Node
|
|
696
|
+
|
|
697
|
+
Node.objects.create(hostname="testserver", address="127.0.0.1")
|
|
698
|
+
|
|
699
|
+
def test_sidebar_app_groups_collapsible_script_present(self):
|
|
700
|
+
url = reverse("admin:nodes_node_changelist")
|
|
701
|
+
resp = self.client.get(url)
|
|
702
|
+
self.assertContains(resp, 'id="admin-collapsible-apps"')
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
class ViewHistoryLoggingTests(TestCase):
|
|
706
|
+
def setUp(self):
|
|
707
|
+
self.client = Client()
|
|
708
|
+
Site.objects.update_or_create(id=1, defaults={"name": "Terminal"})
|
|
709
|
+
|
|
710
|
+
def test_successful_visit_creates_entry(self):
|
|
711
|
+
resp = self.client.get(reverse("pages:index"))
|
|
712
|
+
self.assertEqual(resp.status_code, 200)
|
|
713
|
+
entry = ViewHistory.objects.order_by("-visited_at").first()
|
|
714
|
+
self.assertIsNotNone(entry)
|
|
715
|
+
self.assertEqual(entry.path, "/")
|
|
716
|
+
self.assertEqual(entry.status_code, 200)
|
|
717
|
+
self.assertEqual(entry.error_message, "")
|
|
718
|
+
|
|
719
|
+
def test_error_visit_records_message(self):
|
|
720
|
+
resp = self.client.get("/missing-page/")
|
|
721
|
+
self.assertEqual(resp.status_code, 404)
|
|
722
|
+
entry = (
|
|
723
|
+
ViewHistory.objects.filter(path="/missing-page/")
|
|
724
|
+
.order_by("-visited_at")
|
|
725
|
+
.first()
|
|
726
|
+
)
|
|
727
|
+
self.assertIsNotNone(entry)
|
|
728
|
+
self.assertEqual(entry.status_code, 404)
|
|
729
|
+
self.assertNotEqual(entry.error_message, "")
|
|
730
|
+
|
|
731
|
+
def test_debug_toolbar_requests_not_tracked(self):
|
|
732
|
+
resp = self.client.get(reverse("pages:index"), {"djdt": "toolbar"})
|
|
733
|
+
self.assertEqual(resp.status_code, 200)
|
|
734
|
+
self.assertFalse(ViewHistory.objects.exists())
|
|
735
|
+
|
|
736
|
+
def test_authenticated_user_last_visit_ip_updated(self):
|
|
737
|
+
User = get_user_model()
|
|
738
|
+
user = User.objects.create_user(
|
|
739
|
+
username="history_user", password="pwd", email="history@example.com"
|
|
740
|
+
)
|
|
741
|
+
self.assertTrue(self.client.login(username="history_user", password="pwd"))
|
|
742
|
+
|
|
743
|
+
resp = self.client.get(
|
|
744
|
+
reverse("pages:index"),
|
|
745
|
+
HTTP_X_FORWARDED_FOR="203.0.113.5",
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
self.assertEqual(resp.status_code, 200)
|
|
749
|
+
user.refresh_from_db()
|
|
750
|
+
self.assertEqual(user.last_visit_ip_address, "203.0.113.5")
|
|
751
|
+
|
|
752
|
+
def test_landing_visit_records_lead(self):
|
|
753
|
+
role = NodeRole.objects.create(name="landing-role")
|
|
754
|
+
application = Application.objects.create(
|
|
755
|
+
name="landing-tests-app", description=""
|
|
756
|
+
)
|
|
757
|
+
module = Module.objects.create(
|
|
758
|
+
node_role=role,
|
|
759
|
+
application=application,
|
|
760
|
+
path="/",
|
|
761
|
+
menu="Landing",
|
|
762
|
+
)
|
|
763
|
+
landing = module.landings.get(path="/")
|
|
764
|
+
landing.label = "Home Landing"
|
|
765
|
+
landing.save(update_fields=["label"])
|
|
766
|
+
|
|
767
|
+
resp = self.client.get(
|
|
768
|
+
reverse("pages:index"), HTTP_REFERER="https://example.com/ref"
|
|
769
|
+
)
|
|
770
|
+
|
|
771
|
+
self.assertEqual(resp.status_code, 200)
|
|
772
|
+
lead = LandingLead.objects.latest("created_on")
|
|
773
|
+
self.assertEqual(lead.landing, landing)
|
|
774
|
+
self.assertEqual(lead.path, "/")
|
|
775
|
+
self.assertEqual(lead.referer, "https://example.com/ref")
|
|
776
|
+
|
|
777
|
+
def test_disabled_landing_does_not_record_lead(self):
|
|
778
|
+
role = NodeRole.objects.create(name="landing-role-disabled")
|
|
779
|
+
application = Application.objects.create(
|
|
780
|
+
name="landing-disabled-app", description=""
|
|
781
|
+
)
|
|
782
|
+
module = Module.objects.create(
|
|
783
|
+
node_role=role,
|
|
784
|
+
application=application,
|
|
785
|
+
path="/",
|
|
786
|
+
menu="Landing",
|
|
787
|
+
)
|
|
788
|
+
landing = module.landings.get(path="/")
|
|
789
|
+
landing.enabled = False
|
|
790
|
+
landing.save(update_fields=["enabled"])
|
|
791
|
+
|
|
792
|
+
resp = self.client.get(reverse("pages:index"))
|
|
793
|
+
|
|
794
|
+
self.assertEqual(resp.status_code, 200)
|
|
795
|
+
self.assertFalse(LandingLead.objects.exists())
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
class ViewHistoryAdminTests(TestCase):
|
|
799
|
+
def setUp(self):
|
|
800
|
+
self.client = Client()
|
|
801
|
+
User = get_user_model()
|
|
802
|
+
self.admin = User.objects.create_superuser(
|
|
803
|
+
username="history_admin", password="pwd", email="admin@example.com"
|
|
804
|
+
)
|
|
805
|
+
self.client.force_login(self.admin)
|
|
806
|
+
Site.objects.update_or_create(
|
|
807
|
+
id=1, defaults={"name": "test", "domain": "testserver"}
|
|
808
|
+
)
|
|
809
|
+
|
|
810
|
+
def _create_history(self, path: str, days_offset: int = 0, count: int = 1):
|
|
811
|
+
for _ in range(count):
|
|
812
|
+
entry = ViewHistory.objects.create(
|
|
813
|
+
path=path,
|
|
814
|
+
method="GET",
|
|
815
|
+
status_code=200,
|
|
816
|
+
status_text="OK",
|
|
817
|
+
error_message="",
|
|
818
|
+
view_name="pages:index",
|
|
819
|
+
)
|
|
820
|
+
if days_offset:
|
|
821
|
+
entry.visited_at = timezone.now() - timedelta(days=days_offset)
|
|
822
|
+
entry.save(update_fields=["visited_at"])
|
|
823
|
+
|
|
824
|
+
def test_change_list_includes_graph_link(self):
|
|
825
|
+
resp = self.client.get(reverse("admin:pages_viewhistory_changelist"))
|
|
826
|
+
self.assertContains(resp, reverse("admin:pages_viewhistory_traffic_graph"))
|
|
827
|
+
self.assertContains(resp, "Traffic graph")
|
|
828
|
+
|
|
829
|
+
def test_graph_view_renders_canvas(self):
|
|
830
|
+
resp = self.client.get(reverse("admin:pages_viewhistory_traffic_graph"))
|
|
831
|
+
self.assertContains(resp, "viewhistory-chart")
|
|
832
|
+
self.assertContains(resp, reverse("admin:pages_viewhistory_changelist"))
|
|
833
|
+
self.assertContains(resp, static("core/vendor/chart.umd.min.js"))
|
|
834
|
+
|
|
835
|
+
def test_graph_data_endpoint(self):
|
|
836
|
+
ViewHistory.all_objects.all().delete()
|
|
837
|
+
self._create_history("/", count=2)
|
|
838
|
+
self._create_history("/about/", days_offset=1)
|
|
839
|
+
url = reverse("admin:pages_viewhistory_traffic_data")
|
|
840
|
+
resp = self.client.get(url)
|
|
841
|
+
self.assertEqual(resp.status_code, 200)
|
|
842
|
+
data = resp.json()
|
|
843
|
+
self.assertIn("labels", data)
|
|
844
|
+
self.assertIn("datasets", data)
|
|
845
|
+
self.assertGreater(len(data["labels"]), 0)
|
|
846
|
+
totals = {
|
|
847
|
+
dataset["label"]: sum(dataset["data"]) for dataset in data["datasets"]
|
|
848
|
+
}
|
|
849
|
+
self.assertEqual(totals.get("/"), 2)
|
|
850
|
+
self.assertEqual(totals.get("/about/"), 1)
|
|
851
|
+
|
|
852
|
+
def test_graph_data_includes_late_evening_visits(self):
|
|
853
|
+
target_date = date(2025, 9, 27)
|
|
854
|
+
entry = ViewHistory.objects.create(
|
|
855
|
+
path="/late/",
|
|
856
|
+
method="GET",
|
|
857
|
+
status_code=200,
|
|
858
|
+
status_text="OK",
|
|
859
|
+
error_message="",
|
|
860
|
+
view_name="pages:index",
|
|
861
|
+
)
|
|
862
|
+
local_evening = datetime.combine(target_date, datetime_time(21, 30))
|
|
863
|
+
aware_evening = timezone.make_aware(
|
|
864
|
+
local_evening, timezone.get_current_timezone()
|
|
865
|
+
)
|
|
866
|
+
entry.visited_at = aware_evening.astimezone(datetime_timezone.utc)
|
|
867
|
+
entry.save(update_fields=["visited_at"])
|
|
868
|
+
|
|
869
|
+
url = reverse("admin:pages_viewhistory_traffic_data")
|
|
870
|
+
with patch("pages.admin.timezone.localdate", return_value=target_date):
|
|
871
|
+
resp = self.client.get(url)
|
|
872
|
+
self.assertEqual(resp.status_code, 200)
|
|
873
|
+
data = resp.json()
|
|
874
|
+
totals = {
|
|
875
|
+
dataset["label"]: sum(dataset["data"]) for dataset in data["datasets"]
|
|
876
|
+
}
|
|
877
|
+
self.assertEqual(totals.get("/late/"), 1)
|
|
878
|
+
|
|
879
|
+
def test_graph_data_filters_using_datetime_range(self):
|
|
880
|
+
admin_view = ViewHistoryAdmin(ViewHistory, admin.site)
|
|
881
|
+
with patch.object(ViewHistory.objects, "filter") as mock_filter:
|
|
882
|
+
mock_queryset = mock_filter.return_value
|
|
883
|
+
mock_queryset.exists.return_value = False
|
|
884
|
+
admin_view._build_chart_data()
|
|
885
|
+
|
|
886
|
+
kwargs = mock_filter.call_args.kwargs
|
|
887
|
+
self.assertIn("visited_at__gte", kwargs)
|
|
888
|
+
self.assertIn("visited_at__lt", kwargs)
|
|
889
|
+
|
|
890
|
+
def test_admin_index_displays_widget(self):
|
|
891
|
+
resp = self.client.get(reverse("admin:index"))
|
|
892
|
+
self.assertContains(resp, "viewhistory-mini-module")
|
|
893
|
+
self.assertContains(resp, reverse("admin:pages_viewhistory_traffic_graph"))
|
|
894
|
+
self.assertContains(resp, static("core/vendor/chart.umd.min.js"))
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
class LogViewerAdminTests(SimpleTestCase):
|
|
898
|
+
def setUp(self):
|
|
899
|
+
self.factory = RequestFactory()
|
|
900
|
+
self.logs_dir = Path(settings.BASE_DIR) / "logs"
|
|
901
|
+
self.logs_dir.mkdir(exist_ok=True)
|
|
902
|
+
|
|
903
|
+
def tearDown(self):
|
|
904
|
+
for path in list(self.logs_dir.iterdir()):
|
|
905
|
+
if path.name == ".gitkeep":
|
|
906
|
+
continue
|
|
907
|
+
if path.is_file():
|
|
908
|
+
path.unlink()
|
|
909
|
+
elif path.is_dir():
|
|
910
|
+
shutil.rmtree(path, ignore_errors=True)
|
|
911
|
+
|
|
912
|
+
def _create_log(self, name: str, content: str = "") -> Path:
|
|
913
|
+
path = self.logs_dir / name
|
|
914
|
+
path.write_text(content, encoding="utf-8")
|
|
915
|
+
return path
|
|
916
|
+
|
|
917
|
+
def _build_request(self, params: dict | None = None):
|
|
918
|
+
request = self.factory.get("/admin/logs/viewer/", params or {})
|
|
919
|
+
|
|
920
|
+
class DummyUser:
|
|
921
|
+
is_active = True
|
|
922
|
+
is_staff = True
|
|
923
|
+
is_superuser = True
|
|
924
|
+
|
|
925
|
+
@property
|
|
926
|
+
def is_authenticated(self):
|
|
927
|
+
return True
|
|
928
|
+
|
|
929
|
+
def has_perm(self, perm):
|
|
930
|
+
return True
|
|
931
|
+
|
|
932
|
+
def has_perms(self, perms):
|
|
933
|
+
return True
|
|
934
|
+
|
|
935
|
+
def has_module_perms(self, app_label):
|
|
936
|
+
return True
|
|
937
|
+
|
|
938
|
+
def get_username(self):
|
|
939
|
+
return "tester"
|
|
940
|
+
|
|
941
|
+
request.user = DummyUser()
|
|
942
|
+
request.session = {}
|
|
943
|
+
request.current_app = admin.site.name
|
|
944
|
+
return request
|
|
945
|
+
|
|
946
|
+
def _render(self, params: dict | None = None):
|
|
947
|
+
request = self._build_request(params)
|
|
948
|
+
context = {
|
|
949
|
+
"site_title": "Constellation",
|
|
950
|
+
"site_header": "Constellation",
|
|
951
|
+
"site_url": "/",
|
|
952
|
+
"available_apps": [],
|
|
953
|
+
}
|
|
954
|
+
with patch("pages.admin.admin.site.each_context", return_value=context), patch(
|
|
955
|
+
"pages.context_processors.get_site", return_value=None
|
|
956
|
+
):
|
|
957
|
+
response = log_viewer(request)
|
|
958
|
+
return response
|
|
959
|
+
|
|
960
|
+
def test_log_viewer_lists_available_logs(self):
|
|
961
|
+
self._create_log("example.log", "example content")
|
|
962
|
+
response = self._render()
|
|
963
|
+
self.assertIn("example.log", response.context_data["available_logs"])
|
|
964
|
+
|
|
965
|
+
def test_log_viewer_displays_selected_log(self):
|
|
966
|
+
self._create_log("selected.log", "hello world")
|
|
967
|
+
response = self._render({"log": "selected.log"})
|
|
968
|
+
context = response.context_data
|
|
969
|
+
self.assertEqual(context["selected_log"], "selected.log")
|
|
970
|
+
self.assertIn("hello world", context["log_content"])
|
|
971
|
+
|
|
972
|
+
def test_log_viewer_reports_missing_log(self):
|
|
973
|
+
response = self._render({"log": "missing.log"})
|
|
974
|
+
self.assertIn("requested log could not be found", response.context_data["log_error"])
|
|
975
|
+
|
|
976
|
+
def test_log_viewer_ignores_nested_files(self):
|
|
977
|
+
nested = self.logs_dir / "nested"
|
|
978
|
+
nested.mkdir(exist_ok=True)
|
|
979
|
+
(nested / "hidden.log").write_text("hidden", encoding="utf-8")
|
|
980
|
+
self._create_log("root.log", "root")
|
|
981
|
+
response = self._render()
|
|
982
|
+
self.assertIn("root.log", response.context_data["available_logs"])
|
|
983
|
+
self.assertNotIn("hidden.log", response.context_data["available_logs"])
|
|
984
|
+
|
|
985
|
+
def test_log_viewer_ignores_hidden_files(self):
|
|
986
|
+
hidden_log = self.logs_dir / ".hidden.log"
|
|
987
|
+
hidden_log.write_text("secret", encoding="utf-8")
|
|
988
|
+
self._create_log("visible.log", "visible")
|
|
989
|
+
response = self._render()
|
|
990
|
+
self.assertIn("visible.log", response.context_data["available_logs"])
|
|
991
|
+
self.assertNotIn(".hidden.log", response.context_data["available_logs"])
|
|
992
|
+
|
|
993
|
+
class AdminModelStatusTests(TestCase):
|
|
994
|
+
def setUp(self):
|
|
995
|
+
self.client = Client()
|
|
996
|
+
User = get_user_model()
|
|
997
|
+
self.admin = User.objects.create_superuser(
|
|
998
|
+
username="status_admin", password="pwd", email="admin@example.com"
|
|
999
|
+
)
|
|
1000
|
+
self.client.force_login(self.admin)
|
|
1001
|
+
Site.objects.update_or_create(
|
|
1002
|
+
id=1, defaults={"name": "test", "domain": "testserver"}
|
|
1003
|
+
)
|
|
1004
|
+
from nodes.models import Node
|
|
1005
|
+
|
|
1006
|
+
Node.objects.create(hostname="testserver", address="127.0.0.1")
|
|
1007
|
+
|
|
1008
|
+
@patch("pages.templatetags.admin_extras.connection.introspection.table_names")
|
|
1009
|
+
def test_status_dots_render(self, mock_tables):
|
|
1010
|
+
from django.db import connection
|
|
1011
|
+
|
|
1012
|
+
tables = type(connection.introspection).table_names(connection.introspection)
|
|
1013
|
+
mock_tables.return_value = [t for t in tables if t != "pages_module"]
|
|
1014
|
+
resp = self.client.get(reverse("admin:index"))
|
|
1015
|
+
self.assertContains(resp, 'class="model-status ok"')
|
|
1016
|
+
self.assertContains(resp, 'class="model-status missing"', count=1)
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
class SiteAdminRegisterCurrentTests(TestCase):
|
|
1020
|
+
def setUp(self):
|
|
1021
|
+
self.client = Client()
|
|
1022
|
+
User = get_user_model()
|
|
1023
|
+
self.admin = User.objects.create_superuser(
|
|
1024
|
+
username="site-admin", password="pwd", email="admin@example.com"
|
|
1025
|
+
)
|
|
1026
|
+
self.client.force_login(self.admin)
|
|
1027
|
+
Site.objects.update_or_create(
|
|
1028
|
+
id=1, defaults={"name": "Constellation", "domain": "arthexis.com"}
|
|
1029
|
+
)
|
|
1030
|
+
|
|
1031
|
+
def test_register_current_creates_site(self):
|
|
1032
|
+
resp = self.client.get(reverse("admin:pages_siteproxy_changelist"))
|
|
1033
|
+
self.assertContains(resp, "Register Current")
|
|
1034
|
+
|
|
1035
|
+
resp = self.client.get(reverse("admin:pages_siteproxy_register_current"))
|
|
1036
|
+
self.assertRedirects(resp, reverse("admin:pages_siteproxy_changelist"))
|
|
1037
|
+
self.assertTrue(Site.objects.filter(domain="testserver").exists())
|
|
1038
|
+
site = Site.objects.get(domain="testserver")
|
|
1039
|
+
self.assertEqual(site.name, "testserver")
|
|
1040
|
+
|
|
1041
|
+
@override_settings(ALLOWED_HOSTS=["127.0.0.1", "testserver"])
|
|
1042
|
+
def test_register_current_ip_sets_pages_name(self):
|
|
1043
|
+
resp = self.client.get(
|
|
1044
|
+
reverse("admin:pages_siteproxy_register_current"), HTTP_HOST="127.0.0.1"
|
|
1045
|
+
)
|
|
1046
|
+
self.assertRedirects(resp, reverse("admin:pages_siteproxy_changelist"))
|
|
1047
|
+
site = Site.objects.get(domain="127.0.0.1")
|
|
1048
|
+
self.assertEqual(site.name, "")
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
class SiteAdminScreenshotTests(TestCase):
|
|
1052
|
+
def setUp(self):
|
|
1053
|
+
self.client = Client()
|
|
1054
|
+
User = get_user_model()
|
|
1055
|
+
self.admin = User.objects.create_superuser(
|
|
1056
|
+
username="screenshot-admin", password="pwd", email="admin@example.com"
|
|
1057
|
+
)
|
|
1058
|
+
self.client.force_login(self.admin)
|
|
1059
|
+
Site.objects.update_or_create(
|
|
1060
|
+
id=1, defaults={"name": "Terminal", "domain": "testserver"}
|
|
1061
|
+
)
|
|
1062
|
+
self.node = Node.objects.create(
|
|
1063
|
+
hostname="localhost",
|
|
1064
|
+
address="127.0.0.1",
|
|
1065
|
+
port=80,
|
|
1066
|
+
mac_address=Node.get_current_mac(),
|
|
1067
|
+
)
|
|
1068
|
+
|
|
1069
|
+
@patch("pages.admin.capture_screenshot")
|
|
1070
|
+
def test_capture_screenshot_action(self, mock_capture):
|
|
1071
|
+
screenshot_dir = settings.LOG_DIR / "screenshots"
|
|
1072
|
+
screenshot_dir.mkdir(parents=True, exist_ok=True)
|
|
1073
|
+
file_path = screenshot_dir / "test.png"
|
|
1074
|
+
file_path.write_bytes(b"frontpage")
|
|
1075
|
+
mock_capture.return_value = Path("screenshots/test.png")
|
|
1076
|
+
url = reverse("admin:pages_siteproxy_changelist")
|
|
1077
|
+
response = self.client.post(
|
|
1078
|
+
url,
|
|
1079
|
+
{"action": "capture_screenshot", "_selected_action": [1]},
|
|
1080
|
+
follow=True,
|
|
1081
|
+
)
|
|
1082
|
+
self.assertEqual(response.status_code, 200)
|
|
1083
|
+
self.assertEqual(
|
|
1084
|
+
ContentSample.objects.filter(kind=ContentSample.IMAGE).count(), 1
|
|
1085
|
+
)
|
|
1086
|
+
screenshot = ContentSample.objects.filter(kind=ContentSample.IMAGE).first()
|
|
1087
|
+
self.assertEqual(screenshot.node, self.node)
|
|
1088
|
+
self.assertEqual(screenshot.path, "screenshots/test.png")
|
|
1089
|
+
self.assertEqual(screenshot.method, "ADMIN")
|
|
1090
|
+
link = reverse("admin:nodes_contentsample_change", args=[screenshot.pk])
|
|
1091
|
+
self.assertContains(response, link)
|
|
1092
|
+
mock_capture.assert_called_once_with("http://testserver/")
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
class AdminBadgesWebsiteTests(TestCase):
|
|
1096
|
+
def setUp(self):
|
|
1097
|
+
self.client = Client()
|
|
1098
|
+
User = get_user_model()
|
|
1099
|
+
self.admin = User.objects.create_superuser(
|
|
1100
|
+
username="badge-admin2", password="pwd", email="admin@example.com"
|
|
1101
|
+
)
|
|
1102
|
+
self.client.force_login(self.admin)
|
|
1103
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1104
|
+
Node.objects.update_or_create(
|
|
1105
|
+
mac_address=Node.get_current_mac(),
|
|
1106
|
+
defaults={"hostname": "localhost", "address": "127.0.0.1", "role": role},
|
|
1107
|
+
)
|
|
1108
|
+
Site.objects.update_or_create(
|
|
1109
|
+
id=1, defaults={"name": "", "domain": "127.0.0.1"}
|
|
1110
|
+
)
|
|
1111
|
+
|
|
1112
|
+
@override_settings(ALLOWED_HOSTS=["127.0.0.1", "testserver"])
|
|
1113
|
+
def test_badge_shows_domain_when_site_name_blank(self):
|
|
1114
|
+
resp = self.client.get(reverse("admin:index"), HTTP_HOST="127.0.0.1")
|
|
1115
|
+
self.assertContains(resp, "SITE: 127.0.0.1")
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
class NavAppsTests(TestCase):
|
|
1119
|
+
def setUp(self):
|
|
1120
|
+
self.client = Client()
|
|
1121
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1122
|
+
Node.objects.update_or_create(
|
|
1123
|
+
mac_address=Node.get_current_mac(),
|
|
1124
|
+
defaults={"hostname": "localhost", "address": "127.0.0.1", "role": role},
|
|
1125
|
+
)
|
|
1126
|
+
Site.objects.update_or_create(
|
|
1127
|
+
id=1, defaults={"domain": "127.0.0.1", "name": ""}
|
|
1128
|
+
)
|
|
1129
|
+
app = Application.objects.create(name="Readme")
|
|
1130
|
+
Module.objects.create(
|
|
1131
|
+
node_role=role, application=app, path="/", is_default=True
|
|
1132
|
+
)
|
|
1133
|
+
|
|
1134
|
+
def test_nav_pill_renders(self):
|
|
1135
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1136
|
+
self.assertContains(resp, "README")
|
|
1137
|
+
self.assertContains(resp, "badge rounded-pill")
|
|
1138
|
+
|
|
1139
|
+
def test_nav_pill_renders_with_port(self):
|
|
1140
|
+
resp = self.client.get(reverse("pages:index"), HTTP_HOST="127.0.0.1:8000")
|
|
1141
|
+
self.assertContains(resp, "README")
|
|
1142
|
+
|
|
1143
|
+
def test_nav_pill_uses_menu_field(self):
|
|
1144
|
+
site_app = Module.objects.get()
|
|
1145
|
+
site_app.menu = "Docs"
|
|
1146
|
+
site_app.save()
|
|
1147
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1148
|
+
self.assertContains(resp, 'badge rounded-pill text-bg-secondary">DOCS')
|
|
1149
|
+
self.assertNotContains(resp, 'badge rounded-pill text-bg-secondary">README')
|
|
1150
|
+
|
|
1151
|
+
def test_app_without_root_url_excluded(self):
|
|
1152
|
+
role = NodeRole.objects.get(name="Terminal")
|
|
1153
|
+
app = Application.objects.create(name="core")
|
|
1154
|
+
Module.objects.create(node_role=role, application=app, path="/core/")
|
|
1155
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1156
|
+
self.assertNotContains(resp, 'href="/core/"')
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
class RoleLandingRedirectTests(TestCase):
|
|
1160
|
+
def setUp(self):
|
|
1161
|
+
self.client = Client()
|
|
1162
|
+
Site.objects.update_or_create(
|
|
1163
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1164
|
+
)
|
|
1165
|
+
self.node, _ = Node.objects.update_or_create(
|
|
1166
|
+
mac_address=Node.get_current_mac(),
|
|
1167
|
+
defaults={"hostname": "localhost", "address": "127.0.0.1"},
|
|
1168
|
+
)
|
|
1169
|
+
self.ocpp_app, _ = Application.objects.get_or_create(name="ocpp")
|
|
1170
|
+
self.user_model = get_user_model()
|
|
1171
|
+
|
|
1172
|
+
def _ensure_landing(
|
|
1173
|
+
self, role: NodeRole, landing_path: str, label: str
|
|
1174
|
+
) -> Landing:
|
|
1175
|
+
module, _ = Module.objects.get_or_create(
|
|
1176
|
+
node_role=role,
|
|
1177
|
+
application=self.ocpp_app,
|
|
1178
|
+
defaults={"path": "/ocpp/", "menu": "Chargers"},
|
|
1179
|
+
)
|
|
1180
|
+
if module.path != "/ocpp/":
|
|
1181
|
+
module.path = "/ocpp/"
|
|
1182
|
+
module.save(update_fields=["path"])
|
|
1183
|
+
landing, _ = Landing.objects.get_or_create(
|
|
1184
|
+
module=module,
|
|
1185
|
+
path=landing_path,
|
|
1186
|
+
defaults={
|
|
1187
|
+
"label": label,
|
|
1188
|
+
"enabled": True,
|
|
1189
|
+
"description": "",
|
|
1190
|
+
},
|
|
1191
|
+
)
|
|
1192
|
+
if landing.label != label or not landing.enabled or landing.description:
|
|
1193
|
+
landing.label = label
|
|
1194
|
+
landing.enabled = True
|
|
1195
|
+
landing.description = ""
|
|
1196
|
+
landing.save(update_fields=["label", "enabled", "description"])
|
|
1197
|
+
return landing
|
|
1198
|
+
|
|
1199
|
+
def _configure_role_landing(
|
|
1200
|
+
self, role_name: str, landing_path: str, label: str, priority: int = 0
|
|
1201
|
+
) -> str:
|
|
1202
|
+
role, _ = NodeRole.objects.get_or_create(name=role_name)
|
|
1203
|
+
self.node.role = role
|
|
1204
|
+
self.node.save(update_fields=["role"])
|
|
1205
|
+
landing = self._ensure_landing(role, landing_path, label)
|
|
1206
|
+
RoleLanding.objects.update_or_create(
|
|
1207
|
+
node_role=role,
|
|
1208
|
+
defaults={"landing": landing, "is_deleted": False, "priority": priority},
|
|
1209
|
+
)
|
|
1210
|
+
return landing_path
|
|
1211
|
+
|
|
1212
|
+
def test_satellite_redirects_to_dashboard(self):
|
|
1213
|
+
target = self._configure_role_landing(
|
|
1214
|
+
"Satellite", "/ocpp/", "CPMS Online Dashboard"
|
|
1215
|
+
)
|
|
1216
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1217
|
+
self.assertRedirects(resp, target, fetch_redirect_response=False)
|
|
1218
|
+
|
|
1219
|
+
def test_control_redirects_to_rfid(self):
|
|
1220
|
+
target = self._configure_role_landing(
|
|
1221
|
+
"Control", "/ocpp/rfid/", "RFID Tag Validator"
|
|
1222
|
+
)
|
|
1223
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1224
|
+
self.assertRedirects(resp, target, fetch_redirect_response=False)
|
|
1225
|
+
|
|
1226
|
+
def test_security_group_redirect_takes_priority(self):
|
|
1227
|
+
self._configure_role_landing("Control", "/ocpp/rfid/", "RFID Tag Validator")
|
|
1228
|
+
role = self.node.role
|
|
1229
|
+
group = SecurityGroup.objects.create(name="Operators")
|
|
1230
|
+
group_landing = self._ensure_landing(role, "/ocpp/group/", "Group Landing")
|
|
1231
|
+
RoleLanding.objects.update_or_create(
|
|
1232
|
+
security_group=group,
|
|
1233
|
+
defaults={"landing": group_landing, "priority": 5, "is_deleted": False},
|
|
1234
|
+
)
|
|
1235
|
+
user = self.user_model.objects.create_user("group-user")
|
|
1236
|
+
user.groups.add(group)
|
|
1237
|
+
self.client.force_login(user)
|
|
1238
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1239
|
+
self.assertRedirects(
|
|
1240
|
+
resp, group_landing.path, fetch_redirect_response=False
|
|
1241
|
+
)
|
|
1242
|
+
|
|
1243
|
+
def test_user_redirect_overrides_group_with_higher_priority(self):
|
|
1244
|
+
self._configure_role_landing("Control", "/ocpp/rfid/", "RFID Tag Validator")
|
|
1245
|
+
role = self.node.role
|
|
1246
|
+
group = SecurityGroup.objects.create(name="Operators")
|
|
1247
|
+
group_landing = self._ensure_landing(role, "/ocpp/group/", "Group Landing")
|
|
1248
|
+
RoleLanding.objects.update_or_create(
|
|
1249
|
+
security_group=group,
|
|
1250
|
+
defaults={"landing": group_landing, "priority": 3, "is_deleted": False},
|
|
1251
|
+
)
|
|
1252
|
+
user = self.user_model.objects.create_user("priority-user")
|
|
1253
|
+
user.groups.add(group)
|
|
1254
|
+
user_landing = self._ensure_landing(role, "/ocpp/user/", "User Landing")
|
|
1255
|
+
RoleLanding.objects.update_or_create(
|
|
1256
|
+
user=user,
|
|
1257
|
+
defaults={"landing": user_landing, "priority": 10, "is_deleted": False},
|
|
1258
|
+
)
|
|
1259
|
+
self.client.force_login(user)
|
|
1260
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1261
|
+
self.assertRedirects(
|
|
1262
|
+
resp, user_landing.path, fetch_redirect_response=False
|
|
1263
|
+
)
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
class ConstellationNavTests(TestCase):
|
|
1267
|
+
def setUp(self):
|
|
1268
|
+
self.client = Client()
|
|
1269
|
+
role, _ = NodeRole.objects.get_or_create(name="Constellation")
|
|
1270
|
+
Node.objects.update_or_create(
|
|
1271
|
+
mac_address=Node.get_current_mac(),
|
|
1272
|
+
defaults={
|
|
1273
|
+
"hostname": "localhost",
|
|
1274
|
+
"address": "127.0.0.1",
|
|
1275
|
+
"role": role,
|
|
1276
|
+
},
|
|
1277
|
+
)
|
|
1278
|
+
Site.objects.update_or_create(
|
|
1279
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1280
|
+
)
|
|
1281
|
+
fixtures = [
|
|
1282
|
+
Path(
|
|
1283
|
+
settings.BASE_DIR,
|
|
1284
|
+
"pages",
|
|
1285
|
+
"fixtures",
|
|
1286
|
+
"constellation__application_ocpp.json",
|
|
1287
|
+
),
|
|
1288
|
+
Path(
|
|
1289
|
+
settings.BASE_DIR,
|
|
1290
|
+
"pages",
|
|
1291
|
+
"fixtures",
|
|
1292
|
+
"constellation__module_ocpp.json",
|
|
1293
|
+
),
|
|
1294
|
+
Path(
|
|
1295
|
+
settings.BASE_DIR,
|
|
1296
|
+
"pages",
|
|
1297
|
+
"fixtures",
|
|
1298
|
+
"constellation__landing_ocpp_dashboard.json",
|
|
1299
|
+
),
|
|
1300
|
+
Path(
|
|
1301
|
+
settings.BASE_DIR,
|
|
1302
|
+
"pages",
|
|
1303
|
+
"fixtures",
|
|
1304
|
+
"constellation__landing_ocpp_cp_simulator.json",
|
|
1305
|
+
),
|
|
1306
|
+
Path(
|
|
1307
|
+
settings.BASE_DIR,
|
|
1308
|
+
"pages",
|
|
1309
|
+
"fixtures",
|
|
1310
|
+
"constellation__landing_ocpp_rfid.json",
|
|
1311
|
+
),
|
|
1312
|
+
]
|
|
1313
|
+
call_command("loaddata", *map(str, fixtures))
|
|
1314
|
+
|
|
1315
|
+
def test_rfid_pill_hidden(self):
|
|
1316
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1317
|
+
nav_labels = [
|
|
1318
|
+
module.menu_label.upper() for module in resp.context["nav_modules"]
|
|
1319
|
+
]
|
|
1320
|
+
self.assertNotIn("RFID", nav_labels)
|
|
1321
|
+
self.assertTrue(
|
|
1322
|
+
Module.objects.filter(
|
|
1323
|
+
path="/ocpp/", node_role__name="Constellation"
|
|
1324
|
+
).exists()
|
|
1325
|
+
)
|
|
1326
|
+
self.assertFalse(
|
|
1327
|
+
Module.objects.filter(
|
|
1328
|
+
path="/ocpp/rfid/",
|
|
1329
|
+
node_role__name="Constellation",
|
|
1330
|
+
is_deleted=False,
|
|
1331
|
+
).exists()
|
|
1332
|
+
)
|
|
1333
|
+
ocpp_module = next(
|
|
1334
|
+
module
|
|
1335
|
+
for module in resp.context["nav_modules"]
|
|
1336
|
+
if module.menu_label.upper() == "CHARGERS"
|
|
1337
|
+
)
|
|
1338
|
+
landing_labels = [landing.label for landing in ocpp_module.enabled_landings]
|
|
1339
|
+
self.assertIn("RFID Tag Validator", landing_labels)
|
|
1340
|
+
|
|
1341
|
+
def test_ocpp_dashboard_visible(self):
|
|
1342
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1343
|
+
self.assertContains(resp, 'href="/ocpp/"')
|
|
1344
|
+
|
|
1345
|
+
class ControlNavTests(TestCase):
|
|
1346
|
+
def setUp(self):
|
|
1347
|
+
self.client = Client()
|
|
1348
|
+
role, _ = NodeRole.objects.get_or_create(name="Control")
|
|
1349
|
+
Node.objects.update_or_create(
|
|
1350
|
+
mac_address=Node.get_current_mac(),
|
|
1351
|
+
defaults={
|
|
1352
|
+
"hostname": "localhost",
|
|
1353
|
+
"address": "127.0.0.1",
|
|
1354
|
+
"role": role,
|
|
1355
|
+
},
|
|
1356
|
+
)
|
|
1357
|
+
Site.objects.update_or_create(
|
|
1358
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1359
|
+
)
|
|
1360
|
+
fixtures = [
|
|
1361
|
+
Path(
|
|
1362
|
+
settings.BASE_DIR,
|
|
1363
|
+
"pages",
|
|
1364
|
+
"fixtures",
|
|
1365
|
+
"control__application_ocpp.json",
|
|
1366
|
+
),
|
|
1367
|
+
Path(
|
|
1368
|
+
settings.BASE_DIR,
|
|
1369
|
+
"pages",
|
|
1370
|
+
"fixtures",
|
|
1371
|
+
"control__module_ocpp.json",
|
|
1372
|
+
),
|
|
1373
|
+
Path(
|
|
1374
|
+
settings.BASE_DIR,
|
|
1375
|
+
"pages",
|
|
1376
|
+
"fixtures",
|
|
1377
|
+
"control__landing_ocpp_dashboard.json",
|
|
1378
|
+
),
|
|
1379
|
+
Path(
|
|
1380
|
+
settings.BASE_DIR,
|
|
1381
|
+
"pages",
|
|
1382
|
+
"fixtures",
|
|
1383
|
+
"control__landing_ocpp_cp_simulator.json",
|
|
1384
|
+
),
|
|
1385
|
+
Path(
|
|
1386
|
+
settings.BASE_DIR,
|
|
1387
|
+
"pages",
|
|
1388
|
+
"fixtures",
|
|
1389
|
+
"control__landing_ocpp_rfid.json",
|
|
1390
|
+
),
|
|
1391
|
+
]
|
|
1392
|
+
call_command("loaddata", *map(str, fixtures))
|
|
1393
|
+
|
|
1394
|
+
def test_ocpp_dashboard_visible(self):
|
|
1395
|
+
user = get_user_model().objects.create_user("control", password="pw")
|
|
1396
|
+
self.client.force_login(user)
|
|
1397
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1398
|
+
self.assertEqual(resp.status_code, 200)
|
|
1399
|
+
self.assertContains(resp, 'href="/ocpp/"')
|
|
1400
|
+
self.assertContains(
|
|
1401
|
+
resp, 'badge rounded-pill text-bg-secondary">CHARGERS'
|
|
1402
|
+
)
|
|
1403
|
+
|
|
1404
|
+
def test_header_links_visible_when_defined(self):
|
|
1405
|
+
Reference.objects.create(
|
|
1406
|
+
alt_text="Console",
|
|
1407
|
+
value="https://example.com/console",
|
|
1408
|
+
show_in_header=True,
|
|
1409
|
+
)
|
|
1410
|
+
|
|
1411
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1412
|
+
|
|
1413
|
+
self.assertIn("header_references", resp.context)
|
|
1414
|
+
self.assertTrue(resp.context["header_references"])
|
|
1415
|
+
self.assertContains(resp, "LINKS")
|
|
1416
|
+
self.assertContains(resp, 'href="https://example.com/console"')
|
|
1417
|
+
|
|
1418
|
+
def test_header_links_hidden_when_flag_false(self):
|
|
1419
|
+
Reference.objects.create(
|
|
1420
|
+
alt_text="Hidden",
|
|
1421
|
+
value="https://example.com/hidden",
|
|
1422
|
+
show_in_header=False,
|
|
1423
|
+
)
|
|
1424
|
+
|
|
1425
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1426
|
+
|
|
1427
|
+
self.assertIn("header_references", resp.context)
|
|
1428
|
+
self.assertFalse(resp.context["header_references"])
|
|
1429
|
+
self.assertNotContains(resp, "https://example.com/hidden")
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
class PowerNavTests(TestCase):
|
|
1433
|
+
def setUp(self):
|
|
1434
|
+
self.client = Client()
|
|
1435
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1436
|
+
Node.objects.update_or_create(
|
|
1437
|
+
mac_address=Node.get_current_mac(),
|
|
1438
|
+
defaults={"hostname": "localhost", "address": "127.0.0.1", "role": role},
|
|
1439
|
+
)
|
|
1440
|
+
Site.objects.update_or_create(
|
|
1441
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1442
|
+
)
|
|
1443
|
+
awg_app, _ = Application.objects.get_or_create(name="awg")
|
|
1444
|
+
awg_module, _ = Module.objects.get_or_create(
|
|
1445
|
+
node_role=role, application=awg_app, path="/awg/"
|
|
1446
|
+
)
|
|
1447
|
+
awg_module.create_landings()
|
|
1448
|
+
manuals_app, _ = Application.objects.get_or_create(name="pages")
|
|
1449
|
+
man_module, _ = Module.objects.get_or_create(
|
|
1450
|
+
node_role=role, application=manuals_app, path="/man/"
|
|
1451
|
+
)
|
|
1452
|
+
man_module.create_landings()
|
|
1453
|
+
User = get_user_model()
|
|
1454
|
+
self.user = User.objects.create_user("user", password="pw")
|
|
1455
|
+
|
|
1456
|
+
def test_power_pill_lists_calculators(self):
|
|
1457
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1458
|
+
power_module = None
|
|
1459
|
+
for module in resp.context["nav_modules"]:
|
|
1460
|
+
if module.path == "/awg/":
|
|
1461
|
+
power_module = module
|
|
1462
|
+
break
|
|
1463
|
+
self.assertIsNotNone(power_module)
|
|
1464
|
+
self.assertEqual(power_module.menu_label.upper(), "CALCULATE")
|
|
1465
|
+
landing_labels = {landing.label for landing in power_module.enabled_landings}
|
|
1466
|
+
self.assertIn("AWG Calculator", landing_labels)
|
|
1467
|
+
|
|
1468
|
+
def test_manual_pill_label(self):
|
|
1469
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1470
|
+
manuals_module = None
|
|
1471
|
+
for module in resp.context["nav_modules"]:
|
|
1472
|
+
if module.path == "/man/":
|
|
1473
|
+
manuals_module = module
|
|
1474
|
+
break
|
|
1475
|
+
self.assertIsNotNone(manuals_module)
|
|
1476
|
+
self.assertEqual(manuals_module.menu_label.upper(), "MANUAL")
|
|
1477
|
+
landing_labels = {landing.label for landing in manuals_module.enabled_landings}
|
|
1478
|
+
self.assertIn("Manuals", landing_labels)
|
|
1479
|
+
|
|
1480
|
+
def test_energy_tariff_visible_when_logged_in(self):
|
|
1481
|
+
self.client.force_login(self.user)
|
|
1482
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1483
|
+
power_module = None
|
|
1484
|
+
for module in resp.context["nav_modules"]:
|
|
1485
|
+
if module.path == "/awg/":
|
|
1486
|
+
power_module = module
|
|
1487
|
+
break
|
|
1488
|
+
self.assertIsNotNone(power_module)
|
|
1489
|
+
landing_labels = {landing.label for landing in power_module.enabled_landings}
|
|
1490
|
+
self.assertIn("AWG Calculator", landing_labels)
|
|
1491
|
+
self.assertIn("Energy Tariff Calculator", landing_labels)
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
class StaffNavVisibilityTests(TestCase):
|
|
1495
|
+
def setUp(self):
|
|
1496
|
+
self.client = Client()
|
|
1497
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1498
|
+
Node.objects.update_or_create(
|
|
1499
|
+
mac_address=Node.get_current_mac(),
|
|
1500
|
+
defaults={"hostname": "localhost", "address": "127.0.0.1", "role": role},
|
|
1501
|
+
)
|
|
1502
|
+
Site.objects.update_or_create(
|
|
1503
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1504
|
+
)
|
|
1505
|
+
app = Application.objects.create(name="ocpp")
|
|
1506
|
+
Module.objects.create(node_role=role, application=app, path="/ocpp/")
|
|
1507
|
+
User = get_user_model()
|
|
1508
|
+
self.user = User.objects.create_user("user", password="pw")
|
|
1509
|
+
self.staff = User.objects.create_user("staff", password="pw", is_staff=True)
|
|
1510
|
+
|
|
1511
|
+
def test_nonstaff_pill_hidden(self):
|
|
1512
|
+
self.client.login(username="user", password="pw")
|
|
1513
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1514
|
+
self.assertContains(resp, 'href="/ocpp/"')
|
|
1515
|
+
|
|
1516
|
+
def test_staff_sees_pill(self):
|
|
1517
|
+
self.client.login(username="staff", password="pw")
|
|
1518
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1519
|
+
self.assertContains(resp, 'href="/ocpp/"')
|
|
1520
|
+
|
|
1521
|
+
|
|
1522
|
+
class ApplicationModelTests(TestCase):
|
|
1523
|
+
def test_path_defaults_to_slugified_name(self):
|
|
1524
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1525
|
+
Node.objects.update_or_create(
|
|
1526
|
+
mac_address=Node.get_current_mac(),
|
|
1527
|
+
defaults={"hostname": "localhost", "address": "127.0.0.1", "role": role},
|
|
1528
|
+
)
|
|
1529
|
+
Site.objects.update_or_create(
|
|
1530
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1531
|
+
)
|
|
1532
|
+
app = Application.objects.create(name="core")
|
|
1533
|
+
site_app = Module.objects.create(node_role=role, application=app)
|
|
1534
|
+
self.assertEqual(site_app.path, "/core/")
|
|
1535
|
+
|
|
1536
|
+
def test_installed_flag_false_when_missing(self):
|
|
1537
|
+
app = Application.objects.create(name="missing")
|
|
1538
|
+
self.assertFalse(app.installed)
|
|
1539
|
+
|
|
1540
|
+
def test_verbose_name_property(self):
|
|
1541
|
+
app = Application.objects.create(name="ocpp")
|
|
1542
|
+
config = django_apps.get_app_config("ocpp")
|
|
1543
|
+
self.assertEqual(app.verbose_name, config.verbose_name)
|
|
1544
|
+
|
|
1545
|
+
|
|
1546
|
+
class ApplicationAdminFormTests(TestCase):
|
|
1547
|
+
def test_name_field_uses_local_apps(self):
|
|
1548
|
+
admin_instance = ApplicationAdmin(Application, admin.site)
|
|
1549
|
+
form = admin_instance.get_form(request=None)()
|
|
1550
|
+
choices = [choice[0] for choice in form.fields["name"].choices]
|
|
1551
|
+
self.assertIn("core", choices)
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
class ApplicationAdminDisplayTests(TestCase):
|
|
1555
|
+
def setUp(self):
|
|
1556
|
+
User = get_user_model()
|
|
1557
|
+
self.admin = User.objects.create_superuser(
|
|
1558
|
+
username="app-admin", password="pwd", email="admin@example.com"
|
|
1559
|
+
)
|
|
1560
|
+
self.client = Client()
|
|
1561
|
+
self.client.force_login(self.admin)
|
|
1562
|
+
|
|
1563
|
+
def test_changelist_shows_verbose_name(self):
|
|
1564
|
+
Application.objects.create(name="ocpp")
|
|
1565
|
+
resp = self.client.get(reverse("admin:pages_application_changelist"))
|
|
1566
|
+
config = django_apps.get_app_config("ocpp")
|
|
1567
|
+
self.assertContains(resp, config.verbose_name)
|
|
1568
|
+
|
|
1569
|
+
def test_changelist_shows_description(self):
|
|
1570
|
+
Application.objects.create(
|
|
1571
|
+
name="awg", description="Power, Energy and Cost calculations."
|
|
1572
|
+
)
|
|
1573
|
+
resp = self.client.get(reverse("admin:pages_application_changelist"))
|
|
1574
|
+
self.assertContains(resp, "Power, Energy and Cost calculations.")
|
|
1575
|
+
|
|
1576
|
+
|
|
1577
|
+
class UserManualAdminFormTests(TestCase):
|
|
1578
|
+
def setUp(self):
|
|
1579
|
+
self.manual = UserManual.objects.create(
|
|
1580
|
+
slug="manual-one",
|
|
1581
|
+
title="Manual One",
|
|
1582
|
+
description="Test manual",
|
|
1583
|
+
languages="en",
|
|
1584
|
+
content_html="<p>Manual</p>",
|
|
1585
|
+
content_pdf=base64.b64encode(b"initial").decode("ascii"),
|
|
1586
|
+
)
|
|
1587
|
+
|
|
1588
|
+
def test_widget_uses_slug_for_download(self):
|
|
1589
|
+
admin_instance = UserManualAdmin(UserManual, admin.site)
|
|
1590
|
+
form_class = admin_instance.get_form(request=None, obj=self.manual)
|
|
1591
|
+
form = form_class(instance=self.manual)
|
|
1592
|
+
field = form.fields["content_pdf"]
|
|
1593
|
+
self.assertEqual(field.widget.download_name, f"{self.manual.slug}.pdf")
|
|
1594
|
+
self.assertEqual(field.widget.content_type, "application/pdf")
|
|
1595
|
+
|
|
1596
|
+
def test_upload_encodes_content_pdf(self):
|
|
1597
|
+
admin_instance = UserManualAdmin(UserManual, admin.site)
|
|
1598
|
+
form_class = admin_instance.get_form(request=None, obj=self.manual)
|
|
1599
|
+
payload = {
|
|
1600
|
+
"slug": self.manual.slug,
|
|
1601
|
+
"title": self.manual.title,
|
|
1602
|
+
"description": self.manual.description,
|
|
1603
|
+
"languages": self.manual.languages,
|
|
1604
|
+
"content_html": self.manual.content_html,
|
|
1605
|
+
"pdf_orientation": self.manual.pdf_orientation,
|
|
1606
|
+
}
|
|
1607
|
+
upload = SimpleUploadedFile("manual.pdf", b"PDF data")
|
|
1608
|
+
form = form_class(data=payload, files={"content_pdf": upload}, instance=self.manual)
|
|
1609
|
+
self.assertTrue(form.is_valid(), form.errors.as_json())
|
|
1610
|
+
self.assertEqual(
|
|
1611
|
+
form.cleaned_data["content_pdf"],
|
|
1612
|
+
base64.b64encode(b"PDF data").decode("ascii"),
|
|
1613
|
+
)
|
|
1614
|
+
|
|
1615
|
+
def test_initial_base64_preserved_without_upload(self):
|
|
1616
|
+
admin_instance = UserManualAdmin(UserManual, admin.site)
|
|
1617
|
+
form_class = admin_instance.get_form(request=None, obj=self.manual)
|
|
1618
|
+
payload = {
|
|
1619
|
+
"slug": self.manual.slug,
|
|
1620
|
+
"title": self.manual.title,
|
|
1621
|
+
"description": self.manual.description,
|
|
1622
|
+
"languages": self.manual.languages,
|
|
1623
|
+
"content_html": self.manual.content_html,
|
|
1624
|
+
"pdf_orientation": self.manual.pdf_orientation,
|
|
1625
|
+
}
|
|
1626
|
+
form = form_class(data=payload, files={}, instance=self.manual)
|
|
1627
|
+
self.assertTrue(form.is_valid(), form.errors.as_json())
|
|
1628
|
+
self.assertEqual(form.cleaned_data["content_pdf"], self.manual.content_pdf)
|
|
1629
|
+
|
|
1630
|
+
|
|
1631
|
+
class LandingCreationTests(TestCase):
|
|
1632
|
+
def setUp(self):
|
|
1633
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1634
|
+
Node.objects.update_or_create(
|
|
1635
|
+
mac_address=Node.get_current_mac(),
|
|
1636
|
+
defaults={"hostname": "localhost", "address": "127.0.0.1", "role": role},
|
|
1637
|
+
)
|
|
1638
|
+
self.app, _ = Application.objects.get_or_create(name="pages")
|
|
1639
|
+
Site.objects.update_or_create(
|
|
1640
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1641
|
+
)
|
|
1642
|
+
self.role = role
|
|
1643
|
+
|
|
1644
|
+
def test_landings_created_on_module_creation(self):
|
|
1645
|
+
module = Module.objects.create(
|
|
1646
|
+
node_role=self.role, application=self.app, path="/"
|
|
1647
|
+
)
|
|
1648
|
+
self.assertTrue(module.landings.filter(path="/").exists())
|
|
1649
|
+
|
|
1650
|
+
|
|
1651
|
+
class LandingFixtureTests(TestCase):
|
|
1652
|
+
def test_constellation_fixture_loads_without_duplicates(self):
|
|
1653
|
+
from glob import glob
|
|
1654
|
+
|
|
1655
|
+
NodeRole.objects.get_or_create(name="Constellation")
|
|
1656
|
+
fixtures = glob(
|
|
1657
|
+
str(Path(settings.BASE_DIR, "pages", "fixtures", "constellation__*.json"))
|
|
1658
|
+
)
|
|
1659
|
+
fixtures = sorted(
|
|
1660
|
+
fixtures,
|
|
1661
|
+
key=lambda path: (
|
|
1662
|
+
0 if "__application_" in path else 1 if "__module_" in path else 2
|
|
1663
|
+
),
|
|
1664
|
+
)
|
|
1665
|
+
call_command("loaddata", *fixtures)
|
|
1666
|
+
call_command("loaddata", *fixtures)
|
|
1667
|
+
module = Module.objects.get(path="/ocpp/", node_role__name="Constellation")
|
|
1668
|
+
module.create_landings()
|
|
1669
|
+
self.assertEqual(module.landings.filter(path="/ocpp/rfid/").count(), 1)
|
|
1670
|
+
|
|
1671
|
+
|
|
1672
|
+
class AllowedHostSubnetTests(TestCase):
|
|
1673
|
+
def setUp(self):
|
|
1674
|
+
self.client = Client()
|
|
1675
|
+
Site.objects.update_or_create(
|
|
1676
|
+
id=1, defaults={"domain": "testserver", "name": "pages"}
|
|
1677
|
+
)
|
|
1678
|
+
|
|
1679
|
+
@override_settings(ALLOWED_HOSTS=["10.42.0.0/16", "192.168.0.0/16"])
|
|
1680
|
+
def test_private_network_hosts_allowed(self):
|
|
1681
|
+
resp = self.client.get(reverse("pages:index"), HTTP_HOST="10.42.1.5")
|
|
1682
|
+
self.assertEqual(resp.status_code, 200)
|
|
1683
|
+
resp = self.client.get(reverse("pages:index"), HTTP_HOST="192.168.2.3")
|
|
1684
|
+
self.assertEqual(resp.status_code, 200)
|
|
1685
|
+
|
|
1686
|
+
@override_settings(ALLOWED_HOSTS=["10.42.0.0/16"])
|
|
1687
|
+
def test_host_outside_subnets_disallowed(self):
|
|
1688
|
+
resp = self.client.get(reverse("pages:index"), HTTP_HOST="11.0.0.1")
|
|
1689
|
+
self.assertEqual(resp.status_code, 400)
|
|
1690
|
+
|
|
1691
|
+
|
|
1692
|
+
class RFIDPageTests(TestCase):
|
|
1693
|
+
def setUp(self):
|
|
1694
|
+
self.client = Client()
|
|
1695
|
+
Site.objects.update_or_create(
|
|
1696
|
+
id=1, defaults={"domain": "testserver", "name": "pages"}
|
|
1697
|
+
)
|
|
1698
|
+
User = get_user_model()
|
|
1699
|
+
self.user = User.objects.create_user("rfid-user", password="pwd")
|
|
1700
|
+
|
|
1701
|
+
def test_page_redirects_when_anonymous(self):
|
|
1702
|
+
resp = self.client.get(reverse("rfid-reader"))
|
|
1703
|
+
self.assertEqual(resp.status_code, 302)
|
|
1704
|
+
self.assertIn(reverse("pages:login"), resp.url)
|
|
1705
|
+
|
|
1706
|
+
def test_page_renders_for_authenticated_user(self):
|
|
1707
|
+
self.client.force_login(self.user)
|
|
1708
|
+
resp = self.client.get(reverse("rfid-reader"))
|
|
1709
|
+
self.assertContains(resp, "Scanner ready")
|
|
1710
|
+
|
|
1711
|
+
|
|
1712
|
+
class FaviconTests(TestCase):
|
|
1713
|
+
def setUp(self):
|
|
1714
|
+
self.client = Client()
|
|
1715
|
+
self.tmpdir = tempfile.mkdtemp()
|
|
1716
|
+
self.addCleanup(shutil.rmtree, self.tmpdir)
|
|
1717
|
+
|
|
1718
|
+
def _png(self, name):
|
|
1719
|
+
data = base64.b64decode(
|
|
1720
|
+
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg=="
|
|
1721
|
+
)
|
|
1722
|
+
return SimpleUploadedFile(name, data, content_type="image/png")
|
|
1723
|
+
|
|
1724
|
+
def test_site_app_favicon_preferred_over_site(self):
|
|
1725
|
+
with override_settings(MEDIA_ROOT=self.tmpdir):
|
|
1726
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1727
|
+
Node.objects.update_or_create(
|
|
1728
|
+
mac_address=Node.get_current_mac(),
|
|
1729
|
+
defaults={
|
|
1730
|
+
"hostname": "localhost",
|
|
1731
|
+
"address": "127.0.0.1",
|
|
1732
|
+
"role": role,
|
|
1733
|
+
},
|
|
1734
|
+
)
|
|
1735
|
+
site, _ = Site.objects.update_or_create(
|
|
1736
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1737
|
+
)
|
|
1738
|
+
SiteBadge.objects.create(
|
|
1739
|
+
site=site, badge_color="#28a745", favicon=self._png("site.png")
|
|
1740
|
+
)
|
|
1741
|
+
app = Application.objects.create(name="readme")
|
|
1742
|
+
Module.objects.create(
|
|
1743
|
+
node_role=role,
|
|
1744
|
+
application=app,
|
|
1745
|
+
path="/",
|
|
1746
|
+
is_default=True,
|
|
1747
|
+
favicon=self._png("app.png"),
|
|
1748
|
+
)
|
|
1749
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1750
|
+
self.assertContains(resp, "app.png")
|
|
1751
|
+
|
|
1752
|
+
def test_site_favicon_used_when_app_missing(self):
|
|
1753
|
+
with override_settings(MEDIA_ROOT=self.tmpdir):
|
|
1754
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1755
|
+
Node.objects.update_or_create(
|
|
1756
|
+
mac_address=Node.get_current_mac(),
|
|
1757
|
+
defaults={
|
|
1758
|
+
"hostname": "localhost",
|
|
1759
|
+
"address": "127.0.0.1",
|
|
1760
|
+
"role": role,
|
|
1761
|
+
},
|
|
1762
|
+
)
|
|
1763
|
+
site, _ = Site.objects.update_or_create(
|
|
1764
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1765
|
+
)
|
|
1766
|
+
SiteBadge.objects.create(
|
|
1767
|
+
site=site, badge_color="#28a745", favicon=self._png("site.png")
|
|
1768
|
+
)
|
|
1769
|
+
app = Application.objects.create(name="readme")
|
|
1770
|
+
Module.objects.create(
|
|
1771
|
+
node_role=role, application=app, path="/", is_default=True
|
|
1772
|
+
)
|
|
1773
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1774
|
+
self.assertContains(resp, "site.png")
|
|
1775
|
+
|
|
1776
|
+
def test_default_favicon_used_when_none_defined(self):
|
|
1777
|
+
with override_settings(MEDIA_ROOT=self.tmpdir):
|
|
1778
|
+
role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1779
|
+
Node.objects.update_or_create(
|
|
1780
|
+
mac_address=Node.get_current_mac(),
|
|
1781
|
+
defaults={
|
|
1782
|
+
"hostname": "localhost",
|
|
1783
|
+
"address": "127.0.0.1",
|
|
1784
|
+
"role": role,
|
|
1785
|
+
},
|
|
1786
|
+
)
|
|
1787
|
+
Site.objects.update_or_create(
|
|
1788
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1789
|
+
)
|
|
1790
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1791
|
+
b64 = (
|
|
1792
|
+
Path(settings.BASE_DIR)
|
|
1793
|
+
.joinpath("pages", "fixtures", "data", "favicon.txt")
|
|
1794
|
+
.read_text()
|
|
1795
|
+
.strip()
|
|
1796
|
+
)
|
|
1797
|
+
self.assertContains(resp, b64)
|
|
1798
|
+
|
|
1799
|
+
def test_control_nodes_use_silver_favicon(self):
|
|
1800
|
+
with override_settings(MEDIA_ROOT=self.tmpdir):
|
|
1801
|
+
role, _ = NodeRole.objects.get_or_create(name="Control")
|
|
1802
|
+
Node.objects.update_or_create(
|
|
1803
|
+
mac_address=Node.get_current_mac(),
|
|
1804
|
+
defaults={
|
|
1805
|
+
"hostname": "localhost",
|
|
1806
|
+
"address": "127.0.0.1",
|
|
1807
|
+
"role": role,
|
|
1808
|
+
},
|
|
1809
|
+
)
|
|
1810
|
+
Site.objects.update_or_create(
|
|
1811
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1812
|
+
)
|
|
1813
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1814
|
+
b64 = (
|
|
1815
|
+
Path(settings.BASE_DIR)
|
|
1816
|
+
.joinpath("pages", "fixtures", "data", "favicon_control.txt")
|
|
1817
|
+
.read_text()
|
|
1818
|
+
.strip()
|
|
1819
|
+
)
|
|
1820
|
+
self.assertContains(resp, b64)
|
|
1821
|
+
|
|
1822
|
+
def test_constellation_nodes_use_goldenrod_favicon(self):
|
|
1823
|
+
with override_settings(MEDIA_ROOT=self.tmpdir):
|
|
1824
|
+
role, _ = NodeRole.objects.get_or_create(name="Constellation")
|
|
1825
|
+
Node.objects.update_or_create(
|
|
1826
|
+
mac_address=Node.get_current_mac(),
|
|
1827
|
+
defaults={
|
|
1828
|
+
"hostname": "localhost",
|
|
1829
|
+
"address": "127.0.0.1",
|
|
1830
|
+
"role": role,
|
|
1831
|
+
},
|
|
1832
|
+
)
|
|
1833
|
+
Site.objects.update_or_create(
|
|
1834
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1835
|
+
)
|
|
1836
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1837
|
+
b64 = (
|
|
1838
|
+
Path(settings.BASE_DIR)
|
|
1839
|
+
.joinpath("pages", "fixtures", "data", "favicon_constellation.txt")
|
|
1840
|
+
.read_text()
|
|
1841
|
+
.strip()
|
|
1842
|
+
)
|
|
1843
|
+
self.assertContains(resp, b64)
|
|
1844
|
+
|
|
1845
|
+
def test_satellite_nodes_use_silver_favicon(self):
|
|
1846
|
+
with override_settings(MEDIA_ROOT=self.tmpdir):
|
|
1847
|
+
role, _ = NodeRole.objects.get_or_create(name="Satellite")
|
|
1848
|
+
Node.objects.update_or_create(
|
|
1849
|
+
mac_address=Node.get_current_mac(),
|
|
1850
|
+
defaults={
|
|
1851
|
+
"hostname": "localhost",
|
|
1852
|
+
"address": "127.0.0.1",
|
|
1853
|
+
"role": role,
|
|
1854
|
+
},
|
|
1855
|
+
)
|
|
1856
|
+
Site.objects.update_or_create(
|
|
1857
|
+
id=1, defaults={"domain": "testserver", "name": ""}
|
|
1858
|
+
)
|
|
1859
|
+
resp = self.client.get(reverse("pages:index"))
|
|
1860
|
+
b64 = (
|
|
1861
|
+
Path(settings.BASE_DIR)
|
|
1862
|
+
.joinpath("pages", "fixtures", "data", "favicon_satellite.txt")
|
|
1863
|
+
.read_text()
|
|
1864
|
+
.strip()
|
|
1865
|
+
)
|
|
1866
|
+
self.assertContains(resp, b64)
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
class FavoriteTests(TestCase):
|
|
1870
|
+
def setUp(self):
|
|
1871
|
+
self.client = Client()
|
|
1872
|
+
User = get_user_model()
|
|
1873
|
+
self.user = User.objects.create_superuser(
|
|
1874
|
+
username="favadmin", password="pwd", email="fav@example.com"
|
|
1875
|
+
)
|
|
1876
|
+
ReleaseManager.objects.create(user=self.user)
|
|
1877
|
+
self.client.force_login(self.user)
|
|
1878
|
+
Site.objects.update_or_create(
|
|
1879
|
+
id=1, defaults={"name": "test", "domain": "testserver"}
|
|
1880
|
+
)
|
|
1881
|
+
from nodes.models import Node, NodeRole
|
|
1882
|
+
|
|
1883
|
+
terminal_role, _ = NodeRole.objects.get_or_create(name="Terminal")
|
|
1884
|
+
self.node, _ = Node.objects.update_or_create(
|
|
1885
|
+
mac_address=Node.get_current_mac(),
|
|
1886
|
+
defaults={
|
|
1887
|
+
"hostname": "localhost",
|
|
1888
|
+
"address": "127.0.0.1",
|
|
1889
|
+
"role": terminal_role,
|
|
1890
|
+
},
|
|
1891
|
+
)
|
|
1892
|
+
ContentType.objects.clear_cache()
|
|
1893
|
+
|
|
1894
|
+
def test_add_favorite(self):
|
|
1895
|
+
ct = ContentType.objects.get_by_natural_key("pages", "application")
|
|
1896
|
+
next_url = reverse("admin:pages_application_changelist")
|
|
1897
|
+
url = (
|
|
1898
|
+
reverse("admin:favorite_toggle", args=[ct.id]) + f"?next={quote(next_url)}"
|
|
1899
|
+
)
|
|
1900
|
+
resp = self.client.post(url, {"custom_label": "Apps", "user_data": "on"})
|
|
1901
|
+
self.assertRedirects(resp, next_url)
|
|
1902
|
+
fav = Favorite.objects.get(user=self.user, content_type=ct)
|
|
1903
|
+
self.assertEqual(fav.custom_label, "Apps")
|
|
1904
|
+
self.assertTrue(fav.user_data)
|
|
1905
|
+
|
|
1906
|
+
def test_cancel_link_uses_next(self):
|
|
1907
|
+
ct = ContentType.objects.get_by_natural_key("pages", "application")
|
|
1908
|
+
next_url = reverse("admin:pages_application_changelist")
|
|
1909
|
+
url = (
|
|
1910
|
+
reverse("admin:favorite_toggle", args=[ct.id]) + f"?next={quote(next_url)}"
|
|
1911
|
+
)
|
|
1912
|
+
resp = self.client.get(url)
|
|
1913
|
+
self.assertContains(resp, f'href="{next_url}"')
|
|
1914
|
+
|
|
1915
|
+
def test_existing_favorite_redirects_to_list(self):
|
|
1916
|
+
ct = ContentType.objects.get_by_natural_key("pages", "application")
|
|
1917
|
+
Favorite.objects.create(user=self.user, content_type=ct)
|
|
1918
|
+
url = reverse("admin:favorite_toggle", args=[ct.id])
|
|
1919
|
+
resp = self.client.get(url)
|
|
1920
|
+
self.assertRedirects(resp, reverse("admin:favorite_list"))
|
|
1921
|
+
resp = self.client.get(reverse("admin:favorite_list"))
|
|
1922
|
+
self.assertContains(resp, ct.name)
|
|
1923
|
+
|
|
1924
|
+
def test_update_user_data_from_list(self):
|
|
1925
|
+
ct = ContentType.objects.get_by_natural_key("pages", "application")
|
|
1926
|
+
fav = Favorite.objects.create(user=self.user, content_type=ct)
|
|
1927
|
+
url = reverse("admin:favorite_list")
|
|
1928
|
+
resp = self.client.post(url, {"user_data": [str(fav.pk)]})
|
|
1929
|
+
self.assertRedirects(resp, url)
|
|
1930
|
+
fav.refresh_from_db()
|
|
1931
|
+
self.assertTrue(fav.user_data)
|
|
1932
|
+
|
|
1933
|
+
def test_dashboard_includes_favorites_and_user_data(self):
|
|
1934
|
+
fav_ct = ContentType.objects.get_by_natural_key("pages", "application")
|
|
1935
|
+
Favorite.objects.create(
|
|
1936
|
+
user=self.user, content_type=fav_ct, custom_label="Apps"
|
|
1937
|
+
)
|
|
1938
|
+
NodeRole.objects.create(name="DataRole", is_user_data=True)
|
|
1939
|
+
resp = self.client.get(reverse("admin:index"))
|
|
1940
|
+
self.assertContains(resp, reverse("admin:pages_application_changelist"))
|
|
1941
|
+
self.assertContains(resp, reverse("admin:nodes_noderole_changelist"))
|
|
1942
|
+
|
|
1943
|
+
def test_dashboard_merges_duplicate_future_actions(self):
|
|
1944
|
+
ct = ContentType.objects.get_for_model(NodeRole)
|
|
1945
|
+
Favorite.objects.create(user=self.user, content_type=ct)
|
|
1946
|
+
NodeRole.objects.create(name="DataRole2", is_user_data=True)
|
|
1947
|
+
AdminHistory.objects.create(
|
|
1948
|
+
user=self.user,
|
|
1949
|
+
content_type=ct,
|
|
1950
|
+
url=reverse("admin:nodes_noderole_changelist"),
|
|
1951
|
+
)
|
|
1952
|
+
resp = self.client.get(reverse("admin:index"))
|
|
1953
|
+
url = reverse("admin:nodes_noderole_changelist")
|
|
1954
|
+
self.assertGreaterEqual(resp.content.decode().count(url), 1)
|
|
1955
|
+
self.assertContains(resp, NodeRole._meta.verbose_name_plural)
|
|
1956
|
+
|
|
1957
|
+
def test_dashboard_shows_open_lead_badge(self):
|
|
1958
|
+
InviteLead.objects.create(email="open1@example.com")
|
|
1959
|
+
InviteLead.objects.create(email="open2@example.com")
|
|
1960
|
+
closed = InviteLead.objects.create(email="closed@example.com")
|
|
1961
|
+
closed.status = InviteLead.Status.CLOSED
|
|
1962
|
+
closed.save(update_fields=["status"])
|
|
1963
|
+
assigned = InviteLead.objects.create(email="assigned@example.com")
|
|
1964
|
+
assigned.status = InviteLead.Status.ASSIGNED
|
|
1965
|
+
assigned.save(update_fields=["status"])
|
|
1966
|
+
|
|
1967
|
+
resp = self.client.get(reverse("admin:index"))
|
|
1968
|
+
content = resp.content.decode()
|
|
1969
|
+
|
|
1970
|
+
self.assertIn('class="lead-open-badge"', content)
|
|
1971
|
+
self.assertIn('title="2 open leads"', content)
|
|
1972
|
+
self.assertIn('aria-label="2 open leads"', content)
|
|
1973
|
+
|
|
1974
|
+
def test_dashboard_shows_rfid_release_badge(self):
|
|
1975
|
+
RFID.objects.create(rfid="RFID0001", released=True, allowed=True)
|
|
1976
|
+
RFID.objects.create(rfid="RFID0002", released=True, allowed=False)
|
|
1977
|
+
|
|
1978
|
+
resp = self.client.get(reverse("admin:index"))
|
|
1979
|
+
|
|
1980
|
+
expected = "1 / 2"
|
|
1981
|
+
badge_label = gettext(
|
|
1982
|
+
"%(released_allowed)s released and allowed RFIDs out of %(registered)s registered RFIDs"
|
|
1983
|
+
) % {"released_allowed": 1, "registered": 2}
|
|
1984
|
+
|
|
1985
|
+
self.assertContains(resp, expected)
|
|
1986
|
+
self.assertContains(resp, f'title="{badge_label}"')
|
|
1987
|
+
self.assertContains(resp, f'aria-label="{badge_label}"')
|
|
1988
|
+
|
|
1989
|
+
def test_nav_sidebar_hides_dashboard_badges(self):
|
|
1990
|
+
InviteLead.objects.create(email="open@example.com")
|
|
1991
|
+
RFID.objects.create(rfid="RFID0003", released=True, allowed=True)
|
|
1992
|
+
|
|
1993
|
+
resp = self.client.get(reverse("admin:teams_invitelead_changelist"))
|
|
1994
|
+
|
|
1995
|
+
self.assertNotContains(resp, "lead-open-badge")
|
|
1996
|
+
self.assertNotContains(resp, "rfid-release-badge")
|
|
1997
|
+
|
|
1998
|
+
def test_dashboard_limits_future_actions_to_top_four(self):
|
|
1999
|
+
from pages.templatetags.admin_extras import future_action_items
|
|
2000
|
+
|
|
2001
|
+
role_ct = ContentType.objects.get_for_model(NodeRole)
|
|
2002
|
+
role_url = reverse("admin:nodes_noderole_changelist")
|
|
2003
|
+
AdminHistory.objects.create(
|
|
2004
|
+
user=self.user,
|
|
2005
|
+
content_type=role_ct,
|
|
2006
|
+
url=role_url,
|
|
2007
|
+
)
|
|
2008
|
+
AdminHistory.objects.create(
|
|
2009
|
+
user=self.user,
|
|
2010
|
+
content_type=role_ct,
|
|
2011
|
+
url=f"{role_url}?page=2",
|
|
2012
|
+
)
|
|
2013
|
+
AdminHistory.objects.create(
|
|
2014
|
+
user=self.user,
|
|
2015
|
+
content_type=role_ct,
|
|
2016
|
+
url=f"{role_url}?page=3",
|
|
2017
|
+
)
|
|
2018
|
+
|
|
2019
|
+
app_ct = ContentType.objects.get_for_model(Application)
|
|
2020
|
+
app_url = reverse("admin:pages_application_changelist")
|
|
2021
|
+
AdminHistory.objects.create(
|
|
2022
|
+
user=self.user,
|
|
2023
|
+
content_type=app_ct,
|
|
2024
|
+
url=app_url,
|
|
2025
|
+
)
|
|
2026
|
+
AdminHistory.objects.create(
|
|
2027
|
+
user=self.user,
|
|
2028
|
+
content_type=app_ct,
|
|
2029
|
+
url=f"{app_url}?page=2",
|
|
2030
|
+
)
|
|
2031
|
+
|
|
2032
|
+
module_ct = ContentType.objects.get_for_model(Module)
|
|
2033
|
+
module_url = reverse("admin:pages_module_changelist")
|
|
2034
|
+
AdminHistory.objects.create(
|
|
2035
|
+
user=self.user,
|
|
2036
|
+
content_type=module_ct,
|
|
2037
|
+
url=module_url,
|
|
2038
|
+
)
|
|
2039
|
+
AdminHistory.objects.create(
|
|
2040
|
+
user=self.user,
|
|
2041
|
+
content_type=module_ct,
|
|
2042
|
+
url=f"{module_url}?page=2",
|
|
2043
|
+
)
|
|
2044
|
+
|
|
2045
|
+
package_ct = ContentType.objects.get_for_model(Package)
|
|
2046
|
+
package_url = reverse("admin:core_package_changelist")
|
|
2047
|
+
AdminHistory.objects.create(
|
|
2048
|
+
user=self.user,
|
|
2049
|
+
content_type=package_ct,
|
|
2050
|
+
url=package_url,
|
|
2051
|
+
)
|
|
2052
|
+
|
|
2053
|
+
view_history_ct = ContentType.objects.get_for_model(ViewHistory)
|
|
2054
|
+
view_history_url = reverse("admin:pages_viewhistory_changelist")
|
|
2055
|
+
AdminHistory.objects.create(
|
|
2056
|
+
user=self.user,
|
|
2057
|
+
content_type=view_history_ct,
|
|
2058
|
+
url=view_history_url,
|
|
2059
|
+
)
|
|
2060
|
+
|
|
2061
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2062
|
+
items = future_action_items({"request": resp.wsgi_request})["models"]
|
|
2063
|
+
labels = {item["label"] for item in items}
|
|
2064
|
+
self.assertEqual(len(items), 4)
|
|
2065
|
+
self.assertIn("Node Roles", labels)
|
|
2066
|
+
self.assertIn("Modules", labels)
|
|
2067
|
+
self.assertIn("applications", labels)
|
|
2068
|
+
self.assertIn("View Histories", labels)
|
|
2069
|
+
self.assertNotIn("Packages", labels)
|
|
2070
|
+
ContentType.objects.clear_cache()
|
|
2071
|
+
|
|
2072
|
+
def test_favorite_ct_id_recreates_missing_content_type(self):
|
|
2073
|
+
ct = ContentType.objects.get_by_natural_key("pages", "application")
|
|
2074
|
+
ct.delete()
|
|
2075
|
+
from pages.templatetags.favorites import favorite_ct_id
|
|
2076
|
+
|
|
2077
|
+
new_id = favorite_ct_id("pages", "Application")
|
|
2078
|
+
self.assertIsNotNone(new_id)
|
|
2079
|
+
self.assertTrue(
|
|
2080
|
+
ContentType.objects.filter(
|
|
2081
|
+
pk=new_id, app_label="pages", model="application"
|
|
2082
|
+
).exists()
|
|
2083
|
+
)
|
|
2084
|
+
|
|
2085
|
+
def test_dashboard_uses_change_label(self):
|
|
2086
|
+
ct = ContentType.objects.get_by_natural_key("pages", "application")
|
|
2087
|
+
Favorite.objects.create(user=self.user, content_type=ct)
|
|
2088
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2089
|
+
self.assertContains(resp, "Change Applications")
|
|
2090
|
+
self.assertContains(resp, 'target="_blank" rel="noopener noreferrer"')
|
|
2091
|
+
|
|
2092
|
+
def test_dashboard_links_to_focus_view(self):
|
|
2093
|
+
todo = Todo.objects.create(request="Check docs", url="/docs/")
|
|
2094
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2095
|
+
focus_url = reverse("todo-focus", args=[todo.pk])
|
|
2096
|
+
expected_next = quote(reverse("admin:index"))
|
|
2097
|
+
self.assertContains(
|
|
2098
|
+
resp,
|
|
2099
|
+
f'href="{focus_url}?next={expected_next}"',
|
|
2100
|
+
)
|
|
2101
|
+
|
|
2102
|
+
def test_dashboard_shows_todo_with_done_button(self):
|
|
2103
|
+
todo = Todo.objects.create(request="Do thing")
|
|
2104
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2105
|
+
done_url = reverse("todo-done", args=[todo.pk])
|
|
2106
|
+
self.assertContains(resp, todo.request)
|
|
2107
|
+
self.assertContains(resp, f'action="{done_url}"')
|
|
2108
|
+
self.assertContains(resp, "DONE")
|
|
2109
|
+
|
|
2110
|
+
def test_dashboard_shows_request_details(self):
|
|
2111
|
+
Todo.objects.create(request="Do thing", request_details="More info")
|
|
2112
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2113
|
+
self.assertContains(
|
|
2114
|
+
resp, '<div class="todo-details">More info</div>', html=True
|
|
2115
|
+
)
|
|
2116
|
+
|
|
2117
|
+
def test_dashboard_excludes_todo_changelist_link(self):
|
|
2118
|
+
ct = ContentType.objects.get_for_model(Todo)
|
|
2119
|
+
Favorite.objects.create(user=self.user, content_type=ct)
|
|
2120
|
+
AdminHistory.objects.create(
|
|
2121
|
+
user=self.user,
|
|
2122
|
+
content_type=ct,
|
|
2123
|
+
url=reverse("admin:core_todo_changelist"),
|
|
2124
|
+
)
|
|
2125
|
+
Todo.objects.create(request="Task", is_user_data=True)
|
|
2126
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2127
|
+
changelist = reverse("admin:core_todo_changelist")
|
|
2128
|
+
self.assertNotContains(resp, f'href="{changelist}"')
|
|
2129
|
+
|
|
2130
|
+
def test_dashboard_hides_todos_without_release_manager(self):
|
|
2131
|
+
todo = Todo.objects.create(request="Only Release Manager")
|
|
2132
|
+
User = get_user_model()
|
|
2133
|
+
other_user = User.objects.create_superuser(
|
|
2134
|
+
username="norole", password="pwd", email="norole@example.com"
|
|
2135
|
+
)
|
|
2136
|
+
self.client.force_login(other_user)
|
|
2137
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2138
|
+
self.assertNotContains(resp, "Release manager tasks")
|
|
2139
|
+
self.assertNotContains(resp, todo.request)
|
|
2140
|
+
|
|
2141
|
+
def test_dashboard_hides_todos_for_non_terminal_node(self):
|
|
2142
|
+
todo = Todo.objects.create(request="Terminal Tasks")
|
|
2143
|
+
from nodes.models import NodeRole
|
|
2144
|
+
|
|
2145
|
+
control_role, _ = NodeRole.objects.get_or_create(name="Control")
|
|
2146
|
+
self.node.role = control_role
|
|
2147
|
+
self.node.save(update_fields=["role"])
|
|
2148
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2149
|
+
self.assertNotContains(resp, "Release manager tasks")
|
|
2150
|
+
self.assertNotContains(resp, todo.request)
|
|
2151
|
+
|
|
2152
|
+
def test_dashboard_shows_todos_for_delegate_release_manager(self):
|
|
2153
|
+
todo = Todo.objects.create(request="Delegate Task")
|
|
2154
|
+
User = get_user_model()
|
|
2155
|
+
delegate = User.objects.create_superuser(
|
|
2156
|
+
username="delegate",
|
|
2157
|
+
password="pwd",
|
|
2158
|
+
email="delegate@example.com",
|
|
2159
|
+
)
|
|
2160
|
+
ReleaseManager.objects.create(user=delegate)
|
|
2161
|
+
operator = User.objects.create_superuser(
|
|
2162
|
+
username="operator",
|
|
2163
|
+
password="pwd",
|
|
2164
|
+
email="operator@example.com",
|
|
2165
|
+
)
|
|
2166
|
+
operator.operate_as = delegate
|
|
2167
|
+
operator.full_clean()
|
|
2168
|
+
operator.save()
|
|
2169
|
+
self.client.force_login(operator)
|
|
2170
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2171
|
+
self.assertContains(resp, "Release manager tasks")
|
|
2172
|
+
self.assertContains(resp, todo.request)
|
|
2173
|
+
|
|
2174
|
+
|
|
2175
|
+
class AdminActionListTests(TestCase):
|
|
2176
|
+
def setUp(self):
|
|
2177
|
+
User = get_user_model()
|
|
2178
|
+
User.objects.filter(username="action-admin").delete()
|
|
2179
|
+
self.user = User.objects.create_superuser(
|
|
2180
|
+
username="action-admin",
|
|
2181
|
+
password="pwd",
|
|
2182
|
+
email="action@example.com",
|
|
2183
|
+
)
|
|
2184
|
+
self.factory = RequestFactory()
|
|
2185
|
+
|
|
2186
|
+
def test_profile_actions_available_without_selection(self):
|
|
2187
|
+
from pages.templatetags.admin_extras import model_admin_actions
|
|
2188
|
+
|
|
2189
|
+
request = self.factory.get("/")
|
|
2190
|
+
request.user = self.user
|
|
2191
|
+
context = {"request": request}
|
|
2192
|
+
|
|
2193
|
+
registered = [
|
|
2194
|
+
(model._meta.app_label, model._meta.object_name)
|
|
2195
|
+
for model, admin_instance in admin.site._registry.items()
|
|
2196
|
+
if isinstance(admin_instance, ProfileAdminMixin)
|
|
2197
|
+
]
|
|
2198
|
+
|
|
2199
|
+
for app_label, object_name in registered:
|
|
2200
|
+
with self.subTest(model=f"{app_label}.{object_name}"):
|
|
2201
|
+
actions = model_admin_actions(context, app_label, object_name)
|
|
2202
|
+
labels = {action["label"] for action in actions}
|
|
2203
|
+
self.assertIn("Active Profile", labels)
|
|
2204
|
+
|
|
2205
|
+
def test_quote_report_link_available(self):
|
|
2206
|
+
from pages.templatetags.admin_extras import model_admin_actions
|
|
2207
|
+
|
|
2208
|
+
request = self.factory.get("/")
|
|
2209
|
+
request.user = self.user
|
|
2210
|
+
context = {"request": request}
|
|
2211
|
+
|
|
2212
|
+
actions = model_admin_actions(context, "core", "OdooProfile")
|
|
2213
|
+
labels = {action["label"] for action in actions}
|
|
2214
|
+
self.assertIn("Quote Report", labels)
|
|
2215
|
+
url = next(
|
|
2216
|
+
action["url"]
|
|
2217
|
+
for action in actions
|
|
2218
|
+
if action["label"] == "Quote Report"
|
|
2219
|
+
)
|
|
2220
|
+
self.assertEqual(
|
|
2221
|
+
url,
|
|
2222
|
+
reverse(
|
|
2223
|
+
"admin:core_odooprofile_actions",
|
|
2224
|
+
kwargs={"tool": "generate_quote_report"},
|
|
2225
|
+
),
|
|
2226
|
+
)
|
|
2227
|
+
|
|
2228
|
+
def test_send_net_message_link_available(self):
|
|
2229
|
+
from pages.templatetags.admin_extras import model_admin_actions
|
|
2230
|
+
|
|
2231
|
+
request = self.factory.get("/")
|
|
2232
|
+
request.user = self.user
|
|
2233
|
+
context = {"request": request}
|
|
2234
|
+
|
|
2235
|
+
actions = model_admin_actions(context, "nodes", "NetMessage")
|
|
2236
|
+
labels = {action["label"] for action in actions}
|
|
2237
|
+
self.assertIn("Send Net Message", labels)
|
|
2238
|
+
url = next(
|
|
2239
|
+
action["url"]
|
|
2240
|
+
for action in actions
|
|
2241
|
+
if action["label"] == "Send Net Message"
|
|
2242
|
+
)
|
|
2243
|
+
self.assertEqual(url, reverse("admin:nodes_netmessage_send"))
|
|
2244
|
+
|
|
2245
|
+
|
|
2246
|
+
class AdminModelGraphViewTests(TestCase):
|
|
2247
|
+
def setUp(self):
|
|
2248
|
+
self.client = Client()
|
|
2249
|
+
User = get_user_model()
|
|
2250
|
+
self.user = User.objects.create_user(
|
|
2251
|
+
username="graph-staff", password="pwd", is_staff=True
|
|
2252
|
+
)
|
|
2253
|
+
Site.objects.update_or_create(id=1, defaults={"name": "Terminal"})
|
|
2254
|
+
self.client.force_login(self.user)
|
|
2255
|
+
|
|
2256
|
+
def _mock_graph(self):
|
|
2257
|
+
fake_graph = Mock()
|
|
2258
|
+
fake_graph.source = "digraph {}"
|
|
2259
|
+
fake_graph.engine = "dot"
|
|
2260
|
+
|
|
2261
|
+
def pipe_side_effect(*args, **kwargs):
|
|
2262
|
+
fmt = kwargs.get("format") or (args[0] if args else None)
|
|
2263
|
+
if fmt == "svg":
|
|
2264
|
+
return '<svg xmlns="http://www.w3.org/2000/svg"></svg>'
|
|
2265
|
+
if fmt == "pdf":
|
|
2266
|
+
return b"%PDF-1.4 mock"
|
|
2267
|
+
raise AssertionError(f"Unexpected format: {fmt}")
|
|
2268
|
+
|
|
2269
|
+
fake_graph.pipe.side_effect = pipe_side_effect
|
|
2270
|
+
return fake_graph
|
|
2271
|
+
|
|
2272
|
+
def test_model_graph_renders_controls_and_download_link(self):
|
|
2273
|
+
url = reverse("admin-model-graph", args=["pages"])
|
|
2274
|
+
graph = self._mock_graph()
|
|
2275
|
+
with (
|
|
2276
|
+
patch("pages.views._build_model_graph", return_value=graph),
|
|
2277
|
+
patch("pages.views.shutil.which", return_value="/usr/bin/dot"),
|
|
2278
|
+
):
|
|
2279
|
+
response = self.client.get(url)
|
|
2280
|
+
|
|
2281
|
+
self.assertEqual(response.status_code, 200)
|
|
2282
|
+
self.assertContains(response, "data-model-graph")
|
|
2283
|
+
self.assertContains(response, 'data-graph-action="zoom-in"')
|
|
2284
|
+
self.assertContains(response, "Download PDF")
|
|
2285
|
+
self.assertIn("?format=pdf", response.context_data["download_url"])
|
|
2286
|
+
args, kwargs = graph.pipe.call_args
|
|
2287
|
+
self.assertEqual(kwargs.get("format"), "svg")
|
|
2288
|
+
self.assertEqual(kwargs.get("encoding"), "utf-8")
|
|
2289
|
+
|
|
2290
|
+
def test_model_graph_pdf_download(self):
|
|
2291
|
+
url = reverse("admin-model-graph", args=["pages"])
|
|
2292
|
+
graph = self._mock_graph()
|
|
2293
|
+
with (
|
|
2294
|
+
patch("pages.views._build_model_graph", return_value=graph),
|
|
2295
|
+
patch("pages.views.shutil.which", return_value="/usr/bin/dot"),
|
|
2296
|
+
):
|
|
2297
|
+
response = self.client.get(url, {"format": "pdf"})
|
|
2298
|
+
|
|
2299
|
+
self.assertEqual(response.status_code, 200)
|
|
2300
|
+
self.assertEqual(response["Content-Type"], "application/pdf")
|
|
2301
|
+
app_config = django_apps.get_app_config("pages")
|
|
2302
|
+
expected_slug = slugify(app_config.verbose_name) or app_config.label
|
|
2303
|
+
self.assertIn(
|
|
2304
|
+
f"{expected_slug}-model-graph.pdf", response["Content-Disposition"]
|
|
2305
|
+
)
|
|
2306
|
+
self.assertEqual(response.content, b"%PDF-1.4 mock")
|
|
2307
|
+
args, kwargs = graph.pipe.call_args
|
|
2308
|
+
self.assertEqual(kwargs.get("format"), "pdf")
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
class DatasetteTests(TestCase):
|
|
2312
|
+
def setUp(self):
|
|
2313
|
+
self.client = Client()
|
|
2314
|
+
User = get_user_model()
|
|
2315
|
+
self.user = User.objects.create_user(username="ds", password="pwd")
|
|
2316
|
+
Site.objects.update_or_create(id=1, defaults={"name": "Terminal"})
|
|
2317
|
+
|
|
2318
|
+
def test_datasette_auth_endpoint(self):
|
|
2319
|
+
resp = self.client.get(reverse("pages:datasette-auth"))
|
|
2320
|
+
self.assertEqual(resp.status_code, 401)
|
|
2321
|
+
self.client.force_login(self.user)
|
|
2322
|
+
resp = self.client.get(reverse("pages:datasette-auth"))
|
|
2323
|
+
self.assertEqual(resp.status_code, 200)
|
|
2324
|
+
|
|
2325
|
+
def test_navbar_includes_datasette_when_enabled(self):
|
|
2326
|
+
lock_dir = Path(settings.BASE_DIR) / "locks"
|
|
2327
|
+
lock_dir.mkdir(exist_ok=True)
|
|
2328
|
+
lock_file = lock_dir / "datasette.lck"
|
|
2329
|
+
try:
|
|
2330
|
+
lock_file.touch()
|
|
2331
|
+
resp = self.client.get(reverse("pages:index"))
|
|
2332
|
+
self.assertContains(resp, 'href="/data/"')
|
|
2333
|
+
finally:
|
|
2334
|
+
lock_file.unlink(missing_ok=True)
|
|
2335
|
+
|
|
2336
|
+
def test_admin_home_includes_datasette_button_when_enabled(self):
|
|
2337
|
+
lock_dir = Path(settings.BASE_DIR) / "locks"
|
|
2338
|
+
lock_dir.mkdir(exist_ok=True)
|
|
2339
|
+
lock_file = lock_dir / "datasette.lck"
|
|
2340
|
+
try:
|
|
2341
|
+
lock_file.touch()
|
|
2342
|
+
self.user.is_staff = True
|
|
2343
|
+
self.user.is_superuser = True
|
|
2344
|
+
self.user.save()
|
|
2345
|
+
self.client.force_login(self.user)
|
|
2346
|
+
resp = self.client.get(reverse("admin:index"))
|
|
2347
|
+
self.assertContains(resp, 'href="/data/"')
|
|
2348
|
+
self.assertContains(resp, ">Datasette<")
|
|
2349
|
+
finally:
|
|
2350
|
+
lock_file.unlink(missing_ok=True)
|
|
2351
|
+
|
|
2352
|
+
|
|
2353
|
+
class UserStorySubmissionTests(TestCase):
|
|
2354
|
+
def setUp(self):
|
|
2355
|
+
self.client = Client()
|
|
2356
|
+
self.url = reverse("pages:user-story-submit")
|
|
2357
|
+
User = get_user_model()
|
|
2358
|
+
self.user = User.objects.create_user(username="feedbacker", password="pwd")
|
|
2359
|
+
|
|
2360
|
+
def test_authenticated_submission_defaults_to_username(self):
|
|
2361
|
+
self.client.force_login(self.user)
|
|
2362
|
+
response = self.client.post(
|
|
2363
|
+
self.url,
|
|
2364
|
+
{
|
|
2365
|
+
"rating": 5,
|
|
2366
|
+
"comments": "Loved the experience!",
|
|
2367
|
+
"path": "/wizard/step-1/",
|
|
2368
|
+
"take_screenshot": "1",
|
|
2369
|
+
},
|
|
2370
|
+
)
|
|
2371
|
+
self.assertEqual(response.status_code, 200)
|
|
2372
|
+
self.assertEqual(response.json(), {"success": True})
|
|
2373
|
+
story = UserStory.objects.get()
|
|
2374
|
+
self.assertEqual(story.name, "feedbacker")
|
|
2375
|
+
self.assertEqual(story.rating, 5)
|
|
2376
|
+
self.assertEqual(story.path, "/wizard/step-1/")
|
|
2377
|
+
self.assertEqual(story.user, self.user)
|
|
2378
|
+
self.assertEqual(story.owner, self.user)
|
|
2379
|
+
self.assertTrue(story.is_user_data)
|
|
2380
|
+
self.assertTrue(story.take_screenshot)
|
|
2381
|
+
|
|
2382
|
+
def test_anonymous_submission_uses_provided_name(self):
|
|
2383
|
+
response = self.client.post(
|
|
2384
|
+
self.url,
|
|
2385
|
+
{
|
|
2386
|
+
"name": "Guest Reviewer",
|
|
2387
|
+
"rating": 3,
|
|
2388
|
+
"comments": "It was fine.",
|
|
2389
|
+
"path": "/status/",
|
|
2390
|
+
"take_screenshot": "on",
|
|
2391
|
+
},
|
|
2392
|
+
)
|
|
2393
|
+
self.assertEqual(response.status_code, 200)
|
|
2394
|
+
self.assertEqual(UserStory.objects.count(), 1)
|
|
2395
|
+
story = UserStory.objects.get()
|
|
2396
|
+
self.assertEqual(story.name, "Guest Reviewer")
|
|
2397
|
+
self.assertIsNone(story.user)
|
|
2398
|
+
self.assertIsNone(story.owner)
|
|
2399
|
+
self.assertEqual(story.comments, "It was fine.")
|
|
2400
|
+
self.assertTrue(story.take_screenshot)
|
|
2401
|
+
|
|
2402
|
+
def test_invalid_rating_returns_errors(self):
|
|
2403
|
+
response = self.client.post(
|
|
2404
|
+
self.url,
|
|
2405
|
+
{
|
|
2406
|
+
"rating": 7,
|
|
2407
|
+
"comments": "Way off the scale",
|
|
2408
|
+
"path": "/feedback/",
|
|
2409
|
+
"take_screenshot": "1",
|
|
2410
|
+
},
|
|
2411
|
+
)
|
|
2412
|
+
self.assertEqual(response.status_code, 400)
|
|
2413
|
+
data = response.json()
|
|
2414
|
+
self.assertFalse(UserStory.objects.exists())
|
|
2415
|
+
self.assertIn("rating", data.get("errors", {}))
|
|
2416
|
+
|
|
2417
|
+
def test_anonymous_submission_without_name_uses_fallback(self):
|
|
2418
|
+
response = self.client.post(
|
|
2419
|
+
self.url,
|
|
2420
|
+
{
|
|
2421
|
+
"rating": 2,
|
|
2422
|
+
"comments": "Could be better.",
|
|
2423
|
+
"path": "/feedback/",
|
|
2424
|
+
"take_screenshot": "1",
|
|
2425
|
+
},
|
|
2426
|
+
)
|
|
2427
|
+
self.assertEqual(response.status_code, 200)
|
|
2428
|
+
story = UserStory.objects.get()
|
|
2429
|
+
self.assertEqual(story.name, "Anonymous")
|
|
2430
|
+
self.assertIsNone(story.user)
|
|
2431
|
+
self.assertIsNone(story.owner)
|
|
2432
|
+
self.assertTrue(story.take_screenshot)
|
|
2433
|
+
|
|
2434
|
+
def test_submission_without_screenshot_request(self):
|
|
2435
|
+
response = self.client.post(
|
|
2436
|
+
self.url,
|
|
2437
|
+
{
|
|
2438
|
+
"rating": 4,
|
|
2439
|
+
"comments": "Skip the screenshot, please.",
|
|
2440
|
+
"path": "/feedback/",
|
|
2441
|
+
},
|
|
2442
|
+
)
|
|
2443
|
+
self.assertEqual(response.status_code, 200)
|
|
2444
|
+
story = UserStory.objects.get()
|
|
2445
|
+
self.assertFalse(story.take_screenshot)
|
|
2446
|
+
self.assertIsNone(story.owner)
|
|
2447
|
+
|
|
2448
|
+
|
|
2449
|
+
class UserStoryAdminActionTests(TestCase):
|
|
2450
|
+
def setUp(self):
|
|
2451
|
+
self.client = Client()
|
|
2452
|
+
self.factory = RequestFactory()
|
|
2453
|
+
User = get_user_model()
|
|
2454
|
+
self.admin_user = User.objects.create_superuser(
|
|
2455
|
+
username="admin",
|
|
2456
|
+
email="admin@example.com",
|
|
2457
|
+
password="pwd",
|
|
2458
|
+
)
|
|
2459
|
+
self.story = UserStory.objects.create(
|
|
2460
|
+
path="/",
|
|
2461
|
+
name="Feedback",
|
|
2462
|
+
rating=4,
|
|
2463
|
+
comments="Helpful notes",
|
|
2464
|
+
take_screenshot=True,
|
|
2465
|
+
)
|
|
2466
|
+
self.admin = UserStoryAdmin(UserStory, admin.site)
|
|
2467
|
+
|
|
2468
|
+
def _build_request(self):
|
|
2469
|
+
request = self.factory.post("/admin/pages/userstory/")
|
|
2470
|
+
request.user = self.admin_user
|
|
2471
|
+
request.session = self.client.session
|
|
2472
|
+
setattr(request, "_messages", FallbackStorage(request))
|
|
2473
|
+
return request
|
|
2474
|
+
|
|
2475
|
+
@patch("pages.models.github_issues.create_issue")
|
|
2476
|
+
def test_create_github_issues_action_updates_issue_fields(self, mock_create_issue):
|
|
2477
|
+
response = MagicMock()
|
|
2478
|
+
response.json.return_value = {
|
|
2479
|
+
"html_url": "https://github.com/example/repo/issues/123",
|
|
2480
|
+
"number": 123,
|
|
2481
|
+
}
|
|
2482
|
+
mock_create_issue.return_value = response
|
|
2483
|
+
|
|
2484
|
+
request = self._build_request()
|
|
2485
|
+
queryset = UserStory.objects.filter(pk=self.story.pk)
|
|
2486
|
+
self.admin.create_github_issues(request, queryset)
|
|
2487
|
+
|
|
2488
|
+
self.story.refresh_from_db()
|
|
2489
|
+
self.assertEqual(self.story.github_issue_number, 123)
|
|
2490
|
+
self.assertEqual(
|
|
2491
|
+
self.story.github_issue_url,
|
|
2492
|
+
"https://github.com/example/repo/issues/123",
|
|
2493
|
+
)
|
|
2494
|
+
|
|
2495
|
+
mock_create_issue.assert_called_once()
|
|
2496
|
+
args, kwargs = mock_create_issue.call_args
|
|
2497
|
+
self.assertIn("Feedback for", args[0])
|
|
2498
|
+
self.assertIn("**Rating:**", args[1])
|
|
2499
|
+
self.assertEqual(kwargs.get("labels"), ["feedback"])
|
|
2500
|
+
self.assertEqual(
|
|
2501
|
+
kwargs.get("fingerprint"), f"user-story:{self.story.pk}"
|
|
2502
|
+
)
|
|
2503
|
+
|
|
2504
|
+
@patch("pages.models.github_issues.create_issue")
|
|
2505
|
+
def test_create_github_issues_action_skips_existing_issue(self, mock_create_issue):
|
|
2506
|
+
self.story.github_issue_url = "https://github.com/example/repo/issues/5"
|
|
2507
|
+
self.story.github_issue_number = 5
|
|
2508
|
+
self.story.save(update_fields=["github_issue_url", "github_issue_number"])
|
|
2509
|
+
|
|
2510
|
+
request = self._build_request()
|
|
2511
|
+
queryset = UserStory.objects.filter(pk=self.story.pk)
|
|
2512
|
+
self.admin.create_github_issues(request, queryset)
|
|
2513
|
+
|
|
2514
|
+
mock_create_issue.assert_not_called()
|
|
2515
|
+
|
|
2516
|
+
|
|
2517
|
+
class ClientReportLiveUpdateTests(TestCase):
|
|
2518
|
+
def setUp(self):
|
|
2519
|
+
self.client = Client()
|
|
2520
|
+
|
|
2521
|
+
def test_client_report_includes_interval(self):
|
|
2522
|
+
resp = self.client.get(reverse("pages:client-report"))
|
|
2523
|
+
self.assertEqual(resp.context["request"].live_update_interval, 5)
|
|
2524
|
+
self.assertContains(resp, "setInterval(() => location.reload()")
|
|
2525
|
+
|
|
2526
|
+
|
|
2527
|
+
class ScreenshotSpecInfrastructureTests(TestCase):
|
|
2528
|
+
def test_runner_creates_outputs_and_cleans_old_samples(self):
|
|
2529
|
+
spec = ScreenshotSpec(slug="spec-test", url="/")
|
|
2530
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
2531
|
+
temp_dir = Path(tmp)
|
|
2532
|
+
screenshot_path = temp_dir / "source.png"
|
|
2533
|
+
screenshot_path.write_bytes(b"fake")
|
|
2534
|
+
ContentSample.objects.create(
|
|
2535
|
+
kind=ContentSample.IMAGE,
|
|
2536
|
+
path="old.png",
|
|
2537
|
+
method="spec:old",
|
|
2538
|
+
hash="old-hash",
|
|
2539
|
+
)
|
|
2540
|
+
ContentSample.objects.filter(hash="old-hash").update(
|
|
2541
|
+
created_at=timezone.now() - timedelta(days=8)
|
|
2542
|
+
)
|
|
2543
|
+
with (
|
|
2544
|
+
patch(
|
|
2545
|
+
"pages.screenshot_specs.base.capture_screenshot",
|
|
2546
|
+
return_value=screenshot_path,
|
|
2547
|
+
) as capture_mock,
|
|
2548
|
+
patch(
|
|
2549
|
+
"pages.screenshot_specs.base.save_screenshot", return_value=None
|
|
2550
|
+
) as save_mock,
|
|
2551
|
+
):
|
|
2552
|
+
with ScreenshotSpecRunner(temp_dir) as runner:
|
|
2553
|
+
result = runner.run(spec)
|
|
2554
|
+
self.assertTrue(result.image_path.exists())
|
|
2555
|
+
self.assertTrue(result.base64_path.exists())
|
|
2556
|
+
self.assertEqual(ContentSample.objects.filter(hash="old-hash").count(), 0)
|
|
2557
|
+
capture_mock.assert_called_once()
|
|
2558
|
+
save_mock.assert_called_once_with(screenshot_path, method="spec:spec-test")
|
|
2559
|
+
|
|
2560
|
+
def test_runner_respects_manual_reason(self):
|
|
2561
|
+
spec = ScreenshotSpec(slug="manual-spec", url="/", manual_reason="hardware")
|
|
2562
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
2563
|
+
with ScreenshotSpecRunner(Path(tmp)) as runner:
|
|
2564
|
+
with self.assertRaises(ScreenshotUnavailable):
|
|
2565
|
+
runner.run(spec)
|
|
2566
|
+
|
|
2567
|
+
|
|
2568
|
+
class CaptureUIScreenshotsCommandTests(TestCase):
|
|
2569
|
+
def tearDown(self):
|
|
2570
|
+
registry.unregister("manual-cmd")
|
|
2571
|
+
registry.unregister("auto-cmd")
|
|
2572
|
+
|
|
2573
|
+
def test_manual_spec_emits_warning(self):
|
|
2574
|
+
spec = ScreenshotSpec(slug="manual-cmd", url="/", manual_reason="manual")
|
|
2575
|
+
registry.register(spec)
|
|
2576
|
+
out = StringIO()
|
|
2577
|
+
call_command("capture_ui_screenshots", "--spec", spec.slug, stdout=out)
|
|
2578
|
+
self.assertIn("Skipping manual screenshot", out.getvalue())
|
|
2579
|
+
|
|
2580
|
+
def test_command_invokes_runner(self):
|
|
2581
|
+
spec = ScreenshotSpec(slug="auto-cmd", url="/")
|
|
2582
|
+
registry.register(spec)
|
|
2583
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
2584
|
+
tmp_path = Path(tmp)
|
|
2585
|
+
image_path = tmp_path / "auto-cmd.png"
|
|
2586
|
+
base64_path = tmp_path / "auto-cmd.base64"
|
|
2587
|
+
image_path.write_bytes(b"fake")
|
|
2588
|
+
base64_path.write_text("Zg==", encoding="utf-8")
|
|
2589
|
+
runner = Mock()
|
|
2590
|
+
runner.__enter__ = Mock(return_value=runner)
|
|
2591
|
+
runner.__exit__ = Mock(return_value=None)
|
|
2592
|
+
runner.run.return_value = SimpleNamespace(
|
|
2593
|
+
image_path=image_path,
|
|
2594
|
+
base64_path=base64_path,
|
|
2595
|
+
sample=None,
|
|
2596
|
+
)
|
|
2597
|
+
with patch(
|
|
2598
|
+
"pages.management.commands.capture_ui_screenshots.ScreenshotSpecRunner",
|
|
2599
|
+
return_value=runner,
|
|
2600
|
+
) as runner_cls:
|
|
2601
|
+
out = StringIO()
|
|
2602
|
+
call_command(
|
|
2603
|
+
"capture_ui_screenshots",
|
|
2604
|
+
"--spec",
|
|
2605
|
+
spec.slug,
|
|
2606
|
+
"--output-dir",
|
|
2607
|
+
tmp_path,
|
|
2608
|
+
stdout=out,
|
|
2609
|
+
)
|
|
2610
|
+
runner_cls.assert_called_once()
|
|
2611
|
+
runner.run.assert_called_once_with(spec)
|
|
2612
|
+
self.assertIn("Captured 'auto-cmd'", out.getvalue())
|