From 32e487eca6b12b70cf6ced3b662d815a9bcbb7cb Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 22 Nov 2023 18:58:19 +0000 Subject: [PATCH] still working on tests --- core/TESTS/test_caves.py | 11 ++++++++--- core/views/expo.py | 10 +++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/TESTS/test_caves.py b/core/TESTS/test_caves.py index 8390df5..d86104f 100644 --- a/core/TESTS/test_caves.py +++ b/core/TESTS/test_caves.py @@ -158,7 +158,12 @@ class FixturePageTests(TestCase): """Expect to get Page Not Found and status 404""" ph = self.ph ph = "Probably a mistake." - response = self.client.get("/1623/115") + response = self.client.get("/1623/115/115") + + # content = response.content.decode() + # with open('_test_bare_url115.html', 'w') as f: + # f.write(content) + self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND) content = response.content.decode() @@ -170,11 +175,11 @@ class FixturePageTests(TestCase): ph = self.ph ph = "Probably a mistake." response = self.client.get("/1623-115") - self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND) + self.assertEqual(response.status_code, HTTPStatus.FOUND) # 302 redirected content = response.content.decode() phmatch = re.search(ph, content) - self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'") # 200 & Page Not Found + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'") # 302 & Page Not Found def test_fix_caves284(self): response = self.client.get("/caves") diff --git a/core/views/expo.py b/core/views/expo.py index 8525b16..c8d9482 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -133,7 +133,7 @@ def expowebpage(request, expowebpath, path): if not os.path.isfile(expowebpath / path): # Should not get here if the path has suffix "_edit" print(f" - 404 error in expowebpage() {path}") - return render(request, "pagenotfound.html", {"path": path}, status="404") + return render(request, "pagenotfound.html", {"path": path}, status=404) # print(f' - {sys_getfilesystemencoding()=}') if sys_getfilesystemencoding() != "utf-8": @@ -239,9 +239,9 @@ def mediapage(request, subpath=None, doc_root=None): try: return HttpResponse(content=open(filetobeopened, "rb"), content_type=getmimetype(subpath)) except IOError: - return render(request, "pagenotfound.html", {"path": subpath}, status="404") + return render(request, "pagenotfound.html", {"path": subpath}, status=404) else: - return render(request, "pagenotfound.html", {"path": subpath}, status="404") + return render(request, "pagenotfound.html", {"path": subpath}, status=404) def expopage(request, path): @@ -270,7 +270,7 @@ def expopage(request, path): if (expowebpath / path / p).is_file(): # This needs to reset the path to the new subdirectory return HttpResponseRedirect("/" + str(Path(path) / p)) - return render(request, "pagenotfound.html", {"path": Path(path) / "index.html"}, status="404") + return render(request, "pagenotfound.html", {"path": Path(path) / "index.html"}, status=404) if path.endswith("/"): # we already know it is not a directory. @@ -293,7 +293,7 @@ def expopage(request, path): content_type = getmimetype(path) return HttpResponse(content=content, content_type=content_type) except IOError: - return render(request, "pagenotfound.html", {"path": path}, status="404") + return render(request, "pagenotfound.html", {"path": path}, status=404) def getmimetype(path):