Skip to content

Commit

Permalink
crud views tested
Browse files Browse the repository at this point in the history
  • Loading branch information
csae8092 committed Dec 20, 2023
1 parent 72587ff commit 0df0514
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
58 changes: 50 additions & 8 deletions apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 = [
Expand All @@ -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()
6 changes: 1 addition & 5 deletions pmb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"apis_override_select2js",
"dal",
"dal_select2",
"django_extensions",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -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


Expand Down

0 comments on commit 0df0514

Please sign in to comment.