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

Fixed test to undo side-effect git commit

This commit is contained in:
Philip Sargent
2022-09-12 21:28:07 +03:00
parent 785845598f
commit fd57071411
2 changed files with 13 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ Modified for Expo April 2021.
import unittest
import re
import pathlib
import subprocess
from http import HTTPStatus
from django.test import TestCase, SimpleTestCase, TransactionTestCase, Client
@@ -99,19 +100,20 @@ class PostTests(TestCase):
w = self.wallet
from django.contrib.auth.models import User
u = User.objects.get(username='expotest')
testyear = '2049'
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('/scanupload/2020:00', data={'name': 'test_upload_file.txt', 'uploadfiles': testf })
response = self.client.post(f'/scanupload/{testyear}: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_response.html', 'w') as f:
f.write(content)
for ph in [ r'test_upload_',
r'← 2020#00 →',
rf'← {testyear}#00 →',
r'description written',
r'Plan not required',
r'edit settings or upload a file']:
@@ -119,8 +121,15 @@ class PostTests(TestCase):
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.SCANS_ROOT) / '2020' / '2020#00'/ 'test_upload_file.txt'
remove_file = pathlib.Path(settings.SCANS_ROOT) / f'{testyear}' / f'{testyear}#00'/ 'test_upload_file.txt'
remove_file.unlink()
# Undo the auto create and commit of a new wallet
cwd = settings.DRAWINGS_DATA
sp = subprocess.run([settings.GIT, "reset", "--hard", "master^"], cwd=cwd, capture_output=True, text=True)
print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
if sp.returncode != 0:
print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
def test_photo_upload(self):
'''Expect photo upload to work on any file (contrary to msg on screen)