From e17a21defde917ac92aa9a5123bccabe3a3c2d47 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 18 Apr 2021 01:58:24 +0100 Subject: [PATCH] Tests work on cave, person, expedition pages --- core/TESTS/tests.py | 10 +++ core/TESTS/tests_caves.py | 152 ++++++++++++++++++++++++++++++---- core/fixtures/expo_caves.json | 22 ++++- core/fixtures/expo_exped.json | 18 ++++ core/models/caves.py | 2 +- 5 files changed, 187 insertions(+), 17 deletions(-) create mode 100644 core/fixtures/expo_exped.json diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index 946d579..aed66bb 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -158,6 +158,16 @@ class PageTests(TestCase): phmatch = re.search(ph, content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") + def test_page_ss(self): + response = self.client.get('/survey_scans/') + self.assertEqual(response.status_code, 200) + + ph = r'All Survey scans folders ' + content = response.content.decode() + phmatch = re.search(ph, content) + with open('ss-op.html', 'w') as f: + f.write(content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") def test_page_admin(self): diff --git a/core/TESTS/tests_caves.py b/core/TESTS/tests_caves.py index 2e05ce9..841691c 100644 --- a/core/TESTS/tests_caves.py +++ b/core/TESTS/tests_caves.py @@ -4,36 +4,137 @@ Modified for Expo April 2021. import unittest import re -from django.test import TestCase, SimpleTestCase, TransactionTestCase, Client -from troggle.core.models.caves import Cave +from django.test import TestCase, SimpleTestCase, Client +from troggle.core.models.troggle import Expedition, Person, PersonExpedition +from troggle.core.models.caves import Cave, Area - -class FixturePageTests(TestCase): - # The fixtures have a password hash which is compatible with plain-text password 'secretword' - fixtures = ['auth_users', 'expo_areas', 'expo_caves'] +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'] ph = r'and leads in 800m of tortuous going to' def setUp(self): - from django.contrib.auth.models import User - self.user = User.objects.get(username='expotest') - - def tearDown(self): pass - def test_fix_cave_loaded(self): + def tearDown(self): + pass + + def test_fix_person_loaded(self): + p = Person.objects.get(fullname='Michael Sargent') + self.assertEqual(str(p.first_name), "Michael") + + 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): c = Cave.objects.get(kataster_number='115') self.assertEqual(str(c.description_file), "1623/115.htm") self.assertEqual(str(c.url), "1623/115.htm") 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") + 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_url(self): + 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 +"'") + + +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) + 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) + 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) + 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): ph = self.ph - response = self.client.get('1623/115.htm') - #self.assertEqual(response.status_code, 200) + response = self.client.get('/1623/115.htm') + 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' content = response.content.decode() phmatch = re.search(ph, content) @@ -41,4 +142,25 @@ class FixturePageTests(TestCase): f.write(content) self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") - \ No newline at end of file + def test_fix_cave_bare_url115(self): + '''Expect to get Page Not Found and status 200''' + ph = self.ph + ph = 'Probably a mistake.' + response = self.client.get('/1623/115') + self.assertEqual(response.status_code, 200) + + 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): + '''Expect to get Page Not Found and status 200''' + ph = self.ph + ph = 'Probably a mistake.' + response = self.client.get('/1623-115') + self.assertEqual(response.status_code, 200) + + content = response.content.decode() + phmatch = re.search(ph, content) + self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'") # 200 & Page Not Found diff --git a/core/fixtures/expo_caves.json b/core/fixtures/expo_caves.json index 9dfa78e..ff9ff79 100644 --- a/core/fixtures/expo_caves.json +++ b/core/fixtures/expo_caves.json @@ -16,5 +16,25 @@ "description_file": "1623/115.htm", "url": "1623/115.htm", "filename": "1623-115.html", - "area": [1, 8]}} + "area": [1, 8]}}, + +{"model": "core.cave", "pk": 350, "fields": + {"new_since_parsing": false, "non_public": false, + "official_name": "Seetrichter", + "kataster_code": "", + "kataster_number": "284", + "unofficial_number": "", + "explorers": "

", + "underground_description": "", + "equipment": "

", + "references": "

", + "survey": "

", + "kataster_status": "", + "underground_centre_line": "", + "notes": "A 25m long (22m deep) resurgence in Altausee. At the bottom, at a depth of 72m, there are large round blocks.", "length": "", "depth": "", "extent": "", + "survex_file": "", + "description_file": "", + "url": "1623/284/284.html", + "filename": "1623-284.html", + "area": [1, 11]}} ] \ No newline at end of file diff --git a/core/fixtures/expo_exped.json b/core/fixtures/expo_exped.json new file mode 100644 index 0000000..9d3cc46 --- /dev/null +++ b/core/fixtures/expo_exped.json @@ -0,0 +1,18 @@ +[{"model": "core.expedition", "pk": 44, "fields": + {"new_since_parsing": false, "non_public": false, + "year": "2019", "name": "CUCC expo 2019"}}, + +{"model": "core.personexpedition", "pk": 681, "fields": + {"new_since_parsing": false, "non_public": false, + "expedition": 44, + "person": 250, "slugfield": null, "is_guest": false, "expo_committee_position": null, + "nickname": "Mike"}}, + +{"model": "core.person", "pk": 250, "fields": + {"new_since_parsing": false, "non_public": false, + "first_name": "Michael", + "last_name": "Sargent", + "fullname": "Michael Sargent", "is_vfho": false, "mug_shot": null, + "blurb": "\n\n\n\n\n\n

\n\nMichael Sargent CUCC
\nExpeditions 2014, 15, 16, 17, 18, 19.\n

The first second-generation expo caver in 2014, later members of this exclusive group were Dan Lenartowicz and Sarah Connolly.\n\n\n\n

Pre-expo (pre-student) photos from President's Invite (OUCC) \nand first abseiling instruction (Cambridge).

\n", "orderref": "", + "user": null}} +] \ No newline at end of file diff --git a/core/models/caves.py b/core/models/caves.py index ddb0255..fcaf8d9 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -158,7 +158,7 @@ class Cave(TroggleModel): for e in CaveAndEntrance.objects.filter(cave=self): rs.append(e.entrance_letter) rs.sort() - prevR = None + prevR = '' n = 0 for r in rs: if prevR: