add test for renaming single photo

This commit is contained in:
Philip Sargent 2022-08-11 23:44:19 +03:00
parent 1bbfd1e517
commit 5149cf1ece

View File

@ -125,7 +125,7 @@ class PostTests(TestCase):
logged_in = c.login(username=u.username, password='secretword') logged_in = c.login(username=u.username, password='secretword')
with open('core/fixtures/test_upload_file.txt','r') as testf: 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() content = response.content.decode()
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, HTTPStatus.OK) 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. # 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 = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / 'test_upload_file.txt'
remove_file.unlink() 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): def test_photo_folder_create(self):
'''Create folder for new user '''Create folder for new user