tests.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. from __future__ import unicode_literals
  2. from datetime import date, datetime
  3. import time
  4. import unittest
  5. from django.core.exceptions import FieldError
  6. from django.db import models
  7. from django.db import connection
  8. from django.test import TestCase, override_settings
  9. from .models import Author, MySQLUnixTimestamp
  10. class Div3Lookup(models.Lookup):
  11. lookup_name = 'div3'
  12. def as_sql(self, compiler, connection):
  13. lhs, params = self.process_lhs(compiler, connection)
  14. rhs, rhs_params = self.process_rhs(compiler, connection)
  15. params.extend(rhs_params)
  16. return '(%s) %%%% 3 = %s' % (lhs, rhs), params
  17. def as_oracle(self, compiler, connection):
  18. lhs, params = self.process_lhs(compiler, connection)
  19. rhs, rhs_params = self.process_rhs(compiler, connection)
  20. params.extend(rhs_params)
  21. return 'mod(%s, 3) = %s' % (lhs, rhs), params
  22. class Div3Transform(models.Transform):
  23. lookup_name = 'div3'
  24. def as_sql(self, compiler, connection):
  25. lhs, lhs_params = compiler.compile(self.lhs)
  26. return '(%s) %%%% 3' % lhs, lhs_params
  27. def as_oracle(self, compiler, connection):
  28. lhs, lhs_params = compiler.compile(self.lhs)
  29. return 'mod(%s, 3)' % lhs, lhs_params
  30. class Div3BilateralTransform(Div3Transform):
  31. bilateral = True
  32. class Mult3BilateralTransform(models.Transform):
  33. bilateral = True
  34. lookup_name = 'mult3'
  35. def as_sql(self, compiler, connection):
  36. lhs, lhs_params = compiler.compile(self.lhs)
  37. return '3 * (%s)' % lhs, lhs_params
  38. class UpperBilateralTransform(models.Transform):
  39. bilateral = True
  40. lookup_name = 'upper'
  41. def as_sql(self, compiler, connection):
  42. lhs, lhs_params = compiler.compile(self.lhs)
  43. return 'UPPER(%s)' % lhs, lhs_params
  44. class YearTransform(models.Transform):
  45. lookup_name = 'year'
  46. def as_sql(self, compiler, connection):
  47. lhs_sql, params = compiler.compile(self.lhs)
  48. return connection.ops.date_extract_sql('year', lhs_sql), params
  49. @property
  50. def output_field(self):
  51. return models.IntegerField()
  52. @YearTransform.register_lookup
  53. class YearExact(models.lookups.Lookup):
  54. lookup_name = 'exact'
  55. def as_sql(self, compiler, connection):
  56. # We will need to skip the extract part, and instead go
  57. # directly with the originating field, that is self.lhs.lhs
  58. lhs_sql, lhs_params = self.process_lhs(compiler, connection, self.lhs.lhs)
  59. rhs_sql, rhs_params = self.process_rhs(compiler, connection)
  60. # Note that we must be careful so that we have params in the
  61. # same order as we have the parts in the SQL.
  62. params = lhs_params + rhs_params + lhs_params + rhs_params
  63. # We use PostgreSQL specific SQL here. Note that we must do the
  64. # conversions in SQL instead of in Python to support F() references.
  65. return ("%(lhs)s >= (%(rhs)s || '-01-01')::date "
  66. "AND %(lhs)s <= (%(rhs)s || '-12-31')::date" %
  67. {'lhs': lhs_sql, 'rhs': rhs_sql}, params)
  68. @YearTransform.register_lookup
  69. class YearLte(models.lookups.LessThanOrEqual):
  70. """
  71. The purpose of this lookup is to efficiently compare the year of the field.
  72. """
  73. def as_sql(self, compiler, connection):
  74. # Skip the YearTransform above us (no possibility for efficient
  75. # lookup otherwise).
  76. real_lhs = self.lhs.lhs
  77. lhs_sql, params = self.process_lhs(compiler, connection, real_lhs)
  78. rhs_sql, rhs_params = self.process_rhs(compiler, connection)
  79. params.extend(rhs_params)
  80. # Build SQL where the integer year is concatenated with last month
  81. # and day, then convert that to date. (We try to have SQL like:
  82. # WHERE somecol <= '2013-12-31')
  83. # but also make it work if the rhs_sql is field reference.
  84. return "%s <= (%s || '-12-31')::date" % (lhs_sql, rhs_sql), params
  85. class SQLFunc(models.Lookup):
  86. def __init__(self, name, *args, **kwargs):
  87. super(SQLFunc, self).__init__(*args, **kwargs)
  88. self.name = name
  89. def as_sql(self, compiler, connection):
  90. return '%s()', [self.name]
  91. @property
  92. def output_field(self):
  93. return CustomField()
  94. class SQLFuncFactory(object):
  95. def __init__(self, name):
  96. self.name = name
  97. def __call__(self, *args, **kwargs):
  98. return SQLFunc(self.name, *args, **kwargs)
  99. class CustomField(models.TextField):
  100. def get_lookup(self, lookup_name):
  101. if lookup_name.startswith('lookupfunc_'):
  102. key, name = lookup_name.split('_', 1)
  103. return SQLFuncFactory(name)
  104. return super(CustomField, self).get_lookup(lookup_name)
  105. def get_transform(self, lookup_name):
  106. if lookup_name.startswith('transformfunc_'):
  107. key, name = lookup_name.split('_', 1)
  108. return SQLFuncFactory(name)
  109. return super(CustomField, self).get_transform(lookup_name)
  110. class CustomModel(models.Model):
  111. field = CustomField()
  112. # We will register this class temporarily in the test method.
  113. class InMonth(models.lookups.Lookup):
  114. """
  115. InMonth matches if the column's month is the same as value's month.
  116. """
  117. lookup_name = 'inmonth'
  118. def as_sql(self, compiler, connection):
  119. lhs, lhs_params = self.process_lhs(compiler, connection)
  120. rhs, rhs_params = self.process_rhs(compiler, connection)
  121. # We need to be careful so that we get the params in right
  122. # places.
  123. params = lhs_params + rhs_params + lhs_params + rhs_params
  124. return ("%s >= date_trunc('month', %s) and "
  125. "%s < date_trunc('month', %s) + interval '1 months'" %
  126. (lhs, rhs, lhs, rhs), params)
  127. class DateTimeTransform(models.Transform):
  128. lookup_name = 'as_datetime'
  129. @property
  130. def output_field(self):
  131. return models.DateTimeField()
  132. def as_sql(self, compiler, connection):
  133. lhs, params = compiler.compile(self.lhs)
  134. return 'from_unixtime({})'.format(lhs), params
  135. class LookupTests(TestCase):
  136. def test_basic_lookup(self):
  137. a1 = Author.objects.create(name='a1', age=1)
  138. a2 = Author.objects.create(name='a2', age=2)
  139. a3 = Author.objects.create(name='a3', age=3)
  140. a4 = Author.objects.create(name='a4', age=4)
  141. models.IntegerField.register_lookup(Div3Lookup)
  142. try:
  143. self.assertQuerysetEqual(
  144. Author.objects.filter(age__div3=0),
  145. [a3], lambda x: x
  146. )
  147. self.assertQuerysetEqual(
  148. Author.objects.filter(age__div3=1).order_by('age'),
  149. [a1, a4], lambda x: x
  150. )
  151. self.assertQuerysetEqual(
  152. Author.objects.filter(age__div3=2),
  153. [a2], lambda x: x
  154. )
  155. self.assertQuerysetEqual(
  156. Author.objects.filter(age__div3=3),
  157. [], lambda x: x
  158. )
  159. finally:
  160. models.IntegerField._unregister_lookup(Div3Lookup)
  161. @unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific SQL used")
  162. def test_birthdate_month(self):
  163. a1 = Author.objects.create(name='a1', birthdate=date(1981, 2, 16))
  164. a2 = Author.objects.create(name='a2', birthdate=date(2012, 2, 29))
  165. a3 = Author.objects.create(name='a3', birthdate=date(2012, 1, 31))
  166. a4 = Author.objects.create(name='a4', birthdate=date(2012, 3, 1))
  167. models.DateField.register_lookup(InMonth)
  168. try:
  169. self.assertQuerysetEqual(
  170. Author.objects.filter(birthdate__inmonth=date(2012, 1, 15)),
  171. [a3], lambda x: x
  172. )
  173. self.assertQuerysetEqual(
  174. Author.objects.filter(birthdate__inmonth=date(2012, 2, 1)),
  175. [a2], lambda x: x
  176. )
  177. self.assertQuerysetEqual(
  178. Author.objects.filter(birthdate__inmonth=date(1981, 2, 28)),
  179. [a1], lambda x: x
  180. )
  181. self.assertQuerysetEqual(
  182. Author.objects.filter(birthdate__inmonth=date(2012, 3, 12)),
  183. [a4], lambda x: x
  184. )
  185. self.assertQuerysetEqual(
  186. Author.objects.filter(birthdate__inmonth=date(2012, 4, 1)),
  187. [], lambda x: x
  188. )
  189. finally:
  190. models.DateField._unregister_lookup(InMonth)
  191. def test_div3_extract(self):
  192. models.IntegerField.register_lookup(Div3Transform)
  193. try:
  194. a1 = Author.objects.create(name='a1', age=1)
  195. a2 = Author.objects.create(name='a2', age=2)
  196. a3 = Author.objects.create(name='a3', age=3)
  197. a4 = Author.objects.create(name='a4', age=4)
  198. baseqs = Author.objects.order_by('name')
  199. self.assertQuerysetEqual(
  200. baseqs.filter(age__div3=2),
  201. [a2], lambda x: x)
  202. self.assertQuerysetEqual(
  203. baseqs.filter(age__div3__lte=3),
  204. [a1, a2, a3, a4], lambda x: x)
  205. self.assertQuerysetEqual(
  206. baseqs.filter(age__div3__in=[0, 2]),
  207. [a2, a3], lambda x: x)
  208. self.assertQuerysetEqual(
  209. baseqs.filter(age__div3__in=[2, 4]),
  210. [a2], lambda x: x)
  211. self.assertQuerysetEqual(
  212. baseqs.filter(age__div3__gte=3),
  213. [], lambda x: x)
  214. self.assertQuerysetEqual(
  215. baseqs.filter(age__div3__range=(1, 2)),
  216. [a1, a2, a4], lambda x: x)
  217. finally:
  218. models.IntegerField._unregister_lookup(Div3Transform)
  219. class BilateralTransformTests(TestCase):
  220. def test_bilateral_upper(self):
  221. models.CharField.register_lookup(UpperBilateralTransform)
  222. try:
  223. Author.objects.bulk_create([
  224. Author(name='Doe'),
  225. Author(name='doe'),
  226. Author(name='Foo'),
  227. ])
  228. self.assertQuerysetEqual(
  229. Author.objects.filter(name__upper='doe'),
  230. ["<Author: Doe>", "<Author: doe>"], ordered=False)
  231. finally:
  232. models.CharField._unregister_lookup(UpperBilateralTransform)
  233. def test_bilateral_inner_qs(self):
  234. models.CharField.register_lookup(UpperBilateralTransform)
  235. try:
  236. with self.assertRaises(NotImplementedError):
  237. Author.objects.filter(name__upper__in=Author.objects.values_list('name'))
  238. finally:
  239. models.CharField._unregister_lookup(UpperBilateralTransform)
  240. def test_div3_bilateral_extract(self):
  241. models.IntegerField.register_lookup(Div3BilateralTransform)
  242. try:
  243. a1 = Author.objects.create(name='a1', age=1)
  244. a2 = Author.objects.create(name='a2', age=2)
  245. a3 = Author.objects.create(name='a3', age=3)
  246. a4 = Author.objects.create(name='a4', age=4)
  247. baseqs = Author.objects.order_by('name')
  248. self.assertQuerysetEqual(
  249. baseqs.filter(age__div3=2),
  250. [a2], lambda x: x)
  251. self.assertQuerysetEqual(
  252. baseqs.filter(age__div3__lte=3),
  253. [a3], lambda x: x)
  254. self.assertQuerysetEqual(
  255. baseqs.filter(age__div3__in=[0, 2]),
  256. [a2, a3], lambda x: x)
  257. self.assertQuerysetEqual(
  258. baseqs.filter(age__div3__in=[2, 4]),
  259. [a1, a2, a4], lambda x: x)
  260. self.assertQuerysetEqual(
  261. baseqs.filter(age__div3__gte=3),
  262. [a1, a2, a3, a4], lambda x: x)
  263. self.assertQuerysetEqual(
  264. baseqs.filter(age__div3__range=(1, 2)),
  265. [a1, a2, a4], lambda x: x)
  266. finally:
  267. models.IntegerField._unregister_lookup(Div3BilateralTransform)
  268. def test_bilateral_order(self):
  269. models.IntegerField.register_lookup(Mult3BilateralTransform)
  270. models.IntegerField.register_lookup(Div3BilateralTransform)
  271. try:
  272. a1 = Author.objects.create(name='a1', age=1)
  273. a2 = Author.objects.create(name='a2', age=2)
  274. a3 = Author.objects.create(name='a3', age=3)
  275. a4 = Author.objects.create(name='a4', age=4)
  276. baseqs = Author.objects.order_by('name')
  277. self.assertQuerysetEqual(
  278. baseqs.filter(age__mult3__div3=42),
  279. # mult3__div3 always leads to 0
  280. [a1, a2, a3, a4], lambda x: x)
  281. self.assertQuerysetEqual(
  282. baseqs.filter(age__div3__mult3=42),
  283. [a3], lambda x: x)
  284. finally:
  285. models.IntegerField._unregister_lookup(Mult3BilateralTransform)
  286. models.IntegerField._unregister_lookup(Div3BilateralTransform)
  287. def test_bilateral_fexpr(self):
  288. models.IntegerField.register_lookup(Mult3BilateralTransform)
  289. try:
  290. a1 = Author.objects.create(name='a1', age=1, average_rating=3.2)
  291. a2 = Author.objects.create(name='a2', age=2, average_rating=0.5)
  292. a3 = Author.objects.create(name='a3', age=3, average_rating=1.5)
  293. a4 = Author.objects.create(name='a4', age=4)
  294. baseqs = Author.objects.order_by('name')
  295. self.assertQuerysetEqual(
  296. baseqs.filter(age__mult3=models.F('age')),
  297. [a1, a2, a3, a4], lambda x: x)
  298. self.assertQuerysetEqual(
  299. # Same as age >= average_rating
  300. baseqs.filter(age__mult3__gte=models.F('average_rating')),
  301. [a2, a3], lambda x: x)
  302. finally:
  303. models.IntegerField._unregister_lookup(Mult3BilateralTransform)
  304. @override_settings(USE_TZ=True)
  305. class DateTimeLookupTests(TestCase):
  306. @unittest.skipUnless(connection.vendor == 'mysql', "MySQL specific SQL used")
  307. def test_datetime_output_field(self):
  308. models.PositiveIntegerField.register_lookup(DateTimeTransform)
  309. try:
  310. ut = MySQLUnixTimestamp.objects.create(timestamp=time.time())
  311. y2k = datetime(2000, 1, 1)
  312. self.assertQuerysetEqual(
  313. MySQLUnixTimestamp.objects.filter(timestamp__as_datetime__gt=y2k),
  314. [ut], lambda x: x)
  315. finally:
  316. models.PositiveIntegerField._unregister_lookup(DateTimeTransform)
  317. class YearLteTests(TestCase):
  318. def setUp(self):
  319. models.DateField.register_lookup(YearTransform)
  320. self.a1 = Author.objects.create(name='a1', birthdate=date(1981, 2, 16))
  321. self.a2 = Author.objects.create(name='a2', birthdate=date(2012, 2, 29))
  322. self.a3 = Author.objects.create(name='a3', birthdate=date(2012, 1, 31))
  323. self.a4 = Author.objects.create(name='a4', birthdate=date(2012, 3, 1))
  324. def tearDown(self):
  325. models.DateField._unregister_lookup(YearTransform)
  326. @unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific SQL used")
  327. def test_year_lte(self):
  328. baseqs = Author.objects.order_by('name')
  329. self.assertQuerysetEqual(
  330. baseqs.filter(birthdate__year__lte=2012),
  331. [self.a1, self.a2, self.a3, self.a4], lambda x: x)
  332. self.assertQuerysetEqual(
  333. baseqs.filter(birthdate__year=2012),
  334. [self.a2, self.a3, self.a4], lambda x: x)
  335. self.assertNotIn('BETWEEN', str(baseqs.filter(birthdate__year=2012).query))
  336. self.assertQuerysetEqual(
  337. baseqs.filter(birthdate__year__lte=2011),
  338. [self.a1], lambda x: x)
  339. # The non-optimized version works, too.
  340. self.assertQuerysetEqual(
  341. baseqs.filter(birthdate__year__lt=2012),
  342. [self.a1], lambda x: x)
  343. @unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific SQL used")
  344. def test_year_lte_fexpr(self):
  345. self.a2.age = 2011
  346. self.a2.save()
  347. self.a3.age = 2012
  348. self.a3.save()
  349. self.a4.age = 2013
  350. self.a4.save()
  351. baseqs = Author.objects.order_by('name')
  352. self.assertQuerysetEqual(
  353. baseqs.filter(birthdate__year__lte=models.F('age')),
  354. [self.a3, self.a4], lambda x: x)
  355. self.assertQuerysetEqual(
  356. baseqs.filter(birthdate__year__lt=models.F('age')),
  357. [self.a4], lambda x: x)
  358. def test_year_lte_sql(self):
  359. # This test will just check the generated SQL for __lte. This
  360. # doesn't require running on PostgreSQL and spots the most likely
  361. # error - not running YearLte SQL at all.
  362. baseqs = Author.objects.order_by('name')
  363. self.assertIn(
  364. '<= (2011 || ', str(baseqs.filter(birthdate__year__lte=2011).query))
  365. self.assertIn(
  366. '-12-31', str(baseqs.filter(birthdate__year__lte=2011).query))
  367. def test_postgres_year_exact(self):
  368. baseqs = Author.objects.order_by('name')
  369. self.assertIn(
  370. '= (2011 || ', str(baseqs.filter(birthdate__year=2011).query))
  371. self.assertIn(
  372. '-12-31', str(baseqs.filter(birthdate__year=2011).query))
  373. def test_custom_implementation_year_exact(self):
  374. try:
  375. # Two ways to add a customized implementation for different backends:
  376. # First is MonkeyPatch of the class.
  377. def as_custom_sql(self, compiler, connection):
  378. lhs_sql, lhs_params = self.process_lhs(compiler, connection, self.lhs.lhs)
  379. rhs_sql, rhs_params = self.process_rhs(compiler, connection)
  380. params = lhs_params + rhs_params + lhs_params + rhs_params
  381. return ("%(lhs)s >= str_to_date(concat(%(rhs)s, '-01-01'), '%%%%Y-%%%%m-%%%%d') "
  382. "AND %(lhs)s <= str_to_date(concat(%(rhs)s, '-12-31'), '%%%%Y-%%%%m-%%%%d')" %
  383. {'lhs': lhs_sql, 'rhs': rhs_sql}, params)
  384. setattr(YearExact, 'as_' + connection.vendor, as_custom_sql)
  385. self.assertIn(
  386. 'concat(',
  387. str(Author.objects.filter(birthdate__year=2012).query))
  388. finally:
  389. delattr(YearExact, 'as_' + connection.vendor)
  390. try:
  391. # The other way is to subclass the original lookup and register the subclassed
  392. # lookup instead of the original.
  393. class CustomYearExact(YearExact):
  394. # This method should be named "as_mysql" for MySQL, "as_postgresql" for postgres
  395. # and so on, but as we don't know which DB we are running on, we need to use
  396. # setattr.
  397. def as_custom_sql(self, compiler, connection):
  398. lhs_sql, lhs_params = self.process_lhs(compiler, connection, self.lhs.lhs)
  399. rhs_sql, rhs_params = self.process_rhs(compiler, connection)
  400. params = lhs_params + rhs_params + lhs_params + rhs_params
  401. return ("%(lhs)s >= str_to_date(CONCAT(%(rhs)s, '-01-01'), '%%%%Y-%%%%m-%%%%d') "
  402. "AND %(lhs)s <= str_to_date(CONCAT(%(rhs)s, '-12-31'), '%%%%Y-%%%%m-%%%%d')" %
  403. {'lhs': lhs_sql, 'rhs': rhs_sql}, params)
  404. setattr(CustomYearExact, 'as_' + connection.vendor, CustomYearExact.as_custom_sql)
  405. YearTransform.register_lookup(CustomYearExact)
  406. self.assertIn(
  407. 'CONCAT(',
  408. str(Author.objects.filter(birthdate__year=2012).query))
  409. finally:
  410. YearTransform._unregister_lookup(CustomYearExact)
  411. YearTransform.register_lookup(YearExact)
  412. class TrackCallsYearTransform(YearTransform):
  413. lookup_name = 'year'
  414. call_order = []
  415. def as_sql(self, compiler, connection):
  416. lhs_sql, params = compiler.compile(self.lhs)
  417. return connection.ops.date_extract_sql('year', lhs_sql), params
  418. @property
  419. def output_field(self):
  420. return models.IntegerField()
  421. def get_lookup(self, lookup_name):
  422. self.call_order.append('lookup')
  423. return super(TrackCallsYearTransform, self).get_lookup(lookup_name)
  424. def get_transform(self, lookup_name):
  425. self.call_order.append('transform')
  426. return super(TrackCallsYearTransform, self).get_transform(lookup_name)
  427. class LookupTransformCallOrderTests(TestCase):
  428. def test_call_order(self):
  429. models.DateField.register_lookup(TrackCallsYearTransform)
  430. try:
  431. # junk lookup - tries lookup, then transform, then fails
  432. with self.assertRaises(FieldError):
  433. Author.objects.filter(birthdate__year__junk=2012)
  434. self.assertEqual(TrackCallsYearTransform.call_order,
  435. ['lookup', 'transform'])
  436. TrackCallsYearTransform.call_order = []
  437. # junk transform - tries transform only, then fails
  438. with self.assertRaises(FieldError):
  439. Author.objects.filter(birthdate__year__junk__more_junk=2012)
  440. self.assertEqual(TrackCallsYearTransform.call_order,
  441. ['transform'])
  442. TrackCallsYearTransform.call_order = []
  443. # Just getting the year (implied __exact) - lookup only
  444. Author.objects.filter(birthdate__year=2012)
  445. self.assertEqual(TrackCallsYearTransform.call_order,
  446. ['lookup'])
  447. TrackCallsYearTransform.call_order = []
  448. # Just getting the year (explicit __exact) - lookup only
  449. Author.objects.filter(birthdate__year__exact=2012)
  450. self.assertEqual(TrackCallsYearTransform.call_order,
  451. ['lookup'])
  452. finally:
  453. models.DateField._unregister_lookup(TrackCallsYearTransform)
  454. class CustomisedMethodsTests(TestCase):
  455. def test_overridden_get_lookup(self):
  456. q = CustomModel.objects.filter(field__lookupfunc_monkeys=3)
  457. self.assertIn('monkeys()', str(q.query))
  458. def test_overridden_get_transform(self):
  459. q = CustomModel.objects.filter(field__transformfunc_banana=3)
  460. self.assertIn('banana()', str(q.query))
  461. def test_overridden_get_lookup_chain(self):
  462. q = CustomModel.objects.filter(field__transformfunc_banana__lookupfunc_elephants=3)
  463. self.assertIn('elephants()', str(q.query))
  464. def test_overridden_get_transform_chain(self):
  465. q = CustomModel.objects.filter(field__transformfunc_banana__transformfunc_pear=3)
  466. self.assertIn('pear()', str(q.query))