test(core): Initial Unit Model Test Cases for CenturionAuditMeta Model

ref: #772 #759
This commit is contained in:
2025-05-25 02:58:23 +09:30
parent 8b62014d88
commit 0a35a32136
5 changed files with 93 additions and 56 deletions

View File

@ -83,10 +83,21 @@ class CenturionAuditModelTestCases(
with django_db_blocker.unblock():
content_type = ContentType.objects.get(
app_label = model._meta.app_label,
model = model._meta.model_name,
)
try:
content_type = ContentType.objects.get(
app_label = model._meta.app_label,
model = model._meta.model_name,
)
except ContentType.DoesNotExist:
# Enable Abstract models to be tested
content_type = ContentType.objects.get(
pk = 1,
)
self.kwargs_create_item.update({
'content_type': content_type,

View File

@ -0,0 +1,10 @@
import pytest
from core.models.audit import AuditMetaModel
@pytest.fixture( scope = 'class')
def model(request):
yield AuditMetaModel

View File

@ -0,0 +1,68 @@
import pytest
from core.tests.unit.centurion_sub_abstract.test_unit_centurion_sub_abstract_model import (
CenturionSubAbstractModelInheritedCases,
)
from core.tests.unit.centurion_audit.test_unit_centurion_audit_model import (
CenturionAuditModelInheritedCases,
)
@pytest.mark.models
class MetaAbstractModelTestCases(
CenturionSubAbstractModelInheritedCases,
CenturionAuditModelInheritedCases
):
pass
# parameterized_class_attributes = {
# '_audit_enabled': {
# 'value': False,
# },
# '_notes_enabled': {
# 'value': False,
# }
# }
# check models with model._audit_enabled=True have a model created
# check models with model._audit_enabled=False DONT have a model created
# check the Meta class has the correct attributes
# confirm it exists in sys.modules
# check they inherit form audithistory parent class
class MetaAbstractModelInheritedCases(
MetaAbstractModelTestCases,
):
pass
class MetaAbstractModelPyTest(
MetaAbstractModelTestCases,
):
def test_model_is_abstract(self, model):
assert model._meta.abstract
def test_model_not_proxy(self, model):
assert not model._meta.proxy
def test_model_creation(self):
"""
This test is a duplicate of a test with the same name. As this model
is an abstract model this test is not required.
"""
pass

View File

@ -1,14 +0,0 @@
# import pytest
# from core.models.meta import BaseMetaModel
# @pytest.fixture( scope = 'class')
# def model(request):
# request.cls.model = BaseMetaModel
# yield request.cls.model
# del request.cls.model

View File

@ -1,38 +0,0 @@
import pytest
@pytest.mark.models
class MetaAbstractModelTestCases:
# @pytest.fixture( scope = 'class', autouse = True)
# def setup_class(cls, model):
#
pass
# check models with model._audit_enabled=True have a model created
# check models with model._audit_enabled=False DONT have a model created
# check the Meta class has the correct attributes
# confirm it exists in sys.modules
# check they inherit form audithistory parent class
class MetaAbstractModelInheritedCases(
MetaAbstractModelTestCases,
):
pass
class MetaAbstractModelPyTest(
MetaAbstractModelTestCases,
):
pass