|
3 | 3 | import warnings
|
4 | 4 | from datetime import datetime, timedelta
|
5 | 5 |
|
6 |
| -import django |
7 | 6 | from django.apps import apps
|
8 | 7 | from django.conf import settings
|
9 | 8 | from django.contrib.auth import get_user_model
|
|
28 | 27 | pre_create_historical_m2m_records,
|
29 | 28 | pre_create_historical_record,
|
30 | 29 | )
|
31 |
| -from simple_history.tests.custom_user.models import CustomUser |
32 | 30 | from simple_history.tests.tests.utils import (
|
33 | 31 | database_router_override_settings,
|
34 | 32 | database_router_override_settings_history_in_diff_db,
|
|
72 | 70 | HistoricalCustomFKError,
|
73 | 71 | HistoricalPoll,
|
74 | 72 | HistoricalPollWithHistoricalIPAddress,
|
75 |
| - HistoricalPollWithManyToMany_places, |
76 | 73 | HistoricalState,
|
77 | 74 | InheritedRestaurant,
|
78 | 75 | Library,
|
|
85 | 82 | ModelWithMultipleNoDBIndex,
|
86 | 83 | ModelWithSingleNoDBIndexUnique,
|
87 | 84 | MultiOneToOne,
|
88 |
| - MyOverrideModelNameRegisterMethod1, |
89 |
| - OverrideModelNameAsCallable, |
90 | 85 | OverrideModelNameUsingBaseModel1,
|
91 | 86 | Person,
|
92 | 87 | Place,
|
@@ -800,6 +795,33 @@ def test_history_with_unknown_field(self):
|
800 | 795 | with self.assertNumQueries(0):
|
801 | 796 | new_record.diff_against(old_record, excluded_fields=["unknown_field"])
|
802 | 797 |
|
| 798 | + def test_history_with_deletion_record(self): |
| 799 | + question = "what's up?" |
| 800 | + p = Poll.objects.create(question=question, pub_date=today) |
| 801 | + poll_pk = p.pk |
| 802 | + new_record = p.history.first() |
| 803 | + p.delete() |
| 804 | + |
| 805 | + deletion_record = HistoricalPoll.objects.get(id=poll_pk, history_type="-") |
| 806 | + |
| 807 | + with self.assertNumQueries(0): |
| 808 | + delta = new_record.diff_against( |
| 809 | + deletion_record, included_fields=["question"] |
| 810 | + ) |
| 811 | + self.assertEqual(delta.changed_fields, ["question"]) |
| 812 | + self.assertEqual(len(delta.changes), 1) |
| 813 | + self.assertEqual(delta.changes[0].new, question) |
| 814 | + self.assertEqual(delta.changes[0].old, None) |
| 815 | + |
| 816 | + with self.assertNumQueries(0): |
| 817 | + delta = deletion_record.diff_against( |
| 818 | + new_record, included_fields=["question"] |
| 819 | + ) |
| 820 | + self.assertEqual(delta.changed_fields, ["question"]) |
| 821 | + self.assertEqual(len(delta.changes), 1) |
| 822 | + self.assertEqual(delta.changes[0].new, None) |
| 823 | + self.assertEqual(delta.changes[0].old, question) |
| 824 | + |
803 | 825 |
|
804 | 826 | class GetPrevRecordAndNextRecordTestCase(TestCase):
|
805 | 827 | def assertRecordsMatch(self, record_a, record_b):
|
|
0 commit comments