mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-21 23:01:52 +00:00
New tests for parsing logbooks
This commit is contained in:
parent
3d38611e4f
commit
a3fc9a17ed
@ -151,7 +151,7 @@ class ImportTest(TestCase):
|
||||
|
||||
LOGBOOKS_PATH = settings.EXPOWEB / LOGBOOKS_DIR
|
||||
test_year = "1986"
|
||||
self.test_logbook = LOGBOOKS_PATH / test_year / DEFAULT_LOGBOOK_FILE
|
||||
cls.test_logbook = LOGBOOKS_PATH / test_year / DEFAULT_LOGBOOK_FILE
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
99
core/TESTS/test_parsers.py
Normal file
99
core/TESTS/test_parsers.py
Normal file
@ -0,0 +1,99 @@
|
||||
"""
|
||||
We are using unittest for troggle.
|
||||
|
||||
Note that the database has not been parsed from the source files when these tests are run,
|
||||
so any path that relies on data being in the database will fail.
|
||||
|
||||
The simple redirections to files which exist, e.g. in
|
||||
/expoweb/
|
||||
/expofiles/
|
||||
/expofiles/documents/
|
||||
etc. will test fine.
|
||||
|
||||
But paths like this:
|
||||
/survey_scans/
|
||||
/caves/
|
||||
which rely on database resolution will fail unless a fixture has been set up for
|
||||
them.
|
||||
|
||||
https://docs.djangoproject.com/en/dev/topics/testing/tools/
|
||||
"""
|
||||
import re
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
from django.test import Client, SimpleTestCase, TestCase
|
||||
|
||||
from troggle.core.models.troggle import Expedition, DataIssue, Person, PersonExpedition
|
||||
import troggle.parsers.logbooks as lbp
|
||||
|
||||
TEST_YEAR = "1986"
|
||||
lbp.ENTRIES[TEST_YEAR] = 4 # number of entries in the test logbook
|
||||
|
||||
class ImportTest(TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
def make_person(firstname, lastname, nickname=False, vfho=False, guest=False):
|
||||
fullname = f"{firstname} {lastname}"
|
||||
lookupAttribs = {"first_name": firstname, "last_name": (lastname or "")}
|
||||
nonLookupAttribs = {"is_vfho": vfho, "fullname": fullname, "nickname": nickname}
|
||||
person = Person.objects.create(**nonLookupAttribs, **lookupAttribs)
|
||||
|
||||
lookupAttribs = {"person": person, "expedition": cls.test_expo}
|
||||
nonLookupAttribs = {"is_guest": guest}
|
||||
pe = PersonExpedition.objects.create(**nonLookupAttribs, **lookupAttribs)
|
||||
|
||||
return person
|
||||
|
||||
import troggle.settings as settings
|
||||
|
||||
LOGBOOKS_PATH = settings.EXPOWEB / lbp.LOGBOOKS_DIR
|
||||
|
||||
cls.test_logbook = LOGBOOKS_PATH / TEST_YEAR / lbp.DEFAULT_LOGBOOK_FILE
|
||||
frontmatter_file = LOGBOOKS_PATH / TEST_YEAR / "frontmatter.html"
|
||||
if frontmatter_file.is_file():
|
||||
frontmatter_file.unlink() # delete if it exists
|
||||
|
||||
lookupAttribs = {"year": TEST_YEAR}
|
||||
nonLookupAttribs = {"name": f"CUCC expo-test {TEST_YEAR}"}
|
||||
cls.test_expo = Expedition.objects.create(**nonLookupAttribs, **lookupAttribs)
|
||||
|
||||
fred = make_person("Fred", "Smartarse", nickname="freddy")
|
||||
phil = make_person("Phil", "Tosser", nickname="tosspot")
|
||||
dave = make_person("David", "Smartarse", "")
|
||||
mike = make_person("Michael", "Wideboy", "WB", vfho=True)
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_logbook_exists(self):
|
||||
self.assertTrue(self.test_logbook.is_file())
|
||||
|
||||
def test_logbook_parse(self):
|
||||
|
||||
lbp.LoadLogbook(self.test_expo)
|
||||
|
||||
issues = DataIssue.objects.all()
|
||||
messages = []
|
||||
for i in issues:
|
||||
if i.parser=="logbooks":
|
||||
# f"{self.parser} - {self.message}"
|
||||
messages.append(i.message)
|
||||
print(f"'{i.message}'")
|
||||
|
||||
expected = [
|
||||
" ! - 1986 No name match for: 'Kurt Keinnamen' in entry tid='1986_s02' for this expedition year.",
|
||||
]
|
||||
|
||||
not_expected = [
|
||||
" ! - 1986 No name match for: 'Dave Smartarse' in entry tid='1986_s01' for this expedition year.",
|
||||
" ! - 1986 Warning: logentry: surface - stupour - no expo member author for entry '1986_s03'",
|
||||
" ! - 1986 Warning: logentry: 123 - wave 2 - no expo member author for entry '1986_s02'",
|
||||
]
|
||||
|
||||
for e in expected:
|
||||
self.assertIn(e, messages)
|
Loading…
Reference in New Issue
Block a user