Skip to content

Commit

Permalink
Small improvement of the test for #1196
Browse files Browse the repository at this point in the history
Now also compares the table name of the inherited (base) model, so that
it's easier to see that the history table name is not inherited.
  • Loading branch information
ddabble committed Aug 15, 2023
1 parent 61a9090 commit 5a7bdce
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions simple_history/tests/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,23 @@ def test_history_diff_includes_changed_fields_of_base_model(self):
self.assertEqual(delta.new_record, new_record)
self.assertEqual(expected_change.field, delta.changes[0].field)

def test_inherited_history_table_name_with_table_name_set_in_base_model(self):
def test_history_table_name_is_not_inherited(self):
def assert_table_name(obj, expected_table_name):
history_model = obj.history.model
self.assertEqual(
history_model.__name__, f"Historical{obj._meta.model.__name__}"
)
self.assertEqual(history_model._meta.db_table, expected_table_name)

place = BasePlace.objects.create(name="Place Name")
# This is set in `BasePlace.history`
assert_table_name(place, "base_places_history")

r = InheritedRestaurant.objects.create(name="KFC", serves_hot_dogs=True)
history_model = r.history.model
expected_cls_name = "HistoricalInheritedRestaurant"
expected_table_name = f"tests_{expected_cls_name.lower()}"
self.assertEqual(history_model.__name__, expected_cls_name)
self.assertEqual(history_model._meta.db_table, expected_table_name)
self.assertTrue(isinstance(r, BasePlace))
# The default table name of the history model,
# instead of inheriting from `BasePlace`
assert_table_name(r, f"tests_Historical{r._meta.model.__name__}".lower())

def test_history_diff_with_incorrect_type(self):
p = Poll.objects.create(question="what's up?", pub_date=today)
Expand Down

0 comments on commit 5a7bdce

Please sign in to comment.