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