2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

debugged lbe edit tests

This commit is contained in:
Philip Sargent 2023-09-04 00:25:35 +03:00
parent 2c89cdc1b9
commit 3a04a8490e

View File

@ -24,6 +24,7 @@ from http import HTTPStatus
from django.test import Client, SimpleTestCase, TestCase from django.test import Client, SimpleTestCase, TestCase
from troggle.core.models.logbooks import LogbookEntry
from troggle.core.models.troggle import Expedition, DataIssue, Person, PersonExpedition from troggle.core.models.troggle import Expedition, DataIssue, Person, PersonExpedition
import troggle.parsers.logbooks as lbp import troggle.parsers.logbooks as lbp
@ -80,7 +81,7 @@ class ImportTest(TestCase):
def test_logbook_exists(self): def test_logbook_exists(self):
self.assertTrue(self.test_logbook.is_file()) self.assertTrue(self.test_logbook.is_file())
def test_logbook_parse(self): def test_logbook_parse_issues(self):
"""This is just testing the db not the web page """This is just testing the db not the web page
""" """
lbp.LoadLogbook(self.test_expo) # i.e. load the 1986 logbook lbp.LoadLogbook(self.test_expo) # i.e. load the 1986 logbook
@ -102,9 +103,9 @@ class ImportTest(TestCase):
" ! - 1986 Warning: logentry: surface - stupour - no expo member author for entry '1986-07-31a'", " ! - 1986 Warning: logentry: surface - stupour - no expo member author for entry '1986-07-31a'",
" ! - 1986 Warning: logentry: 123 - wave 2 - no expo member author for entry '1986-08-01a'", " ! - 1986 Warning: logentry: 123 - wave 2 - no expo member author for entry '1986-08-01a'",
] ]
with open('_test_response.txt', 'w') as f: # with open('_test_response.txt', 'w') as f:
for m in messages: # for m in messages:
f.write(m) # f.write(m)
messages_text = ", ".join(messages) messages_text = ", ".join(messages)
for e in expected: for e in expected:
phmatch = re.search(e, messages_text) phmatch = re.search(e, messages_text)
@ -119,7 +120,7 @@ class ImportTest(TestCase):
response = self.client.get(f"/logbookentry/1986-07-27/1986-07-27a") response = self.client.get(f"/logbookentry/1986-07-27/1986-07-27a")
self.assertEqual(response.status_code, HTTPStatus.OK) self.assertEqual(response.status_code, HTTPStatus.OK)
content = response.content.decode() content = response.content.decode()
# with open('_test_response.html', 'w') as f: # with open('_test_response_1986-07-27a.html', 'w') as f:
# f.write(content) # f.write(content)
expected = [ expected = [
"<title>Logbook CUCC expo-test 1986 123 - 123 Wave 1</title>", "<title>Logbook CUCC expo-test 1986 123 - 123 Wave 1</title>",
@ -139,11 +140,11 @@ class ImportTest(TestCase):
response = self.client.get(f"/logbookedit/") response = self.client.get(f"/logbookedit/")
self.assertEqual(response.status_code, HTTPStatus.OK) self.assertEqual(response.status_code, HTTPStatus.OK)
content = response.content.decode() content = response.content.decode()
with open('_test_response.html', 'w') as f: # with open('_test_response.html', 'w') as f:
f.write(content) # f.write(content)
expected = [ expected = [
"New Logbook Entry in ", "New Logbook Entry in ",
"Other names (comma separated)", "Everyone else involved",
"Place: cave name, or 'plateau', 'topcamp' etc.", "Place: cave name, or 'plateau', 'topcamp' etc.",
] ]
for ph in expected: for ph in expected:
@ -152,18 +153,24 @@ class ImportTest(TestCase):
def test_lbe_edit(self): def test_lbe_edit(self):
"""This page requires the user to be logged in first, hence the extra shenanigans
"""
c = self.client c = self.client
u = self.user u = self.user
c.login(username=u.username, password="secretword") c.login(username=u.username, password="secretword")
response = self.client.get(f"/logbookedit/1986-07-27a") lbp.LoadLogbook(self.test_expo) # i.e. load the 1986 logbook, which has this logbook entry
# muliple loads are overwriting the lbes and incrementing the a, b, c etc, so get one that works
lbe = LogbookEntry.objects.get(date="1986-07-31") # only one on this date in fixture
response = self.client.get(f"/logbookedit/{lbe.slug}")
self.assertEqual(response.status_code, HTTPStatus.OK) self.assertEqual(response.status_code, HTTPStatus.OK)
content = response.content.decode() content = response.content.decode()
with open('_test_response_edit.html', 'w') as f: # with open('_test_response_edit.html', 'w') as f:
f.write(content) # f.write(content)
expected = [ expected = [
"Edit Logbook Entry on 1986-07-27", "Edit Logbook Entry on 1986-07-31",
"Other names (comma separated)", "Other names \(comma separated\)", # regex so slashes need to be espcaped
"Place: cave name, or 'plateau', 'topcamp' etc.", "Place: cave name, or 'plateau', 'topcamp' etc.",
] ]
for ph in expected: for ph in expected: