tests for new /site_media/ management

This commit is contained in:
Philip Sargent 2021-03-31 23:41:46 +01:00
parent 2690203912
commit 8f790309ce
3 changed files with 74 additions and 26 deletions

View File

@ -207,6 +207,9 @@ class PageTests(TestCase):
def test_page_expofiles_dir(self):
# Flat file tests.
response = self.client.get('/expofiles/')
if response.status_code != 200:
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
content = response.content.decode()
for ph in [ r'a href="/expofiles/geotiffsurveys">/geotiffsurveys/',
@ -218,6 +221,9 @@ class PageTests(TestCase):
def test_page_survey_scans_dir(self):
# Flat file tests.
response = self.client.get('/expofiles/surveyscans')
if response.status_code != 200:
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
content = response.content.decode()
for ph in [ r'<a href="/expofiles/surveyscans/2004">/2004/',
@ -242,6 +248,9 @@ class PageTests(TestCase):
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 != 200:
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
content = response.content.decode()
ph = r'notice_generale_cordes_courant'
@ -251,6 +260,9 @@ class PageTests(TestCase):
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 != 200:
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
content = response.content.decode()
ph = r'notice_generale_cordes_courant'
@ -295,6 +307,42 @@ class PageTests(TestCase):
self.assertEqual(response.status_code, 200)
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 != 200:
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.content), 39482 )
def test_page_photos_ok(self):
# Flat file tests.
response = self.client.get('/photos/2018/PhilipSargent/corin.jpg')
if response.status_code != 200:
self.assertEqual(response.status_code, 302)
if response.status_code != 302:
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.content), 67487 )
def test_page_photos_not_ok(self):
# Flat file tests.
response = self.client.get('/photos/2018/PhilipSargent/corin.jpeg')
self.assertEqual(response.status_code, 200)
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, 200)
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/')

View File

@ -29,7 +29,7 @@ from credentials import EXPOUSERPASS
from credentials import EMAIL_HOST_PASSWORD
SERVERPORT = '8000'
EXPOFILESREMOTE = False # if True, then re-routes urls in expofiles to remote sever
EXPOFILESREMOTE = False # if True, then re-routes urls in expofiles to remote sever. Tests are then less accurate.
#SECURE_SSL_REDIRECT = True # breaks 7 tests in test suite 301 not 200 (or 302) and runserver fails completely
# --------------------- MEDIA redirections BEGIN ---------------------