mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
This reverts4f8c7fd9d9and adds two regression tests: - test_related_manager_refresh(), and - test_create_copy_with_m2m(). Thanks joeli for the report. Backport of5e0aa362d9from main
This commit is contained in:
@@ -92,6 +92,25 @@ class ManyToManyTests(TestCase):
|
||||
a5.authors.remove(user_2.username)
|
||||
self.assertSequenceEqual(a5.authors.all(), [])
|
||||
|
||||
def test_related_manager_refresh(self):
|
||||
user_1 = User.objects.create(username="Jean")
|
||||
user_2 = User.objects.create(username="Joe")
|
||||
self.a3.authors.add(user_1.username)
|
||||
self.assertSequenceEqual(user_1.article_set.all(), [self.a3])
|
||||
# Change the username on a different instance of the same user.
|
||||
user_1_from_db = User.objects.get(pk=user_1.pk)
|
||||
self.assertSequenceEqual(user_1_from_db.article_set.all(), [self.a3])
|
||||
user_1_from_db.username = "Paul"
|
||||
self.a3.authors.set([user_2.username])
|
||||
user_1_from_db.save()
|
||||
# Assign a different article.
|
||||
self.a4.authors.add(user_1_from_db.username)
|
||||
self.assertSequenceEqual(user_1_from_db.article_set.all(), [self.a4])
|
||||
# Refresh the instance with an evaluated related manager.
|
||||
user_1.refresh_from_db()
|
||||
self.assertEqual(user_1.username, "Paul")
|
||||
self.assertSequenceEqual(user_1.article_set.all(), [self.a4])
|
||||
|
||||
def test_add_remove_invalid_type(self):
|
||||
msg = "Field 'id' expected a number but got 'invalid'."
|
||||
for method in ["add", "remove"]:
|
||||
|
||||
Reference in New Issue
Block a user