(self)
| 1695 | self.assertEqual(ages, "50, 49") |
| 1696 | |
| 1697 | def test_using_is_honored_custom_qs(self): |
| 1698 | B = Book.objects.using("other") |
| 1699 | A = Author.objects.using("other") |
| 1700 | book1 = B.create(title="Poems") |
| 1701 | book2 = B.create(title="Sense and Sensibility") |
| 1702 | |
| 1703 | A.create(name="Charlotte Bronte", first_book=book1) |
| 1704 | A.create(name="Jane Austen", first_book=book2) |
| 1705 | |
| 1706 | # Implicit hinting |
| 1707 | with self.assertNumQueries(2, using="other"): |
| 1708 | prefetch = Prefetch("first_time_authors", queryset=Author.objects.all()) |
| 1709 | books = "".join( |
| 1710 | "%s (%s)\n" |
| 1711 | % (b.title, ", ".join(a.name for a in b.first_time_authors.all())) |
| 1712 | for b in B.prefetch_related(prefetch) |
| 1713 | ) |
| 1714 | self.assertEqual( |
| 1715 | books, |
| 1716 | "Poems (Charlotte Bronte)\nSense and Sensibility (Jane Austen)\n", |
| 1717 | ) |
| 1718 | # Explicit using on the same db. |
| 1719 | with self.assertNumQueries(2, using="other"): |
| 1720 | prefetch = Prefetch( |
| 1721 | "first_time_authors", queryset=Author.objects.using("other") |
| 1722 | ) |
| 1723 | books = "".join( |
| 1724 | "%s (%s)\n" |
| 1725 | % (b.title, ", ".join(a.name for a in b.first_time_authors.all())) |
| 1726 | for b in B.prefetch_related(prefetch) |
| 1727 | ) |
| 1728 | self.assertEqual( |
| 1729 | books, |
| 1730 | "Poems (Charlotte Bronte)\nSense and Sensibility (Jane Austen)\n", |
| 1731 | ) |
| 1732 | |
| 1733 | # Explicit using on a different db. |
| 1734 | with ( |
| 1735 | self.assertNumQueries(1, using="default"), |
| 1736 | self.assertNumQueries(1, using="other"), |
| 1737 | ): |
| 1738 | prefetch = Prefetch( |
| 1739 | "first_time_authors", queryset=Author.objects.using("default") |
| 1740 | ) |
| 1741 | books = "".join( |
| 1742 | "%s (%s)\n" |
| 1743 | % (b.title, ", ".join(a.name for a in b.first_time_authors.all())) |
| 1744 | for b in B.prefetch_related(prefetch) |
| 1745 | ) |
| 1746 | self.assertEqual(books, "Poems ()\n" "Sense and Sensibility ()\n") |
| 1747 | |
| 1748 | |
| 1749 | class Ticket19607Tests(TestCase): |
nothing calls this directly
no test coverage detected