test fixed to match new code

This commit is contained in:
Philip Sargent 2022-09-23 21:23:15 +03:00
parent 9d56e467cd
commit c3672b476c

View File

@ -13,6 +13,7 @@ from http import HTTPStatus
from django.test import TestCase, SimpleTestCase, TransactionTestCase, Client from django.test import TestCase, SimpleTestCase, TransactionTestCase, Client
from troggle.core.models.survex import Wallet from troggle.core.models.survex import Wallet
from troggle.core.models.troggle import Expedition
import troggle.settings as settings import troggle.settings as settings
@ -80,7 +81,9 @@ class PostTests(TestCase):
self.user = User.objects.get(username='expotest') self.user = User.objects.get(username='expotest')
self.client = Client() self.client = Client()
wname = "2020#00" testyear = '2022'
wname = f'{testyear}:00'
self.testyear = testyear
w = Wallet() w = Wallet()
w.pk = 9100 w.pk = 9100
w.fpath = str(pathlib.Path(settings.SCANS_ROOT, wname)) w.fpath = str(pathlib.Path(settings.SCANS_ROOT, wname))
@ -88,6 +91,11 @@ class PostTests(TestCase):
w.save() w.save()
self.wallet = w self.wallet = w
e = Expedition()
e.year = testyear
e.save()
self.expedition = e
def test_scan_upload(self): def test_scan_upload(self):
'''Expect scan upload to wallet to work on any file '''Expect scan upload to wallet to work on any file
@ -100,7 +108,7 @@ class PostTests(TestCase):
w = self.wallet w = self.wallet
from django.contrib.auth.models import User from django.contrib.auth.models import User
u = User.objects.get(username='expotest') u = User.objects.get(username='expotest')
testyear = '2049' testyear = self.testyear
self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE') self.assertTrue(u.is_active, 'User \'' + u.username + '\' is INACTIVE')
logged_in = c.login(username=u.username, password='secretword') logged_in = c.login(username=u.username, password='secretword')
@ -120,15 +128,15 @@ class PostTests(TestCase):
phmatch = re.search(ph, content) phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
# Does not use the filename Django actually uses, assumes it is unchanged. Potential bug. # # Does not use the filename Django actually uses, assumes it is unchanged. Potential bug.
remove_file = pathlib.Path(settings.SCANS_ROOT) / f'{testyear}' / f'{testyear}#00'/ 'test_upload_file.txt' # remove_file = pathlib.Path(settings.SCANS_ROOT) / f'{testyear}' / f'{testyear}#00'/ 'test_upload_file.txt'
remove_file.unlink() # remove_file.unlink()
# Undo the auto create and commit of a new wallet # # Undo the auto create and commit of a new wallet
cwd = settings.DRAWINGS_DATA # cwd = settings.DRAWINGS_DATA
sp = subprocess.run([settings.GIT, "reset", "--hard", "master^"], cwd=cwd, capture_output=True, text=True) # 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)}') # print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
if sp.returncode != 0: # if sp.returncode != 0:
print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}') # print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
def test_photo_upload(self): def test_photo_upload(self):