dwg upload and django admin extra search

This commit is contained in:
Philip Sargent
2021-05-05 00:35:10 +01:00
parent 44b6770b6a
commit d374779c47
13 changed files with 333 additions and 239 deletions

View File

@@ -86,20 +86,49 @@ class PostTests(TestCase):
self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
logged_in = c.login(username=u.username, password='secretword')
with open('README.txt','r') as testf:
response = self.client.post('/scanupload/2021:00', data={'title': '2021#00', 'name': 'README.txt', 'scanfiles': testf })
with open('core/fixtures/test_upload_file.txt','r') as testf:
response = self.client.post('/scanupload/2020:00', 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_up.html', 'w') as f:
# with open('testresponse.html', 'w') as f:
# f.write(content)
t = re.search('<em>README', content)
self.assertIsNotNone(t, 'Logged in but failed to see "<em>\'README"' )
t = re.search(' saved as', content)
self.assertIsNotNone(t, 'Logged in but failed to see "File(s) saved as"' )
t = re.search('/expofiles/surveyscans/2021/2021%2300/README', content)
self.assertIsNotNone(t, 'Logged in but failed to see "/expofiles/..."' )
for ph in [ r'test_upload_',
r'&larr; 2020#00 &rarr;',
r'Upload more?']:
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
def test_dwg_upload(self):
'''Test file upload. Need to login first.
First upload is refused as it is a TXT file
Second upload is an image and suceeds.
'''
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('/dwgupload/uploads', data={'name': 'test_upload_file.txt', 'uploadfiles': testf })
content = response.content.decode()
self.assertEqual(response.status_code, 200)
t = re.search('Files refused:', content)
self.assertIsNotNone(t, 'Logged in but failed to see "Files refused:"' )
with open('core/fixtures/test_upload_nosuffix','r') as testf:
response = self.client.post('/dwgupload/uploads', data={'name': 'test_upload_nosuffix', 'uploadfiles': testf })
content = response.content.decode()
with open('testresponse.html', 'w') as f:
f.write(content)
self.assertEqual(response.status_code, 200)
for ph in [ r'Upload more',
r' saved as ',
r'Clicking on a filename only']:
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
class ComplexLoginTests(TestCase):