summaryrefslogtreecommitdiffstats
path: root/core/TESTS/test_parsers.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-02-24 22:55:18 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2023-02-24 22:55:18 +0000
commita3fc9a17ed7b874434ce9ac5908bdc7fe377203e (patch)
tree2b1531711647b3ecd89f0d762594814c04d86d88 /core/TESTS/test_parsers.py
parent3d38611e4f684da4819efa763d99a2df6eb83b15 (diff)
downloadtroggle-a3fc9a17ed7b874434ce9ac5908bdc7fe377203e.tar.gz
troggle-a3fc9a17ed7b874434ce9ac5908bdc7fe377203e.tar.bz2
troggle-a3fc9a17ed7b874434ce9ac5908bdc7fe377203e.zip
New tests for parsing logbooks
Diffstat (limited to 'core/TESTS/test_parsers.py')
-rw-r--r--core/TESTS/test_parsers.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/core/TESTS/test_parsers.py b/core/TESTS/test_parsers.py
new file mode 100644
index 0000000..110dadc
--- /dev/null
+++ b/core/TESTS/test_parsers.py
@@ -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)