2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2026-03-01 03:01:41 +00:00

clean up tests

This commit is contained in:
2025-12-17 21:59:43 +00:00
parent 31a7b62ca9
commit 09a9b6e18f
4 changed files with 24 additions and 52 deletions

View File

@@ -69,7 +69,6 @@ def create_cave(
areacode="1623",
kataster_number="115",
filename="1623-115.html",
url="1623/115.url",
description_file="1623/115.htm",
underground_description="",
notes="",
@@ -95,12 +94,8 @@ def create_cave(
c.kataster_number = kataster_number
c.unofficial_number = unofficial_number
c.explorers = explorers
# If an explicit official_name was provided use it; otherwise
# leave it unset
if official_name:
c.official_name = official_name
c.official_name = official_name
c.filename = filename
c.url = url
c.description_file = description_file
c.underground_description = underground_description
c.notes = notes
@@ -111,6 +106,7 @@ def create_cave(
c.depth = depth
c.extent = extent
c.survex_file = survex_file
c.save()
return c
@@ -134,7 +130,6 @@ def create_expo_caves():
areacode="1623",
kataster_number="115",
filename="1623-115.html",
url="1623/115.url",
description_file="1623/115.htm",
underground_description=und_desc_115,
official_name="Schnellzughöhle",
@@ -150,7 +145,6 @@ def create_expo_caves():
areacode="1623",
kataster_number="284",
filename="1623-284.html",
url="1623/284/284.html",
description_file="",
official_name="Seetrichter (Lake bottom)",
notes=(

View File

@@ -12,6 +12,9 @@ import settings
from troggle.core.models.caves import Cave
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.utils import current_expo
from .factories import create_cave, create_expo_caves
from .factories import create_expedition, create_person, create_personexpedition
current_year = current_expo()
@@ -44,16 +47,15 @@ class FixtureTests(TestCase):
@classmethod
def setUpTestData(cls):
# replicate the minimal data formerly provided by fixtures
from .factories import create_expedition, create_person, create_personexpedition, create_cave
from .factories import create_expedition, create_person, create_personexpedition, create_cave, create_expo_caves
exp = create_expedition(pk=44, year="2019", name="CUCC expo 2019")
person = create_person(pk=250, first_name="Michael", last_name="Sargent", fullname="Michael Sargent", slug="michael-sargent")
create_personexpedition(pk=681, expedition=exp, person=person)
# two notable caves used by tests
create_cave(pk=43, areacode="1623", kataster_number="115", filename="1623-115.html", url="1623/115.url", description_file="1623/115.htm", underground_description="This is the main entrance ... The entrance leads to a ... and leads in 800m of tortuous going to The Confluence")
create_cave(pk=350, areacode="1623", kataster_number="284", filename="1623-284.html", url="1623/284/284.html", description_file="", official_name="Seetrichter (Lake bottom)", notes="A 25m long (22m deep) resurgence in Altausee. At the bottom, at a depth of 72m, there are large round blocks.")
create_expo_caves()
def setUp(self):
create_user(name="expo") # needed for current_year()
@@ -100,7 +102,6 @@ class FixtureTests(TestCase):
def test_fix_cave_loaded115(self):
c = Cave.objects.get(kataster_number="115")
self.assertEqual(str(c.description_file), "1623/115.htm")
self.assertEqual(str(c.url), "1623/115.url") # intentional
self.assertEqual(str(c.filename), "1623-115.html")
self.assertEqual(str(c.areacode), "1623")
@@ -111,7 +112,6 @@ class FixtureTests(TestCase):
def test_fix_cave_loaded284(self):
c = Cave.objects.get(kataster_number="284")
self.assertEqual(str(c.description_file), "")
self.assertEqual(str(c.url), "1623/284/284.html")
self.assertEqual(str(c.filename), "1623-284.html")
ph = r"at a depth of 72m, there are large round blocks"
@@ -130,13 +130,8 @@ class FixturePageTests(TestCase):
@classmethod
def setUpTestData(cls):
# ensure cave stubs exist for the page tests (some tests create more caves in setUp)
from .factories import create_cave
create_cave(pk=43, areacode="1623", kataster_number="115", filename="1623-115.html", url="1623/115.url", description_file="1623/115.htm", underground_description="... leads in 800m of tortuous going to ...")
create_cave(pk=350, areacode="1623", kataster_number="284", filename="1623-284.html", url="1623/284/284.html", description_file="", notes="At the bottom, at a depth of 72m, there are large round blocks.")
create_expo_caves()
# also create expedition/person data used by page rendering
from .factories import create_expedition, create_person, create_personexpedition
exp = create_expedition(pk=44, year="2019", name="CUCC expo 2019")
person = create_person(pk=250, first_name="Michael", last_name="Sargent", fullname="Michael Sargent", slug="michael-sargent")
@@ -197,27 +192,6 @@ class FixturePageTests(TestCase):
# f.write(content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_fix_cave_url115(self):
ph = "leads in 800m of tortuous going to"
response = self.client.get("/1623/115.url") # yes this is intentional, see the inserted data above & fixture
self.assertEqual(response.status_code, HTTPStatus.OK)
content = response.content.decode()
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_fix_cave_url284(self):
response = self.client.get("/1623/284/284.html")
self.assertEqual(response.status_code, HTTPStatus.OK)
ph = r"at a depth of 72m, there are large round blocks"
content = response.content.decode()
phmatch = re.search(ph, content)
# with open('cave-url284.html', 'w') as f:
# f.write(content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
def test_fix_cave_bare_url115(self):
"""Expect to get Page Not Found and status 404"""
ph = self.ph
@@ -255,8 +229,8 @@ class FixturePageTests(TestCase):
ph = r"Seetrichter"
ph_alt = r"1623-284"
phmatch = re.search(ph, content) or re.search(ph_alt, content)
# with open('_cave_caves284.html', 'w') as f:
# f.write(content)
with open('_cave_caves284.html', 'w') as f:
f.write(content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "' or '" + ph_alt + "'")
# Although the Cave object exists, it looks like we get a bad slug error when trying to get a QM page.

View File

@@ -147,7 +147,13 @@ class PostTests(TestCase):
self.assertTrue(u.is_active, "User '" + u.username + "' is INACTIVE")
c.login(username=u.username, password="secretword")
# Just uploading a file does NOT do any git commit.
# You need to create or edit a contents.json file for that to happen.
# But this does now seem to happen.
# This is crashing *sometimes* in the git diff part of the utils. git_add() function
# because it is not in a git folder when run in a test.
# when run just as test_logins it is fine, when run with all teh other tests it crashes.
with open("core/fixtures/test_upload_file.txt", "r") as testf:
response = self.client.post(
f"/walletedit/{testyear}:00", data={"name": "test_upload_file.txt", "uploadfiles": testf, "who_are_you": "Gumby <gumby@tent.expo>"}
@@ -171,9 +177,7 @@ class PostTests(TestCase):
remove_file = pathlib.Path(settings.SCANS_ROOT) / f'{testyear}' / f'{testyear}#00'/ 'test_upload_file.txt'
remove_file.unlink()
# Just uploading a file does NOT do any git commit.
# You need to create or edit a contents.json file for that to happen.
def test_photo_upload(self):
"""Expect photo upload to work on any file (contrary to msg on screen)
Upload into current default year.

View File

@@ -368,16 +368,16 @@ def git_add(filename, cwd, commands=[]):
"""
git = settings.GIT
# what is the purpose of this 'git diff' ? To prevent merge conflicts happening I guess,
# so we do not have to reverse a 'git add'
# print(f"git diff {filename} in {cwd}")
cmd_diff = [git, "diff", filename]
# what is the purpose of this 'git diff' ? Assumed to be a fossil.
# it sometimes crashes with return code 129: wrong arguments.
print(f"git diff {filename} in {cwd}")
cmd_diff = [git, "diff"]
commands.append(cmd_diff)
cp_diff = subprocess.run(cmd_diff, cwd=cwd, capture_output=True, text=True)
if cp_diff.returncode != 0:
msgdata = f"Ask a nerd to fix this DIFF problem in git_add().\n--{cp_diff.stderr}\n--{cp_diff.stdout}\n--return code:{str(cp_diff.returncode)}"
msgdata = f"Ask a nerd to fix this DIFF problem in git_add().\n--stderr:{cp_diff.stderr}\n--stdout:{cp_diff.stdout}\n--return code:{str(cp_diff.returncode)}"
raise WriteAndCommitError(
f"CANNOT git ADD on server for this file {filename}.\n\n" + msgdata
f"CANNOT git DIFF on server in {cwd}\n\n" + msgdata
)
# print(f"git add {filename} in {cwd}")