def test_all(self): query_set = self.Child.objects.all() actual = sql.serialize_query(query_set.query) self.assertEqual(actual, ( frozenset([u'children']), (), ))
def test_filter_in(self): query_set = self.Child.objects.filter(child_field__in=['this-one', 'that-one']) actual = sql.serialize_query(query_set.query) self.assertEqual(actual, ( frozenset(['children']), ( False, 'AND', frozenset([(u'children', u'child_field', u'in', True, frozenset(['this-one', 'that-one']))]), ), ))
def test_serialization(self): query_set = self.Child.objects.filter(parent_id=1L, child_field=u'thís-øne') actual = sql.serialize_query(query_set.query) self.assertEqual(actual, ( # Tables frozenset([u'children']), # Conditions ( False, u'AND', frozenset([(u'children', u'child_field', u'exact', True, u'thís-øne'), (u'children', u'parent_id', u'exact', True, 1L)]), ), ))
def test_serialization(self): expected = ( # Tables frozenset([u'children']), # Conditions ( False, u'AND', frozenset([(u'children', u'child_field', u'exact', True, u'this-one'), (u'children', u'parent_id', u'exact', True, 1L)]), ), ) for query_set in self.query_sets: actual = sql.serialize_query(query_set.query) self.assertEqual(actual, expected)
def test_filter_range(self): query_set = self.BetterChild.objects.filter(created__range=[ datetime.date(2010, 1, 10), datetime.datetime(2011, 5, 15, 8, 10, 10) ]) actual = sql.serialize_query(query_set.query) self.assertEqual(actual, ( frozenset(['children']), ( False, 'AND', frozenset([(u'children', u'created', u'range', datetime.datetime, ( '2010-01-10 00:00:00-06:00', # applies CST '2011-05-15 08:10:10-05:00' # applies CDT ))]), ), ))
def test_exclude(self): query_set = self.Child.objects.exclude(parent_id=1, child_field='this-one') actual = sql.serialize_query(query_set.query) self.assertEqual(actual, ( frozenset([u'children']), ( # Always starts with non-exclusionary base False, u'AND', frozenset([ # Condition is itself a "where" node (i.e. parenthetical) ( True, # NOT ... u'AND', frozenset([(u'children', u'child_field', u'exact', True, u'this-one'), (u'children', u'parent_id', u'exact', True, 1L)]), ), ]), ), ))
def test_exclude_multi(self): query_set = self.Child.objects.exclude(parent_id=1).exclude(child_field='this-one') actual = sql.serialize_query(query_set.query) self.assertEqual(actual, ( frozenset([u'children']), ( False, u'AND', frozenset([ ( True, # NOT ... u'AND', frozenset([(u'children', u'child_field', u'exact', True, u'this-one')]), ), ( True, # NOT ... u'AND', frozenset([(u'children', u'parent_id', u'exact', True, 1L)]), ), ]), ), ))
def test_or(self): query_set = self.Child.objects.filter( models.Q(parent_id=1) | models.Q(child_field='this-one') ) actual = sql.serialize_query(query_set.query) self.assertEqual(actual, ( # Tables frozenset([u'children']), # Conditions ( # Always starts with non-exclusionary base False, u'AND', frozenset([ # Condition is itself a "where" node (i.e. parenthetical) ( False, u'OR', frozenset([(u'children', u'child_field', u'exact', True, u'this-one'), (u'children', u'parent_id', u'exact', True, 1L)]), ), ]), ), ))