summaryrefslogtreecommitdiffstats
path: root/core/TESTS/tests.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-03-31 20:18:46 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2021-03-31 20:18:46 +0100
commite1cf43c260c75b3e047d02c49d8e26b2bb14e153 (patch)
tree08a432cacd9b312b213b16570d087bf85044468e /core/TESTS/tests.py
parenta6ed0a964e8d3c99eff918d1fbe1abbd6c222460 (diff)
downloadtroggle-e1cf43c260c75b3e047d02c49d8e26b2bb14e153.tar.gz
troggle-e1cf43c260c75b3e047d02c49d8e26b2bb14e153.tar.bz2
troggle-e1cf43c260c75b3e047d02c49d8e26b2bb14e153.zip
trailing slashes fixed
Diffstat (limited to 'core/TESTS/tests.py')
-rw-r--r--core/TESTS/tests.py141
1 files changed, 122 insertions, 19 deletions
diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py
index 610149e..852fb08 100644
--- a/core/TESTS/tests.py
+++ b/core/TESTS/tests.py
@@ -12,10 +12,10 @@ 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/3.0/topics/testing/tools/
"""
import unittest
@@ -23,11 +23,6 @@ import re
from django.test import TestCase, SimpleTestCase, Client
class SimpleTest(SimpleTestCase):
- def test_basic_addition(self):
- """
- Tests that 1 + 1 always equals 2.
- """
- self.assertEqual(1 + 1, 2)
def test_test_setting(self):
from django.conf import settings
self.assertEqual(settings.EMAIL_BACKEND, 'django.core.mail.backends.locmem.EmailBackend')
@@ -109,26 +104,105 @@ class PageTests(TestCase):
# 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, 200)
+ ph = r'CUCC in Austria'
+ 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/')
+ def test_expoweb_root(self):
+ response = self.client.get('')
+ content = response.content.decode()
+ self.assertEqual(response.status_code, 200)
+ 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, 200)
- h1 = re.search(r'<h1 id="site-name">Troggle administration</h1>', content)
+ ph = r'CUCC in Austria'
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
- def test_page_admindocs(self):
- response = self.client.get('/admin/login/models/')
+ def test_expoweb_dir(self):
+ response = self.client.get('/handbook')
content = response.content.decode()
self.assertEqual(response.status_code, 200)
- h1 = re.search(r'<h1>Model documentation</h1>', content)
+ ph = r'Introduction to expo'
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+
+ def test_expoweb_dirslash(self):
+ response = self.client.get('/handbook/')
+ content = response.content.decode()
+ self.assertEqual(response.status_code, 200)
+ ph = r'Introduction to expo'
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+
+ def test_expoweb_dir_no_index(self):
+ response = self.client.get('/handbook/troggle')
+ content = response.content.decode()
+ self.assertEqual(response.status_code, 200)
+ 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_htm(self):
+ response = self.client.get('/handbook/index.htm')
+ content = response.content.decode()
+ self.assertEqual(response.status_code, 200)
+ 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/zyxxypqrqx.html')
+ content = response.content.decode()
+ self.assertEqual(response.status_code, 200)
+ 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/zyxxypqrqx/')
+ self.assertEqual(response.status_code, 200)
+ 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_cave_kataster_not_found(self):
+ # database not loaded, so no caves found
+ response = self.client.get('/cave/115')
+ self.assertEqual(response.status_code, 200)
+ content = response.content.decode()
+ ph = r"Cave not found in database"
+ 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, 200)
+ ph = r'<h1 id="site-name">Troggle 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/')
content = response.content.decode()
self.assertEqual(response.status_code, 302)
- h1 = re.search(r'<td>logbookentry_set.all</td>', content)
def test_page_expofiles_dir(self):
# Flat file tests.
@@ -165,6 +239,26 @@ class PageTests(TestCase):
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')
+ self.assertEqual(response.status_code, 200)
+ 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/')
+ self.assertEqual(response.status_code, 200)
+ 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')
@@ -172,7 +266,7 @@ class PageTests(TestCase):
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 2299270) # fails, but is working manually!
+ self.assertEqual(len(response.content), 2299270)
def test_page_expofile_document_rope_pdf(self):
# Flat file tests.
@@ -181,7 +275,7 @@ class PageTests(TestCase):
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 76197) # fails, but is working manually!
+ self.assertEqual(len(response.content), 76197)
def test_page_expofile_document_png(self):
# Flat file tests.
@@ -190,7 +284,7 @@ class PageTests(TestCase):
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 69921) # fails, but is working manually!
+ self.assertEqual(len(response.content), 69921)
def test_page_expofile_writeup(self):
# Flat file tests.
@@ -199,7 +293,7 @@ class PageTests(TestCase):
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 12915413) # fails, but is working manually!
+ self.assertEqual(len(response.content), 12915413)
def test_page_survey_scans_empty(self):
# this gets an empty page as the database has not been loaded
@@ -215,7 +309,16 @@ class PageTests(TestCase):
response = self.client.get('/tunneldataraw/')
self.assertEqual(response.status_code, 200)
content = response.content.decode()
- ph = r'<h1>Page not found tunneldataraw/</h1>'
+ ph = r"<h1>Directory not found"
+ 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, 200)
+ content = response.content.decode()
+ ph = r"<h1>Directory not found"
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")