From e6601e1bf723e43d2b53f98b31bfc07bd8728f1f Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 21 Aug 2024 15:48:49 +0300 Subject: [PATCH] fix pointless error messages in tests --- core/TESTS/test_caves.py | 23 ++++++++++++++++------- core/views/caves.py | 16 ++++++++-------- settings.py | 3 +++ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core/TESTS/test_caves.py b/core/TESTS/test_caves.py index 2fb3102..10dd9db 100644 --- a/core/TESTS/test_caves.py +++ b/core/TESTS/test_caves.py @@ -8,6 +8,8 @@ from http import HTTPStatus from django.test import Client, TestCase from django.contrib.auth.models import User +import settings + from troggle.core.models.caves import Cave from troggle.core.models.troggle import Person, PersonExpedition, Expedition from troggle.core.utils import current_expo @@ -24,6 +26,11 @@ def create_user(name=None, last_name="Caver", is_superuser=False): u.save() return u +def create_cave(areacode="1623", kataster_number="000", official_name=""): + c = Cave(areacode=areacode, kataster_number=kataster_number, official_name=official_name) + c.save() + return c + # import troggle.settings as settings # FIXTURE_DIRS = settings.PYTHON_PATH / "core" /"fixtures" @@ -102,14 +109,10 @@ class FixtureTests(TestCase): class FixturePageTests(TestCase): - """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. And the - fixtures are certainly loaded into the db as the other tests show. + """The fixtures have a password hash which is compatible with plain-text password 'secretword' + The hash CHANGES whenever Django upgrades the encryption key length. Better to create the test uses + algorithmically and not via a fixture. """ - - # The fixtures have a password hash which is compatible with plain-text password 'secretword' - # The hash CHANGES whenever Django upgrades the encryption key length. Better to create the test uses - # algorithmically and not via a fixture. fixtures = ["expo_caves", "expo_exped"] ph = r"and leads in 800m of tortuous going to" @@ -118,6 +121,11 @@ class FixturePageTests(TestCase): pass def setUp(self): + for kataster_number in settings.NOTABLECAVES1623: + create_cave(areacode="1623", kataster_number=kataster_number) + for kataster_number in settings.NOTABLECAVES1626: + create_cave(areacode="1626", kataster_number=kataster_number) + create_user(name="expo") create_user(name="expotest") create_user(name="expotestadmin", is_superuser = True) @@ -129,6 +137,7 @@ class FixturePageTests(TestCase): def tearDown(self): User.objects.all().delete() + Cave.objects.all().delete() def test_fix_expedition(self): response = self.client.get("/expedition/2019") diff --git a/core/views/caves.py b/core/views/caves.py index 01fca9b..75b50a9 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -178,19 +178,19 @@ def caveKey(c): def getnotablecaves(): notablecaves = [] - for kataster_number in settings.NOTABLECAVESHREFS: + for kataster_number in settings.NOTABLECAVES1623: try: cave = Cave.objects.get(kataster_number=kataster_number, areacode="1623") notablecaves.append(cave) except: - print(" ! Notable Caves: FAILED to get only one cave per kataster_number OR invalid number for: "+kataster_number) + print(" ! Notable Caves: FAILED to get only one cave per kataster_number OR invalid number for: 1623-"+kataster_number) - try: - hc = Cave.objects.get(kataster_number=359, areacode="1626") - notablecaves.append(hc) - except: - # fails during the tests because this cave has not been loaded for tests, so catch it here. - pass + for kataster_number in settings.NOTABLECAVES1626: + try: + cave = Cave.objects.get(kataster_number=kataster_number, areacode="1626") + notablecaves.append(cave) + except: + print(" ! Notable Caves: FAILED to get only one cave per kataster_number OR invalid number for: 1626-"+kataster_number) print(notablecaves) return notablecaves diff --git a/settings.py b/settings.py index 3bd1d14..77b5520 100644 --- a/settings.py +++ b/settings.py @@ -37,6 +37,9 @@ CAVERN = "cavern" # for parsing .svx files and producing .3d files SURVEXPORT = "survexport" # for parsing .3d files and producing .pos files MOGRIFY = "mogrify" # for rotating images +NOTABLECAVES1623 = ["290", "291", "264", "258", "204"] +NOTABLECAVES1626 = ["359"] + # Note that this builds upon the django system installed # global settings in # django/conf/global_settings.py which is automatically loaded first.