mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-15 23:07:07 +00:00
fix side effects in tests: git and file upload
This commit is contained in:
@@ -7,10 +7,12 @@ Modified for Expo April 2021.
|
||||
|
||||
import unittest
|
||||
import re
|
||||
import pathlib
|
||||
from http import HTTPStatus
|
||||
|
||||
from django.test import TestCase, SimpleTestCase, TransactionTestCase, Client
|
||||
|
||||
import troggle.settings as settings
|
||||
|
||||
class DataTests(TestCase ):
|
||||
'''These check that the NULL and NON-UNIQUE constraints are working in the database '''
|
||||
@@ -77,7 +79,8 @@ class PostTests(TestCase):
|
||||
self.client = Client()
|
||||
|
||||
def test_scan_upload(self):
|
||||
'''Test file upload. Need to login first.
|
||||
'''Expect scan upload to wallet to work on any file
|
||||
Need to login first.
|
||||
'''
|
||||
c = self.client
|
||||
from django.contrib.auth.models import User
|
||||
@@ -91,18 +94,22 @@ class PostTests(TestCase):
|
||||
content = response.content.decode()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
# with open('testresponse.html', 'w') as f:
|
||||
# with open('_test_response.html', 'w') as f:
|
||||
# f.write(content)
|
||||
for ph in [ r'test_upload_',
|
||||
r'← 2020#00 →',
|
||||
r'Upload more?']:
|
||||
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.SURVEY_SCANS) / '2020' / '2020#00'/ 'test_upload_file.txt'
|
||||
remove_file.unlink()
|
||||
|
||||
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.
|
||||
|
||||
def test_dwg_upload_txt(self):
|
||||
'''Expect .txt file to be refused upload
|
||||
Need to login first.
|
||||
'''
|
||||
c = self.client
|
||||
from django.contrib.auth.models import User
|
||||
@@ -118,17 +125,32 @@ class PostTests(TestCase):
|
||||
t = re.search('Files refused:', content)
|
||||
self.assertIsNotNone(t, 'Logged in but failed to see "Files refused:"' )
|
||||
|
||||
def test_dwg_upload_drawing(self):
|
||||
'''Expect no-suffix file to upload
|
||||
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_nosuffix','r') as testf:
|
||||
response = self.client.post('/dwgupload/uploads', data={'name': 'test_upload_nosuffix', 'uploadfiles': testf })
|
||||
response = self.client.post('/dwguploadnogit/uploads', data={'name': 'test_upload_nosuffix', 'uploadfiles': testf })
|
||||
content = response.content.decode()
|
||||
with open('testresponse.html', 'w') as f:
|
||||
f.write(content)
|
||||
# with open('_test_response.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 +"'")
|
||||
|
||||
# Does not use the filename Django actually uses, assumes it is unchanged. Potential bug.
|
||||
remove_file = pathlib.Path(settings.DRAWINGS_DATA) / 'uploads' / 'test_upload_nosuffix'
|
||||
remove_file.unlink()
|
||||
|
||||
|
||||
class ComplexLoginTests(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user