Skip to content

Commit

Permalink
test(m2m-fields): add tests that should pass
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineauger committed Apr 20, 2023
1 parent 1daa2ae commit 5b42804
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions simple_history/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions simple_history/tests/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
PollWithHistoricalIPAddress,
PollWithManyToMany,
PollWithManyToManyCustomHistoryID,
PollWithManyToManyThroughFields,
PollWithManyToManyWithIPAddress,
PollWithNonEditableField,
PollWithSeveralManyToMany,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5b42804

Please sign in to comment.