summaryrefslogtreecommitdiffstats
path: root/core/TESTS/tests_logins.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2021-10-31 19:25:45 +0200
committerPhilip Sargent <philip.sargent@gmail.com>2021-10-31 19:25:45 +0200
commit2869f228d4f22976c0da4b106d901fccc3b6d59b (patch)
tree9f149761322d70c6abcd17b4175b57f218d2618e /core/TESTS/tests_logins.py
parent252fcc4716f546169294dd740c92e79d81731c47 (diff)
downloadtroggle-2869f228d4f22976c0da4b106d901fccc3b6d59b.tar.gz
troggle-2869f228d4f22976c0da4b106d901fccc3b6d59b.tar.bz2
troggle-2869f228d4f22976c0da4b106d901fccc3b6d59b.zip
fix side effects in tests: git and file upload
Diffstat (limited to 'core/TESTS/tests_logins.py')
-rw-r--r--core/TESTS/tests_logins.py40
1 files changed, 31 insertions, 9 deletions
diff --git a/core/TESTS/tests_logins.py b/core/TESTS/tests_logins.py
index 4c021aa..b09b7b6 100644
--- a/core/TESTS/tests_logins.py
+++ b/core/TESTS/tests_logins.py
@@ -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'&larr; 2020#00 &rarr;',
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):