test(core): Ensure Method clean_fields functions for CenturionNotesModel

ref: #779 #778
This commit is contained in:
2025-05-30 11:16:30 +09:30
parent 1fa3278b73
commit b37a284a0a
4 changed files with 98 additions and 7 deletions

View File

@ -108,13 +108,25 @@ class NoteMetaModel(
def clean(self):
if not self.created_by:
raise ValidationError(
code = 'no_user_supplied',
message = 'No user was supplied for this model note.'
)
super().clean()
def clean_fields(self, exclude = None):
if not getattr(self, 'model', None):
raise ValidationError(
code = 'no_model_supplied',
message = 'Unable to process the history, no model was supplied.'
message = 'No model was supplied for his "Model note".'
)

View File

@ -113,6 +113,7 @@ class CenturionNoteModelTestCases(
})
@pytest.mark.xfail( reason = 'Model does not require method' )
def test_method_value_not_default___str__(self, model, model_instance ):
"""Test Method

View File

@ -1,5 +1,10 @@
import inspect
import pytest
from django.core.exceptions import (
ValidationError
)
from core.tests.unit.centurion_sub_abstract.test_unit_centurion_sub_abstract_model import (
CenturionSubAbstractModelInheritedCases,
)
@ -16,6 +21,46 @@ class MetaAbstractModelTestCases(
):
def test_method_centurionnotes_clean_fields_called(self, mocker, model_instance):
"""Test Class Method
Ensure method `core.models.centurion.CenturionModel.delete()` is called
when `model.delete()` is called.
"""
clean_fields = mocker.patch('core.models.centurion_notes.NoteMetaModel.clean_fields', return_value = None)
model_instance.clean_fields()
clean_fields.assert_called_once()
def test_method_centurionnotes_clean_fields_no_model_exception(self, mocker, model_instance):
"""Test Class Method
Ensure method `core.models.centurion.CenturionModel.delete()` is called
when `model.delete()` is called.
"""
class MockManager:
def get(*args, **kwargs):
return model_instance
model_instance.objects = MockManager()
model_instance.model = None
# clean_fields = mocker.patch('core.models.centurion_notes.NoteMetaModel.clean_fields', return_value = None)
with pytest.raises( ValidationError ) as e:
model_instance.clean_fields()
assert e.value.code == 'no_model_supplied'
def test_method_get_url_attribute__is_submodel_set(self, mocker, model_instance, settings):
"""Test Class Method
@ -67,7 +112,7 @@ class MetaAbstractModelInheritedCases(
assert model.model_tag is not None
def test_method_get_url_attribute__is_submodel_set(self, mocker, model_instance, audit_model):
def test_method_get_url_attribute__is_submodel_set(self, mocker, model_instance, note_model):
"""Test Class Method
Ensure method `get_url` calls reverse
@ -79,7 +124,7 @@ class MetaAbstractModelInheritedCases(
reverse = mocker.patch('rest_framework.reverse._reverse', return_value = site_path)
instance = audit_model()
instance = note_model()
instance.id = 1
model_instance.id = 1
@ -104,13 +149,13 @@ class MetaAbstractModelInheritedCases(
def test_method_get_url_kwargs(self, mocker, model_instance, audit_model):
def test_method_get_url_kwargs(self, mocker, model_instance, note_model):
"""Test Class Method
Ensure method `get_url_kwargs` returns the correct value.
"""
instance = audit_model()
instance = note_model()
instance.id = 1
model_instance.id = 1
@ -126,6 +171,24 @@ class MetaAbstractModelInheritedCases(
}
def test_method_centurionnotes_clean_fields_no_errors(self, mocker, model_instance, note_model, organization_one):
"""Test Class Method
Ensure method `core.models.centurion_notes.NoteMetaModel.clean_fields()` throws no errors
when called.
"""
clean_fields = mocker.patch('core.models.centurion_notes.CenturionModelNote.clean_fields', return_value = None)
instance = note_model()
instance.id = 1
instance.organization = organization_one
model_instance.id = 1
model_instance.model = instance
model_instance.clean_fields()
class MetaAbstractModelPyTest(
@ -158,3 +221,18 @@ class MetaAbstractModelPyTest(
is an abstract model this test is not required.
"""
pass
def test_method_clean_fields_default_attributes(self, model_instance):
"""Test Class Method
Ensure method `clean_fields` has the defined default attributes.
"""
sig = inspect.signature(model_instance.clean_fields)
exclude = sig.parameters['exclude'].default
assert(
exclude == None
)

View File

@ -79,7 +79,7 @@ class ModelNotesMetaModelTestCases(
"""
@pytest.fixture( scope = 'class' )
def audit_model(self, request):
def note_model(self, request):
return request.cls.note_model_class
@ -90,7 +90,7 @@ class ModelNotesMetaModelTestCases(
return request.cls.model_class
@pytest.mark.skip( reason = 'ToDo: Figure out how to dynomagic add audit_model instance' )
@pytest.mark.skip( reason = 'ToDo: Figure out how to dynomagic add note_model instance' )
def test_model_creation(self, model, user):
pass