feat(core): remove unnessecary method clean_fields from audit model

ref: #772 #759
This commit is contained in:
2025-05-25 08:57:49 +09:30
parent 5e169eb7f8
commit 12ec0f34f9
3 changed files with 1 additions and 68 deletions

View File

@ -126,31 +126,6 @@ class CenturionAudit(
def clean_fields(self, exclude: set = None):
"""Clean Model Fields
The Audit Sub-Model that inherits from this model must implement this
method so as to populate the history fields with the history data.
Args:
exclude (set, optional): List of fields to exclude. Defaults to
None.
Raises:
NotImplementedError: The Audit sub-model that inheirts has failed
to implement this method.
"""
if type(self) is not CenturionAudit:
raise NotImplementedError(
'Audit sub models must implement this method to populate fields'
)
super().clean_fields( exclude = exclude )
def get_model_history(self, model: models.Model) -> bool:
"""Populate fields `self.before` and `self.after`

View File

@ -134,48 +134,6 @@ class CenturionAuditModelPyTest(
def test_method_clean_fields_calls_super_clean_fields(self, mocker, model_instance):
"""Test Class Method
Ensure method `clean_fields` calls `super().clean_fields` with the defined attributes.
"""
super_clean_fields = mocker.patch('core.models.centurion.CenturionModel.clean_fields', return_value = None)
model_instance.clean_fields()
super_clean_fields.assert_called_with(
exclude = None
)
def test_method_clean_fields_not_implemented_exception(self, mocker, model):
"""Test Class Method
Ensure method `clean_fields` raises an exception if the child model
does not implement its own method of the same name.
"""
class MockModel(model):
class Meta:
app_label = 'core'
verbose_name = 'mock instance'
managed = False
mock_model = MockModel()
del apps.all_models['core']['mockmodel']
super_clean_fields = mocker.patch('core.models.centurion.CenturionModel.full_clean', return_value = None)
with pytest.raises(NotImplementedError):
mock_model.clean_fields()
def test_method_get_model_history_default_attributes(self, model_instance):
"""Test Class Method

View File

@ -13,8 +13,8 @@ from core.tests.unit.centurion_audit.test_unit_centurion_audit_model import (
@pytest.mark.models
class MetaAbstractModelTestCases(
CenturionAuditModelInheritedCases,
CenturionSubAbstractModelInheritedCases,
CenturionAuditModelInheritedCases
):
def test_method_centurionauditsub_clean_fields_called(self, mocker, model_instance):