mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-18 09:57:10 +00:00
tidy trailing slash everywhere & fix tests
This commit is contained in:
@@ -96,6 +96,7 @@ class SimpleTest(SimpleTestCase):
|
||||
import troggle.parsers.QMs
|
||||
import troggle.parsers.scans
|
||||
import troggle.parsers.survex
|
||||
import troggle.parsers.users
|
||||
import troggle.settings
|
||||
from troggle.parsers.logbooks import GetCaveLookup
|
||||
|
||||
@@ -106,6 +107,14 @@ class SimpleTest(SimpleTestCase):
|
||||
from django.http import HttpResponse
|
||||
from django.urls import reverse
|
||||
|
||||
def test_import_users_urls(self):
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
from cryptography.fernet import Fernet
|
||||
from pathlib import Path
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
def test_import_urls(self):
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ class PostTests(TestCase):
|
||||
|
||||
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}
|
||||
"/photoupload", data={"name": "test_upload_file.txt", "renameto": "", "uploadfiles": testf}
|
||||
)
|
||||
content = response.content.decode()
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
@@ -224,7 +224,7 @@ class PostTests(TestCase):
|
||||
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}
|
||||
"/photoupload", data={"name": "test_upload_file.txt", "renameto": rename, "uploadfiles": testf}
|
||||
)
|
||||
content = response.content.decode()
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
@@ -255,11 +255,11 @@ class PostTests(TestCase):
|
||||
self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
|
||||
c.login(username=u.username, password="secretword")
|
||||
|
||||
response = self.client.post("/photoupload/", data={"photographer": "GussieFinkNottle"})
|
||||
response = self.client.post("/photoupload", data={"photographer": "GussieFinkNottle"})
|
||||
content = response.content.decode()
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
# with open('_test_response.html', 'w') as f:
|
||||
# f.write(content)
|
||||
# f.write(content)
|
||||
for ph in [r"Create new Photographer folder", r"/GussieFinkNottle/"]:
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
@@ -206,7 +206,7 @@ class ImportTest(TestCase):
|
||||
|
||||
def test_survexfiles(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/survexfile/caves/")
|
||||
response = self.client.get("/survexfile/caves")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
# with open('_test_response.html', 'w') as f:
|
||||
|
||||
@@ -141,18 +141,17 @@ class URLTests(TestCase):
|
||||
|
||||
def test_url_allscans(self):
|
||||
"""Test the {% url "allscans" %} reverse resolution
|
||||
path('survey_scans/', allscans, name="allscans"), # all the scans in all wallets
|
||||
path('survey_scans', allscans, name="allscans"), # all the scans in all wallets
|
||||
"""
|
||||
reversed_url = reverse('allscans') # NB _ must be written as - if present in name
|
||||
self.assertEqual(reversed_url, "/survey_scans/")
|
||||
self.assertEqual(reversed_url, "/survey_scans")
|
||||
|
||||
def test_url_survexcaveslist(self):
|
||||
"""Test the {% url "allscans" %} reverse resolution
|
||||
path('survexfile/caves', survex.survexcaveslist, name="survexcaveslist"),
|
||||
path('survexfile/caves/', survex.survexcaveslist, name="survexcaveslist"), # auto slash not working
|
||||
"""
|
||||
reversed_url = reverse('survexcaveslist') # NB _ must be written as - if present in name
|
||||
self.assertEqual(reversed_url, "/survexfile/caves/")
|
||||
self.assertEqual(reversed_url, "/survexfile/caves")
|
||||
|
||||
def test_url_threed(self):
|
||||
"""Test the {% url "threed" %} reverse resolution
|
||||
|
||||
@@ -457,7 +457,7 @@ class PageTests(TestCase):
|
||||
|
||||
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, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
for ph in [
|
||||
|
||||
@@ -36,6 +36,12 @@ class TroggleAppendSlashMiddleware(MiddlewareMixin):
|
||||
do NOT include
|
||||
troggle.core.middleware.TroggleAppendSlashMiddleware
|
||||
in settings.py
|
||||
|
||||
FURTHER WARNING
|
||||
If playing about with this, the 301 redirects that it creates will be cached INDEFINITELY by any browser you
|
||||
used to test it, e.g. /css/main.css with be permanetly redirected to /css/main2.css/ with dreadful
|
||||
consequences, similarly for any images visited. You have to go into your browser settings and delete all cached
|
||||
files to recover from this.
|
||||
"""
|
||||
|
||||
def process_request(self, request):
|
||||
|
||||
@@ -23,7 +23,7 @@ from troggle.core.utils import (
|
||||
write_and_commit,
|
||||
)
|
||||
from troggle.parsers.users import get_encryptor, ENCRYPTED_DIR, how_many_previous_expos
|
||||
|
||||
from .auth import login_required_if_public
|
||||
|
||||
"""The new user signup form and expo user management system in 2025.
|
||||
"""
|
||||
@@ -50,7 +50,7 @@ def signupok(request):
|
||||
{"year": SIGNUP_YEAR, "dates": SIGNUP_DATES, "signup_user": signup_user, "signedup_people": signedup_people},
|
||||
)
|
||||
|
||||
|
||||
@login_required_if_public
|
||||
def signup(request):
|
||||
"""Displays and processes the applicant signup form for the forthcoming expo
|
||||
The user must be logged-on as a personal login and that is
|
||||
@@ -75,11 +75,12 @@ def signup(request):
|
||||
if len(people) == 1:
|
||||
signup_person = people[0]
|
||||
form_read_only = False
|
||||
# else:
|
||||
experience = how_many_previous_expos(signup_person)
|
||||
else:
|
||||
experience = 0
|
||||
# No, just make the form read-only.
|
||||
# return HttpResponseRedirect("/accounts/login")
|
||||
|
||||
experience = how_many_previous_expos(signup_person)
|
||||
|
||||
if request.method == "POST": # If the form has been submitted...
|
||||
pageform = ExpoSignupForm(request.POST) # A form bound to the POST data
|
||||
|
||||
Reference in New Issue
Block a user