From 5b428042d2d99b8ab387c62553c96c96955b7bba Mon Sep 17 00:00:00 2001 From: Antoine Auger Date: Mon, 27 Mar 2023 12:09:03 +0200 Subject: [PATCH] test(m2m-fields): add tests that should pass --- simple_history/tests/models.py | 14 ++++++++++++++ simple_history/tests/tests/test_models.py | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/simple_history/tests/models.py b/simple_history/tests/models.py index 5bfc74b44..8cc5b4408 100644 --- a/simple_history/tests/models.py +++ b/simple_history/tests/models.py @@ -133,6 +133,15 @@ class PollWithManyToMany(models.Model): history = HistoricalRecords(m2m_fields=[places]) +class PollWithManyToManyThroughFields(models.Model): + question = models.CharField(max_length=200) + people = models.ManyToManyField( + "Place", through="Venue", through_fields=("place", "guest") + ) + + history = HistoricalRecords(m2m_fields=[people]) + + class PollWithManyToManyCustomHistoryID(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField("date published") @@ -312,6 +321,11 @@ class Restaurant(Place): updates = HistoricalRecords() +class Venue(models.Model): + place = models.ForeignKey("Place", on_delete=models.CASCADE, null=True) + guest = models.ForeignKey("Person", on_delete=models.CASCADE, null=True) + + class Person(models.Model): name = models.CharField(max_length=100) diff --git a/simple_history/tests/tests/test_models.py b/simple_history/tests/tests/test_models.py index 5dd87aeb8..43c23e7f6 100644 --- a/simple_history/tests/tests/test_models.py +++ b/simple_history/tests/tests/test_models.py @@ -101,6 +101,7 @@ PollWithHistoricalIPAddress, PollWithManyToMany, PollWithManyToManyCustomHistoryID, + PollWithManyToManyThroughFields, PollWithManyToManyWithIPAddress, PollWithNonEditableField, PollWithSeveralManyToMany, @@ -1909,6 +1910,12 @@ def setUp(self): self.poll = self.model.objects.create(question="what's up?", pub_date=today) +class PollWithManyToManyThroughFieldsTest(TestCase): + def setUp(self): + self.model = PollWithManyToManyThroughFields + self.history_model = self.model.history.model + + class ManyToManyTest(TestCase): def setUp(self): self.model = PollWithManyToMany