summaryrefslogtreecommitdiffstats
path: root/core/TESTS
diff options
context:
space:
mode:
Diffstat (limited to 'core/TESTS')
-rw-r--r--core/TESTS/test_imports.py158
-rw-r--r--core/TESTS/tests.py532
-rw-r--r--core/TESTS/tests_caves.py193
-rw-r--r--core/TESTS/tests_logins.py437
4 files changed, 693 insertions, 627 deletions
diff --git a/core/TESTS/test_imports.py b/core/TESTS/test_imports.py
index e0f420d..99d9a30 100644
--- a/core/TESTS/test_imports.py
+++ b/core/TESTS/test_imports.py
@@ -27,36 +27,44 @@ from django.test import Client, SimpleTestCase, TestCase
class SimpleTest(SimpleTestCase):
def test_test_setting(self):
- from django.conf import settings
- self.assertEqual(settings.EMAIL_BACKEND, 'django.core.mail.backends.locmem.EmailBackend')
+ from django.conf import settings
+
+ self.assertEqual(settings.EMAIL_BACKEND, "django.core.mail.backends.locmem.EmailBackend")
import troggle.settings as settings
+
def test_import_TroggleModel(self):
from troggle.core.models.troggle import TroggleModel
+
def test_import_Cave(self):
from troggle.core.models.caves import Cave
+
def test_import_parsers_surveys(self):
- #from PIL import Image
+ # from PIL import Image
from functools import reduce
from troggle.core.utils import save_carefully
+
def test_import_parsers_survex(self):
import troggle.core.models.caves as models_caves
import troggle.core.models.survex as models_survex
import troggle.core.models.troggle as models
import troggle.settings as settings
- from troggle.core.views import (caves, drawings, other, scans,
- statistics, survex, uploads)
+ from troggle.core.views import caves, drawings, other, scans, statistics, survex, uploads
from troggle.core.views.caves import cavepage, ent
from troggle.core.views.other import frontpage
from troggle.parsers.people import GetPersonExpeditionNameLookup
+
def test_import_views_uploads(self):
from troggle.core.views.uploads import dwgupload, scanupload
+
def test_import_parsers_QMs(self):
from troggle.core.models.logbooks import QM
+
def test_import_parsers_people(self):
from html import unescape
from unidecode import unidecode
+
def test_import_parsers_logbooks(self):
from django.template.defaultfilters import slugify
from django.utils.timezone import get_current_timezone, make_aware
@@ -64,6 +72,7 @@ class SimpleTest(SimpleTestCase):
from parsers.people import GetPersonExpeditionNameLookup
from troggle.core.models.logbooks import CaveSlug, QM, LogbookEntry, PersonLogEntry
from troggle.core.models.troggle import DataIssue, Expedition
+
def test_import_core_views_caves(self):
from django.conf import settings
from django.contrib.auth.decorators import login_required
@@ -71,13 +80,11 @@ class SimpleTest(SimpleTestCase):
from django.shortcuts import get_object_or_404, render
import troggle.core.views.expo
- from troggle.core.forms import (CaveAndEntranceFormSet, CaveForm,
- EntranceForm, EntranceLetterForm)
- from troggle.core.models.caves import (Area, Cave, CaveAndEntrance,
- Entrance,
- EntranceSlug, SurvexStation)
+ from troggle.core.forms import CaveAndEntranceFormSet, CaveForm, EntranceForm, EntranceLetterForm
+ from troggle.core.models.caves import Area, Cave, CaveAndEntrance, Entrance, EntranceSlug, SurvexStation
from troggle.core.models.troggle import Expedition
from troggle.core.views.auth import login_required_if_public
+
def test_import_parsers_mix(self):
import troggle.parsers.caves
import troggle.parsers.drawings
@@ -87,7 +94,8 @@ class SimpleTest(SimpleTestCase):
import troggle.parsers.scans
import troggle.parsers.survex
import troggle.settings
- from troggle.parsers.logbooks import GetCaveLookup
+ from troggle.parsers.logbooks import GetCaveLookup
+
def test_import_imports(self):
from django.contrib.auth.models import User
from django.core import management
@@ -107,25 +115,33 @@ class SimpleTest(SimpleTestCase):
from troggle.core.views import caves, other, statistics, survex
from troggle.core.views.auth import expologin, expologout
from troggle.core.views.caves import cavepage, ent
- from troggle.core.views.expo import (editexpopage, expofiles_redirect,
- expofilessingle, expopage, map,
- mapfile, mediapage)
- from troggle.core.views.logbooks import (Expeditions_jsonListView,
- Expeditions_tsvListView,
- expedition,
- get_logbook_entries,
- get_people, logbookentry,
- notablepersons, person,
- personexpedition)
+ from troggle.core.views.expo import (
+ editexpopage,
+ expofiles_redirect,
+ expofilessingle,
+ expopage,
+ map,
+ mapfile,
+ mediapage,
+ )
+ from troggle.core.views.logbooks import (
+ Expeditions_jsonListView,
+ Expeditions_tsvListView,
+ expedition,
+ get_logbook_entries,
+ get_people,
+ logbookentry,
+ notablepersons,
+ person,
+ personexpedition,
+ )
from troggle.core.views.other import controlpanel
from troggle.core.views.prospect import prospecting, prospecting_image
- from troggle.core.views.statistics import (dataissues, pathsreport,
- stats)
- from troggle.core.views.survex import (survexcavesingle,
- survexcaveslist, svx)
+ from troggle.core.views.statistics import dataissues, pathsreport, stats
+ from troggle.core.views.survex import survexcavesingle, survexcaveslist, svx
-class SubprocessTest(TestCase):
+class SubprocessTest(TestCase):
@classmethod
def setUpTestData(cls):
pass
@@ -137,91 +153,103 @@ class SubprocessTest(TestCase):
pass
def test_utf8(self):
- '''Expects that utf8 is the default encoding when opening files
- '''
+ """Expects that utf8 is the default encoding when opening files"""
import locale
import sys
- self.assertTrue( sys.getdefaultencoding() == "utf-8", f'{sys.getdefaultencoding()} - UTF8 error in getdefaultencoding')
- self.assertTrue( sys.getfilesystemencoding() == "utf-8", f'{sys.getfilesystemencoding()} - UTF8 error in getfilesystemencoding')
- self.assertTrue( locale.getdefaultlocale()[1] == "UTF-8", f'{locale.getdefaultlocale()} - UTF8 error in locale.getdefaultlocale')
- self.assertTrue( locale.getpreferredencoding() == "UTF-8", f'{locale.getpreferredencoding()} - UTF8 error in locale.getpreferredencoding')
-
+
+ self.assertTrue(
+ sys.getdefaultencoding() == "utf-8", f"{sys.getdefaultencoding()} - UTF8 error in getdefaultencoding"
+ )
+ self.assertTrue(
+ sys.getfilesystemencoding() == "utf-8",
+ f"{sys.getfilesystemencoding()} - UTF8 error in getfilesystemencoding",
+ )
+ self.assertTrue(
+ locale.getdefaultlocale()[1] == "UTF-8",
+ f"{locale.getdefaultlocale()} - UTF8 error in locale.getdefaultlocale",
+ )
+ self.assertTrue(
+ locale.getpreferredencoding() == "UTF-8",
+ f"{locale.getpreferredencoding()} - UTF8 error in locale.getpreferredencoding",
+ )
+
def test_installs(self):
- ''' Expects external software installed: cavern, survexport, git
+ """Expects external software installed: cavern, survexport, git
(but not whether it actually works)
- '''
+ """
import troggle.settings as settings
for i in [settings.CAVERN, settings.SURVEXPORT, settings.GIT]:
# Define command as string and then split() into list format
- cmd = f'which {i}'.split()
+ cmd = f"which {i}".split()
try:
sp = subprocess.check_call(cmd, shell=False)
except subprocess.CalledProcessError:
- self.assertTrue( False, f'no {i} installed')
+ self.assertTrue(False, f"no {i} installed")
def test_repos_git_status(self):
- ''' Expects clean git repos with no added files and no merge failures
- '''
+ """Expects clean git repos with no added files and no merge failures"""
from pathlib import Path
import troggle.settings as settings
+
TROGGLE_PATH = Path(settings.REPOS_ROOT_PATH) / "troggle"
- for cwd in [settings.SURVEX_DATA, settings.EXPOWEB, settings.DRAWINGS_DATA, TROGGLE_PATH]:
+ for cwd in [settings.SURVEX_DATA, settings.EXPOWEB, settings.DRAWINGS_DATA, TROGGLE_PATH]:
sp = subprocess.run([settings.GIT, "status"], cwd=cwd, capture_output=True, text=True)
out = str(sp.stdout)
if len(out) > 160:
out = out[:75] + "\n <Long output curtailed>\n" + out[-75:]
- print(f'git output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
+ print(f"git output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}")
if sp.returncode != 0:
- print(f'git output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
-
- self.assertTrue( sp.returncode == 0, f'{cwd} - git is unhappy')
+ print(f"git output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}")
+
+ self.assertTrue(sp.returncode == 0, f"{cwd} - git is unhappy")
content = sp.stdout
- ph = r'Your branch is up[ -]to[ -]date'
- phmatch = re.search(ph, content)
+ ph = r"Your branch is up[ -]to[ -]date"
+ phmatch = re.search(ph, content)
msg = f'{cwd} - Failed to find expected git output: "{ph}"'
self.assertIsNotNone(phmatch, msg)
- ph1 = r'no changes added to commit'
- phmatch1 = re.search(ph1, content)
- ph2 = r'nothing to commit'
- phmatch2 = re.search(ph2, content)
+ ph1 = r"no changes added to commit"
+ phmatch1 = re.search(ph1, content)
+ ph2 = r"nothing to commit"
+ phmatch2 = re.search(ph2, content)
phmatch = phmatch1 or phmatch2
msg = f'{cwd} - Failed to find expected git output: "{ph1}" or "{ph2}"'
self.assertIsNotNone(phmatch, msg)
def test_loser_survex_status(self):
- ''' Expects no failures of survex files
- '''
+ """Expects no failures of survex files"""
from pathlib import Path
import troggle.settings as settings
+
cwd = settings.SURVEX_DATA
- for survey in ["1623.svx", "1626.svx"]:
+ for survey in ["1623.svx", "1626.svx"]:
sp = subprocess.run([settings.CAVERN, survey], cwd=cwd, capture_output=True, text=True)
out = str(sp.stdout)
if len(out) > 160:
out = out[:75] + "\n <Long output curtailed>\n" + out[-75:]
# print(f'survex output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
if sp.returncode != 0:
- print(f'survex output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
-
- self.assertTrue( sp.returncode == 0, f'{cwd} - survex is unhappy')
+ print(
+ f"survex output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}"
+ )
+
+ self.assertTrue(sp.returncode == 0, f"{cwd} - survex is unhappy")
content = sp.stdout
- ph = r'Total length of survey legs'
- phmatch = re.search(ph, content)
+ ph = r"Total length of survey legs"
+ phmatch = re.search(ph, content)
msg = f'{cwd} - Failed to find expected survex output: "{ph}"'
self.assertIsNotNone(phmatch, msg)
-
- ph1 = r'Time used'
- phmatch1 = re.search(ph1, content)
- ph2 = r'vertical length of survey le'
- phmatch2 = re.search(ph2, content)
-
+
+ ph1 = r"Time used"
+ phmatch1 = re.search(ph1, content)
+ ph2 = r"vertical length of survey le"
+ phmatch2 = re.search(ph2, content)
+
phmatch = phmatch1 or phmatch2
msg = f'{cwd} - Failed to find expected survex output: "{ph1}" or "{ph2}"'
self.assertIsNotNone(phmatch, msg)
-
diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py
index cc10c14..5176859 100644
--- a/core/TESTS/tests.py
+++ b/core/TESTS/tests.py
@@ -1,4 +1,4 @@
-'''
+"""
We are using unittest for troggle.
Note that the database has not been parsed from the source files when these tests are run,
@@ -17,13 +17,13 @@ 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/
-'''
+"""
-todo = '''ADD TESTS when we are redirecting /expofiles/ to a remote file-delivering site
+todo = """ADD TESTS when we are redirecting /expofiles/ to a remote file-delivering site
- Add test for running cavern to produce a .3d file
-'''
+"""
import re
import unittest
@@ -32,436 +32,450 @@ from http import HTTPStatus
from django.test import Client, SimpleTestCase, TestCase
-#class SimplePageTest(unittest.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
+ """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..
+ # 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('')
+ 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 +"'")
+ 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('/')
+ 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 +"'")
+ 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')
+ response = self.client.get("/pathsreport")
self.assertEqual(response.status_code, 200)
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 +"'")
+ 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 = self.client.get("/handbook")
content = response.content.decode()
- self.assertEqual(response.status_code, 302) # directory, so redirects to /index.htm
+ self.assertEqual(response.status_code, 302) # directory, so redirects to /index.htm
def test_expoweb_dirslash(self):
- response = self.client.get('/handbook/')
+ response = self.client.get("/handbook/")
content = response.content.decode()
- self.assertEqual(response.status_code, 302) # directory, so redirects to /index.htm
-
+ self.assertEqual(response.status_code, 302) # directory, so redirects to /index.htm
+
def test_expoweb_dir_no_index(self):
- response = self.client.get('/handbook/troggle')
+ response = self.client.get("/handbook/troggle")
content = response.content.decode()
self.assertEqual(response.status_code, 404)
- ph = r'Page not found handbook/troggle/index.html'
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
-
+ 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')
+ response = self.client.get("/years/1999/index.htm")
content = response.content.decode()
- self.assertEqual(response.status_code, 200) # 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 +"'")
-
+ self.assertEqual(response.status_code, 200) # 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')
+ response = self.client.get("/years/2015/index.html")
content = response.content.decode()
- self.assertEqual(response.status_code, 200) # 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 +"'")
+ self.assertEqual(response.status_code, 200) # 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')
+ 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)
- #print("\n ! - test_expoweb_dir_with_index2\n{}\n{}".format(response.reason_phrase, content))
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
-
+ self.assertEqual(response.status_code, 200)
+ 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')
+ 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 +"'")
+ 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')
+ response = self.client.get("/handbook/_test_zyxxypqrqx.html")
content = response.content.decode()
self.assertEqual(response.status_code, 404)
- ph = r'<h1>Page not found'
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ 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/')
+ response = self.client.get("/handbook/_test_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 +"'")
+ 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')
+ response = self.client.get("/troggle")
self.assertEqual(response.status_code, 200)
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 +"'")
-
+ 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/')
+ response = self.client.get("/troggle/")
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 +"'")
-
+ 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')
+ response = self.client.get("/guidebook/t/via201.jpg")
self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 6057)
+ 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
- response = self.client.get('/1623/115.htm')
+ response = self.client.get("/1623/115.htm")
self.assertEqual(response.status_code, 404)
content = response.content.decode()
ph = r"Page not found 1623/115.htm"
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_caves_page(self):
- response = self.client.get('/caves')
+ response = self.client.get("/caves")
self.assertEqual(response.status_code, 200)
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 +"'")
+ 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')
+ response = self.client.get("/caves")
self.assertEqual(response.status_code, 200)
content = response.content.decode()
ph = r"115"
- phmatch = re.search(ph, content)
- self.assertIsNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ phmatch = re.search(ph, content)
+ self.assertIsNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_page_ss(self):
- response = self.client.get('/survey_scans/')
- self.assertEqual(response.status_code, 200)
-
- ph = r'All Survey scans folders '
+ response = self.client.get("/survey_scans/")
+ self.assertEqual(response.status_code, 200)
+
+ ph = r"All Survey scans folders "
content = response.content.decode()
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ 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/')
+ response = self.client.get("/admin/login/")
content = response.content.decode()
self.assertEqual(response.status_code, 200)
ph = r'<h1 id="site-name">Troggle database administration</h1>'
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ 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 = self.client.get("/admin/doc/models/core.expedition/")
content = response.content.decode()
self.assertEqual(response.status_code, 302)
def test_page_expofiles_root_dir(self):
# Root expofiles - odd interaction with url parsing so needs testing
- response = self.client.get('/expofiles')
+ response = self.client.get("/expofiles")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ 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/',
- 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 +"'")
+ self.assertEqual(response.status_code, 200)
+ 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/')
+ response = self.client.get("/expofiles/")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ 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/',
- 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 +"'")
+ self.assertEqual(response.status_code, 200)
+ 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')
+ response = self.client.get("/expofiles/99badness99")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ 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/',
- 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 +"'")
+ self.assertEqual(response.status_code, 200)
+ 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/')
+ response = self.client.get("/expofiles/documents/")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ 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/documents/bier-tent-instructions.pdf">bier-tent-instructions.pdf',
- r'a href="/expofiles/documents/boc.pdf">boc.pdf',
- r'a href="/expofiles/documents/bierbook">/bierbook' ]:
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ self.assertEqual(response.status_code, 200)
+ 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/bierbook">/bierbook',
+ ]:
+ 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')
+ response = self.client.get("/expofiles/surveyscans")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ 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/',
- 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 +"'")
+ self.assertEqual(response.status_code, 200)
+ 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, 200)
- 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 +"'")
+ response = self.client.get("/folk/index.htm")
+ content = response.content.decode()
+ self.assertEqual(response.status_code, 200)
+ 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')
+ response = self.client.get("/expofiles/documents")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
+ 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 +"'")
+ 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/')
+ response = self.client.get("/expofiles/documents/")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
+ 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 +"'")
-
-
+ 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')
+ response = self.client.get("/expofiles/documents/surveying/tunnel-loefflerCP35-only.pdf")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 2299270)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.content), 2299270)
def test_page_expofile_document_rope_pdf(self):
# Flat file tests.
- response = self.client.get('/expofiles/documents/rope-age-agm-2019.pdf')
+ response = self.client.get("/expofiles/documents/rope-age-agm-2019.pdf")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 76197)
+ self.assertEqual(response.status_code, 200)
+ 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')
+ response = self.client.get("/expofiles/documents/callout-2012.png")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 69921)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(len(response.content), 69921)
def test_page_expofile_writeup(self):
# Flat file tests.
- response = self.client.get('/expofiles/writeups/1982/logbook1982.pdf')
+ response = self.client.get("/expofiles/writeups/1982/logbook1982.pdf")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 12915413)
-
+ 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')
+ response = self.client.get("/site_media/surveyHover.gif")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 39482 ) # need to check it is not just an error page
-
+ self.assertEqual(response.status_code, 200)
+ 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')
+ response = self.client.get("/site_media/css/trog3.css")
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
- 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 +"'")
+ self.assertEqual(response.status_code, 200)
+ 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
+ response = self.client.get("/photos/2018/PhilipSargent/corin.jpg") # exists
if response.status_code != 200:
- self.assertEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
if response.status_code != 302:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.content), 67487 ) # need to check it is not just an error page
+ self.assertEqual(response.status_code, 200)
+ 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
+ response = self.client.get("/photos/2018/PhilipSargent/_corin.jpeg") # does not exist
self.assertEqual(response.status_code, 404)
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 +"'")
+ 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/')
+ 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 +"'")
+ 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/')
+ response = self.client.get("/survey_scans/")
self.assertEqual(response.status_code, 200)
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 +"'")
+ 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/')
+ response = self.client.get("/dwgdataraw/")
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 +"'")
+ 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')
+ response = self.client.get("/dwgfiles")
self.assertEqual(response.status_code, 200)
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 +"'")
+ 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/')
+ response = self.client.get("/dwgfiles/")
self.assertEqual(response.status_code, 200)
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 +"'")
+ 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/')
+ 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 +"'")
+ 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')
+ response = self.client.get("/survexfile/not_a_real_cave_number")
self.assertEqual(response.status_code, 200)
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 +"'")
+ ph = r"Cave Identifier not found in database"
+ 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
@@ -470,39 +484,35 @@ class PageTests(TestCase):
# 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 != 200:
- # self.assertEqual(response.status_code, 302)
- # if response.status_code != 302:
- # self.assertEqual(response.status_code, 200)
- # 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 != 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'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)
-
-
-
+# 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 != 200:
+# self.assertEqual(response.status_code, 302)
+# if response.status_code != 302:
+# self.assertEqual(response.status_code, 200)
+# 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 != 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'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)
diff --git a/core/TESTS/tests_caves.py b/core/TESTS/tests_caves.py
index 732ebe8..3d9270d 100644
--- a/core/TESTS/tests_caves.py
+++ b/core/TESTS/tests_caves.py
@@ -12,171 +12,166 @@ from troggle.core.models.troggle import Expedition, Person, PersonExpedition
class FixtureTests(TestCase):
- '''These just hit the database.
+ """These just hit the database.
They do not exercise the GET and url functions
- '''
- fixtures = ['auth_users', 'expo_areas', 'expo_caves', 'expo_exped']
- ph = r'and leads in 800m of tortuous going to'
+ """
+
+ fixtures = ["auth_users", "expo_areas", "expo_caves", "expo_exped"]
+ ph = r"and leads in 800m of tortuous going to"
def setUp(self):
pass
def tearDown(self):
pass
-
+
def test_fix_person_loaded(self):
- p = Person.objects.get(fullname='Michael Sargent')
+ p = Person.objects.get(fullname="Michael Sargent")
self.assertEqual(str(p.first_name), "Michael")
def test_fix_person_loaded(self):
- pe = PersonExpedition.objects.get(pk='681')
- self.assertEqual(str(pe.person.fullname), 'Michael Sargent')
- self.assertEqual(str(pe.expedition.year), '2019')
+ pe = PersonExpedition.objects.get(pk="681")
+ self.assertEqual(str(pe.person.fullname), "Michael Sargent")
+ self.assertEqual(str(pe.expedition.year), "2019")
def test_fix_area_loaded(self):
- a = Area.objects.get(short_name='1623')
+ a = Area.objects.get(short_name="1623")
self.assertEqual(str(a.short_name), "1623")
-
+
def test_fix_cave_loaded115(self):
- c = Cave.objects.get(kataster_number='115')
+ c = Cave.objects.get(kataster_number="115")
self.assertEqual(str(c.description_file), "1623/115.htm")
- self.assertEqual(str(c.url), "1623/115.url") # intentional
+ self.assertEqual(str(c.url), "1623/115.url") # intentional
self.assertEqual(str(c.filename), "1623-115.html")
-
+
# c.area is a 'ManyRelatedManager' object and not iterable
- #self.assertEqual(str(c.[0].short_name), "1623")
-
+ # self.assertEqual(str(c.[0].short_name), "1623")
+
ph = self.ph
- phmatch = re.search(ph, c.underground_description)
- self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph +"'")
+ phmatch = re.search(ph, c.underground_description)
+ self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph + "'")
def test_fix_cave_loaded284(self):
- c = Cave.objects.get(kataster_number='284')
+ c = Cave.objects.get(kataster_number="284")
self.assertEqual(str(c.description_file), "")
self.assertEqual(str(c.url), "1623/284/284.html")
self.assertEqual(str(c.filename), "1623-284.html")
-
- ph = r'at a depth of 72m, there are large round blocks'
- phmatch = re.search(ph, c.notes)
- self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph +"'")
+ ph = r"at a depth of 72m, there are large round blocks"
+ phmatch = re.search(ph, c.notes)
+ self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph + "'")
def test_page_personexpedition(self):
- response = self.client.get('/personexpedition/MichaelSargent/2019')
- content = response.content.decode()
+ response = self.client.get("/personexpedition/MichaelSargent/2019")
+ content = response.content.decode()
# with open('testresponse.html','w') as tr:
- # tr.writelines(content)
- self.assertEqual(response.status_code, 200)
- for ph in [ r'Michael Sargent',
- r'Table of all trips and surveys aligned by date' ]:
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ # tr.writelines(content)
+ self.assertEqual(response.status_code, 200)
+ for ph in [r"Michael Sargent", r"Table of all trips and surveys aligned by date"]:
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
# Need to add a fixture so that this actually has a logbook entry and a trip/svx in it.
class FixturePageTests(TestCase):
- '''Currently nothing that runs troggle works - all do 404. Must be something in a template rendering crash?
+ """Currently nothing that runs troggle works - all do 404. Must be something in a template rendering crash?
ordinary pages are OK, and expopages and expofiles are OK, even though they come through troggle.
- '''
+ """
+
# The fixtures have a password hash which is compatible with plain-text password 'secretword'
- fixtures = ['auth_users', 'expo_areas', 'expo_caves', 'expo_exped']
- ph = r'and leads in 800m of tortuous going to'
+ fixtures = ["auth_users", "expo_areas", "expo_caves", "expo_exped"]
+ ph = r"and leads in 800m of tortuous going to"
@classmethod
def setUpTestData(cls):
pass
-
def setUp(self):
from django.contrib.auth.models import User
- self.user = User.objects.get(username='expotest')
-
- # Every test needs a client.
+
+ self.user = User.objects.get(username="expotest")
+
+ # Every test needs a client.
self.client = Client()
def tearDown(self):
pass
-
def test_fix_expedition(self):
- response = self.client.get('/expedition/2019')
- self.assertEqual(response.status_code, 200)
-
- ph = r'Michael Sargent'
-
- content = response.content.decode()
- phmatch = re.search(ph, content)
- # with open('exped-op.html', 'w') as f:
- # f.write(content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ response = self.client.get("/expedition/2019")
+ self.assertEqual(response.status_code, 200)
+ ph = r"Michael Sargent"
+
+ content = response.content.decode()
+ phmatch = re.search(ph, content)
+ # with open('exped-op.html', 'w') as f:
+ # f.write(content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_fix_personexped(self):
- response = self.client.get('/personexpedition/MichaelSargent/2019')
- self.assertEqual(response.status_code, 200)
-
- ph = r'Table of all trips and surveys aligned by date'
-
+ response = self.client.get("/personexpedition/MichaelSargent/2019")
+ self.assertEqual(response.status_code, 200)
+
+ ph = r"Table of all trips and surveys aligned by date"
+
content = response.content.decode()
- phmatch = re.search(ph, content)
- # with open('persexped-op.html', 'w') as f:
- # f.write(content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ phmatch = re.search(ph, content)
+ # with open('persexped-op.html', 'w') as f:
+ # f.write(content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_fix_person(self):
- response = self.client.get('/person/MichaelSargent')
- self.assertEqual(response.status_code, 200)
-
- ph = r'second-generation expo caver '
-
- content = response.content.decode()
- phmatch = re.search(ph, content)
- # with open('person-op.html', 'w') as f:
- # f.write(content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ response = self.client.get("/person/MichaelSargent")
+ self.assertEqual(response.status_code, 200)
+
+ ph = r"second-generation expo caver "
+ content = response.content.decode()
+ phmatch = re.search(ph, content)
+ # with open('person-op.html', 'w') as f:
+ # f.write(content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_fix_cave_url115(self):
ph = self.ph
- response = self.client.get('/1623/115.url') # yes this is intentional, see the inserted data above & fixture
- self.assertEqual(response.status_code, 200)
-
+ response = self.client.get("/1623/115.url") # yes this is intentional, see the inserted data above & fixture
+ self.assertEqual(response.status_code, 200)
+
content = response.content.decode()
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
-
def test_fix_cave_url284(self):
- response = self.client.get('/1623/284/284.html')
- self.assertEqual(response.status_code, 200)
-
- ph = r'at a depth of 72m, there are large round blocks'
-
+ response = self.client.get("/1623/284/284.html")
+ self.assertEqual(response.status_code, 200)
+
+ ph = r"at a depth of 72m, there are large round blocks"
+
content = response.content.decode()
- phmatch = re.search(ph, content)
- # with open('cave-op.html', 'w') as f:
- # f.write(content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
+ phmatch = re.search(ph, content)
+ # with open('cave-op.html', 'w') as f:
+ # f.write(content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_fix_cave_bare_url115(self):
- '''Expect to get Page Not Found and status 404'''
+ """Expect to get Page Not Found and status 404"""
ph = self.ph
- ph = 'Probably a mistake.'
- response = self.client.get('/1623/115')
- self.assertEqual(response.status_code, 404)
-
- content = response.content.decode()
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") # 200 & Page Not Found
+ ph = "Probably a mistake."
+ response = self.client.get("/1623/115")
+ self.assertEqual(response.status_code, 404)
+ content = response.content.decode()
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'") # 200 & Page Not Found
def test_fix_cave_slug115(self):
- '''Expect to get Page Not Found and status 404'''
+ """Expect to get Page Not Found and status 404"""
ph = self.ph
- ph = 'Probably a mistake.'
- response = self.client.get('/1623-115')
- self.assertEqual(response.status_code, 404)
-
+ ph = "Probably a mistake."
+ response = self.client.get("/1623-115")
+ self.assertEqual(response.status_code, 404)
+
content = response.content.decode()
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") # 200 & Page Not Found
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'") # 200 & Page Not Found
diff --git a/core/TESTS/tests_logins.py b/core/TESTS/tests_logins.py
index 02eceb6..365ec04 100644
--- a/core/TESTS/tests_logins.py
+++ b/core/TESTS/tests_logins.py
@@ -18,377 +18,410 @@ from troggle.core.models.survex import Wallet
from troggle.core.models.troggle import Expedition
-class DataTests(TestCase ):
- '''These check that the NULL and NON-UNIQUE constraints are working in the database '''
+class DataTests(TestCase):
+ """These check that the NULL and NON-UNIQUE constraints are working in the database"""
+
@classmethod
def setUpTestData(cls):
pass
def setUp(self):
from django.contrib.auth.models import User
+
u = User()
u.pk = 9000
- u.user_id = 8000
- u.username, u.password ='stinker', 'secretword'
- u.email='philip.sargent+SP@gmail.com'
- u.first_name, u.last_name ='Stinker', 'Pinker'
+ u.user_id = 8000
+ u.username, u.password = "stinker", "secretword"
+ u.email = "philip.sargent+SP@gmail.com"
+ u.first_name, u.last_name = "Stinker", "Pinker"
u.save()
self.user = u
-
+
def tearDown(self):
- #self.member.delete() # must delete member before user
- #self.user.delete() # horrible crash, why?
+ # self.member.delete() # must delete member before user
+ # self.user.delete() # horrible crash, why?
pass
-
+
+
class FixturePageTests(TestCase):
# The fixtures have a password hash which is compatible with plain-text password 'secretword'
- fixtures = ['auth_users']
+ fixtures = ["auth_users"]
def setUp(self):
from django.contrib.auth.models import User
- self.user = User.objects.get(username='expotest')
-
+
+ self.user = User.objects.get(username="expotest")
+
def tearDown(self):
pass
def test_fix_admin_login_fail(self):
c = self.client
from django.contrib.auth.models import User
- u = User.objects.get(username='expotest')
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
-
- logged_in = c.login(username=u.username, password='secretword') # fails to work if password=u.password !
- self.assertTrue(logged_in, 'FAILED to login as \'' + u.username + '\'')
-
- response = c.get('/admin/')
+
+ u = User.objects.get(username="expotest")
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+
+ logged_in = c.login(username=u.username, password="secretword") # fails to work if password=u.password !
+ self.assertTrue(logged_in, "FAILED to login as '" + u.username + "'")
+
+ response = c.get("/admin/")
content = response.content.decode()
- # with open('admin-op.html', 'w') as f:
- # f.write(content)
- t = re.search(r'Troggle administration', content)
- self.assertIsNone(t, 'Logged in as \'' + u.username + '\' (not staff) but still managed to get the Admin page' )
+ # with open('admin-op.html', 'w') as f:
+ # f.write(content)
+ t = re.search(r"Troggle administration", content)
+ self.assertIsNone(t, "Logged in as '" + u.username + "' (not staff) but still managed to get the Admin page")
+
class PostTests(TestCase):
- '''Tests scanupload form
- '''
- fixtures = ['auth_users']
+ """Tests scanupload form"""
+
+ fixtures = ["auth_users"]
@classmethod
def setUpTestData(cls):
pass
-
+
def setUp(self):
from django.contrib.auth.models import User
- self.user = User.objects.get(username='expotest')
+
+ self.user = User.objects.get(username="expotest")
self.client = Client()
-
- testyear = '2022'
- wname = f'{testyear}:00'
+
+ testyear = "2022"
+ wname = f"{testyear}:00"
self.testyear = testyear
w = Wallet()
w.pk = 9100
w.fpath = str(pathlib.Path(settings.SCANS_ROOT, wname))
- w.walletname = wname
+ w.walletname = wname
w.save()
self.wallet = w
-
+
e = Expedition()
e.year = testyear
e.save()
self.expedition = e
-
def test_scan_upload(self):
- '''Expect scan upload to wallet to work on any file
+ """Expect scan upload to wallet to work on any file
Need to login first.
-
+
This upload form looks for the Cave and the Wallet, so the test fails if the database is not loaded with the cave
identified in the wallet
- '''
+ """
c = self.client
w = self.wallet
from django.contrib.auth.models import User
- u = User.objects.get(username='expotest')
+
+ u = User.objects.get(username="expotest")
testyear = self.testyear
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
- logged_in = c.login(username=u.username, password='secretword')
- with open('core/fixtures/test_upload_file.txt','r') as testf:
- response = self.client.post(f'/scanupload/{testyear}:00', data={'name': 'test_upload_file.txt', 'uploadfiles': testf })
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+ logged_in = c.login(username=u.username, password="secretword")
+
+ with open("core/fixtures/test_upload_file.txt", "r") as testf:
+ response = self.client.post(
+ f"/scanupload/{testyear}:00", data={"name": "test_upload_file.txt", "uploadfiles": testf}
+ )
content = response.content.decode()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, HTTPStatus.OK)
- with open('_test_response.html', 'w') as f:
- f.write(content)
- for ph in [ r'test_upload_',
- rf'&larr; {testyear}#00 &rarr;',
- r'description written',
- r'Plan not required',
- r'edit settings or upload a file']:
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
-
+ with open("_test_response.html", "w") as f:
+ f.write(content)
+ for ph in [
+ r"test_upload_",
+ rf"&larr; {testyear}#00 &rarr;",
+ r"description written",
+ r"Plan not required",
+ r"edit settings or upload a file",
+ ]:
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
+
# # Does not use the filename Django actually uses, assumes it is unchanged. Potential bug.
# remove_file = pathlib.Path(settings.SCANS_ROOT) / f'{testyear}' / f'{testyear}#00'/ 'test_upload_file.txt'
# remove_file.unlink()
# # Undo the auto create and commit of a new wallet
- # cwd = settings.DRAWINGS_DATA
+ # cwd = settings.DRAWINGS_DATA
# sp = subprocess.run([settings.GIT, "reset", "--hard", "master^"], cwd=cwd, capture_output=True, text=True)
# print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
# if sp.returncode != 0:
- # print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
-
+ # print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
def test_photo_upload(self):
- '''Expect photo upload to work on any file (contrary to msg on screen)
+ """Expect photo upload to work on any file (contrary to msg on screen)
Upload into current default year. settings.PHOTOS_YEAR
Deletes file afterwards
Need to login first.
- '''
+ """
c = self.client
from django.contrib.auth.models import User
- u = User.objects.get(username='expotest')
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
- logged_in = c.login(username=u.username, password='secretword')
- with open('core/fixtures/test_upload_file.txt','r') as testf:
- response = self.client.post('/photoupload/', data={'name': 'test_upload_file.txt', 'renameto': '', 'uploadfiles': testf })
+ u = User.objects.get(username="expotest")
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+ logged_in = c.login(username=u.username, password="secretword")
+
+ with open("core/fixtures/test_upload_file.txt", "r") as testf:
+ response = self.client.post(
+ "/photoupload/", data={"name": "test_upload_file.txt", "renameto": "", "uploadfiles": testf}
+ )
content = response.content.decode()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, HTTPStatus.OK)
- # with open('_test_response.html', 'w') as f:
- # f.write(content)
- for ph in [ r'test_upload_',
- r'Upload photos into /photos/'+str(settings.PHOTOS_YEAR),
- r' you can create a new folder in your name',
- r'Create new Photographer folder',
- r'only photo image files are accepted']:
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
-
+ # with open('_test_response.html', 'w') as f:
+ # f.write(content)
+ for ph in [
+ r"test_upload_",
+ r"Upload photos into /photos/" + str(settings.PHOTOS_YEAR),
+ r" you can create a new folder in your name",
+ r"Create new Photographer folder",
+ r"only photo image files are accepted",
+ ]:
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
+
# Does not use the filename Django actually uses, assumes it is unchanged. Potential bug.
- remove_file = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / 'test_upload_file.txt'
+ remove_file = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / "test_upload_file.txt"
remove_file.unlink()
-
+
def test_photo_upload_rename(self):
- '''Expect photo upload to work on any file (contrary to msg on screen)
+ """Expect photo upload to work on any file (contrary to msg on screen)
Upload into current default year. settings.PHOTOS_YEAR
Deletes file afterwards
Need to login first.
- '''
+ """
c = self.client
from django.contrib.auth.models import User
- u = User.objects.get(username='expotest')
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
- logged_in = c.login(username=u.username, password='secretword')
-
- rename = 'RENAMED-FILE.JPG'
- with open('core/fixtures/test_upload_file.txt','r') as testf:
- response = self.client.post('/photoupload/', data={'name': 'test_upload_file.txt', 'renameto': rename, 'uploadfiles': testf })
+
+ u = User.objects.get(username="expotest")
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+ logged_in = c.login(username=u.username, password="secretword")
+
+ rename = "RENAMED-FILE.JPG"
+ with open("core/fixtures/test_upload_file.txt", "r") as testf:
+ response = self.client.post(
+ "/photoupload/", data={"name": "test_upload_file.txt", "renameto": rename, "uploadfiles": testf}
+ )
content = response.content.decode()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, HTTPStatus.OK)
- # with open('_test_response.html', 'w') as f:
- # f.write(content)
+ # with open('_test_response.html', 'w') as f:
+ # f.write(content)
for ph in [rename]:
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
-
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
+
# Does not use the filename Django actually uses, assumes it is unchanged. Potential bug.
remove_file = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / rename
remove_file.unlink()
def test_photo_folder_create(self):
- '''Create folder for new user
+ """Create folder for new user
Create in current default year. settings.PHOTOS_YEAR
Deletes folder afterwards
Need to login first.
- '''
+ """
c = self.client
from django.contrib.auth.models import User
- u = User.objects.get(username='expotest')
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
- logged_in = c.login(username=u.username, password='secretword')
- response = self.client.post('/photoupload/', data={'photographer': 'GussieFinkNottle'})
+ u = User.objects.get(username="expotest")
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+ logged_in = c.login(username=u.username, password="secretword")
+
+ response = self.client.post("/photoupload/", data={"photographer": "GussieFinkNottle"})
content = response.content.decode()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, HTTPStatus.OK)
- # with open('_test_response.html', 'w') as f:
- # f.write(content)
- for ph in [r'/GussieFinkNottle/',
- r'Create new Photographer folder']:
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
-
+ # with open('_test_response.html', 'w') as f:
+ # f.write(content)
+ for ph in [r"/GussieFinkNottle/", r"Create new Photographer folder"]:
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
+
# Does not use the filename Django actually uses, assumes it is unchanged. Potential bug.
- remove_dir = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / 'GussieFinkNottle'
+ remove_dir = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / "GussieFinkNottle"
remove_dir.rmdir()
-
-
def test_dwg_upload_txt(self):
- '''Expect .pdf file to be refused upload
+ """Expect .pdf file to be refused upload
Need to login first.
- '''
+ """
c = self.client
from django.contrib.auth.models import User
- u = User.objects.get(username='expotest')
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
- logged_in = c.login(username=u.username, password='secretword')
- with open('core/fixtures/test_upload_file.pdf','r') as testf:
- response = self.client.post('/dwgupload/uploads', data={'name': 'test_upload_file.txt', 'uploadfiles': testf })
+ u = User.objects.get(username="expotest")
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+ logged_in = c.login(username=u.username, password="secretword")
+
+ with open("core/fixtures/test_upload_file.pdf", "r") as testf:
+ response = self.client.post(
+ "/dwgupload/uploads", data={"name": "test_upload_file.txt", "uploadfiles": testf}
+ )
content = response.content.decode()
self.assertEqual(response.status_code, 200)
- t = re.search('Files refused:', content)
- self.assertIsNotNone(t, 'Logged in but failed to see "Files refused:"' )
+ t = re.search("Files refused:", content)
+ self.assertIsNotNone(t, 'Logged in but failed to see "Files refused:"')
def test_dwg_upload_drawing(self):
- '''Expect no-suffix file to upload
+ """Expect no-suffix file to upload
Note that this skips the git commit process. That would need a new test.
Need to login first.
- '''
+ """
c = self.client
from django.contrib.auth.models import User
- u = User.objects.get(username='expotest')
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
- logged_in = c.login(username=u.username, password='secretword')
- with open('core/fixtures/test_upload_nosuffix','r') as testf:
- response = self.client.post('/dwguploadnogit/uploads', data={'name': 'test_upload_nosuffix', 'uploadfiles': testf })
+ u = User.objects.get(username="expotest")
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+ logged_in = c.login(username=u.username, password="secretword")
+
+ with open("core/fixtures/test_upload_nosuffix", "r") as testf:
+ response = self.client.post(
+ "/dwguploadnogit/uploads", data={"name": "test_upload_nosuffix", "uploadfiles": testf}
+ )
content = response.content.decode()
- # with open('_test_response.html', 'w') as f:
- # f.write(content)
+ # with open('_test_response.html', 'w') as f:
+ # f.write(content)
self.assertEqual(response.status_code, 200)
- for ph in [ r'test_upload_nosuffix',
- r'You cannot create folders here',
- r'Creating a folder is done by a nerd']:
- phmatch = re.search(ph, content)
- self.assertIsNotNone(phmatch, "Expect no-suffix file to upload OK. Failed to find expected text: '" + ph +"'")
-
+ for ph in [
+ r"test_upload_nosuffix",
+ r"You cannot create folders here",
+ r"Creating a folder is done by a nerd",
+ ]:
+ phmatch = re.search(ph, content)
+ self.assertIsNotNone(
+ phmatch, "Expect no-suffix file to upload OK. Failed to find expected text: '" + ph + "'"
+ )
+
# Does not use the filename Django actually uses, assumes it is unchanged. Bug: accumulates one file with random name added each time it is run.
- remove_file = pathlib.Path(settings.DRAWINGS_DATA) / 'uploads' / 'test_upload_nosuffix'
+ remove_file = pathlib.Path(settings.DRAWINGS_DATA) / "uploads" / "test_upload_nosuffix"
remove_file.unlink()
class ComplexLoginTests(TestCase):
- '''These test the login and capabilities of logged-in users, they do not use fixtures'''
+ """These test the login and capabilities of logged-in users, they do not use fixtures"""
+
def setUp(self):
- '''setUp runs once for each test in this class'''
+ """setUp runs once for each test in this class"""
from django.contrib.auth.models import User
u = User()
u.pk = 9000
- u.user_id = 8000
- u.username, u.password ='expotest', 'secretword'
- u.email='philip.sargent+ET@gmail.com'
- u.first_name, u.last_name ='ExpoTest', 'Caver'
+ u.user_id = 8000
+ u.username, u.password = "expotest", "secretword"
+ u.email = "philip.sargent+ET@gmail.com"
+ u.first_name, u.last_name = "ExpoTest", "Caver"
u.is_staff = True
u.is_superuser = True
-
- u.set_password(u.password) # This creates a new salt and thus a new key for EACH test
- u.save() # vital that we save all this before attempting login
- #print ('\n',u.password)
+
+ u.set_password(u.password) # This creates a new salt and thus a new key for EACH test
+ u.save() # vital that we save all this before attempting login
+ # print ('\n',u.password)
self.user = u
-
+
def tearDown(self):
- self.client.logout() # not needed as each test creates a new self.client
- #self.member.delete()
+ self.client.logout() # not needed as each test creates a new self.client
+ # self.member.delete()
##self.user.delete() # id attribute set to None !
pass
# def test_login_redirect_for_non_logged_on_user(self): # need to fix this in real system
- # c = self.client
- # # Need to login first. Tests that we are redirected to login page if not logged in
- # response = c.get('noinfo/cave-number-index')
- # self.assertRedirects(response, "/login/?next=/committee/appointments/")
+ # c = self.client
+ # # Need to login first. Tests that we are redirected to login page if not logged in
+ # response = c.get('noinfo/cave-number-index')
+ # self.assertRedirects(response, "/login/?next=/committee/appointments/")
def test_ordinary_login(self):
c = self.client
u = self.user
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
-
- logged_in = c.login(username=u.username, password='secretword') # fails to work if password=u.password !
- self.assertTrue(logged_in, 'FAILED to login as \'' + u.username + '\'')
-
- response = c.get('/accounts/login/') # defined by auth system
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+
+ logged_in = c.login(username=u.username, password="secretword") # fails to work if password=u.password !
+ self.assertTrue(logged_in, "FAILED to login as '" + u.username + "'")
+
+ response = c.get("/accounts/login/") # defined by auth system
content = response.content.decode()
- t = re.search(r'You are now logged in', content)
- self.assertIsNotNone(t, 'Logged in as \'' + u.username + '\' but failed to get \'Now you can\' greeting' )
+ t = re.search(r"You are now logged in", content)
+ self.assertIsNotNone(t, "Logged in as '" + u.username + "' but failed to get 'Now you can' greeting")
def test_authentication_login(self):
c = self.client
u = self.user
-
- self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
-
+
+ self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
+
# This is weird. I thought that the user had to login before she was in the authenticated state
- self.assertTrue(u.is_authenticated, 'User \'' + u.username + '\' is NOT AUTHENTICATED before login')
-
- logged_in = c.login(username=u.username, password='secretword') # fails to work if password=u.password !
- self.assertTrue(logged_in, 'FAILED to login as \'' + u.username + '\'')
+ self.assertTrue(u.is_authenticated, "User '" + u.username + "' is NOT AUTHENTICATED before login")
+
+ logged_in = c.login(username=u.username, password="secretword") # fails to work if password=u.password !
+ self.assertTrue(logged_in, "FAILED to login as '" + u.username + "'")
+
+ self.assertTrue(u.is_authenticated, "User '" + u.username + "' is NOT AUTHENTICATED after login")
- self.assertTrue(u.is_authenticated, 'User \'' + u.username + '\' is NOT AUTHENTICATED after login')
-
# c.logout() # This next test always means user is still authenticated after logout. Surely not?
# self.assertFalse(u.is_authenticated, 'User \'' + u.username + '\' is STILL AUTHENTICATED after logout')
-
+
def test_admin_login(self):
c = self.client
u = self.user
- logged_in = c.login(username=u.username, password='secretword') # fails to work if password=u.password !
- self.assertTrue(logged_in, 'FAILED to login as \'' + u.username + '\'')
+ logged_in = c.login(username=u.username, password="secretword") # fails to work if password=u.password !
+ self.assertTrue(logged_in, "FAILED to login as '" + u.username + "'")
- response = c.get('/admin/')
+ response = c.get("/admin/")
content = response.content.decode()
- # with open('admin-op.html', 'w') as f:
- # f.write(content)
- t = re.search(r'Troggle database administration', content)
- self.assertIsNotNone(t, 'Logged in as \'' + u.username + '\' but failed to get the Troggle Admin page' )
+ # with open('admin-op.html', 'w') as f:
+ # f.write(content)
+ t = re.search(r"Troggle database administration", content)
+ self.assertIsNotNone(t, "Logged in as '" + u.username + "' but failed to get the Troggle Admin page")
def test_noinfo_login(self):
from django.contrib.auth.models import User
- c = self.client # inherited from TestCase
- u = self.user
- logged_in = c.login(username=u.username, password='secretword') # fails if password=u.password !
- self.assertTrue(logged_in, 'FAILED to login as \'' + u.username + '\'')
- response = c.get('/stats') # a page with the Troggle menus
+ c = self.client # inherited from TestCase
+ u = self.user
+
+ logged_in = c.login(username=u.username, password="secretword") # fails if password=u.password !
+ self.assertTrue(logged_in, "FAILED to login as '" + u.username + "'")
+ response = c.get("/stats") # a page with the Troggle menus
content = response.content.decode()
- t = re.search(r'User\:expotest', content)
- self.assertIsNotNone(t, 'Logged in as \'' + u.username + '\' but failed to get \'User:expotest\' heading' )
+ t = re.search(r"User\:expotest", content)
+ self.assertIsNotNone(t, "Logged in as '" + u.username + "' but failed to get 'User:expotest' heading")
- response = c.get('/noinfo/cave-number-index')
+ response = c.get("/noinfo/cave-number-index")
content = response.content.decode()
- t = re.search(r'2001-07 Hoffnungschacht', content)
- self.assertIsNotNone(t, 'Logged in as \'' + u.username + '\' but failed to get /noinfo/ content')
-
+ t = re.search(r"2001-07 Hoffnungschacht", content)
+ self.assertIsNotNone(t, "Logged in as '" + u.username + "' but failed to get /noinfo/ content")
+
def test_user_force(self):
- from django.conf import settings
+ from django.conf import settings
+
c = self.client
u = self.user
-
+
try:
c.force_login(u)
except:
- self.assertIsNotNone(None, 'Unexpected exception trying to force_login as \'' + u.username + '\' but failed (Bad Django documentation?)')
-
- response = c.get('/stats') # a page with the Troggle menus
+ self.assertIsNotNone(
+ None,
+ "Unexpected exception trying to force_login as '"
+ + u.username
+ + "' but failed (Bad Django documentation?)",
+ )
+
+ response = c.get("/stats") # a page with the Troggle menus
content = response.content.decode()
- t = re.search(r'Log out', content)
- self.assertIsNotNone(t, 'Forced logged in as \'' + u.username + '\' but failed to get Log out heading' )
+ t = re.search(r"Log out", content)
+ self.assertIsNotNone(t, "Forced logged in as '" + u.username + "' but failed to get Log out heading")
- response = c.get('/accounts/login/')
+ response = c.get("/accounts/login/")
content = response.content.decode()
- t = re.search(r'You are now logged in', content)
- self.assertIsNotNone(t, 'Forced logged in as \'' + u.username + '\' but failed to get /accounts/profile/ content')
-
+ t = re.search(r"You are now logged in", content)
+ self.assertIsNotNone(t, "Forced logged in as '" + u.username + "' but failed to get /accounts/profile/ content")