2016-04-18 20:59:01 +08:00
|
|
|
from operator import attrgetter
|
|
|
|
|
|
|
|
from django.test.testcases import TestCase
|
|
|
|
|
|
|
|
from .models import Address, Contact, Customer
|
|
|
|
|
|
|
|
|
|
|
|
class TestLookupQuery(TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
cls.address = Address.objects.create(company=1, customer_id=20)
|
|
|
|
cls.customer1 = Customer.objects.create(company=1, customer_id=20)
|
|
|
|
cls.contact1 = Contact.objects.create(company_code=1, customer_code=20)
|
|
|
|
|
|
|
|
def test_deep_mixed_forward(self):
|
2022-09-24 18:29:58 +08:00
|
|
|
self.assertQuerySetEqual(
|
2016-04-18 20:59:01 +08:00
|
|
|
Address.objects.filter(customer__contacts=self.contact1),
|
|
|
|
[self.address.id],
|
|
|
|
attrgetter("id"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_deep_mixed_backward(self):
|
2022-09-24 18:29:58 +08:00
|
|
|
self.assertQuerySetEqual(
|
2016-04-18 20:59:01 +08:00
|
|
|
Contact.objects.filter(customer__address=self.address),
|
|
|
|
[self.contact1.id],
|
|
|
|
attrgetter("id"),
|
|
|
|
)
|