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 Sep 28, 2023
1 parent fd9aa52 commit 2042634
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions simple_history/tests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Document,
Employee,
FileModel,
Group,
Paper,
Person,
Planet,
Expand Down Expand Up @@ -43,6 +44,7 @@ def test_method(self, obj):
history_list_display = ["title", "test_method"]


admin.site.register(Group, SimpleHistoryAdmin)
admin.site.register(Poll, SimpleHistoryAdmin)
admin.site.register(Choice, ChoiceAdmin)
admin.site.register(Person, PersonAdmin)
Expand Down
22 changes: 22 additions & 0 deletions simple_history/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,28 @@ class PollWithManyToMany(models.Model):
history = HistoricalRecords(m2m_fields=[places])


class Membership(models.Model):
group = models.ForeignKey("Group", on_delete=models.CASCADE)
person = models.ForeignKey("Person", on_delete=models.CASCADE)
inviter = models.ForeignKey(
"Person",
on_delete=models.CASCADE,
related_name="membership_invites",
)
invite_reason = models.CharField(max_length=64)


class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(
"Person",
through="tests.Membership",
through_fields=("group", "person"),
)

history = HistoricalRecords(m2m_fields=[members])


class PollWithManyToManyCustomHistoryID(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField("date published")
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,
Group,
PollWithManyToManyWithIPAddress,
PollWithNonEditableField,
PollWithSelfManyToMany,
Expand Down Expand Up @@ -1939,6 +1940,12 @@ def setUp(self):
self.poll = self.model.objects.create(question="what's up?", pub_date=today)


class GroupWithManyToManyThroughFieldsTest(TestCase):
def setUp(self):
self.model = Group
self.history_model = self.model.history.model


class ManyToManyTest(TestCase):
def setUp(self):
self.model = PollWithManyToMany
Expand Down

0 comments on commit 2042634

Please sign in to comment.