diff --git a/core/TESTS/test_imports.py b/core/TESTS/test_imports.py new file mode 100644 index 0000000..b726ae8 --- /dev/null +++ b/core/TESTS/test_imports.py @@ -0,0 +1,92 @@ +""" +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/ +/expofiles/ +/expofiles/documents/ +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 +import re +from django.test import TestCase, SimpleTestCase, Client + +class SimpleTest(SimpleTestCase): + def test_test_setting(self): + from django.conf import settings + self.assertEqual(settings.EMAIL_BACKEND, 'django.core.mail.backends.locmem.EmailBackend') + def test_import_TroggleModel(self): + from troggle.core.models 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 utils import save_carefully + from functools import reduce + def test_import_parsers_survex(self): + import troggle.settings as settings + import troggle.core.models as models + import troggle.core.models_caves as models_caves + import troggle.core.models_survex as models_survex + from troggle.parsers.people import GetPersonExpeditionNameLookup + from troggle.core.views.caves import MapLocations + def test_import_parsers_QMs(self): + from troggle.core.models_caves import QM, Cave, LogbookEntry + from utils import save_carefully + def test_import_parsers_people(self): + from html.parser import HTMLParser + 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 + from troggle.core.models import DataIssue, Expedition + from troggle.core.models_caves import Cave, LogbookEntry, PersonTrip + from parsers.people import GetPersonExpeditionNameLookup + def test_import_core_views_caves(self): + from django.http import HttpResponse, HttpResponseRedirect + from django.shortcuts import get_object_or_404, render + import troggle.core.views.expo + from troggle.core.models import Expedition + from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation + from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm + from troggle.core.views.login import login_required_if_public + from django.contrib.auth.decorators import login_required + from django.conf import settings + def test_import_parsers_mix(self): + from troggle.parsers.logbooks import GetCaveLookup + import troggle.settings + import troggle.logbooksdump + import troggle.parsers.caves + import troggle.parsers.people + import troggle.parsers.surveys + import troggle.parsers.logbooks + import troggle.parsers.QMs + import troggle.parsers.survex + def test_import_imports(self): + from django.core import management + from django.db import connection, close_old_connections, connections + from django.contrib.auth.models import User + from django.http import HttpResponse + from django.urls import reverse + + def test_import_urls(self): + from django.conf import settings + from django.conf.urls import url, include + from django.views.generic.base import RedirectView + from django.views.generic.edit import UpdateView + from django.views.generic.list import ListView + from django.contrib import admin + from django.urls import reverse, resolve + + diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index d7eeec3..11f3bc4 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -22,73 +22,6 @@ import unittest import re from django.test import TestCase, SimpleTestCase, Client -class SimpleTest(SimpleTestCase): - def test_test_setting(self): - from django.conf import settings - self.assertEqual(settings.EMAIL_BACKEND, 'django.core.mail.backends.locmem.EmailBackend') - def test_import_TroggleModel(self): - from troggle.core.models 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 utils import save_carefully - from functools import reduce - def test_import_parsers_survex(self): - import troggle.settings as settings - import troggle.core.models as models - import troggle.core.models_caves as models_caves - import troggle.core.models_survex as models_survex - from troggle.parsers.people import GetPersonExpeditionNameLookup - from troggle.core.views.caves import MapLocations - def test_import_parsers_QMs(self): - from troggle.core.models_caves import QM, Cave, LogbookEntry - from utils import save_carefully - def test_import_parsers_people(self): - from html.parser import HTMLParser - 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 - from troggle.core.models import DataIssue, Expedition - from troggle.core.models_caves import Cave, LogbookEntry, PersonTrip - from parsers.people import GetPersonExpeditionNameLookup - def test_import_core_views_caves(self): - from django.http import HttpResponse, HttpResponseRedirect - from django.shortcuts import get_object_or_404, render - import troggle.core.views.expo - from troggle.core.models import Expedition - from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation - from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm - from troggle.core.views.login import login_required_if_public - from django.contrib.auth.decorators import login_required - from django.conf import settings - def test_import_parsers_mix(self): - from troggle.parsers.logbooks import GetCaveLookup - import troggle.settings - import troggle.logbooksdump - import troggle.parsers.caves - import troggle.parsers.people - import troggle.parsers.surveys - import troggle.parsers.logbooks - import troggle.parsers.QMs - import troggle.parsers.survex - def test_import_imports(self): - from django.core import management - from django.db import connection, close_old_connections, connections - from django.contrib.auth.models import User - from django.http import HttpResponse - from django.urls import reverse - - def test_import_urls(self): - from django.conf import settings - from django.conf.urls import url, include - from django.views.generic.base import RedirectView - from django.views.generic.edit import UpdateView - from django.views.generic.list import ListView - from django.contrib import admin - from django.urls import reverse, resolve - #class SimplePageTest(unittest.TestCase): class PageTests(TestCase): @@ -191,6 +124,25 @@ class PageTests(TestCase): 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, 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 +"'") + + + def test_expoweb_troggle_default_slash(self): + response = self.client.get('/troggle/') + self.assertEqual(response.status_code, 200) + content = response.content.decode() + ph = r"

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('/1623/others/t/via201.jpg') diff --git a/settings.py b/settings.py index a8bff2e..4deb6da 100644 --- a/settings.py +++ b/settings.py @@ -163,6 +163,5 @@ QM_PATTERN="\[\[\s*[Qq][Mm]:([ABC]?)(\d{4})-(\d*)-(\d*)\]\]" TEST_RUNNER = 'django.test.runner.DiscoverRunner' from localsettings import * - #localsettings needs to take precedence. Call it to override any existing vars. -print("+ finished importing troggle/settings.py") + diff --git a/templates/base.html b/templates/base.html index 7e2d1d3..2afab1f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -4,22 +4,23 @@ - + {% block title %}Troggle{% endblock %} {% block head %}{% endblock %} - +