Skip to content

Commit 6692985

Browse files
committed
Refactored CreateHistoryModelTests
1 parent effbfb2 commit 6692985

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

simple_history/tests/tests/test_models.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -894,33 +894,38 @@ def test_get_next_record_with_excluded_field(self):
894894

895895

896896
class CreateHistoryModelTests(unittest.TestCase):
897+
@staticmethod
898+
def create_history_model(model, inherited):
899+
custom_model_name_prefix = "MockHistorical"
900+
records = HistoricalRecords(
901+
# Provide a custom history model name, to prevent name collisions
902+
# with existing historical models
903+
custom_model_name=lambda name: f"{custom_model_name_prefix}{name}",
904+
)
905+
records.module = model.__module__
906+
return records.create_history_model(model, inherited)
907+
897908
def test_create_history_model_with_one_to_one_field_to_integer_field(self):
898-
records = HistoricalRecords()
899-
records.module = AdminProfile.__module__
900909
try:
901-
records.create_history_model(AdminProfile, False)
910+
self.create_history_model(AdminProfile, False)
902911
except Exception:
903912
self.fail(
904913
"SimpleHistory should handle foreign keys to one to one"
905914
"fields to integer fields without throwing an exception"
906915
)
907916

908917
def test_create_history_model_with_one_to_one_field_to_char_field(self):
909-
records = HistoricalRecords()
910-
records.module = Bookcase.__module__
911918
try:
912-
records.create_history_model(Bookcase, False)
919+
self.create_history_model(Bookcase, False)
913920
except Exception:
914921
self.fail(
915922
"SimpleHistory should handle foreign keys to one to one"
916923
"fields to char fields without throwing an exception."
917924
)
918925

919926
def test_create_history_model_with_multiple_one_to_ones(self):
920-
records = HistoricalRecords()
921-
records.module = MultiOneToOne.__module__
922927
try:
923-
records.create_history_model(MultiOneToOne, False)
928+
self.create_history_model(MultiOneToOne, False)
924929
except Exception:
925930
self.fail(
926931
"SimpleHistory should handle foreign keys to one to one"

0 commit comments

Comments
 (0)