diff --git a/core/TESTS/tests_logins.py b/core/TESTS/tests_logins.py index a91e13e..7b47365 100644 --- a/core/TESTS/tests_logins.py +++ b/core/TESTS/tests_logins.py @@ -125,7 +125,7 @@ class PostTests(TestCase): logged_in = c.login(username=u.username, password='secretword') with open('core/fixtures/test_upload_file.txt','r') as testf: - response = self.client.post('/photoupload/', data={'name': 'test_upload_file.txt', 'uploadfiles': testf }) + response = self.client.post('/photoupload/', data={'name': 'test_upload_file.txt', 'renameto': '', 'uploadfiles': testf }) content = response.content.decode() self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, HTTPStatus.OK) @@ -142,6 +142,35 @@ class PostTests(TestCase): # Does not use the filename Django actually uses, assumes it is unchanged. Potential bug. remove_file = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / 'test_upload_file.txt' remove_file.unlink() + + def test_photo_upload_rename(self): + '''Expect photo upload to work on any file (contrary to msg on screen) + Upload into current default year. settings.PHOTOS_YEAR + Deletes file afterwards + Need to login first. + ''' + c = self.client + from django.contrib.auth.models import User + u = User.objects.get(username='expotest') + + self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE') + logged_in = c.login(username=u.username, password='secretword') + + rename = 'RENAMED-FILE.JPG' + with open('core/fixtures/test_upload_file.txt','r') as testf: + response = self.client.post('/photoupload/', data={'name': 'test_upload_file.txt', 'renameto': rename, 'uploadfiles': testf }) + content = response.content.decode() + self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, HTTPStatus.OK) + # with open('_test_response.html', 'w') as f: + # f.write(content) + for ph in [rename]: + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + + # Does not use the filename Django actually uses, assumes it is unchanged. Potential bug. + remove_file = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / rename + remove_file.unlink() def test_photo_folder_create(self): '''Create folder for new user