summaryrefslogtreecommitdiff
path: root/tests/admin_views/tests.py
diff options
context:
space:
mode:
authorLincoln Smith <lincoln.smith@anu.edu.au>2017-04-05 13:54:46 +1000
committerTim Graham <timograham@gmail.com>2017-06-14 13:07:06 -0400
commit15b465c584f49a1d43b6c18796f83521ee4ffc22 (patch)
treea15da857498224fa76c27b149a5ba7bbbfc978dd /tests/admin_views/tests.py
parent451b585c2f76507b1be9d855a41cf2bb5aad6026 (diff)
Fixed #27998 -- Made ManyToManyField changes logged in admin's object history.
Diffstat (limited to 'tests/admin_views/tests.py')
-rw-r--r--tests/admin_views/tests.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 16cc8d4b71..eee375e9f6 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -54,12 +54,13 @@ from .models import (
ModelWithStringPrimaryKey, OtherStory, Paper, Parent,
ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona, Picture,
Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post,
- PrePopulatedPost, Promo, Question, Recommendation, Recommender,
- RelatedPrepopulated, RelatedWithUUIDPKModel, Report, Restaurant,
- RowLevelChangePermissionModel, SecretHideout, Section, ShortMessage,
- Simple, State, Story, Subscriber, SuperSecretHideout, SuperVillain,
- Telegram, TitleTranslation, Topping, UnchangeableObject, UndeletableObject,
- UnorderedObject, Villain, Vodcast, Whatsit, Widget, Worker, WorkHour,
+ PrePopulatedPost, Promo, Question, ReadablePizza, Recommendation,
+ Recommender, RelatedPrepopulated, RelatedWithUUIDPKModel, Report,
+ Restaurant, RowLevelChangePermissionModel, SecretHideout, Section,
+ ShortMessage, Simple, State, Story, Subscriber, SuperSecretHideout,
+ SuperVillain, Telegram, TitleTranslation, Topping, UnchangeableObject,
+ UndeletableObject, UnorderedObject, Villain, Vodcast, Whatsit, Widget,
+ Worker, WorkHour,
)
@@ -876,6 +877,17 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
response = self.client.get(reverse('admin:admin_views_undeletableobject_change', args=(instance.pk,)))
self.assertNotContains(response, 'deletelink')
+ def test_change_view_logs_m2m_field_changes(self):
+ """Changes to ManyToManyFields are included in the object's history."""
+ pizza = ReadablePizza.objects.create(name='Cheese')
+ cheese = Topping.objects.create(name='cheese')
+ post_data = {'name': pizza.name, 'toppings': [cheese.pk]}
+ response = self.client.post(reverse('admin:admin_views_readablepizza_change', args=(pizza.pk,)), post_data)
+ self.assertRedirects(response, reverse('admin:admin_views_readablepizza_changelist'))
+ pizza_ctype = ContentType.objects.get_for_model(ReadablePizza, for_concrete_model=False)
+ log = LogEntry.objects.filter(content_type=pizza_ctype, object_id=pizza.pk).first()
+ self.assertEqual(log.get_change_message(), 'Changed toppings.')
+
def test_allows_attributeerror_to_bubble_up(self):
"""
AttributeErrors are allowed to bubble when raised inside a change list