summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py45
1 files changed, 41 insertions, 4 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 349408465..bbb449fe3 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -23,6 +23,8 @@ import os
import shutil
from StringIO import StringIO
+from django.apps import apps
+
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
@@ -38,6 +40,7 @@ from django.test.runner import DiscoverRunner
from ishtar_common import models
from ishtar_common import views
+from ishtar_common.apps import admin_site
from ishtar_common.utils import post_save_point
@@ -347,6 +350,13 @@ class AdminGenTypeTest(TestCase):
models_with_data = gen_models + [models.ImporterModel]
models = models_with_data
module_name = 'ishtar_common'
+ ishtar_apps = [
+ 'ishtar_common', 'archaeological_files', 'archaeological_operations',
+ 'archaeological_context_records', 'archaeological_warehouse',
+ 'archaeological_finds'
+ ]
+ readonly_models = ['archaeological_finds.Property',
+ 'archaeological_finds.Treatment']
def setUp(self):
self.password = 'mypassword'
@@ -359,16 +369,34 @@ class AdminGenTypeTest(TestCase):
self.client.login(username=self.username, password=self.password)
def test_listing_and_detail(self):
- for model in self.models:
+ models = []
+ for app in self.ishtar_apps:
+ app_models = apps.get_app_config(app).get_models()
+ for model in app_models:
+ if model in admin_site._registry:
+ models.append((app, model))
+ for app, model in models:
# quick test to verify basic access to listing
- base_url = '/admin/{}/{}/'.format(self.module_name,
- model.__name__.lower())
+ base_url = '/admin/{}/{}/'.format(app, model.__name__.lower())
url = base_url
response = self.client.get(url)
self.assertEqual(
response.status_code, 200,
msg="Can not access admin list for {}.".format(model))
- if model in self.models_with_data:
+ nb = model.objects.count()
+ url = base_url + "add/"
+ response = self.client.get(url)
+ if app + "." + model.__name__ in self.readonly_models:
+ continue
+ self.assertEqual(
+ response.status_code, 200,
+ msg="Can not access admin add page for {}.".format(model))
+ self.assertEqual(
+ nb, model.objects.count(),
+ msg="A ghost object have been created on access to add page "
+ "for {}.".format(model))
+
+ if nb:
url = base_url + "{}/change/".format(model.objects.all()[0].pk)
response = self.client.get(url)
self.assertEqual(
@@ -1046,6 +1074,15 @@ class IshtarBasicTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertIn('class="sheet"', response.content)
+ def test_town_cache(self):
+ models.Town.objects.create(name="Sin City", numero_insee="99999")
+ town = models.Town.objects.get(numero_insee="99999")
+ self.assertEqual(town.cached_label, "Sin City - 99")
+ town.year = 2050
+ town.save()
+ town = models.Town.objects.get(numero_insee="99999")
+ self.assertEqual(town.cached_label, "Sin City - 99 (2050)")
+
class GeomaticTest(TestCase):
def test_post_save_point(self):