test_agnostic_order_trimjoin.py 861 B

123456789101112131415161718192021222324252627
  1. from operator import attrgetter
  2. from django.test.testcases import TestCase
  3. from .models import Address, Contact, Customer
  4. class TestLookupQuery(TestCase):
  5. @classmethod
  6. def setUpTestData(cls):
  7. cls.address = Address.objects.create(company=1, customer_id=20)
  8. cls.customer1 = Customer.objects.create(company=1, customer_id=20)
  9. cls.contact1 = Contact.objects.create(company_code=1, customer_code=20)
  10. def test_deep_mixed_forward(self):
  11. self.assertQuerySetEqual(
  12. Address.objects.filter(customer__contacts=self.contact1),
  13. [self.address.id],
  14. attrgetter("id"),
  15. )
  16. def test_deep_mixed_backward(self):
  17. self.assertQuerySetEqual(
  18. Contact.objects.filter(customer__address=self.address),
  19. [self.contact1.id],
  20. attrgetter("id"),
  21. )