From 2b6a15cf8fb368446ffaf3c8ad0f90b16e02db21 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 26 May 2025 16:19:05 +0930 Subject: [PATCH] test(core): Add Functional model Test Suite for CenturionAuditModel ref: #773 #515 --- .../tests/unit/test_preperation_work.py | 4 +- app/conftest.py | 2 +- .../functional/centurion_audit/conftest.py | 10 +++ .../test_functional_centurion_audit_model.py | 61 +++++++++++++++++++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 app/core/tests/functional/centurion_audit/conftest.py create mode 100644 app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py diff --git a/app/centurion/tests/unit/test_preperation_work.py b/app/centurion/tests/unit/test_preperation_work.py index d60afd43..17dd57db 100644 --- a/app/centurion/tests/unit/test_preperation_work.py +++ b/app/centurion/tests/unit/test_preperation_work.py @@ -66,7 +66,7 @@ class MetaChecksPyTest: - notes_models = get_models( [ 'base', 'history', 'note', 'ticket' ] ) + notes_models = get_models( [ 'audithistory', 'base', 'history', 'note', 'ticket' ] ) @pytest.mark.xfail( reason = 'Test Checks if installed models has a notes table' ) @@ -100,7 +100,7 @@ class MetaChecksPyTest: - history_models = get_models( [ 'base', 'history', 'note', 'ticket' ] ) + history_models = get_models( [ 'audithistory', 'base', 'history', 'note', 'ticket' ] ) @pytest.mark.xfail( reason = 'Test Checks if installed models has a History table' ) diff --git a/app/conftest.py b/app/conftest.py index 92c081f0..a976e791 100644 --- a/app/conftest.py +++ b/app/conftest.py @@ -266,7 +266,7 @@ def pytest_generate_tests(metafunc): -@pytest.fixture( scope = 'function') +@pytest.fixture( scope = 'class') def content_type(): from django.contrib.contenttypes.models import ContentType diff --git a/app/core/tests/functional/centurion_audit/conftest.py b/app/core/tests/functional/centurion_audit/conftest.py new file mode 100644 index 00000000..a5879014 --- /dev/null +++ b/app/core/tests/functional/centurion_audit/conftest.py @@ -0,0 +1,10 @@ +import pytest + +from core.models.audit import CenturionAudit + + + +@pytest.fixture( scope = 'class') +def model(request): + + yield CenturionAudit diff --git a/app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py b/app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py new file mode 100644 index 00000000..3f030c8c --- /dev/null +++ b/app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py @@ -0,0 +1,61 @@ +import pytest + +from django.apps import apps +from django.conf import settings + +from core.models.audit import CenturionAudit + +from core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model import ( + CenturionAbstractModelInheritedCases +) + + +@pytest.mark.audit_models +class CenturionAuditModelTestCases( + CenturionAbstractModelInheritedCases +): + + + kwargs_create_item = { + 'before': {}, + 'after': { + 'after_key': 'after_value' + }, + 'action': CenturionAudit.Actions.ADD, + 'user': 'fixture sets value', + 'content_type': 'fixture sets value', + } + + + @pytest.fixture( scope = 'class', autouse = True ) + def setup_vars(self, content_type, django_db_blocker, user, model): + + with django_db_blocker.unblock(): + + try: + + content_type = content_type.objects.get( + app_label = model._meta.app_label, + model = model._meta.model_name, + ) + + except content_type.DoesNotExist: + # Enable Abstract models to be tested + + content_type = content_type.objects.get( + pk = 1, + ) + + + self.kwargs_create_item.update({ + 'content_type': content_type, + 'user': user, + }) + + + +class CenturionAuditModelInheritedCases( + CenturionAuditModelTestCases, +): + + pass