2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-12-02 23:01:54 +00:00
troggle/core/TESTS/tests_caves.py

180 lines
6.7 KiB
Python
Raw Normal View History

2021-04-17 20:45:38 +01:00
"""
Modified for Expo April 2021.
"""
import unittest
import re
from django.test import TestCase, SimpleTestCase, Client
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
from troggle.core.models.caves import Cave, Area
2021-04-17 20:45:38 +01:00
class FixtureTests(TestCase):
'''These just hit the database.
They do not exercise the GET and url functions
'''
fixtures = ['auth_users', 'expo_areas', 'expo_caves', 'expo_exped']
2021-04-17 23:59:11 +01:00
ph = r'and leads in 800m of tortuous going to'
2021-04-17 20:45:38 +01:00
def setUp(self):
pass
2021-04-17 20:45:38 +01:00
def tearDown(self):
pass
def test_fix_person_loaded(self):
p = Person.objects.get(fullname='Michael Sargent')
self.assertEqual(str(p.first_name), "Michael")
2021-04-17 20:45:38 +01:00
def test_fix_person_loaded(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_area_loaded(self):
a = Area.objects.get(short_name='1623')
self.assertEqual(str(a.short_name), "1623")
def test_fix_cave_loaded115(self):
2021-04-17 23:59:11 +01:00
c = Cave.objects.get(kataster_number='115')
self.assertEqual(str(c.description_file), "1623/115.htm")
2022-03-18 20:00:15 +00:00
self.assertEqual(str(c.url), "1623/115.url") # intentional
2021-04-17 23:59:11 +01:00
self.assertEqual(str(c.filename), "1623-115.html")
# c.area is a 'ManyRelatedManager' object and not iterable
#self.assertEqual(str(c.[0].short_name), "1623")
2021-04-17 23:59:11 +01:00
ph = self.ph
phmatch = re.search(ph, c.underground_description)
self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph +"'")
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'
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/MichaelSargent/2019')
content = response.content.decode()
# with open('testresponse.html','w') as tr:
# tr.writelines(content)
self.assertEqual(response.status_code, 200)
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):
'''Currently nothing that runs troggle works - all do 404. Must be something in a template rendering crash?
ordinary pages are OK, and expopages and expofiles are OK, even though they come through troggle.
'''
# The fixtures have a password hash which is compatible with plain-text password 'secretword'
fixtures = ['auth_users', 'expo_areas', 'expo_caves', 'expo_exped']
ph = r'and leads in 800m of tortuous going to'
@classmethod
def setUpTestData(cls):
pass
def setUp(self):
from django.contrib.auth.models import User
self.user = User.objects.get(username='expotest')
# Every test needs a client.
self.client = Client()
def tearDown(self):
pass
def test_fix_expedition(self):
response = self.client.get('/expedition/2019')
self.assertEqual(response.status_code, 200)
ph = r'Michael Sargent'
content = response.content.decode()
phmatch = re.search(ph, content)
2021-04-23 03:05:22 +01:00
# with open('exped-op.html', 'w') as f:
# f.write(content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
def test_fix_personexped(self):
response = self.client.get('/personexpedition/MichaelSargent/2019')
self.assertEqual(response.status_code, 200)
ph = r'Table of all trips and surveys aligned by date'
content = response.content.decode()
phmatch = re.search(ph, content)
2021-04-23 03:05:22 +01:00
# with open('persexped-op.html', 'w') as f:
# f.write(content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
def test_fix_person(self):
response = self.client.get('/person/MichaelSargent')
self.assertEqual(response.status_code, 200)
ph = r'second-generation expo caver '
content = response.content.decode()
phmatch = re.search(ph, content)
2021-04-23 03:05:22 +01:00
# with open('person-op.html', 'w') as f:
# f.write(content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
def test_fix_cave_url115(self):
2021-04-17 23:59:11 +01:00
ph = self.ph
2022-03-18 20:00:15 +00:00
response = self.client.get('/1623/115.url') # yes this is intentional, see the inserted data above & fixture
self.assertEqual(response.status_code, 200)
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, 200)
ph = r'at a depth of 72m, there are large round blocks'
2021-04-17 23:59:11 +01:00
content = response.content.decode()
phmatch = re.search(ph, content)
2021-04-23 03:05:22 +01:00
# with open('cave-op.html', 'w') as f:
# f.write(content)
2021-04-17 23:59:11 +01:00
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
def test_fix_cave_bare_url115(self):
2021-05-03 20:35:35 +01:00
'''Expect to get Page Not Found and status 404'''
ph = self.ph
ph = 'Probably a mistake.'
response = self.client.get('/1623/115')
2021-05-03 20:35:35 +01:00
self.assertEqual(response.status_code, 404)
content = response.content.decode()
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") # 200 & Page Not Found
def test_fix_cave_slug115(self):
2021-05-03 20:35:35 +01:00
'''Expect to get Page Not Found and status 404'''
ph = self.ph
ph = 'Probably a mistake.'
response = self.client.get('/1623-115')
2021-05-03 20:35:35 +01:00
self.assertEqual(response.status_code, 404)
content = response.content.decode()
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") # 200 & Page Not Found