mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 10:37:16 +00:00
Nearly fixed test suite
This commit is contained in:
@@ -6,10 +6,24 @@ import re
|
||||
from http import HTTPStatus
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from troggle.core.models.caves import Cave
|
||||
from troggle.core.models.troggle import Person, PersonExpedition
|
||||
from troggle.core.models.troggle import Person, PersonExpedition, Expedition
|
||||
from troggle.core.utils import current_expo
|
||||
|
||||
current_year = current_expo()
|
||||
|
||||
|
||||
def create_user(name=None, last_name="Caver", is_superuser=False):
|
||||
u = User()
|
||||
u.username = name
|
||||
u.email = f"philip.sargent+{name}@gmail.com"
|
||||
u.first_name, u.last_name = name, last_name
|
||||
u.set_password("secretword") # all test users have same password
|
||||
u.save()
|
||||
return u
|
||||
|
||||
# import troggle.settings as settings
|
||||
# FIXTURE_DIRS = settings.PYTHON_PATH / "core" /"fixtures"
|
||||
|
||||
@@ -18,24 +32,52 @@ class FixtureTests(TestCase):
|
||||
They do not exercise the GET and url functions
|
||||
"""
|
||||
|
||||
fixtures = ["auth_users", "expo_caves", "expo_exped"]
|
||||
fixtures = ["expo_caves", "expo_exped"]
|
||||
ph = r"and leads in 800m of tortuous going to"
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
create_user(name="expo") # needed for current_year()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
User.objects.all().delete()
|
||||
|
||||
def test_fix_person_loaded(self):
|
||||
def test_fix_person_loaded_byname(self):
|
||||
p = Person.objects.get(fullname="Michael Sargent")
|
||||
self.assertEqual(str(p.first_name), "Michael")
|
||||
|
||||
def test_fix_person_loaded(self):
|
||||
def test_fix_personexped_loaded_bypk(self):
|
||||
pe = PersonExpedition.objects.get(pk="681")
|
||||
self.assertEqual(str(pe.person.fullname), "Michael Sargent")
|
||||
self.assertEqual(str(pe.expedition.year), "2019")
|
||||
|
||||
def test_fix_expedition_loaded(self):
|
||||
e = Expedition.objects.get(pk="44")
|
||||
self.assertEqual(str(e.year), "2019")
|
||||
|
||||
def test_page_person(self):
|
||||
response = self.client.get("/person/michael-sargent")
|
||||
content = response.content.decode()
|
||||
# with open('testresponseperson.html','w') as tr:
|
||||
# tr.writelines(content)
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
for ph in [r"Michael Sargent", r"has been on expo in the following years"]:
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
|
||||
def test_page_personexpedition(self):
|
||||
# Not working despite all components present and correct
|
||||
response = self.client.get("/personexpedition/michael-sargent/2019")
|
||||
content = response.content.decode()
|
||||
# with open('testresponse.html','w') as tr:
|
||||
# tr.writelines(content)
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
for ph in [r"Michael Sargent", r"Table of all trips and surveys aligned by date"]:
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
|
||||
# Need to add a fixture so that this actually has a logbook entry and a trip/svx in it.
|
||||
|
||||
def test_fix_cave_loaded115(self):
|
||||
c = Cave.objects.get(kataster_number="115")
|
||||
self.assertEqual(str(c.description_file), "1623/115.htm")
|
||||
@@ -43,9 +85,6 @@ class FixtureTests(TestCase):
|
||||
self.assertEqual(str(c.filename), "1623-115.html")
|
||||
self.assertEqual(str(c.areacode), "1623")
|
||||
|
||||
# c.area is a 'ManyRelatedManager' object and not iterable
|
||||
# self.assertEqual(str(c.[0].short_name), "1623")
|
||||
|
||||
ph = self.ph
|
||||
phmatch = re.search(ph, c.underground_description)
|
||||
self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph + "'")
|
||||
@@ -60,16 +99,6 @@ class FixtureTests(TestCase):
|
||||
phmatch = re.search(ph, c.notes)
|
||||
self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph + "'")
|
||||
|
||||
def test_page_personexpedition(self):
|
||||
response = self.client.get("/personexpedition/michael-sargent/2019")
|
||||
content = response.content.decode()
|
||||
# with open('testresponse.html','w') as tr:
|
||||
# tr.writelines(content)
|
||||
self.assertEqual(response.status_code, HTTPStatus.OK)
|
||||
for ph in [r"Michael Sargent", r"Table of all trips and surveys aligned by date"]:
|
||||
phmatch = re.search(ph, content)
|
||||
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph + "'")
|
||||
# Need to add a fixture so that this actually has a logbook entry and a trip/svx in it.
|
||||
|
||||
|
||||
class FixturePageTests(TestCase):
|
||||
@@ -81,7 +110,7 @@ class FixturePageTests(TestCase):
|
||||
# The fixtures have a password hash which is compatible with plain-text password 'secretword'
|
||||
# The hash CHANGES whenever Django upgrades the encryption key length. Better to create the test uses
|
||||
# algorithmically and not via a fixture.
|
||||
fixtures = ["auth_users", "expo_caves", "expo_exped"]
|
||||
fixtures = ["expo_caves", "expo_exped"]
|
||||
ph = r"and leads in 800m of tortuous going to"
|
||||
|
||||
@classmethod
|
||||
@@ -89,7 +118,9 @@ class FixturePageTests(TestCase):
|
||||
pass
|
||||
|
||||
def setUp(self):
|
||||
from django.contrib.auth.models import User
|
||||
create_user(name="expo")
|
||||
create_user(name="expotest")
|
||||
create_user(name="expotestadmin", is_superuser = True)
|
||||
|
||||
self.user = User.objects.get(username="expotest")
|
||||
|
||||
@@ -97,7 +128,7 @@ class FixturePageTests(TestCase):
|
||||
self.client = Client()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
User.objects.all().delete()
|
||||
|
||||
def test_fix_expedition(self):
|
||||
response = self.client.get("/expedition/2019")
|
||||
|
||||
Reference in New Issue
Block a user