forked from expo/troggle
163 lines
5.5 KiB
Python
163 lines
5.5 KiB
Python
"""Simple test factories used to replace fixtures in tests.
|
|
|
|
These avoid adding external dependencies like factory_boy and provide small
|
|
helpers to create models with predictable defaults and optional PKs so tests
|
|
that relied on fixture PKs continue to work.
|
|
"""
|
|
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
|
|
from troggle.core.models.caves import Cave
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
def create_user(username, first_name=None, last_name="Caver", is_superuser=False):
|
|
u = User()
|
|
u.username = username
|
|
u.email = f"{username}@example.test"
|
|
u.first_name = first_name or username
|
|
u.last_name = last_name
|
|
u.set_password("secretword")
|
|
u.is_superuser = is_superuser
|
|
u.save()
|
|
return u
|
|
|
|
|
|
def create_expedition(pk=None, year="2019", name="CUCC expo 2019"):
|
|
e = Expedition()
|
|
if pk is not None:
|
|
e.pk = pk
|
|
e.year = year
|
|
e.name = name
|
|
e.save()
|
|
return e
|
|
|
|
|
|
def create_person(pk=None, first_name="Michael", last_name="Sargent", fullname="Michael Sargent", slug="michael-sargent", blurb=None):
|
|
ms_blurb = """\n\n\n\n\n\n<p><img class=\"onleft\" src=\"/folk/i/mikey0.jpg\">\n
|
|
<img class=\"onright\" src=\"/folk/i/mikey1.jpg\" height=\"400\"\nalt=\"\" />\n
|
|
<b>Michael Sargent</b> CUCC<br />\nExpeditions 2014, 15, 16, 17, 18, 19.\n
|
|
<p>The first second-generation expo caver in 2014, later members of this exclusive group
|
|
were Dan Lenartowicz and Sarah Connolly.\n\n\n
|
|
<img class=\"onleft\" src=\"/folk/i/michaelsargent.jpg\">\n<im\n\n
|
|
<hr style=\"clear: both\" /><p class=\"caption\">Pre-expo (pre-student)
|
|
photos from President's Invite (OUCC) \nand first abseiling instruction (Cambridge).</p>\n
|
|
"""
|
|
p = Person()
|
|
if pk is not None:
|
|
p.pk = pk
|
|
p.first_name = first_name
|
|
p.last_name = last_name
|
|
p.fullname = fullname
|
|
p.slug = slug
|
|
# provide a small default blurb consistent with fixtures for pages
|
|
p.blurb = blurb if blurb is not None else ms_blurb
|
|
p.save()
|
|
return p
|
|
|
|
|
|
def create_personexpedition(pk=None, expedition=None, person=None):
|
|
pe = PersonExpedition()
|
|
if pk is not None:
|
|
pe.pk = pk
|
|
pe.expedition = expedition
|
|
pe.person = person
|
|
pe.save()
|
|
return pe
|
|
|
|
|
|
def create_cave(
|
|
pk=None,
|
|
areacode="1623",
|
|
kataster_number="115",
|
|
filename="1623-115.html",
|
|
url="1623/115.url",
|
|
description_file="1623/115.htm",
|
|
underground_description="",
|
|
notes="",
|
|
official_name="",
|
|
non_public=False,
|
|
kataster_code="",
|
|
unofficial_number="",
|
|
explorers="",
|
|
equipment="",
|
|
references="",
|
|
survey="",
|
|
length="",
|
|
depth="",
|
|
extent="",
|
|
survex_file="",
|
|
):
|
|
c = Cave()
|
|
if pk is not None:
|
|
c.pk = pk
|
|
c.areacode = areacode
|
|
c.non_public = non_public
|
|
c.kataster_code = kataster_code
|
|
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.filename = filename
|
|
c.url = url
|
|
c.description_file = description_file
|
|
c.underground_description = underground_description
|
|
c.notes = notes
|
|
c.equipment = equipment
|
|
c.references = references
|
|
c.survey = survey
|
|
c.length = length
|
|
c.depth = depth
|
|
c.extent = extent
|
|
c.survex_file = survex_file
|
|
c.save()
|
|
return c
|
|
|
|
|
|
def create_expo_caves():
|
|
"""Create the two cave fixtures used historically by the test-suite (115 and 284).
|
|
|
|
This mirrors the content of `core/fixtures/expo_caves.json` so tests that
|
|
relied on those fixture rows can use this factory instead.
|
|
"""
|
|
# Cave 115 (Schnellzughöhle) - includes an underground_description fragment
|
|
und_desc_115 = (
|
|
"This is the main entrance through which the majority of the "
|
|
"<a href=\"41.htm\">Stellerweghöhle</a> system was explored. See the separate "
|
|
"<a href=\"41/115.htm#ent115\">full guidebook description</a> for details, just an overview is given here.</p>"
|
|
"<p>The entrance leads to a non-obvious way on to the head of the short <b>Bell Pitch</b>, from where very awkward going leads out to a bigger passage to reach <b>The Ramp</b> a series of off-vertical pitches. The damper but technically easier <b>Inlet Pitches</b> drop to a Big Chamber, from where <b>Pete's Purgatory</b> starts, and leads in 800m of tortuous going to <b>The Confluence</b> and the larger streamway leading to the deepest point.</p>"
|
|
)
|
|
|
|
create_cave(
|
|
pk=43,
|
|
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",
|
|
notes=(
|
|
"The Austrian Kataster has adopted a very perverse way of numbering things. "
|
|
"Their numbers are as follows: 115a Stellerweghöhle entrance 41a etc."
|
|
),
|
|
)
|
|
|
|
# Cave 284 (Seetrichter)
|
|
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."
|
|
),
|
|
)
|
|
|
|
return Cave.objects.filter(pk__in=[43, 350])
|