From f5a989e60394ac11f5dce886468a34533caefcbf Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Tue, 2 Jan 2018 09:42:24 -0500 Subject: Fixed #28974 -- Made refresh_from_db() hint routers about its instance. --- tests/multiple_database/tests.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tests/multiple_database') diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index 50859a3dc6..ab88ecf875 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -2,6 +2,7 @@ import datetime import pickle from io import StringIO from operator import attrgetter +from unittest.mock import Mock from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType @@ -103,6 +104,14 @@ class QueryTestCase(TestCase): self.assertEqual(dive.title, "Dive into Python (on default)") self.assertEqual(dive._state.db, "default") + def test_refresh_router_instance_hint(self): + router = Mock() + router.db_for_read.return_value = None + book = Book.objects.create(title='Dive Into Python', published=datetime.date(1957, 10, 12)) + with self.settings(DATABASE_ROUTERS=[router]): + book.refresh_from_db() + router.db_for_read.assert_called_once_with(Book, instance=book) + def test_basic_queries(self): "Queries are constrained to a single database" dive = Book.objects.using('other').create(title="Dive into Python", published=datetime.date(2009, 5, 4)) -- cgit v1.3