2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-26 09:11:54 +00:00
troggle/core/TESTS/tests.py

146 lines
5.9 KiB
Python
Raw Normal View History

2020-06-03 21:57:05 +01:00
"""
2020-06-28 14:42:26 +01:00
We are using unittest for troggle.
2020-06-03 21:57:05 +01:00
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
https://docs.python.org/3.8/library/doctest.html
https://docs.djangoproject.com/en/3.0/topics/testing/tools/
"""
2020-07-19 01:23:07 +01:00
import unittest
import re
from django.test import TestCase, SimpleTestCase, Client
2020-06-03 21:57:05 +01:00
class SimpleTest(SimpleTestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
def test_import_TroggleModel(self):
from troggle.core.models import TroggleModel
def test_import_Cave(self):
from troggle.core.models_caves import Cave
def test_import_parsers_surveys(self):
from PIL import Image
from utils import save_carefully
from functools import reduce
def test_import_parsers_survex(self):
import troggle.settings as settings
import troggle.core.models as models
import troggle.core.models_caves as models_caves
import troggle.core.models_survex as models_survex
from troggle.parsers.people import GetPersonExpeditionNameLookup
from troggle.core.views_caves import MapLocations
def test_import_parsers_QMs(self):
from troggle.core.models_caves import QM, Cave, LogbookEntry
from utils import save_carefully
def test_import_parsers_people(self):
from html.parser import HTMLParser
from unidecode import unidecode
def test_import_parsers_logbooks(self):
from django.template.defaultfilters import slugify
from django.utils.timezone import get_current_timezone, make_aware
from troggle.core.models import DataIssue, Expedition
from troggle.core.models_caves import Cave, LogbookEntry, PersonTrip
2020-06-03 21:57:05 +01:00
from parsers.people import GetPersonExpeditionNameLookup
def test_import_core_views_caves(self):
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from troggle.core.models import Expedition
from troggle.core.models_caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation
2020-06-03 21:57:05 +01:00
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
from troggle.helper import login_required_if_public
2020-07-19 01:23:07 +01:00
from django.contrib.auth.decorators import login_required
from django.conf import settings
2020-06-06 22:51:55 +01:00
def test_import_parses_mix(self):
2020-06-28 14:42:26 +01:00
from troggle.parsers.logbooks import GetCaveLookup
2020-06-06 22:51:55 +01:00
import troggle.settings
#import troggle.flatpages.models
2020-06-06 22:51:55 +01:00
import troggle.logbooksdump
2020-06-16 16:07:36 +01:00
import troggle.parsers.caves
2020-06-06 22:51:55 +01:00
import troggle.parsers.people
import troggle.parsers.surveys
import troggle.parsers.logbooks
import troggle.parsers.QMs
2020-06-16 16:07:36 +01:00
import troggle.parsers.survex
def test_import_imports(self):
from django.core import management
from django.db import connection, close_old_connections, connections
from django.contrib.auth.models import User
from django.http import HttpResponse
2020-06-18 21:50:16 +01:00
from django.urls import reverse
2020-06-03 21:57:05 +01:00
2020-07-19 01:23:07 +01:00
#class SimplePageTest(unittest.TestCase):
class PageTests(TestCase):
@classmethod
def setUpTestData(cls):
# Set up data for the whole TestCase
#cls.foo = Foo.objects.create(bar="Test")
# Some test using self.foo in tests below..
# read in some SQL ?
pass
def setUp(self):
# Every test needs a client.
self.client = Client()
def test_page_admin(self):
# Issue a GET request.
response = self.client.get('/admin/login/')
content = response.content.decode()
self.assertEqual(response.status_code, 200)
h1 = re.search(r'<h1 id="site-name">Troggle administration</h1>', content)
def test_page_folk(self):
# This page is separately generated, so it has the full data content
response = self.client.get('/folk/')
content = response.content.decode()
self.assertEqual(response.status_code, 200)
# Check that the rendered context has the correct title
phrase = re.search(r'active contribution to the expedition', content)
phrase = re.search(r'Naomi Griffiths', content)
phrase = re.search(r'Gail Smith', content)
phrase = re.search(r'Phil Wigglesworth', content)
phrase = re.search(r'A more obscure record of longest gap between expos has', content)
def test_page_expofile(self):
# Flat file tests.
response = self.client.get('/expofiles/documents/surveying/tunnel-loefflerCP35-only.pdf')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.content), 2299270)
response = self.client.get('/expofiles/writeups/1982/logbook1982.pdf')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.content), 12915413)
def test_page_ss(self):
# this gets an empty page as the database has not been loaded
response = self.client.get('/survey_scans/')
self.assertEqual(response.status_code, 200)
#response = self.client.get('/survey_scans/1991surveybook/page0002.png')
#response = self.client.get('/survey_scans/1991surveybook/')
#content = response.content.decode()
#print(content)
#png93 = re.search(r'/page0093.png">page0093.png</a></td>', content)
def test_page_tunnel(self):
# this fails as the database has not been loaded so there is no Tunnel file
#response = self.client.get('/tunneldataraw/107/107sketch-v2.xml')
response = self.client.get('/tunneldataraw/')
self.assertEqual(response.status_code, 200)
2020-06-03 21:57:05 +01:00
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}