mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
Replace assertTrue with assertEqual
This commit is contained in:
parent
77ef852706
commit
629d8e62c6
1 changed files with 123 additions and 107 deletions
|
|
@ -45,7 +45,7 @@ class SimpleModelTest(TestCase):
|
|||
obj = self.obj
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(obj.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(obj.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
try:
|
||||
history = obj.history.get()
|
||||
|
|
@ -69,8 +69,9 @@ class SimpleModelTest(TestCase):
|
|||
obj.save()
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count() == 1,
|
||||
self.assertEqual(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count(),
|
||||
1,
|
||||
msg="There is one log entry for 'UPDATE'",
|
||||
)
|
||||
|
||||
|
|
@ -108,8 +109,9 @@ class SimpleModelTest(TestCase):
|
|||
obj.boolean = True
|
||||
obj.save(update_fields=[])
|
||||
|
||||
self.assertTrue(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count() == 0,
|
||||
self.assertEqual(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count(),
|
||||
0,
|
||||
msg="There is no log entries created",
|
||||
)
|
||||
obj.refresh_from_db()
|
||||
|
|
@ -136,13 +138,13 @@ class SimpleModelTest(TestCase):
|
|||
obj.delete()
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(
|
||||
self.assertEqual(
|
||||
LogEntry.objects.filter(
|
||||
content_type=history.content_type,
|
||||
object_pk=history.object_pk,
|
||||
action=LogEntry.Action.DELETE,
|
||||
).count()
|
||||
== 1,
|
||||
).count(),
|
||||
1,
|
||||
msg="There is one log entry for 'DELETE'",
|
||||
)
|
||||
|
||||
|
|
@ -308,8 +310,9 @@ class SimpleIncludeModelTest(TestCase):
|
|||
obj.text = "New text"
|
||||
obj.save(update_fields=["text"])
|
||||
|
||||
self.assertTrue(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count() == 0,
|
||||
self.assertEqual(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count(),
|
||||
0,
|
||||
msg="Text change was not logged, even when passed explicitly",
|
||||
)
|
||||
|
||||
|
|
@ -326,17 +329,17 @@ class SimpleIncludeModelTest(TestCase):
|
|||
def test_register_include_fields(self):
|
||||
sim = SimpleIncludeModel(label="Include model", text="Looong text")
|
||||
sim.save()
|
||||
self.assertTrue(sim.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(sim.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change label, record
|
||||
sim.label = "Changed label"
|
||||
sim.save()
|
||||
self.assertTrue(sim.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(sim.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
# Change text, ignore
|
||||
sim.text = "Short text"
|
||||
sim.save()
|
||||
self.assertTrue(sim.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(sim.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
|
||||
class SimpleExcludeModelTest(TestCase):
|
||||
|
|
@ -347,25 +350,26 @@ class SimpleExcludeModelTest(TestCase):
|
|||
obj.text = "New text"
|
||||
obj.save(update_fields=["text"])
|
||||
|
||||
self.assertTrue(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count() == 0,
|
||||
self.assertEqual(
|
||||
obj.history.filter(action=LogEntry.Action.UPDATE).count(),
|
||||
0,
|
||||
msg="Text change was not logged, even when passed explicitly",
|
||||
)
|
||||
|
||||
def test_register_exclude_fields(self):
|
||||
sem = SimpleExcludeModel(label="Exclude model", text="Looong text")
|
||||
sem.save()
|
||||
self.assertTrue(sem.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(sem.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change label, record it.
|
||||
sem.label = "Changed label"
|
||||
sem.save()
|
||||
self.assertTrue(sem.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(sem.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
# Change text, ignore it.
|
||||
sem.text = "Short text"
|
||||
sem.save()
|
||||
self.assertTrue(sem.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(sem.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
|
||||
class SimpleMappingModelTest(TestCase):
|
||||
|
|
@ -376,28 +380,32 @@ class SimpleMappingModelTest(TestCase):
|
|||
sku="ASD301301A6", vtxt="2.1.5", not_mapped="Not mapped"
|
||||
)
|
||||
smm.save()
|
||||
self.assertTrue(
|
||||
smm.history.latest().changes_dict["sku"][1] == "ASD301301A6",
|
||||
self.assertEqual(
|
||||
smm.history.latest().changes_dict["sku"][1],
|
||||
"ASD301301A6",
|
||||
msg="The diff function retains 'sku' and can be retrieved.",
|
||||
)
|
||||
self.assertTrue(
|
||||
smm.history.latest().changes_dict["not_mapped"][1] == "Not mapped",
|
||||
self.assertEqual(
|
||||
smm.history.latest().changes_dict["not_mapped"][1],
|
||||
"Not mapped",
|
||||
msg="The diff function does not map 'not_mapped' and can be retrieved.",
|
||||
)
|
||||
self.assertTrue(
|
||||
smm.history.latest().changes_display_dict["Product No."][1]
|
||||
== "ASD301301A6",
|
||||
self.assertEqual(
|
||||
smm.history.latest().changes_display_dict["Product No."][1],
|
||||
"ASD301301A6",
|
||||
msg="The diff function maps 'sku' as 'Product No.' and can be retrieved.",
|
||||
)
|
||||
self.assertTrue(
|
||||
smm.history.latest().changes_display_dict["Version"][1] == "2.1.5",
|
||||
self.assertEqual(
|
||||
smm.history.latest().changes_display_dict["Version"][1],
|
||||
"2.1.5",
|
||||
msg=(
|
||||
"The diff function maps 'vtxt' as 'Version' through verbose_name"
|
||||
" setting on the model field and can be retrieved."
|
||||
),
|
||||
)
|
||||
self.assertTrue(
|
||||
smm.history.latest().changes_display_dict["not mapped"][1] == "Not mapped",
|
||||
self.assertEqual(
|
||||
smm.history.latest().changes_display_dict["not mapped"][1],
|
||||
"Not mapped",
|
||||
msg=(
|
||||
"The diff function uses the django default verbose name for 'not_mapped'"
|
||||
" and can be retrieved."
|
||||
|
|
@ -421,18 +429,20 @@ class AdditionalDataModelTest(TestCase):
|
|||
label="Additional data to log entries", related=related_model
|
||||
)
|
||||
obj_with_additional_data.save()
|
||||
self.assertTrue(
|
||||
obj_with_additional_data.history.count() == 1, msg="There is 1 log entry"
|
||||
self.assertEqual(
|
||||
obj_with_additional_data.history.count(), 1, msg="There is 1 log entry"
|
||||
)
|
||||
log_entry = obj_with_additional_data.history.get()
|
||||
extra_data = log_entry.additional_data
|
||||
self.assertIsNotNone(extra_data)
|
||||
self.assertTrue(
|
||||
extra_data["related_model_text"] == related_model.text,
|
||||
self.assertEqual(
|
||||
extra_data["related_model_text"],
|
||||
related_model.text,
|
||||
msg="Related model's text is logged",
|
||||
)
|
||||
self.assertTrue(
|
||||
extra_data["related_model_id"] == related_model.id,
|
||||
self.assertEqual(
|
||||
extra_data["related_model_id"],
|
||||
related_model.id,
|
||||
msg="Related model's id is logged",
|
||||
)
|
||||
|
||||
|
|
@ -455,7 +465,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change timestamp to same datetime and timezone
|
||||
timestamp = datetime.datetime(2017, 1, 10, 12, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -465,7 +475,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.save()
|
||||
|
||||
# Nothing should have changed
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
def test_model_with_different_timezone(self):
|
||||
timestamp = datetime.datetime(2017, 1, 10, 12, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -479,7 +489,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change timestamp to same datetime in another timezone
|
||||
timestamp = datetime.datetime(2017, 1, 10, 13, 0, tzinfo=self.utc_plus_one)
|
||||
|
|
@ -487,7 +497,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.save()
|
||||
|
||||
# Nothing should have changed
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
def test_model_with_different_datetime(self):
|
||||
timestamp = datetime.datetime(2017, 1, 10, 12, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -501,7 +511,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change timestamp to another datetime in the same timezone
|
||||
timestamp = datetime.datetime(2017, 1, 10, 13, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -509,7 +519,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.save()
|
||||
|
||||
# The time should have changed.
|
||||
self.assertTrue(dtm.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(dtm.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
def test_model_with_different_date(self):
|
||||
timestamp = datetime.datetime(2017, 1, 10, 12, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -523,7 +533,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change timestamp to another datetime in the same timezone
|
||||
date = datetime.datetime(2017, 1, 11)
|
||||
|
|
@ -531,7 +541,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.save()
|
||||
|
||||
# The time should have changed.
|
||||
self.assertTrue(dtm.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(dtm.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
def test_model_with_different_time(self):
|
||||
timestamp = datetime.datetime(2017, 1, 10, 12, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -545,7 +555,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change timestamp to another datetime in the same timezone
|
||||
time = datetime.time(6, 0)
|
||||
|
|
@ -553,7 +563,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.save()
|
||||
|
||||
# The time should have changed.
|
||||
self.assertTrue(dtm.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(dtm.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
def test_model_with_different_time_and_timezone(self):
|
||||
timestamp = datetime.datetime(2017, 1, 10, 12, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -567,7 +577,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(dtm.history.count() == 1, msg="There is one log entry")
|
||||
self.assertEqual(dtm.history.count(), 1, msg="There is one log entry")
|
||||
|
||||
# Change timestamp to another datetime and another timezone
|
||||
timestamp = datetime.datetime(2017, 1, 10, 14, 0, tzinfo=self.utc_plus_one)
|
||||
|
|
@ -575,7 +585,7 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.save()
|
||||
|
||||
# The time should have changed.
|
||||
self.assertTrue(dtm.history.count() == 2, msg="There are two log entries")
|
||||
self.assertEqual(dtm.history.count(), 2, msg="There are two log entries")
|
||||
|
||||
def test_changes_display_dict_datetime(self):
|
||||
timestamp = datetime.datetime(2017, 1, 10, 15, 0, tzinfo=timezone.utc)
|
||||
|
|
@ -590,9 +600,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
)
|
||||
dtm.save()
|
||||
localized_timestamp = timestamp.astimezone(gettz(settings.TIME_ZONE))
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["timestamp"][1]
|
||||
== dateformat.format(localized_timestamp, settings.DATETIME_FORMAT),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["timestamp"][1],
|
||||
dateformat.format(localized_timestamp, settings.DATETIME_FORMAT),
|
||||
msg=(
|
||||
"The datetime should be formatted according to Django's settings for"
|
||||
" DATETIME_FORMAT"
|
||||
|
|
@ -602,9 +612,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
dtm.timestamp = timestamp
|
||||
dtm.save()
|
||||
localized_timestamp = timestamp.astimezone(gettz(settings.TIME_ZONE))
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["timestamp"][1]
|
||||
== dateformat.format(localized_timestamp, settings.DATETIME_FORMAT),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["timestamp"][1],
|
||||
dateformat.format(localized_timestamp, settings.DATETIME_FORMAT),
|
||||
msg=(
|
||||
"The datetime should be formatted according to Django's settings for"
|
||||
" DATETIME_FORMAT"
|
||||
|
|
@ -613,9 +623,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
|
||||
# Change USE_L10N = True
|
||||
with self.settings(USE_L10N=True, LANGUAGE_CODE="en-GB"):
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["timestamp"][1]
|
||||
== formats.localize(localized_timestamp),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["timestamp"][1],
|
||||
formats.localize(localized_timestamp),
|
||||
msg=(
|
||||
"The datetime should be formatted according to Django's settings for"
|
||||
" USE_L10N is True with a different LANGUAGE_CODE."
|
||||
|
|
@ -634,9 +644,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["date"][1]
|
||||
== dateformat.format(date, settings.DATE_FORMAT),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["date"][1],
|
||||
dateformat.format(date, settings.DATE_FORMAT),
|
||||
msg=(
|
||||
"The date should be formatted according to Django's settings for"
|
||||
" DATE_FORMAT unless USE_L10N is True."
|
||||
|
|
@ -645,9 +655,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
date = datetime.date(2017, 1, 11)
|
||||
dtm.date = date
|
||||
dtm.save()
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["date"][1]
|
||||
== dateformat.format(date, settings.DATE_FORMAT),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["date"][1],
|
||||
dateformat.format(date, settings.DATE_FORMAT),
|
||||
msg=(
|
||||
"The date should be formatted according to Django's settings for"
|
||||
" DATE_FORMAT unless USE_L10N is True."
|
||||
|
|
@ -656,9 +666,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
|
||||
# Change USE_L10N = True
|
||||
with self.settings(USE_L10N=True, LANGUAGE_CODE="en-GB"):
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["date"][1]
|
||||
== formats.localize(date),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["date"][1],
|
||||
formats.localize(date),
|
||||
msg=(
|
||||
"The date should be formatted according to Django's settings for"
|
||||
" USE_L10N is True with a different LANGUAGE_CODE."
|
||||
|
|
@ -677,9 +687,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
naive_dt=self.now,
|
||||
)
|
||||
dtm.save()
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["time"][1]
|
||||
== dateformat.format(time, settings.TIME_FORMAT),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["time"][1],
|
||||
dateformat.format(time, settings.TIME_FORMAT),
|
||||
msg=(
|
||||
"The time should be formatted according to Django's settings for"
|
||||
" TIME_FORMAT unless USE_L10N is True."
|
||||
|
|
@ -688,9 +698,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
time = datetime.time(6, 0)
|
||||
dtm.time = time
|
||||
dtm.save()
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["time"][1]
|
||||
== dateformat.format(time, settings.TIME_FORMAT),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["time"][1],
|
||||
dateformat.format(time, settings.TIME_FORMAT),
|
||||
msg=(
|
||||
"The time should be formatted according to Django's settings for"
|
||||
" TIME_FORMAT unless USE_L10N is True."
|
||||
|
|
@ -699,9 +709,9 @@ class DateTimeFieldModelTest(TestCase):
|
|||
|
||||
# Change USE_L10N = True
|
||||
with self.settings(USE_L10N=True, LANGUAGE_CODE="en-GB"):
|
||||
self.assertTrue(
|
||||
dtm.history.latest().changes_display_dict["time"][1]
|
||||
== formats.localize(time),
|
||||
self.assertEqual(
|
||||
dtm.history.latest().changes_display_dict["time"][1],
|
||||
formats.localize(time),
|
||||
msg=(
|
||||
"The time should be formatted according to Django's settings for"
|
||||
" USE_L10N is True with a different LANGUAGE_CODE."
|
||||
|
|
@ -741,7 +751,7 @@ class UnregisterTest(TestCase):
|
|||
obj = self.obj
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(obj.history.count() == 0, msg="There are no log entries")
|
||||
self.assertEqual(obj.history.count(), 0, msg="There are no log entries")
|
||||
|
||||
def test_unregister_update(self):
|
||||
"""Updates are not logged after unregistering."""
|
||||
|
|
@ -753,7 +763,7 @@ class UnregisterTest(TestCase):
|
|||
obj.save()
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(obj.history.count() == 0, msg="There are no log entries")
|
||||
self.assertEqual(obj.history.count(), 0, msg="There are no log entries")
|
||||
|
||||
def test_unregister_delete(self):
|
||||
"""Deletion is not logged after unregistering."""
|
||||
|
|
@ -764,7 +774,7 @@ class UnregisterTest(TestCase):
|
|||
obj.delete()
|
||||
|
||||
# Check for log entries
|
||||
self.assertTrue(LogEntry.objects.count() == 0, msg="There are no log entries")
|
||||
self.assertEqual(LogEntry.objects.count(), 0, msg="There are no log entries")
|
||||
|
||||
|
||||
class ChoicesFieldModelTest(TestCase):
|
||||
|
|
@ -780,28 +790,30 @@ class ChoicesFieldModelTest(TestCase):
|
|||
|
||||
def test_changes_display_dict_single_choice(self):
|
||||
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["status"][1] == "Red",
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["status"][1],
|
||||
"Red",
|
||||
msg="The human readable text 'Red' is displayed.",
|
||||
)
|
||||
self.obj.status = ChoicesFieldModel.GREEN
|
||||
self.obj.save()
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["status"][1] == "Green",
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["status"][1],
|
||||
"Green",
|
||||
msg="The human readable text 'Green' is displayed.",
|
||||
)
|
||||
|
||||
def test_changes_display_dict_multiplechoice(self):
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["multiplechoice"][1]
|
||||
== "Red, Yellow, Green",
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["multiplechoice"][1],
|
||||
"Red, Yellow, Green",
|
||||
msg="The human readable text 'Red, Yellow, Green' is displayed.",
|
||||
)
|
||||
self.obj.multiplechoice = ChoicesFieldModel.RED
|
||||
self.obj.save()
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["multiplechoice"][1]
|
||||
== "Red",
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["multiplechoice"][1],
|
||||
"Red",
|
||||
msg="The human readable text 'Red' is displayed.",
|
||||
)
|
||||
|
||||
|
|
@ -816,32 +828,32 @@ class CharfieldTextfieldModelTest(TestCase):
|
|||
)
|
||||
|
||||
def test_changes_display_dict_longchar(self):
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["longchar"][1]
|
||||
== f"{self.PLACEHOLDER_LONGCHAR[:140]}...",
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["longchar"][1],
|
||||
f"{self.PLACEHOLDER_LONGCHAR[:140]}...",
|
||||
msg="The string should be truncated at 140 characters with an ellipsis at the end.",
|
||||
)
|
||||
SHORTENED_PLACEHOLDER = self.PLACEHOLDER_LONGCHAR[:139]
|
||||
self.obj.longchar = SHORTENED_PLACEHOLDER
|
||||
self.obj.save()
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["longchar"][1]
|
||||
== SHORTENED_PLACEHOLDER,
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["longchar"][1],
|
||||
SHORTENED_PLACEHOLDER,
|
||||
msg="The field should display the entire string because it is less than 140 characters",
|
||||
)
|
||||
|
||||
def test_changes_display_dict_longtextfield(self):
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["longtextfield"][1]
|
||||
== f"{self.PLACEHOLDER_LONGTEXTFIELD[:140]}...",
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["longtextfield"][1],
|
||||
f"{self.PLACEHOLDER_LONGTEXTFIELD[:140]}...",
|
||||
msg="The string should be truncated at 140 characters with an ellipsis at the end.",
|
||||
)
|
||||
SHORTENED_PLACEHOLDER = self.PLACEHOLDER_LONGTEXTFIELD[:139]
|
||||
self.obj.longtextfield = SHORTENED_PLACEHOLDER
|
||||
self.obj.save()
|
||||
self.assertTrue(
|
||||
self.obj.history.latest().changes_display_dict["longtextfield"][1]
|
||||
== SHORTENED_PLACEHOLDER,
|
||||
self.assertEqual(
|
||||
self.obj.history.latest().changes_display_dict["longtextfield"][1],
|
||||
SHORTENED_PLACEHOLDER,
|
||||
msg="The field should display the entire string because it is less than 140 characters",
|
||||
)
|
||||
|
||||
|
|
@ -859,26 +871,30 @@ class PostgresArrayFieldModelTest(TestCase):
|
|||
return self.obj.history.latest().changes_display_dict["arrayfield"][1]
|
||||
|
||||
def test_changes_display_dict_arrayfield(self):
|
||||
self.assertTrue(
|
||||
self.latest_array_change == "Red, Green",
|
||||
self.assertEqual(
|
||||
self.latest_array_change,
|
||||
"Red, Green",
|
||||
msg="The human readable text for the two choices, 'Red, Green' is displayed.",
|
||||
)
|
||||
self.obj.arrayfield = [PostgresArrayFieldModel.GREEN]
|
||||
self.obj.save()
|
||||
self.assertTrue(
|
||||
self.latest_array_change == "Green",
|
||||
self.assertEqual(
|
||||
self.latest_array_change,
|
||||
"Green",
|
||||
msg="The human readable text 'Green' is displayed.",
|
||||
)
|
||||
self.obj.arrayfield = []
|
||||
self.obj.save()
|
||||
self.assertTrue(
|
||||
self.latest_array_change == "",
|
||||
self.assertEqual(
|
||||
self.latest_array_change,
|
||||
"",
|
||||
msg="The human readable text '' is displayed.",
|
||||
)
|
||||
self.obj.arrayfield = [PostgresArrayFieldModel.GREEN]
|
||||
self.obj.save()
|
||||
self.assertTrue(
|
||||
self.latest_array_change == "Green",
|
||||
self.assertEqual(
|
||||
self.latest_array_change,
|
||||
"Green",
|
||||
msg="The human readable text 'Green' is displayed.",
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue