From 81b5198cd127f47e888ae6ef3760a18793f9819e Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sat, 16 Sep 2023 19:53:39 +0300 Subject: [PATCH] fix code so tests work --- core/TESTS/tests.py | 2 ++ core/views/caves.py | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index 00a5021..4d3286f 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -173,6 +173,8 @@ class PageTests(TestCase): self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'") def test_caves_page(self): + # Throws up lots of cave error msgs because it is looking at something which is not loaded for the tests + # but the test itself does not fail response = self.client.get("/caves") self.assertEqual(response.status_code, HTTPStatus.OK) content = response.content.decode() diff --git a/core/views/caves.py b/core/views/caves.py index ef234c1..5196bce 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -114,10 +114,14 @@ def getnotablecaves(): cave = Cave.objects.get(kataster_number=kataster_number, areacode="1623") notablecaves.append(cave) except: - print(" ! 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: "+kataster_number) - hc = Cave.objects.get(kataster_number=359, areacode="1626") - notablecaves.append(hc) + 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 print(notablecaves) return notablecaves