mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 08:41:51 +00:00
Now 99 tests
This commit is contained in:
parent
1cb81cbb09
commit
6ab7a340e2
@ -21,6 +21,7 @@ https://docs.djangoproject.com/en/dev/topics/testing/tools/
|
||||
import re
|
||||
import subprocess
|
||||
import unittest
|
||||
from http import HTTPStatus
|
||||
|
||||
from django.test import Client, SimpleTestCase, TestCase
|
||||
|
||||
@ -100,3 +101,27 @@ class ImportTest(TestCase):
|
||||
self.assertIn(e, messages)
|
||||
for e in not_expected:
|
||||
self.assertNotIn(e, messages)
|
||||
|
||||
def test_aliases(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get(f"/aliases/{TEST_YEAR}")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
with open('_test_response.html', 'w') as f:
|
||||
f.write(content)
|
||||
ph = f"'fsmartarse'"
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
|
||||
def test_people(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/people")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
with open('_test_response.html', 'w') as f:
|
||||
f.write(content)
|
||||
ph = f"<td><a href=\"/personexpedition/FredSmartarse/{TEST_YEAR}\">{TEST_YEAR}</a></td>"
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
@ -476,6 +476,71 @@ class PageTests(TestCase):
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
|
||||
def test_statistics(self):
|
||||
response = self.client.get("/statistics")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
ph = r"0 expeditions: 0 people, 0 caves and 0 logbook entries."
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
def test_stats(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/stats")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
ph = r"Total length: 0.0 km adding up the total for each year."
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
def test_dataissues(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/dataissues")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
ph = r"as well as these import/parsing issues"
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
def test_therionissues(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/therionissues")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
ph = r"! Un-parsed image filename"
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
def test_surveximport(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/surveximport")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
# with open('_test_response.html', 'w') as f:
|
||||
# f.write(content)
|
||||
ph = r"The number at the left-hand margin is the depth"
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
def test_survexdebug(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/survexdebug")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
ph = r"Running list of warnings during import"
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
def test_eastings(self):
|
||||
# Needs another test with test data
|
||||
response = self.client.get("/eastings")
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
content = response.content.decode()
|
||||
ph = r"<tr><th>Survex Station</th><th>x</th><th>y</th></tr>"
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
|
||||
# ADD TESTS when we are redirecting /expofiles/ to get the actual files using e.g.
|
||||
# import requests
|
||||
# page = requests.get("http://dataquestio.github.io/web-scraping-pages/simple.html")
|
||||
|
@ -1849,7 +1849,7 @@ class LoadingSurvex:
|
||||
Path(svxpath).parent
|
||||
|
||||
if not svxpath.is_file():
|
||||
message = f' ! BAD survex file "{fullpath}" specified in *include in {calledpath} '
|
||||
message = f' ! BAD. "{fullpath}" is not a file, specified in *include in {calledpath} '
|
||||
stash_data_issue(parser="survex", message=message)
|
||||
print(message)
|
||||
return
|
||||
@ -2033,8 +2033,6 @@ def FindAndLoadSurvex(survexblockroot):
|
||||
svx_scan.svxfileslist = [] # free memory
|
||||
svx_scan = None # Hmm. Does this actually delete all the instance variables if they are lists, dicts etc.?
|
||||
|
||||
print(f" - RunSurvexIfNeeded cavern on '{fullpathtotop}'", file=sys.stderr)
|
||||
omit_scan.RunSurvexIfNeeded(fullpathtotop, fullpathtotop)
|
||||
omit_scan.check_unique_name(fullpathtotop)
|
||||
omit_scan.uniquefile[unseensroot] = ["0"]
|
||||
|
||||
@ -2130,6 +2128,45 @@ def FindAndLoadSurvex(survexblockroot):
|
||||
|
||||
return legsnumber
|
||||
|
||||
def parse_one_file(fpath): # --------------------------------------in progress-------------------
|
||||
"""Parse just one file. Use when re-loading after editing.
|
||||
NB careful of *include lines, which may exist! Ignore them.
|
||||
"""
|
||||
print("\n - Loading One Survex file (LinearLoad)", file=sys.stderr)
|
||||
svx_load = LoadingSurvex()
|
||||
|
||||
omitsfileroot = MakeOmitFileRoot(fpath) # NO! This always creats a SurvexFile object. We are overwriting one..
|
||||
survexomitsroot = SurvexBlock(
|
||||
name=OMITBLOCK, survexpath="", survexfile=omitsfileroot, legsall=0, legslength=0.0
|
||||
)
|
||||
survexomitsroot.save()
|
||||
# SurvexBlock.objects.all().delete()
|
||||
# SurvexFile.objects.all().delete()
|
||||
# SurvexDirectory.objects.all().delete()
|
||||
# SurvexPersonRole.objects.all().delete()
|
||||
# SurvexStation.objects.all().delete()
|
||||
print(" - Loading Survex Blocks...")
|
||||
|
||||
svx_load.survexdict[survexfileroot.survexdirectory] = []
|
||||
svx_load.survexdict[survexfileroot.survexdirectory].append(survexfileroot)
|
||||
svx_load.svxdirs[""] = survexfileroot.survexdirectory
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
svx_load.LinearLoad(survexblockroot, survexfileroot.path, collatefilename)
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
legsnumber = svx_load.legsnumber
|
||||
|
||||
print(f" - Number of SurvexDirectories: {len(svx_load.survexdict):,}")
|
||||
tf = 0
|
||||
for d in svx_load.survexdict:
|
||||
tf += len(svx_load.survexdict[d])
|
||||
print(f" - Number of SurvexFiles: {tf:,}")
|
||||
print(f" - Number of Survex legs: {legsnumber:,}")
|
||||
|
||||
# Now set Django SurvexFile object..
|
||||
|
||||
svx_load = None
|
||||
|
||||
def MakeSurvexFileRoot():
|
||||
"""Returns a file_object.path = SURVEX_TOPNAME associated with directory_object.path = SURVEX_DATA"""
|
||||
|
Loading…
Reference in New Issue
Block a user