login decorator moved into views & .gitignore

This commit is contained in:
Philip Sargent 2021-04-02 15:51:14 +01:00
parent c8cc1673e0
commit d841faa057
8 changed files with 32 additions and 19 deletions

16
.gitignore vendored
View File

@ -15,22 +15,17 @@ _1623.pos
_1623.svx _1623.svx
_16230.svx _16230.svx
cave-lookup.json cave-lookup.json
core/migrations/0001_initial.py core/migrations/*
credentials.py
db* db*
desktop.ini desktop.ini
diffsettings.txt diffsettings.txt
flatpages/migrations/0001_initial.py
ignored-files.log ignored-files.log
import_profile.json import_profile.json
lines-of-python.txt lines-of-python.txt
lines-of-templates.txt lines-of-templates.txt
loadlogbk.log loadlogbk.log
loadsurvexblks.log loadsurvexblks.log
localsettings.py
localsettings-expo-live.py
logbktrips.shelve logbktrips.shelve
media/images/*
memdump.sql memdump.sql
my_project.dot my_project.dot
parsing_log.txt parsing_log.txt
@ -45,4 +40,13 @@ troggle.sqlite-journal
troggle_log.txt troggle_log.txt
tunnel-import.log tunnel-import.log
logbktrips.shelve.db logbktrips.shelve.db
credentials.py
localsettings.py localsettings.py
localsettings-expo-live.py
_deploy/old/localsettings-expo-live.py
_deploy/old/localsettings.py
debian/localsettings.py
debian/credentials.py
wsl/localsettings.py
wsl/credentials.py

View File

@ -60,7 +60,7 @@ class SimpleTest(SimpleTestCase):
from troggle.core.models import Expedition from troggle.core.models import Expedition
from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation 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.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
from troggle.helper import login_required_if_public from troggle.core.views.login import login_required_if_public
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.conf import settings from django.conf import settings
def test_import_parsers_mix(self): def test_import_parsers_mix(self):
@ -92,6 +92,9 @@ class SimpleTest(SimpleTestCase):
#class SimplePageTest(unittest.TestCase): #class SimplePageTest(unittest.TestCase):
class PageTests(TestCase): class PageTests(TestCase):
'''These tests may appear to be redundant, but in fact they exercise different bits of code. The urls.py
dispatcher is sending these URLs view via different 'view' handlers, and they all need verifying.
'''
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
# Set up data for the whole TestCase # Set up data for the whole TestCase
@ -112,14 +115,6 @@ class PageTests(TestCase):
phmatch = re.search(ph, content) phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
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): def test_expoweb_root_slash(self):
response = self.client.get('/') response = self.client.get('/')
content = response.content.decode() content = response.content.decode()
@ -177,6 +172,11 @@ class PageTests(TestCase):
phmatch = re.search(ph, content) phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") 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')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.content), 6057)
def test_cave_kataster_not_found(self): def test_cave_kataster_not_found(self):
# database not loaded, so no caves found # database not loaded, so no caves found
@ -378,6 +378,9 @@ class PageTests(TestCase):
phmatch = re.search(ph, content) phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
# ADD TESTS when we are redirecting /expofiles/ to get the actual files using e.g.
# import requests
# page = requests.get("http://dataquestio.github.io/web-scraping-pages/simple.html")
# these need a fixture to load the datbase before they will pass # 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 # we also need tests for invalid queries to check that error pages are right

View File

@ -9,6 +9,12 @@ from troggle.core.models import Person, PersonExpedition, Expedition, DataIssue
from troggle.core.models_caves import Cave, Area, Entrance, CaveAndEntrance, LogbookEntry, PersonTrip, QM from troggle.core.models_caves import Cave, Area, Entrance, CaveAndEntrance, LogbookEntry, PersonTrip, QM
from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexStation, ScansFolder, SingleScan from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexStation, ScansFolder, SingleScan
'''This code significantly adds to the capabilities of the Django Management control panel for Troggle data.
In particular, it enables JSON export of any data with 'export_as_json'
and configures the search fields to be used within the control panel.
What is the search path for the css and js inclusions in the Media subclasses though ?!
'''
class TroggleModelAdmin(admin.ModelAdmin): class TroggleModelAdmin(admin.ModelAdmin):

View File

@ -19,7 +19,7 @@ from troggle.core.views import expo
from troggle.core.models import Expedition, DataIssue from troggle.core.models import Expedition, DataIssue
from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation, GetCaveLookup from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation, GetCaveLookup
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
from troggle.helper import login_required_if_public from .login import login_required_if_public
class MapLocations(object): class MapLocations(object):
p = [ p = [

View File

@ -13,7 +13,7 @@ from django.contrib import admin
import django.forms as forms import django.forms as forms
from troggle.helper import login_required_if_public from .login import login_required_if_public
from troggle.core.models_caves import Cave from troggle.core.models_caves import Cave
import troggle.core.views.caves import troggle.core.views.caves
import troggle.settings as settings import troggle.settings as settings

View File

@ -18,7 +18,7 @@ from troggle.core.forms import getTripForm # , get_name, PersonForm
from troggle.core.models import Expedition, Person, PersonExpedition from troggle.core.models import Expedition, Person, PersonExpedition
from troggle.core.models_caves import LogbookEntry, PersonTrip from troggle.core.models_caves import LogbookEntry, PersonTrip
from troggle.core.models_survex import SurvexBlock from troggle.core.models_survex import SurvexBlock
from troggle.helper import login_required_if_public from .login import login_required_if_public
from troggle.parsers.logbooks import LoadLogbookForExpedition from troggle.parsers.logbooks import LoadLogbookForExpedition
from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.people import GetPersonExpeditionNameLookup

View File

@ -11,7 +11,7 @@ from django.template import Context, loader
import troggle.parsers.imports import troggle.parsers.imports
from troggle.core.models import Expedition, Person, PersonExpedition from troggle.core.models import Expedition, Person, PersonExpedition
from troggle.core.models_caves import LogbookEntry, QM, Cave, PersonTrip from troggle.core.models_caves import LogbookEntry, QM, Cave, PersonTrip
from troggle.helper import login_required_if_public from .login import login_required_if_public
from troggle.core.forms import UploadFileForm from troggle.core.forms import UploadFileForm
print("** importing troggle/core/views.other.py") print("** importing troggle/core/views.other.py")