Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Forgot to add custom_lookups tests in prev commit

  • Loading branch information...
commit 11501c29c9352d17f22f3a0f59d3b805913dedcc 1 parent 83173b9
Anssi Kääriäinen authored January 12, 2014

Showing 1 changed file with 13 additions and 13 deletions. Show diff stats Hide diff stats

  1. 26  tests/custom_lookups/tests.py
26  tests/custom_lookups/tests.py
@@ -7,7 +7,7 @@
7 7
 from django.db import connection
8 8
 
9 9
 
10  
-class Div3Lookup(models.lookups.Lookup):
  10
+class Div3Lookup(models.Lookup):
11 11
     lookup_name = 'div3'
12 12
 
13 13
     def as_sql(self, qn, connection):
@@ -17,7 +17,7 @@ def as_sql(self, qn, connection):
17 17
         return '%s %%%% 3 = %s' % (lhs, rhs), params
18 18
 
19 19
 
20  
-class Div3Extract(models.lookups.Extract):
  20
+class Div3Transform(models.Transform):
21 21
     lookup_name = 'div3'
22 22
 
23 23
     def as_sql(self, qn, connection):
@@ -25,7 +25,7 @@ def as_sql(self, qn, connection):
25 25
         return '%s %%%% 3' % (lhs,), lhs_params
26 26
 
27 27
 
28  
-class YearExtract(models.lookups.Extract):
  28
+class YearTransform(models.Transform):
29 29
     lookup_name = 'year'
30 30
 
31 31
     def as_sql(self, qn, connection):
@@ -53,7 +53,7 @@ def as_sql(self, qn, connection):
53 53
         return ("%(lhs)s >= (%(rhs)s || '-01-01')::date "
54 54
                 "AND %(lhs)s <= (%(rhs)s || '-12-31')::date" %
55 55
                 {'lhs': lhs_sql, 'rhs': rhs_sql}, params)
56  
-YearExtract.register_lookup(YearExact)
  56
+YearTransform.register_lookup(YearExact)
57 57
 
58 58
 
59 59
 class YearLte(models.lookups.LessThanOrEqual):
@@ -62,7 +62,7 @@ class YearLte(models.lookups.LessThanOrEqual):
62 62
     """
63 63
 
64 64
     def as_sql(self, qn, connection):
65  
-        # Skip the YearExtract above us (no possibility for efficient
  65
+        # Skip the YearTransform above us (no possibility for efficient
66 66
         # lookup otherwise).
67 67
         real_lhs = self.lhs.lhs
68 68
         lhs_sql, params = self.process_lhs(qn, connection, real_lhs)
@@ -73,7 +73,7 @@ def as_sql(self, qn, connection):
73 73
         #     WHERE somecol <= '2013-12-31')
74 74
         # but also make it work if the rhs_sql is field reference.
75 75
         return "%s <= (%s || '-12-31')::date" % (lhs_sql, rhs_sql), params
76  
-YearExtract.register_lookup(YearLte)
  76
+YearTransform.register_lookup(YearLte)
77 77
 
78 78
 
79 79
 # We will register this class temporarily in the test method.
@@ -155,7 +155,7 @@ def test_birthdate_month(self):
155 155
             models.DateField._unregister_lookup(InMonth)
156 156
 
157 157
     def test_div3_extract(self):
158  
-        models.IntegerField.register_lookup(Div3Extract)
  158
+        models.IntegerField.register_lookup(Div3Transform)
159 159
         try:
160 160
             a1 = Author.objects.create(name='a1', age=1)
161 161
             a2 = Author.objects.create(name='a2', age=2)
@@ -172,19 +172,19 @@ def test_div3_extract(self):
172 172
                 baseqs.filter(age__div3__in=[0, 2]),
173 173
                 [a2, a3], lambda x: x)
174 174
         finally:
175  
-            models.IntegerField._unregister_lookup(Div3Extract)
  175
+            models.IntegerField._unregister_lookup(Div3Transform)
176 176
 
177 177
 
178 178
 class YearLteTests(TestCase):
179 179
     def setUp(self):
180  
-        models.DateField.register_lookup(YearExtract)
  180
+        models.DateField.register_lookup(YearTransform)
181 181
         self.a1 = Author.objects.create(name='a1', birthdate=date(1981, 2, 16))
182 182
         self.a2 = Author.objects.create(name='a2', birthdate=date(2012, 2, 29))
183 183
         self.a3 = Author.objects.create(name='a3', birthdate=date(2012, 1, 31))
184 184
         self.a4 = Author.objects.create(name='a4', birthdate=date(2012, 3, 1))
185 185
 
186 186
     def tearDown(self):
187  
-        models.DateField._unregister_lookup(YearExtract)
  187
+        models.DateField._unregister_lookup(YearTransform)
188 188
 
189 189
     @unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific SQL used")
190 190
     def test_year_lte(self):
@@ -270,10 +270,10 @@ def as_custom_sql(self, qn, connection):
270 270
                             "AND %(lhs)s <= str_to_date(CONCAT(%(rhs)s, '-12-31'), '%%%%Y-%%%%m-%%%%d')" %
271 271
                             {'lhs': lhs_sql, 'rhs': rhs_sql}, params)
272 272
             setattr(CustomYearExact, 'as_' + connection.vendor, CustomYearExact.as_custom_sql)
273  
-            YearExtract.register_lookup(CustomYearExact)
  273
+            YearTransform.register_lookup(CustomYearExact)
274 274
             self.assertIn(
275 275
                 'CONCAT(',
276 276
                 str(Author.objects.filter(birthdate__year=2012).query))
277 277
         finally:
278  
-            YearExtract._unregister_lookup(CustomYearExact)
279  
-            YearExtract.register_lookup(YearExact)
  278
+            YearTransform._unregister_lookup(CustomYearExact)
  279
+            YearTransform.register_lookup(YearExact)

0 notes on commit 11501c2

Please sign in to comment.
Something went wrong with that request. Please try again.