diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2021-04-30 18:02:05 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2021-04-30 18:02:05 +0100 |
commit | 8f1d6e2cc22563bd4fca94f5e7e08085154e8262 (patch) | |
tree | 9f453f93a840191b5857168a9359bfb83c9184b0 /core/TESTS/tests_logins.py | |
parent | fde30685a82d835f99a46b4b5f37335f6390980e (diff) | |
download | troggle-8f1d6e2cc22563bd4fca94f5e7e08085154e8262.tar.gz troggle-8f1d6e2cc22563bd4fca94f5e7e08085154e8262.tar.bz2 troggle-8f1d6e2cc22563bd4fca94f5e7e08085154e8262.zip |
file upload integration test working
Diffstat (limited to 'core/TESTS/tests_logins.py')
-rw-r--r-- | core/TESTS/tests_logins.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/TESTS/tests_logins.py b/core/TESTS/tests_logins.py index 45bd33e..66e69c6 100644 --- a/core/TESTS/tests_logins.py +++ b/core/TESTS/tests_logins.py @@ -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''' |