2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-14 15:37:19 +00:00

file upload integration test working

This commit is contained in:
Philip Sargent
2021-04-30 18:02:05 +01:00
parent fde30685a8
commit 8f1d6e2cc2
8 changed files with 128 additions and 102 deletions

View File

@@ -7,6 +7,8 @@ Modified for Expo April 2021.
import unittest
import re
from http import HTTPStatus
from django.test import TestCase, SimpleTestCase, TransactionTestCase, Client
@@ -61,6 +63,41 @@ class FixturePageTests(TestCase):
t = re.search(r'Troggle administration', content)
self.assertIsNone(t, 'Logged in as \'' + u.username + '\' (not staff) but still managed to get the Admin page' )
class PostTests(TestCase):
'''
'''
fixtures = ['auth_users']
@classmethod
def setUpTestData(cls):
pass
def setUp(self):
from django.contrib.auth.models import User
self.user = User.objects.get(username='expotest')
self.client = Client()
def test_scan_upload(self):
'''Test file 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('README.txt','r') as testf:
response = self.client.post('/scanupload/2021:02', data={'title': '2021#00', 'name': 'README.txt', 'scanfiles': 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:
f.write(content)
t = re.search(r'README.txt', content)
self.assertIsNone(t, 'Logged in as \'' + u.username + '\' (not staff) but failed to upload file' )
class ComplexLoginTests(TestCase):
'''These test the login and capabilities of logged-in users, they do not use fixtures'''