summaryrefslogtreecommitdiffstats
path: root/core/TESTS/tests.py
blob: 57c15badf275585b2e3ef97158b2c9cae748ced8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
"""
We are using unittest for troggle.

Note that the database has not been parsed from the source files when these tests are run,
so any path that relies on data being in the database will fail.

The simple redirections to files which exist, e.g. in
/expoweb/
/photos/
etc. will test fine.

But paths like this:
/survey_scans/
/caves/
which rely on database resolution will fail unless a fixture has been set up for
them.

https://docs.djangoproject.com/en/dev/topics/testing/tools/
"""


todo = """ - ADD TESTS when we are redirecting /expofiles/ to a remote file-delivering site

- Add test for running cavern to produce a .3d file

- Add tests for editing the TXT files

- add "author" tests for the git add and commit stuff for uploaded files, inc on DEVSERVER or not
"""

import re
from http import HTTPStatus

from django.test import Client, TestCase


# class SimplePageTest(unittest.TestCase):
class PageTests(TestCase):
    """These tests may appear to be redundant, but in fact they exercise different bits of code. The urls.py
    dispatcher is sending these URLs view via different 'view' handlers, and they all need verifying.
    """

    @classmethod
    def setUpTestData(cls):
        # Set up data for the whole TestCase
        # cls.foo = Foo.objects.create(bar="Test")
        # Some test using self.foo in tests below..
        # read in some SQL ?
        pass

    def setUp(self):
        # Every test needs a client.
        self.client = Client()

    def test_expoweb_root(self):
        response = self.client.get("")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)
        ph = r"CUCC in Austria"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_root_slash(self):
        response = self.client.get("/")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)
        ph = r"CUCC in Austria"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_paths(self):
        response = self.client.get("/pathsreport")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"This report is generated from"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_dir(self):
        response = self.client.get("/handbook")
        response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.FOUND)  # 302 directory, so redirects to /index.htm

    def test_expoweb_dirslash(self):
        response = self.client.get("/handbook/")
        response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.FOUND)  # 302 directory, so redirects to /index.htm

    def test_expoweb_dir_no_index(self):
        response = self.client.get("/handbook/troggle")
        content = response.content.decode()
        # with open('testresponse.html','w') as tr:
            # tr.writelines(content)
        self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
        ph = r"Page not found 'handbook/troggle/index.html'"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_dir_with_index_htm(self):
        response = self.client.get("/years/1999/index.htm")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)  # directory, so redirects to /index.htm
        ph = r"Passage descriptions for 1999"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_dir_with_index_html(self):
        response = self.client.get("/years/2015/index.html")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)  # directory, so redirects to /index.htm
        ph = r"Things left at top camp 2014"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_dir_with_index2(self):
        response = self.client.get("/handbook/index.htm")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)
        ph = r"Introduction to expo"
        phmatch = re.search(ph, content)
        # print("\n ! - test_expoweb_dir_with_index2\n{}\n{}".format(response.reason_phrase, content))
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_htm(self):
        response = self.client.get("/handbook/index.htm")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)
        ph = r"Introduction to expo"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_notfound(self):
        response = self.client.get("/handbook/_test_zyxxypqrqx.html")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
        ph = r"<h1>Page not found"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_no_dir(self):
        # slash where there should not be one
        response = self.client.get("/handbook/_test_zyxxypqrqx/")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"<h1>Directory not found"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_troggle_default(self):
        # default page after logon
        response = self.client.get("/troggle")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"expeditions the club has undertaken"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_troggle_default_slash(self):
        response = self.client.get("/troggle/")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"<h1>Directory not found"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_expoweb_via_areaid(self):
        # the dispatcher takes a detour via the cave renering procedure for this
        response = self.client.get("/guidebook/t/via201.jpg")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        self.assertEqual(len(response.content), 6057)

    def test_cave_kataster_not_found(self):
        # database not loaded, so no caves found; so looks for a generic expopage and fails
        # NEEDS TO BE REDONE AFETR cave id rewriting removed after the data is fixed in all teh cave description
        # pages that link to photos
        response = self.client.get("/1234/115.htm")
        self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
        content = response.content.decode()
        ph = r"Page not found '1234/115.htm'"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_caves_page(self):
        # Throws up lots of cave error msgs because it is looking at something which is not loaded for the tests
        # but the test itself does not fail
        response = self.client.get("/caves")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"Cave Number Index - kept updated"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_caves_page_kataster_not_found(self):
        response = self.client.get("/caves")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"115"
        phmatch = re.search(ph, content)
        self.assertIsNone(phmatch, "Unexpectedly found unexpected text: '" + ph + "'")

    def test_page_ss(self):
        response = self.client.get("/survey_scans")
        self.assertEqual(response.status_code, HTTPStatus.OK)

        ph = r"All Survey scans folders "
        content = response.content.decode()
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_admin(self):
        # see the login page
        response = self.client.get("/admin/login/")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)
        ph = r'<h1 id="site-name">Troggle database administration</h1>'
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_admindocs_exped(self):
        # Get redirected to login page
        response = self.client.get("/admin/doc/models/core.expedition/")
        response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.FOUND) # 302

    def test_page_expofiles_root_dir(self):
        # Root expofiles - odd interaction with url parsing so needs testing
        response = self.client.get("/expofiles")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()
            for ph in [
                r'a href="/expofiles/geotiffsurveys">/geotiffsurveys/',
                r'<a href="/expofiles/photos">/photos/',
                r'<a href="/expofiles/surveyscans">/surveyscans/',
            ]:
                phmatch = re.search(ph, content)
                self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_expofiles_root_slash_dir(self):
        # Root expofiles - odd interaction with url parsing so needs testing
        response = self.client.get("/expofiles/")
        if response.status_code != HTTPStatus.OK: # 200
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND: # 302
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()
            for ph in [
                r'a href="/expofiles/geotiffsurveys">/geotiffsurveys/',
                r'<a href="/expofiles/photos">/photos/',
                r'<a href="/expofiles/surveyscans">/surveyscans/',
            ]:
                phmatch = re.search(ph, content)
                self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_expofiles_badness(self):
        # should display expofiles directory contents not its parent
        response = self.client.get("/expofiles/99badness99")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()
            for ph in [
                r'a href="/expofiles/geotiffsurveys">/geotiffsurveys/',
                r'<a href="/expofiles/photos">/photos/',
                r'<a href="/expofiles/surveyscans">/surveyscans/',
            ]:
                phmatch = re.search(ph, content)
                self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_expofiles_docs_dir(self):
        # Flat file tests.
        response = self.client.get("/expofiles/documents/")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()
            for ph in [
                r'a href="/expofiles/documents/bier-tent-instructions.pdf">bier-tent-instructions.pdf',
                r'a href="/expofiles/documents/boc.pdf">boc.pdf',
                r'a href="/expofiles/documents/idiots-guide-expo-git.pdf"',
            ]:
                phmatch = re.search(ph, content)
                self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_survey_scans_dir(self):
        # Flat file tests.
        response = self.client.get("/expofiles/surveyscans")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()
            for ph in [
                r'<a href="/expofiles/surveyscans/2004">/2004/',
                r'<a href="/expofiles/surveyscans/1989LUSS">/1989LUSS/',
                r'<a href="/expofiles/surveyscans/2018">/2018',
            ]:
                phmatch = re.search(ph, content)
                self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_folk(self):
        # This page is separately generated, so it has the full data content
        response = self.client.get("/folk/index.htm")
        content = response.content.decode()
        self.assertEqual(response.status_code, HTTPStatus.OK)
        for ph in [
            r"involves some active contribution",
            r"Naomi Griffiths",
            r"Gail Smith",
            r"Phil Wigglesworth",
            r"A more obscure record of longest gap between expos has",
        ]:
            phmatch = re.search(ph, content)
            self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_expofile_documents(self):
        # this gets an empty page as the database has not been loaded
        response = self.client.get("/expofiles/documents")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()
            ph = r"notice_generale_cordes_courant"
            phmatch = re.search(ph, content)
            self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_expofile_documents_slash(self):
        # this gets an empty page as the database has not been loaded
        response = self.client.get("/expofiles/documents/")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()
            ph = r"notice_generale_cordes_courant"
            phmatch = re.search(ph, content)
            self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_expofile_document_loeffler_pdf(self):
        # Flat file tests.
        response = self.client.get("/expofiles/documents/surveying/tunnel-loefflerCP35-only.pdf")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertEqual(len(response.content), 2299270)

    def test_page_expofile_document_rope_pdf(self):
        # Flat file tests.
        response = self.client.get("/expofiles/documents/ropes/rope-age-agm-2019.pdf")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertEqual(len(response.content), 76197)

    def test_page_expofile_document_png(self):
        # Flat file tests.
        response = self.client.get("/expofiles/documents/callout-2012.png")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertEqual(len(response.content), 69921)

    def test_page_expofile_writeup(self):
        # Flat file tests.
        response = self.client.get("/expofiles/writeups/1982/logbook1982.pdf")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertEqual(len(response.content), 12915413)

    def test_page_site_media_ok(self):
        # Flat file tests.
        response = self.client.get("/site_media/surveyHover.gif")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertEqual(len(response.content), 39482)  # need to check it is not just an error page

    def test_page_site_media_css(self):
        # Flat file tests.
        response = self.client.get("/site_media/css/trog3.css")
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            content = response.content.decode()  # need to check it is not just an error page
            ph = r"This text is used by the test system to determine that trog3.css loaded correctly"
            phmatch = re.search(ph, content)
            self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_photos_ok(self):
        # Flat file tests.
        response = self.client.get("/photos/2018/PhilipSargent/corin.jpg")  # exists
        if response.status_code != HTTPStatus.OK:
            self.assertEqual(response.status_code, HTTPStatus.FOUND)
        if response.status_code != HTTPStatus.FOUND:
            self.assertEqual(response.status_code, HTTPStatus.OK)
            self.assertEqual(len(response.content), 67487)  # need to check it is not just an error page

    def test_page_photos_not_ok(self):
        # Flat file tests.
        response = self.client.get("/photos/2018/PhilipSargent/_corin.jpeg")  # does not exist
        self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
        content = response.content.decode()
        ph = r"<title>Page not found '2018/PhilipSargent/_corin.jpeg'</title>"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_photos_dir(self):
        # Flat file tests.
        response = self.client.get("/photos/2018/PhilipSargent/")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"Directory not displayed"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_survey_scans_empty(self):
        # this gets an empty page as the database has not been loaded
        response = self.client.get("/survey_scans")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"contains the scanned original in-cave survey notes and sketches"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_dwgdataraw_empty(self):
        # this gets an empty page as the database has not been loaded
        response = self.client.get("/dwgdataraw/")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"<h1>Directory not found"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_dwgallfiles_empty(self):
        # this gets an empty page as the database has not been loaded
        response = self.client.get("/dwgfiles")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        for ph in [
            r"All Tunnel and Therion files",
            r"<th>Wallets</th><th>Scan files in the wallets</th><th>Frames</th></tr>",
        ]:
            phmatch = re.search(ph, content)
            self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_dwgallfiles_empty_slash(self):
        # this gets an empty page as the database has not been loaded
        response = self.client.get("/dwgfiles")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        for ph in [
            r"All Tunnel and Therion files",
            r"<th>Wallets</th><th>Scan files in the wallets</th><th>Frames</th></tr>",
        ]:
            phmatch = re.search(ph, content)
            self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_page_slash_empty(self):
        # tslash where there should not be one
        response = self.client.get("/expedition/1979/")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"<h1>Directory not found"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_not_found_survexfile_cave(self):
        response = self.client.get("/survexfile/not_a_real_cave_number")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"Cave Identifier not found in database"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")


    def test_dataissues(self):
        # Needs another test with test data
        response = self.client.get("/dataissues")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"as well as these import/parsing issues"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_therionissues(self):
        # Needs another test with test data
        response = self.client.get("/therionissues")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"! Un-parsed image filename"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_surveximport(self):
        # Needs another test with test data
        response = self.client.get("/surveximport")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        # with open('_test_response.html', 'w') as f:
            # f.write(content)
        ph = r"The number at the left-hand margin is the depth"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_survexdebug(self):
        # Needs another test with test data
        response = self.client.get("/survexdebug")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = r"Running list of warnings during import"
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")

    def test_stations(self):
        # Needs another test with test data
        response = self.client.get("/stations")
        self.assertEqual(response.status_code, HTTPStatus.OK)
        content = response.content.decode()
        ph = "<tr><th>Survex Station</th><th>x "
        phmatch = re.search(ph, content)
        self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")


# ADD TESTS when we are redirecting /expofiles/ to get the actual files using e.g.
# import requests
# page = requests.get("http://dataquestio.github.io/web-scraping-pages/simple.html")

# these need a fixture to load the datbase before they will pass
# we also need tests for invalid queries to check that error pages are right

# def test_page_survey_scans_khplan2_png(self):
# # this has an error as the database has not been loaded yet in the tests
# response = self.client.get('/survey_scans/smkhs/khplan2.png')
# if response.status_code != HTTPStatus.OK:
# self.assertEqual(response.status_code, HTTPStatus.FOUND)
# if response.status_code != HTTPStatus.FOUND:
# self.assertEqual(response.status_code, HTTPStatus.OK)
# self.assertEqual(len(response.content), 823304) # fails, but is working manually!

# def test_page_dwgdataraw_107sketch_xml(self):
# # this has an error as the database has not been loaded yet in the tests
# response = self.client.get('/dwgdataraw/107/107sketch-v2.xml')
# if response.status_code != HTTPStatus.OK:
# self.assertEqual(response.status_code, HTTPStatus.FOUND)
# if response.status_code != HTTPStatus.FOUND:
# self.assertEqual(response.status_code, HTTPStatus.OK)
# content = response.content.decode()
# for ph in [ r'tunneldate="2014-08-21 11:34:00"',
# r'<sketchsubset subname="Caves of the Loser Plateau"/>',
# r'sfsketch="ollyjen107drawings',
# r'sfsketch="surveyscans/2014/2014#01',
# r'aa-js-plan.png"' ]:
# phmatch    = re.search(ph, content)
# self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")


# database not loaded yet:
# response = self.client.get('/survey_scans/1991surveybook/page0002.png')
# response = self.client.get('/survey_scans/1991surveybook/')
# content = response.content.decode()
# print(content)
# png93    = re.search(r'/page0093.png">page0093.png</a></td>', content)