diff --git a/core/TESTS/tests_logins.py b/core/TESTS/tests_logins.py index e07907f..5998881 100644 --- a/core/TESTS/tests_logins.py +++ b/core/TESTS/tests_logins.py @@ -98,7 +98,9 @@ class PostTests(TestCase): # f.write(content) for ph in [ r'test_upload_', r'← 2020#00 →', - r'Upload more?']: + r'description written', + r'plan not required', + r'Upload scan into wallet']: phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") @@ -106,6 +108,67 @@ class PostTests(TestCase): remove_file = pathlib.Path(settings.SURVEY_SCANS) / '2020' / '2020#00'/ 'test_upload_file.txt' remove_file.unlink() + def test_photo_upload(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') + + with open('core/fixtures/test_upload_file.txt','r') as testf: + response = self.client.post('/photoupload/', data={'name': 'test_upload_file.txt', '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 [ r'test_upload_', + r'Upload photos into /photos/'+str(settings.PHOTOS_YEAR), + r' you can create a new folder in your name', + r'Create new Photographer folder', + r'only photo image files are accepted']: + 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) / 'test_upload_file.txt' + remove_file.unlink() + + def test_photo_folder_create(self): + '''Create folder for new user + Create in current default year. settings.PHOTOS_YEAR + Deletes folder 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') + + response = self.client.post('/photoupload/', data={'photographer': 'GussieFinkNottle'}) + 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 [r'/GussieFinkNottle/', + r'Create new Photographer folder']: + 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_dir = pathlib.Path(settings.PHOTOS_ROOT, settings.PHOTOS_YEAR) / 'GussieFinkNottle' + remove_dir.rmdir() + + def test_dwg_upload_txt(self): '''Expect .pdf file to be refused upload