test(core): Unit Test Centurion Model method get_url_kwargs
ref: #775 #759 #767
This commit is contained in:
@ -267,10 +267,8 @@ class AuditMetaModel(
|
||||
kwargs = {}
|
||||
|
||||
kwargs.update({
|
||||
'app_label': self._meta.app_label,
|
||||
'model_name': str(self._meta.model_name).replace('audithistory', ''),
|
||||
'model_id': self.model.id,
|
||||
**super().get_url_kwargs(),
|
||||
'model_name': str(self._meta.model_name).replace('audithistory', ''),
|
||||
})
|
||||
|
||||
return kwargs
|
||||
|
@ -303,3 +303,17 @@ class CenturionSubModel(
|
||||
class Meta:
|
||||
|
||||
abstract = True
|
||||
|
||||
|
||||
def get_url_kwargs(self):
|
||||
|
||||
kwargs = {}
|
||||
|
||||
kwargs.update({
|
||||
**super().get_url_kwargs(),
|
||||
'app_label': self._meta.app_label,
|
||||
'model_name': str(self._meta.model_name),
|
||||
'model_id': self.model.id,
|
||||
})
|
||||
|
||||
return kwargs
|
||||
|
@ -191,6 +191,20 @@ class CenturionAbstractModelTestCases(
|
||||
|
||||
|
||||
|
||||
def test_method_get_url_kwargs(self, mocker, model_instance, settings):
|
||||
"""Test Class Method
|
||||
|
||||
Ensure method `get_url_kwargs` returns the correct value.
|
||||
"""
|
||||
|
||||
model_instance.id = 1
|
||||
|
||||
url = model_instance.get_url_kwargs()
|
||||
|
||||
assert model_instance.get_url_kwargs() == { 'pk': model_instance.id }
|
||||
|
||||
|
||||
|
||||
def test_method_validate_field_not_none_raises_exception(self, model):
|
||||
""" Test Class Method
|
||||
|
||||
@ -828,36 +842,6 @@ class CenturionAbstractModelPyTest(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_method_save_audit_enabled_sets__after_create_model(self, mocker, model_instance):
|
||||
"""Test Class Method
|
||||
|
||||
|
@ -139,18 +139,13 @@ class MetaAbstractModelPyTest(
|
||||
|
||||
mocker.patch('core.models.audit.CenturionAudit.get_model_history', return_value = False)
|
||||
|
||||
# super_clean_fields = mocker.patch('core.models.audit.CenturionAudit.clean_fields', return_value = None)
|
||||
|
||||
|
||||
with pytest.raises( ValidationError ) as e:
|
||||
|
||||
model_instance.clean_fields()
|
||||
|
||||
|
||||
assert e.value.code == 'did_not_process_history'
|
||||
# super_clean_fields.assert_called_with(
|
||||
# exclude = None
|
||||
# )
|
||||
|
||||
|
||||
|
||||
def test_method_clean_fields_exception_no_model(self, mocker, model_instance):
|
||||
@ -162,10 +157,6 @@ class MetaAbstractModelPyTest(
|
||||
|
||||
model_instance.model = None
|
||||
|
||||
# mocker.patch('core.models.audit.CenturionAudit.get_model_history', return_value = False)
|
||||
|
||||
# super_clean_fields = mocker.patch('core.models.audit.CenturionAudit.clean_fields', return_value = None)
|
||||
|
||||
|
||||
with pytest.raises( ValidationError ) as e:
|
||||
|
||||
@ -173,6 +164,3 @@ class MetaAbstractModelPyTest(
|
||||
|
||||
|
||||
assert e.value.code == 'no_model_supplied'
|
||||
# super_clean_fields.assert_called_with(
|
||||
# exclude = None
|
||||
# )
|
||||
|
@ -39,9 +39,41 @@ class CenturionSubAbstractModelTestCases(
|
||||
|
||||
url = model_instance.get_url( relative = True)
|
||||
|
||||
del model_instance.model
|
||||
reverse.assert_called_with(
|
||||
url_basename,
|
||||
None,
|
||||
{
|
||||
'app_label': model_instance._meta.app_label,
|
||||
'model_name': model_instance._meta.model_name,
|
||||
'model_id': model_instance.model.id,
|
||||
'pk': model_instance.id,
|
||||
},
|
||||
None,
|
||||
None
|
||||
)
|
||||
|
||||
|
||||
|
||||
def test_method_get_url_kwargs(self, mocker, model_instance, settings):
|
||||
"""Test Class Method
|
||||
|
||||
Ensure method `get_url_kwargs` returns the correct value.
|
||||
"""
|
||||
|
||||
model_instance.id = 1
|
||||
model_instance.model = model_instance
|
||||
|
||||
url = model_instance.get_url_kwargs()
|
||||
|
||||
assert model_instance.get_url_kwargs() == {
|
||||
'app_label': model_instance._meta.app_label,
|
||||
'model_name': model_instance._meta.model_name,
|
||||
'model_id': model_instance.model.id,
|
||||
'pk': model_instance.id,
|
||||
}
|
||||
|
||||
|
||||
|
||||
reverse.assert_called_with( url_basename, None, { 'pk': model_instance.id }, None, None )
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user