test(core): Add Functional model Test Suite for CenturionAuditModel

ref: #773 #515
This commit is contained in:
2025-05-26 16:19:05 +09:30
parent a46187f36e
commit 2b6a15cf8f
4 changed files with 74 additions and 3 deletions

View File

@ -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' )

View File

@ -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

View File

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

View File

@ -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