troggle-unchained/core/TESTS/test_imports.py

139 lines
5.9 KiB
Python

"""
We are using unittest for troggle.
Note that the database has not been parsed from the source files when these tests are run,
so any path that relies on data being in the database will fail.
The simple redirections to files which exist, e.g. in
/expoweb/
/expofiles/
/expofiles/documents/
etc. will test fine.
But paths like this:
/survey_scans/
/caves/
which rely on database resolution will fail unless a fixture has been set up for
them.
https://docs.djangoproject.com/en/3.0/topics/testing/tools/
"""
import unittest
import re
import subprocess
from django.test import TestCase, SimpleTestCase, Client
class SimpleTest(SimpleTestCase):
def test_test_setting(self):
from django.conf import settings
self.assertEqual(settings.EMAIL_BACKEND, 'django.core.mail.backends.locmem.EmailBackend')
import troggle.settings as settings
def test_import_TroggleModel(self):
from troggle.core.models.troggle 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 troggle.core.utils import save_carefully
from functools import reduce
def test_import_parsers_survex(self):
import troggle.settings as settings
import troggle.core.models.troggle as models
import troggle.core.models.survex as models_survex
import troggle.core.models.caves as models_caves
from troggle.parsers.people import GetPersonExpeditionNameLookup
from troggle.core.views.other import frontpage
from troggle.core.views.caves import ent, cavepage
from troggle.core.views import scans, drawings, other, caves, statistics, survex, uploads
def test_import_views_uploads(self):
from troggle.core.views.uploads import dwgupload, scanupload
def test_import_parsers_QMs(self):
from troggle.core.models.caves import QM, Cave, LogbookEntry
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.troggle import DataIssue, Expedition
from troggle.core.models.caves import Cave, LogbookEntry, PersonTrip
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
import troggle.core.views.expo
from troggle.core.models.troggle import Expedition
from troggle.core.models.caves import CaveSlug, Cave, CaveAndEntrance, QM, EntranceSlug, Entrance, Area, SurvexStation
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, EntranceForm, EntranceLetterForm
from troggle.core.views.auth import login_required_if_public
from django.contrib.auth.decorators import login_required
from django.conf import settings
def test_import_parsers_mix(self):
from troggle.parsers.logbooks import GetCaveLookup
import troggle.settings
import troggle.parsers.caves
import troggle.parsers.people
import troggle.parsers.drawings
import troggle.parsers.scans
import troggle.parsers.logbooks
import troggle.parsers.QMs
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
from django.urls import reverse
def test_import_urls(self):
from django.conf import settings
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib import auth
from django.urls import reverse, resolve
from django.views.generic.base import RedirectView
from django.views.generic.edit import UpdateView
from django.views.generic.list import ListView
from troggle.core.views import other, caves, statistics, survex
from troggle.core.views.auth import expologin, expologout
from troggle.core.views.caves import ent, cavepage
from troggle.core.views.expo import expofiles_redirect, expofilessingle, expopage, editexpopage, mediapage, map, mapfile
from troggle.core.views.logbooks import expedition, personexpedition, Expeditions_tsvListView, Expeditions_jsonListView
from troggle.core.views.logbooks import get_logbook_entries, logbookentry, logbookSearch
from troggle.core.views.logbooks import notablepersons, person, get_people
from troggle.core.views.other import controlpanel
from troggle.core.views.prospect import prospecting
from troggle.core.views.prospect import prospecting_image
from troggle.core.views.statistics import pathsreport, stats, dataissues
from troggle.core.views.survex import survexcaveslist, survexcavesingle, svx
class SubprocessTest(TestCase):
@classmethod
def setUpTestData(cls):
pass
def setUp(self):
pass
def tearDown(self):
pass
def test_installs(self):
'''Expects external software installed: cavern, survexport, git
(but not whether it actually works)
'''
import troggle.settings as settings
for i in [settings.CAVERN, settings.SURVEXPORT, settings.GIT]:
# Define command as string and then split() into list format
cmd = f'which {i}'.split()
try:
sp = subprocess.check_call(cmd, shell=False)
except subprocess.CalledProcessError:
self.assertTrue( False, f'no {i} installed')