def test_foreign_key(self): order = Order.objects.get(pk=self.order.pk) with self.assert_lazy_error('Order.purchaser'): with no_lazy_queries(): order.purchaser order = Order.objects.select_related('purchaser').get(pk=self.order.pk) with self.assertNumQueries(0): with no_lazy_queries(): self.assertEqual(order.purchaser, self.account)
def test_one_to_one(self): profile = Profile.objects.get(pk=self.profile.pk) with self.assert_lazy_error('Profile.account'): with no_lazy_queries(): profile.account profile = (Profile.objects .select_related('account') .get(pk=self.profile.pk)) with self.assertNumQueries(0): with no_lazy_queries(): self.assertEqual(profile.account, self.account)
def test_reverse_one_to_one(self): account = Account.objects.get(pk=self.account.pk) with self.assert_lazy_error('Account.profile'): with no_lazy_queries(): account.profile account = (Account.objects .select_related('profile') .get(pk=self.account.pk)) with self.assertNumQueries(0): with no_lazy_queries(): self.assertEqual(account.profile, self.profile)