From 0df0514a568cea3f10cdc435a614c9013175787e Mon Sep 17 00:00:00 2001 From: csae8092 Date: Wed, 20 Dec 2023 12:45:39 +0100 Subject: [PATCH] crud views tested --- apis_core/apis_entities/tests.py | 58 +++++++++++++++++++++++++++----- pmb/settings.py | 6 +--- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/apis_core/apis_entities/tests.py b/apis_core/apis_entities/tests.py index 0185d8b..b870579 100644 --- a/apis_core/apis_entities/tests.py +++ b/apis_core/apis_entities/tests.py @@ -1,4 +1,4 @@ -# from django.apps import apps +from django.apps import apps from django.test import TestCase, Client from django.contrib.auth.models import User @@ -9,6 +9,8 @@ USER = {"username": "testuser", "password": "somepassword"} BAHR = {"name": "Bahr", "first_name": "Hermann", "start_date_written": "1900"} +MODELS = list(apps.all_models["apis_entities"].values()) + class EntitiesTestCase(TestCase): fixtures = [ @@ -19,21 +21,61 @@ def setUp(self): # Create two users User.objects.create_user(**USER) - def test_001_person_list_view(self): - url = Person.get_listview_url() - response = client.get(url) - self.assertEqual(response.status_code, 200) + def test_001_list_view(self): + for x in MODELS: + try: + url = x.get_listview_url() + except AttributeError: + url = False + if url: + response = client.get(url) + self.assertEqual(response.status_code, 200) + + def test_002_detailviews(self): + for x in MODELS: + item = x.objects.first() + try: + url = item.get_absolute_url() + except AttributeError: + url = False + if url: + response = client.get(url, {"pk": item.id}) + self.assertEqual(response.status_code, 200) + + def test_003_editviews(self): + client.login(**USER) + for x in MODELS: + item = x.objects.first() + try: + url = item.get_edit_url() + except AttributeError: + url = False + if url: + response = client.get(url, {"pk": item.id}) + self.assertEqual(response.status_code, 200) + + def test_004_createviews_logged_in(self): + client.login(**USER) + for x in MODELS: + item = x.objects.first() + try: + url = item.get_createview_url() + except AttributeError: + url = False + if url: + response = client.get(url, {"pk": item.id}) + self.assertEqual(response.status_code, 200) - def test_002_check_fixtures(self): + def test_004_check_fixtures(self): items = Person.objects.all().count() self.assertEqual(items, 2) - def test_003_create_person(self): + def test_005_create_person(self): item, created = Person.objects.get_or_create(**BAHR) self.assertTrue(created) self.assertEqual(item.name, "Bahr") - def test_004_delete_person(self): + def test_006_delete_person(self): item, _ = Person.objects.get_or_create(**BAHR) self.assertEqual(item.name, "Bahr") item.delete() diff --git a/pmb/settings.py b/pmb/settings.py index 4dc729b..c95b8c7 100644 --- a/pmb/settings.py +++ b/pmb/settings.py @@ -27,6 +27,7 @@ "apis_override_select2js", "dal", "dal_select2", + "django_extensions", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", @@ -51,11 +52,6 @@ CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" CRISPY_TEMPLATE_PACK = "bootstrap5" -if os.environ.get("DEV"): - INSTALLED_APPS = INSTALLED_APPS + [ - "django_extensions", - ] - CSRF_USE_SESSIONS = True