mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-01-19 13:22:58 +00:00
making test more robust
This commit is contained in:
@@ -10,6 +10,7 @@ uv run manage.py test -v 3 troggle.core.TESTS.test_logins
|
||||
|
||||
import pathlib
|
||||
import re
|
||||
import tempfile
|
||||
from http import HTTPStatus
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
@@ -240,8 +241,7 @@ class PostTests(TestCase):
|
||||
remove_file = pathlib.Path(settings.PHOTOS_ROOT, current_year) / rename
|
||||
if remove_file.is_file():
|
||||
remove_file.unlink()
|
||||
|
||||
|
||||
|
||||
|
||||
def test_photo_folder_create(self):
|
||||
"""Create folder for new user
|
||||
@@ -258,8 +258,8 @@ class PostTests(TestCase):
|
||||
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)
|
||||
with open('_test_response.html', 'w') as f:
|
||||
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 + "'")
|
||||
|
||||
@@ -399,6 +399,12 @@ def photoupload(request, folder=None):
|
||||
message = f'\n !! Permissions failure ?! 0 attempting to mkdir "{(ctx["yearpath"] / newphotographer)}"'
|
||||
print(message)
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
# refresh directory listing so the response shows the newly created folder
|
||||
try:
|
||||
dirs = [f.name for f in ctx["yearpath"].iterdir() if f.is_dir()]
|
||||
except FileNotFoundError:
|
||||
dirs = []
|
||||
ctx["dirs"] = sorted(dirs)
|
||||
return ctx
|
||||
|
||||
# else form for uploads / renames
|
||||
|
||||
Reference in New Issue
Block a user