@ -62,6 +62,8 @@ class CenturionAudit(
|
||||
verbose_name = 'Content Model'
|
||||
)
|
||||
|
||||
model = None # is overridden with the model field in child-model
|
||||
|
||||
before = models.JSONField(
|
||||
blank = True,
|
||||
help_text = 'Value before Change',
|
||||
|
@ -193,10 +193,15 @@ class CenturionAuditModelPyTest(
|
||||
not have attribute `_before` populated
|
||||
"""
|
||||
|
||||
default = model_instance.before
|
||||
model_instance.before = None
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
|
||||
model_instance.get_model_history( model = model_instance )
|
||||
|
||||
model_instance.before = default
|
||||
|
||||
assert e.value.code == 'model_missing_before_data'
|
||||
|
||||
|
||||
@ -208,6 +213,9 @@ class CenturionAuditModelPyTest(
|
||||
not have attribute `_after` populated
|
||||
"""
|
||||
|
||||
default = model_instance.after
|
||||
model_instance.after = None
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
|
||||
model_instance._before = {'key': 'value'}
|
||||
@ -216,6 +224,8 @@ class CenturionAuditModelPyTest(
|
||||
|
||||
del model_instance._before
|
||||
|
||||
model_instance.after = default
|
||||
|
||||
assert e.value.code == 'model_missing_after_data'
|
||||
|
||||
|
||||
@ -227,6 +237,13 @@ class CenturionAuditModelPyTest(
|
||||
`_after` and `_before` attributes are te same
|
||||
"""
|
||||
|
||||
default_a = model_instance.after
|
||||
model_instance.after = None
|
||||
|
||||
default_b = model_instance.before
|
||||
model_instance.before = None
|
||||
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
|
||||
model_instance._after = {'key': 'value'}
|
||||
@ -237,6 +254,9 @@ class CenturionAuditModelPyTest(
|
||||
del model_instance._after
|
||||
del model_instance._before
|
||||
|
||||
model_instance.after = default_a
|
||||
model_instance.before = default_b
|
||||
|
||||
assert e.value.code == 'before_and_after_same'
|
||||
|
||||
|
||||
@ -251,6 +271,10 @@ class CenturionAuditModelPyTest(
|
||||
model_instance._after = {'key': 'value', **test_value}
|
||||
model_instance._before = {'key': 'value'}
|
||||
|
||||
|
||||
model_instance.after = None
|
||||
|
||||
|
||||
model_instance.get_model_history( model = model_instance )
|
||||
|
||||
del model_instance._after
|
||||
@ -270,6 +294,10 @@ class CenturionAuditModelPyTest(
|
||||
model_instance._after = { **test_value, 'key_1': 'value_1' }
|
||||
model_instance._before = { **test_value }
|
||||
|
||||
|
||||
model_instance.before = None
|
||||
|
||||
|
||||
model_instance.get_model_history( model = model_instance )
|
||||
|
||||
del model_instance._after
|
||||
|
10
app/tests/fixtures/model_centurionaudit.py
vendored
10
app/tests/fixtures/model_centurionaudit.py
vendored
@ -12,7 +12,10 @@ def model_centurionaudit():
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def kwargs_centurionaudit(django_db_blocker, kwargs_centurionmodel, kwargs_user, model_user):
|
||||
def kwargs_centurionaudit(django_db_blocker,
|
||||
kwargs_centurionmodel, model_contenttype,
|
||||
kwargs_user, model_user
|
||||
):
|
||||
|
||||
kwargs = kwargs_centurionmodel.copy()
|
||||
del kwargs['model_notes']
|
||||
@ -39,7 +42,10 @@ def kwargs_centurionaudit(django_db_blocker, kwargs_centurionmodel, kwargs_user,
|
||||
},
|
||||
'action': CenturionAudit.Actions.ADD,
|
||||
'user': user,
|
||||
'content_type': 'fixture sets value',
|
||||
'content_type': model_contenttype.objects.get(
|
||||
app_label = user._meta.app_label,
|
||||
model = user._meta.model_name,
|
||||
),
|
||||
}
|
||||
|
||||
yield kwargs.copy()
|
||||
|
Reference in New Issue
Block a user