diff --git a/core/TESTS/test_logins.py b/core/TESTS/test_logins.py index 9602b94..60b9d7f 100644 --- a/core/TESTS/test_logins.py +++ b/core/TESTS/test_logins.py @@ -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 + "'") diff --git a/core/views/uploads.py b/core/views/uploads.py index 02f4d04..396890a 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -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