<s> from __future__ import absolute_import , unicode_literals <EOL> import datetime <EOL> from operator import attrgetter <EOL> import pickle <EOL> import sys <EOL> from django . conf import settings <EOL> from django . core . exceptions import FieldError <EOL> from django . db import DatabaseError , connection , connections , DEFAULT_DB_ALIAS <EOL> from django . db . models import Count <EOL> from django . db . models . query import Q , ITER_CHUNK_SIZE , EmptyQuerySet <EOL> from django . db . models . sql . where import WhereNode , EverythingNode , NothingNode <EOL> from django . db . models . sql . datastructures import EmptyResultSet <EOL> from django . test import TestCase , skipUnlessDBFeature <EOL> from django . test . utils import str_prefix <EOL> from django . utils import unittest <EOL> from django . utils . datastructures import SortedDict <EOL> from . models import ( Annotation , Article , Author , Celebrity , Child , Cover , <EOL> Detail , DumbCategory , ExtraInfo , Fan , Item , LeafA , LoopX , LoopZ , <EOL> ManagedModel , Member , NamedCategory , Note , Number , Plaything , PointerA , <EOL> Ranking , Related , Report , ReservedName , Tag , TvChef , Valid , X , Food , Eaten , <EOL> Node , ObjectA , ObjectB , ObjectC , CategoryItem , SimpleCategory , <EOL> SpecialCategory , OneToOneCategory , NullableName , ProxyCategory , <EOL> SingleObject , RelatedObject , ModelA , ModelD ) <EOL> class BaseQuerysetTest ( TestCase ) : <EOL> def assertValueQuerysetEqual ( self , qs , values ) : <EOL> return self . assertQuerysetEqual ( qs , values , transform = lambda x : x ) <EOL> class Queries1Tests ( BaseQuerysetTest ) : <EOL> def setUp ( self ) : <EOL> generic = NamedCategory . objects . create ( name = "<STR_LIT>" ) <EOL> self . t1 = Tag . objects . create ( name = '<STR_LIT>' , category = generic ) <EOL> self . t2 = Tag . objects . create ( name = '<STR_LIT>' , parent = self . t1 , category = generic ) <EOL> self . t3 = Tag . objects . create ( name = '<STR_LIT>' , parent = self . t1 ) <EOL> t4 = Tag . objects . create ( name = '<STR_LIT>' , parent = self . t3 ) <EOL> self . t5 = Tag . objects . create ( name = '<STR_LIT>' , parent = self . t3 ) <EOL> self . n1 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:1> ) <EOL> n2 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:bar>' , id = <NUM_LIT:2> ) <EOL> self . n3 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:3> ) <EOL> ann1 = Annotation . objects . create ( name = '<STR_LIT>' , tag = self . t1 ) <EOL> ann1 . notes . add ( self . n1 ) <EOL> ann2 = Annotation . objects . create ( name = '<STR_LIT>' , tag = t4 ) <EOL> ann2 . notes . add ( n2 , self . n3 ) <EOL> self . e2 = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = n2 , value = <NUM_LIT> ) <EOL> e1 = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = self . n1 , value = <NUM_LIT> ) <EOL> self . a1 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e1 ) <EOL> self . a2 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e1 ) <EOL> a3 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = self . e2 ) <EOL> self . a4 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = self . e2 ) <EOL> self . time1 = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) <EOL> self . time2 = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> time3 = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) <EOL> time4 = datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . i1 = Item . objects . create ( name = '<STR_LIT>' , created = self . time1 , modified = self . time1 , creator = self . a1 , note = self . n3 ) <EOL> self . i1 . tags = [ self . t1 , self . t2 ] <EOL> self . i2 = Item . objects . create ( name = '<STR_LIT>' , created = self . time2 , creator = self . a2 , note = n2 ) <EOL> self . i2 . tags = [ self . t1 , self . t3 ] <EOL> self . i3 = Item . objects . create ( name = '<STR_LIT>' , created = time3 , creator = self . a2 , note = self . n3 ) <EOL> i4 = Item . objects . create ( name = '<STR_LIT>' , created = time4 , creator = self . a4 , note = self . n3 ) <EOL> i4 . tags = [ t4 ] <EOL> self . r1 = Report . objects . create ( name = '<STR_LIT>' , creator = self . a1 ) <EOL> Report . objects . create ( name = '<STR_LIT>' , creator = a3 ) <EOL> Report . objects . create ( name = '<STR_LIT>' ) <EOL> self . rank1 = Ranking . objects . create ( rank = <NUM_LIT:2> , author = self . a2 ) <EOL> Cover . objects . create ( title = "<STR_LIT>" , item = i4 ) <EOL> Cover . objects . create ( title = "<STR_LIT>" , item = self . i2 ) <EOL> def test_ticket1050 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__isnull = True ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__id__isnull = True ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket1801 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( item = self . i2 ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( item = self . i3 ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( item = self . i2 ) & Author . objects . filter ( item = self . i3 ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket2306 ( self ) : <EOL> query = Item . objects . filter ( tags = self . t2 ) . query <EOL> self . assertTrue ( query . LOUTER not in [ x [ <NUM_LIT:2> ] for x in query . alias_map . values ( ) ] ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags = self . t1 ) ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags = self . t1 ) ) . filter ( Q ( tags = self . t2 ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags = self . t1 ) ) . filter ( Q ( creator__name = '<STR_LIT>' ) | Q ( tags = self . t2 ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags = self . t1 ) & Q ( tags = self . t2 ) ) , <EOL> [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags = self . t1 ) , Q ( creator__name = '<STR_LIT>' ) | Q ( tags = self . t2 ) ) , <EOL> [ ] <EOL> ) <EOL> qs = Author . objects . filter ( ranking__rank = <NUM_LIT:2> , ranking__id = self . rank1 . id ) <EOL> self . assertQuerysetEqual ( list ( qs ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:2> , qs . query . count_active_tables ( ) , <NUM_LIT:2> ) <EOL> qs = Author . objects . filter ( ranking__rank = <NUM_LIT:2> ) . filter ( ranking__id = self . rank1 . id ) <EOL> self . assertEqual ( qs . query . count_active_tables ( ) , <NUM_LIT:3> ) <EOL> def test_ticket4464 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags = self . t1 ) . filter ( tags = self . t2 ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__in = [ self . t1 , self . t2 ] ) . distinct ( ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__in = [ self . t1 , self . t2 ] ) . filter ( tags = self . t3 ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__in = [ self . t1 , self . t2 ] ) . order_by ( '<STR_LIT:name>' ) [ : <NUM_LIT:3> ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__in = [ self . t1 , self . t2 ] ) . distinct ( ) . order_by ( '<STR_LIT:name>' ) [ : <NUM_LIT:3> ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_tickets_2080_3592 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( item__name = '<STR_LIT>' ) | Author . objects . filter ( name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( item__name = '<STR_LIT>' ) | Q ( name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( name = '<STR_LIT>' ) | Q ( item__name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( item__name = '<STR_LIT>' ) | Q ( report__name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket6074 ( self ) : <EOL> self . assertQuerysetEqual ( Author . objects . filter ( Q ( id__in = [ ] ) ) , [ ] ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( id__in = [ ] ) | Q ( id__in = [ ] ) ) , <EOL> [ ] <EOL> ) <EOL> def test_tickets_1878_2939 ( self ) : <EOL> self . assertEqual ( Item . objects . values ( '<STR_LIT>' ) . distinct ( ) . count ( ) , <NUM_LIT:3> ) <EOL> xx = Item ( name = '<STR_LIT>' , created = self . time1 , creator = self . a2 , note = self . n1 ) <EOL> xx . save ( ) <EOL> self . assertEqual ( <EOL> Item . objects . exclude ( name = '<STR_LIT>' ) . values ( '<STR_LIT>' , '<STR_LIT:name>' ) . distinct ( ) . count ( ) , <EOL> <NUM_LIT:4> <EOL> ) <EOL> self . assertEqual ( <EOL> Item . objects . exclude ( name = '<STR_LIT>' ) . extra ( select = { '<STR_LIT:foo>' : '<STR_LIT:%s>' } , select_params = ( <NUM_LIT:1> , ) ) . values ( '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT:foo>' ) . distinct ( ) . count ( ) , <EOL> <NUM_LIT:4> <EOL> ) <EOL> self . assertEqual ( <EOL> Item . objects . exclude ( name = '<STR_LIT>' ) . extra ( select = { '<STR_LIT:foo>' : '<STR_LIT:%s>' } , select_params = ( <NUM_LIT:1> , ) ) . values ( '<STR_LIT>' , '<STR_LIT:name>' ) . distinct ( ) . count ( ) , <EOL> <NUM_LIT:4> <EOL> ) <EOL> xx . delete ( ) <EOL> def test_ticket7323 ( self ) : <EOL> self . assertEqual ( Item . objects . values ( '<STR_LIT>' , '<STR_LIT:name>' ) . count ( ) , <NUM_LIT:4> ) <EOL> def test_ticket2253 ( self ) : <EOL> q1 = Item . objects . order_by ( '<STR_LIT:name>' ) <EOL> q2 = Item . objects . filter ( id = self . i1 . id ) <EOL> self . assertQuerysetEqual ( <EOL> q1 , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( q2 , [ '<STR_LIT>' ] ) <EOL> self . assertQuerysetEqual ( <EOL> ( q1 | q2 ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( ( q1 & q2 ) . order_by ( '<STR_LIT:name>' ) , [ '<STR_LIT>' ] ) <EOL> q1 = Item . objects . filter ( tags = self . t1 ) <EOL> q2 = Item . objects . filter ( note = self . n3 , tags = self . t2 ) <EOL> q3 = Item . objects . filter ( creator = self . a4 ) <EOL> self . assertQuerysetEqual ( <EOL> ( ( q1 & q2 ) | q3 ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_order_by_tables ( self ) : <EOL> q1 = Item . objects . order_by ( '<STR_LIT:name>' ) <EOL> q2 = Item . objects . filter ( id = self . i1 . id ) <EOL> list ( q2 ) <EOL> self . assertEqual ( len ( ( q1 & q2 ) . order_by ( '<STR_LIT:name>' ) . query . tables ) , <NUM_LIT:1> ) <EOL> def test_order_by_join_unref ( self ) : <EOL> """<STR_LIT>""" <EOL> qs = Celebrity . objects . order_by ( '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , str ( qs . query ) ) <EOL> qs = qs . order_by ( '<STR_LIT:id>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , str ( qs . query ) ) <EOL> def test_tickets_4088_4306 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Report . objects . filter ( creator = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Report . objects . filter ( creator__num = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( Report . objects . filter ( creator__id = <NUM_LIT> ) , [ ] ) <EOL> self . assertQuerysetEqual ( <EOL> Report . objects . filter ( creator__id = self . a1 . id ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Report . objects . filter ( creator__name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket4510 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( report__name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket7378 ( self ) : <EOL> self . assertQuerysetEqual ( self . a1 . report_set . all ( ) , [ '<STR_LIT>' ] ) <EOL> def test_tickets_5324_6704 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( tags__name = '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) . distinct ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( tags__name = '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) . distinct ( ) . reverse ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . exclude ( item__name = '<STR_LIT>' ) . distinct ( ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( tags__name = '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( tags__name = '<STR_LIT>' ) . exclude ( tags__name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> query = Item . objects . exclude ( creator__in = [ self . a1 , self . a2 ] ) . query <EOL> self . assertTrue ( query . LOUTER not in [ x [ <NUM_LIT:2> ] for x in query . alias_map . values ( ) ] ) <EOL> qs = Author . objects . filter ( id = self . a1 . id ) . filter ( Q ( extra__note = self . n1 ) | Q ( item__note = self . n3 ) ) <EOL> self . assertEqual ( <EOL> len ( [ x [ <NUM_LIT:2> ] for x in qs . query . alias_map . values ( ) if x [ <NUM_LIT:2> ] == query . LOUTER and qs . query . alias_refcount [ x [ <NUM_LIT:1> ] ] ] ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . filter ( parent__isnull = True ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( parent__isnull = True ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( Q ( parent__name = '<STR_LIT>' ) | Q ( parent__isnull = True ) ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( Q ( parent__isnull = True ) | Q ( parent__name = '<STR_LIT>' ) ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( Q ( parent__parent__isnull = True ) ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . filter ( ~ Q ( parent__parent__isnull = True ) ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket2091 ( self ) : <EOL> t = Tag . objects . get ( name = '<STR_LIT>' ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__in = [ t ] ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_heterogeneous_qs_combination ( self ) : <EOL> self . assertRaisesMessage ( <EOL> AssertionError , <EOL> '<STR_LIT>' , <EOL> lambda : Author . objects . all ( ) & Tag . objects . all ( ) <EOL> ) <EOL> self . assertRaisesMessage ( <EOL> AssertionError , <EOL> '<STR_LIT>' , <EOL> lambda : Author . objects . all ( ) | Tag . objects . all ( ) <EOL> ) <EOL> def test_ticket3141 ( self ) : <EOL> self . assertEqual ( Author . objects . extra ( select = { '<STR_LIT:foo>' : '<STR_LIT:1>' } ) . count ( ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( <EOL> Author . objects . extra ( select = { '<STR_LIT:foo>' : '<STR_LIT:%s>' } , select_params = ( <NUM_LIT:1> , ) ) . count ( ) , <EOL> <NUM_LIT:4> <EOL> ) <EOL> def test_ticket2400 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( item__isnull = True ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . filter ( item__isnull = True ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket2496 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . extra ( tables = [ '<STR_LIT>' ] ) . select_related ( ) . order_by ( '<STR_LIT:name>' ) [ : <NUM_LIT:1> ] , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_tickets_2076_7256 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . order_by ( '<STR_LIT>' , '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Cover . objects . all ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . order_by ( '<STR_LIT>' , '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( tags__isnull = False ) . order_by ( '<STR_LIT>' , '<STR_LIT:id>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> qs = Item . objects . order_by ( '<STR_LIT:name>' ) <EOL> self . assertQuerysetEqual ( <EOL> qs , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertEqual ( len ( qs . query . tables ) , <NUM_LIT:1> ) <EOL> def test_tickets_2874_3002 ( self ) : <EOL> qs = Item . objects . select_related ( ) . order_by ( '<STR_LIT>' , '<STR_LIT:name>' ) <EOL> self . assertQuerysetEqual ( <EOL> qs , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertTrue ( repr ( qs [ <NUM_LIT:0> ] . note ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( qs [ <NUM_LIT:0> ] . creator . extra . note ) , '<STR_LIT>' ) <EOL> def test_ticket3037 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( creator__name = '<STR_LIT>' , name = '<STR_LIT>' ) | Q ( creator__name = '<STR_LIT>' , name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_tickets_5321_7070 ( self ) : <EOL> self . assertValueQuerysetEqual ( <EOL> Note . objects . values ( '<STR_LIT>' ) . distinct ( ) . order_by ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ { '<STR_LIT>' : '<STR_LIT:foo>' } , { '<STR_LIT>' : '<STR_LIT:bar>' } , { '<STR_LIT>' : '<STR_LIT:foo>' } ] <EOL> ) <EOL> def test_ticket4358 ( self ) : <EOL> self . assertTrue ( '<STR_LIT>' in ExtraInfo . objects . values ( ) [ <NUM_LIT:0> ] ) <EOL> self . assertValueQuerysetEqual ( <EOL> ExtraInfo . objects . values ( '<STR_LIT>' ) , <EOL> [ { '<STR_LIT>' : <NUM_LIT:1> } , { '<STR_LIT>' : <NUM_LIT:2> } ] <EOL> ) <EOL> self . assertValueQuerysetEqual ( <EOL> ExtraInfo . objects . values ( '<STR_LIT>' ) , <EOL> [ { '<STR_LIT>' : <NUM_LIT:1> } , { '<STR_LIT>' : <NUM_LIT:2> } ] <EOL> ) <EOL> def test_ticket2902 ( self ) : <EOL> s = [ ( '<STR_LIT:a>' , '<STR_LIT:%s>' ) , ( '<STR_LIT:b>' , '<STR_LIT:%s>' ) ] <EOL> params = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:2> } . keys ( ) == [ '<STR_LIT:a>' , '<STR_LIT:b>' ] : <EOL> s . reverse ( ) <EOL> params . reverse ( ) <EOL> d = Item . objects . extra ( select = SortedDict ( s ) , select_params = params ) . values ( '<STR_LIT:a>' , '<STR_LIT:b>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( d , { '<STR_LIT:a>' : '<STR_LIT>' , '<STR_LIT:b>' : '<STR_LIT>' } ) <EOL> l = Item . objects . extra ( select = { '<STR_LIT:count>' : '<STR_LIT>' } ) . order_by ( '<STR_LIT>' ) <EOL> self . assertEqual ( [ o . count for o in l ] , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> def test_ticket6154 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( id = self . a1 . id ) . filter ( Q ( extra__note = self . n1 ) | Q ( item__note = self . n3 ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( extra__note = self . n1 ) | Q ( item__note = self . n3 ) ) . filter ( id = self . a1 . id ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket6981 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . select_related ( '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket9926 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . select_related ( "<STR_LIT>" , "<STR_LIT>" ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . select_related ( '<STR_LIT>' , "<STR_LIT>" ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_tickets_6180_6203 ( self ) : <EOL> self . assertEqual ( Item . objects . count ( ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( len ( Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) [ <NUM_LIT:0> ] , datetime . datetime ( <NUM_LIT> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> def test_tickets_7087_12242 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) . extra ( select = { '<STR_LIT:a>' : <NUM_LIT:1> } ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . extra ( select = { '<STR_LIT:a>' : <NUM_LIT:1> } ) . dates ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> name = "<STR_LIT>" <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) . extra ( where = [ '<STR_LIT>' ] , params = [ name ] ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . extra ( where = [ '<STR_LIT>' ] , params = [ name ] ) . dates ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket7155 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket7098 ( self ) : <EOL> self . assertValueQuerysetEqual ( <EOL> Item . objects . values ( '<STR_LIT>' ) . order_by ( '<STR_LIT>' , '<STR_LIT:id>' ) , <EOL> [ { '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : '<STR_LIT>' } , { '<STR_LIT>' : '<STR_LIT>' } ] <EOL> ) <EOL> def test_ticket7096 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . filter ( parent = self . t1 , name = '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( parent = self . t1 , name = '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( tags__name = '<STR_LIT>' , name = '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) . distinct ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( name__in = [ '<STR_LIT>' , '<STR_LIT>' ] ) . exclude ( tags__name = '<STR_LIT>' ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( ~ Q ( tags__name = '<STR_LIT>' , name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( ~ Q ( tags__name = '<STR_LIT>' , name = '<STR_LIT>' ) , name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( ~ Q ( tags__name = '<STR_LIT>' , name = '<STR_LIT>' ) , name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_tickets_7204_7506 ( self ) : <EOL> pickle . dumps ( Item . objects . all ( ) ) <EOL> def test_ticket7813 ( self ) : <EOL> qs = Item . objects . select_related ( ) <EOL> query = qs . query . get_compiler ( qs . db ) . as_sql ( ) [ <NUM_LIT:0> ] <EOL> query2 = pickle . loads ( pickle . dumps ( qs . query ) ) <EOL> self . assertEqual ( <EOL> query2 . get_compiler ( qs . db ) . as_sql ( ) [ <NUM_LIT:0> ] , <EOL> query <EOL> ) <EOL> def test_deferred_load_qs_pickling ( self ) : <EOL> qs = Item . objects . defer ( '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> q2 = pickle . loads ( pickle . dumps ( qs ) ) <EOL> self . assertEqual ( list ( qs ) , list ( q2 ) ) <EOL> q3 = pickle . loads ( pickle . dumps ( qs , pickle . HIGHEST_PROTOCOL ) ) <EOL> self . assertEqual ( list ( qs ) , list ( q3 ) ) <EOL> def test_ticket7277 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> self . n1 . annotation_set . filter ( Q ( tag = self . t5 ) | Q ( tag__children = self . t5 ) | Q ( tag__children__children = self . t5 ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_tickets_7448_7707 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( created__in = [ self . time1 , self . time2 ] ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket7235 ( self ) : <EOL> q = EmptyQuerySet ( ) <EOL> self . assertQuerysetEqual ( q . all ( ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . filter ( x = <NUM_LIT:10> ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . exclude ( y = <NUM_LIT:3> ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . complex_filter ( { '<STR_LIT>' : <NUM_LIT:1> } ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . select_related ( '<STR_LIT>' , '<STR_LIT>' ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . annotate ( Count ( '<STR_LIT>' ) ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . order_by ( '<STR_LIT>' , '<STR_LIT>' ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . distinct ( ) , [ ] ) <EOL> self . assertQuerysetEqual ( <EOL> q . extra ( select = { '<STR_LIT>' : "<STR_LIT>" } ) , <EOL> [ ] <EOL> ) <EOL> q . query . low_mark = <NUM_LIT:1> <EOL> self . assertRaisesMessage ( <EOL> AssertionError , <EOL> '<STR_LIT>' , <EOL> q . extra , select = { '<STR_LIT>' : "<STR_LIT>" } <EOL> ) <EOL> self . assertQuerysetEqual ( q . reverse ( ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . defer ( '<STR_LIT>' , '<STR_LIT>' ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . only ( '<STR_LIT>' , '<STR_LIT>' ) , [ ] ) <EOL> def test_ticket7791 ( self ) : <EOL> self . assertEqual ( <EOL> len ( Note . objects . order_by ( '<STR_LIT>' ) . distinct ( ) ) , <EOL> <NUM_LIT:3> <EOL> ) <EOL> qs = Item . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> _ = pickle . loads ( pickle . dumps ( qs ) ) <EOL> def test_ticket9997 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . filter ( name__in = Tag . objects . filter ( parent = self . t1 ) . values ( '<STR_LIT:name>' ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertRaisesMessage ( <EOL> TypeError , <EOL> '<STR_LIT>' , <EOL> lambda : Tag . objects . filter ( name__in = Tag . objects . filter ( parent = self . t1 ) . values ( '<STR_LIT:name>' , '<STR_LIT:id>' ) ) <EOL> ) <EOL> self . assertRaisesMessage ( <EOL> TypeError , <EOL> '<STR_LIT>' , <EOL> lambda : Tag . objects . filter ( name__in = Tag . objects . filter ( parent = self . t1 ) . values_list ( '<STR_LIT:name>' , '<STR_LIT:id>' ) ) <EOL> ) <EOL> def test_ticket9985 ( self ) : <EOL> self . assertValueQuerysetEqual ( <EOL> Note . objects . values_list ( "<STR_LIT>" , flat = True ) . values ( "<STR_LIT:id>" ) . order_by ( "<STR_LIT:id>" ) , <EOL> [ { '<STR_LIT:id>' : <NUM_LIT:1> } , { '<STR_LIT:id>' : <NUM_LIT:2> } , { '<STR_LIT:id>' : <NUM_LIT:3> } ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Annotation . objects . filter ( notes__in = Note . objects . filter ( note = "<STR_LIT>" ) . values_list ( '<STR_LIT>' ) . values ( '<STR_LIT:id>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket10205 ( self ) : <EOL> self . assertEqual ( Tag . objects . filter ( name__in = ( ) ) . update ( name = "<STR_LIT:foo>" ) , <NUM_LIT:0> ) <EOL> def test_ticket10432 ( self ) : <EOL> def f ( ) : <EOL> return iter ( [ ] ) <EOL> n_obj = Note . objects . all ( ) [ <NUM_LIT:0> ] <EOL> def g ( ) : <EOL> for i in [ n_obj . pk ] : <EOL> yield i <EOL> self . assertQuerysetEqual ( Note . objects . filter ( pk__in = f ( ) ) , [ ] ) <EOL> self . assertEqual ( list ( Note . objects . filter ( pk__in = g ( ) ) ) , [ n_obj ] ) <EOL> def test_ticket10742 ( self ) : <EOL> subq = Author . objects . filter ( num__lt = <NUM_LIT> ) <EOL> qs = Author . objects . filter ( pk__in = subq ) <EOL> self . assertQuerysetEqual ( qs , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( subq . _result_cache is None ) <EOL> subq = Author . objects . filter ( num__lt = <NUM_LIT> ) <EOL> qs = Author . objects . exclude ( pk__in = subq ) <EOL> self . assertQuerysetEqual ( qs , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( subq . _result_cache is None ) <EOL> subq = Author . objects . filter ( num__lt = <NUM_LIT> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( pk__in = subq ) & Q ( name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertTrue ( subq . _result_cache is None ) <EOL> def test_ticket7076 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( modified = self . time1 ) . order_by ( '<STR_LIT:name>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( parent__name = self . t1 . name ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket7181 ( self ) : <EOL> self . assertEqual ( len ( Tag . objects . order_by ( '<STR_LIT>' ) ) , <NUM_LIT:5> ) <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . none ( ) | Note . objects . all ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . all ( ) | Note . objects . none ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( Note . objects . none ( ) & Note . objects . all ( ) , [ ] ) <EOL> self . assertQuerysetEqual ( Note . objects . all ( ) & Note . objects . none ( ) , [ ] ) <EOL> def test_ticket9411 ( self ) : <EOL> qs = Tag . objects . values_list ( '<STR_LIT:id>' , flat = True ) . order_by ( '<STR_LIT:id>' ) <EOL> qs . query . bump_prefix ( ) <EOL> first = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( list ( qs ) , list ( range ( first , first + <NUM_LIT:5> ) ) ) <EOL> def test_ticket8439 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( item__note__extrainfo = self . e2 ) | Q ( report = self . r1 , name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Author . objects . filter ( Q ( report = self . r1 , name = '<STR_LIT>' ) | Q ( item__note__extrainfo = self . e2 ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Annotation . objects . filter ( Q ( tag__parent = self . t1 ) | Q ( notes__note = '<STR_LIT>' , name = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> xx = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = self . n3 ) <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . filter ( Q ( extrainfo__author = self . a1 ) | Q ( extrainfo = xx ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> xx . delete ( ) <EOL> q = Note . objects . filter ( Q ( extrainfo__author = self . a1 ) | Q ( extrainfo = xx ) ) . query <EOL> self . assertEqual ( <EOL> len ( [ x [ <NUM_LIT:2> ] for x in q . alias_map . values ( ) if x [ <NUM_LIT:2> ] == q . LOUTER and q . alias_refcount [ x [ <NUM_LIT:1> ] ] ] ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> def test_ticket17429 ( self ) : <EOL> """<STR_LIT>""" <EOL> original_ordering = Tag . _meta . ordering <EOL> Tag . _meta . ordering = None <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . all ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ) <EOL> Tag . _meta . ordering = original_ordering <EOL> def test_exclude ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( tags__name = '<STR_LIT>' ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ Q ( tags__name = '<STR_LIT>' ) ) ] ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( Q ( tags__name = '<STR_LIT>' ) | Q ( tags__name = '<STR_LIT>' ) ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ ( Q ( tags__name = '<STR_LIT>' ) | Q ( tags__name = '<STR_LIT>' ) ) ) ] ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( Q ( tags__name = '<STR_LIT>' ) | ~ Q ( tags__name = '<STR_LIT>' ) ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ ( Q ( tags__name = '<STR_LIT>' ) | ~ Q ( tags__name = '<STR_LIT>' ) ) ) ] ) <EOL> def test_nested_exclude ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( ~ Q ( tags__name = '<STR_LIT>' ) ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ ~ Q ( tags__name = '<STR_LIT>' ) ) ] ) <EOL> def test_double_exclude ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags__name = '<STR_LIT>' ) ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ ~ Q ( tags__name = '<STR_LIT>' ) ) ] ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags__name = '<STR_LIT>' ) ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ Q ( ~ Q ( tags__name = '<STR_LIT>' ) ) ) ] ) <EOL> @ unittest . expectedFailure <EOL> def test_exclude_in ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . exclude ( Q ( tags__name__in = [ '<STR_LIT>' , '<STR_LIT>' ] ) ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ Q ( tags__name__in = [ '<STR_LIT>' , '<STR_LIT>' ] ) ) ] ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( Q ( tags__name__in = [ '<STR_LIT>' , '<STR_LIT>' ] ) ) , <EOL> [ repr ( i ) for i in Item . objects . filter ( ~ ~ Q ( tags__name__in = [ '<STR_LIT>' , '<STR_LIT>' ] ) ) ] ) <EOL> def test_ticket19672 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Report . objects . filter ( Q ( creator__isnull = False ) & <EOL> ~ Q ( creator__extra__value = <NUM_LIT> ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> class Queries2Tests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> Number . objects . create ( num = <NUM_LIT:4> ) <EOL> Number . objects . create ( num = <NUM_LIT:8> ) <EOL> Number . objects . create ( num = <NUM_LIT:12> ) <EOL> def test_ticket4289 ( self ) : <EOL> self . assertQuerysetEqual ( Number . objects . filter ( num__lt = <NUM_LIT:4> ) , [ ] ) <EOL> self . assertQuerysetEqual ( Number . objects . filter ( num__gt = <NUM_LIT:8> , num__lt = <NUM_LIT:12> ) , [ ] ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__gt = <NUM_LIT:8> , num__lt = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( Q ( num__lt = <NUM_LIT:4> ) | Q ( num__gt = <NUM_LIT:8> , num__lt = <NUM_LIT:12> ) ) , <EOL> [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( Q ( num__gt = <NUM_LIT:8> , num__lt = <NUM_LIT:12> ) | Q ( num__lt = <NUM_LIT:4> ) ) , <EOL> [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( Q ( num__gt = <NUM_LIT:8> ) & Q ( num__lt = <NUM_LIT:12> ) | Q ( num__lt = <NUM_LIT:4> ) ) , <EOL> [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( Q ( num__gt = <NUM_LIT:7> ) & Q ( num__lt = <NUM_LIT:12> ) | Q ( num__lt = <NUM_LIT:4> ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket12239 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__gt = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( Number . objects . filter ( num__gt = <NUM_LIT:12> ) , [ ] ) <EOL> self . assertQuerysetEqual ( Number . objects . filter ( num__gt = <NUM_LIT> ) , [ ] ) <EOL> self . assertQuerysetEqual ( Number . objects . filter ( num__gt = <NUM_LIT> ) , [ ] ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lt = <NUM_LIT:12> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lt = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lt = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__gte = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__gte = <NUM_LIT:12> ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__gte = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( Number . objects . filter ( num__gte = <NUM_LIT> ) , [ ] ) <EOL> self . assertQuerysetEqual ( Number . objects . filter ( num__gte = <NUM_LIT> ) , [ ] ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lte = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lte = <NUM_LIT:12> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lte = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lte = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( num__lte = <NUM_LIT> ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket7411 ( self ) : <EOL> for num in range ( <NUM_LIT:2> * ITER_CHUNK_SIZE + <NUM_LIT:1> ) : <EOL> _ = Number . objects . create ( num = num ) <EOL> for i , obj in enumerate ( Number . objects . all ( ) ) : <EOL> obj . save ( ) <EOL> if i > <NUM_LIT:10> : break <EOL> def test_ticket7759 ( self ) : <EOL> count = Number . objects . count ( ) <EOL> qs = Number . objects . all ( ) <EOL> def run ( ) : <EOL> for obj in qs : <EOL> return qs . count ( ) == count <EOL> self . assertTrue ( run ( ) ) <EOL> class Queries3Tests ( BaseQuerysetTest ) : <EOL> def test_ticket7107 ( self ) : <EOL> self . assertQuerysetEqual ( Valid . objects . all ( ) , [ ] ) <EOL> def test_ticket8683 ( self ) : <EOL> self . assertRaisesMessage ( <EOL> AssertionError , <EOL> "<STR_LIT>" , <EOL> Item . objects . dates , '<STR_LIT:name>' , '<STR_LIT>' <EOL> ) <EOL> class Queries4Tests ( BaseQuerysetTest ) : <EOL> def setUp ( self ) : <EOL> generic = NamedCategory . objects . create ( name = "<STR_LIT>" ) <EOL> self . t1 = Tag . objects . create ( name = '<STR_LIT>' , category = generic ) <EOL> n1 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:1> ) <EOL> n2 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:bar>' , id = <NUM_LIT:2> ) <EOL> e1 = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = n1 ) <EOL> e2 = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = n2 ) <EOL> self . a1 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e1 ) <EOL> self . a3 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e2 ) <EOL> self . r1 = Report . objects . create ( name = '<STR_LIT>' , creator = self . a1 ) <EOL> self . r2 = Report . objects . create ( name = '<STR_LIT>' , creator = self . a3 ) <EOL> self . r3 = Report . objects . create ( name = '<STR_LIT>' ) <EOL> Item . objects . create ( name = '<STR_LIT>' , created = datetime . datetime . now ( ) , note = n1 , creator = self . a1 ) <EOL> Item . objects . create ( name = '<STR_LIT>' , created = datetime . datetime . now ( ) , note = n1 , creator = self . a3 ) <EOL> def test_ticket14876 ( self ) : <EOL> q1 = Report . objects . filter ( Q ( creator__isnull = True ) | Q ( creator__extra__info = '<STR_LIT>' ) ) <EOL> q2 = Report . objects . filter ( Q ( creator__isnull = True ) ) | Report . objects . filter ( Q ( creator__extra__info = '<STR_LIT>' ) ) <EOL> self . assertQuerysetEqual ( q1 , [ "<STR_LIT>" , "<STR_LIT>" ] , ordered = False ) <EOL> self . assertEqual ( str ( q1 . query ) , str ( q2 . query ) ) <EOL> q1 = Report . objects . filter ( Q ( creator__extra__info = '<STR_LIT>' ) | Q ( creator__isnull = True ) ) <EOL> q2 = Report . objects . filter ( Q ( creator__extra__info = '<STR_LIT>' ) ) | Report . objects . filter ( Q ( creator__isnull = True ) ) <EOL> self . assertQuerysetEqual ( q1 , [ "<STR_LIT>" , "<STR_LIT>" ] , ordered = False ) <EOL> self . assertEqual ( str ( q1 . query ) , str ( q2 . query ) ) <EOL> q1 = Item . objects . filter ( Q ( creator = self . a1 ) | Q ( creator__report__name = '<STR_LIT>' ) ) . order_by ( ) <EOL> q2 = Item . objects . filter ( Q ( creator = self . a1 ) ) . order_by ( ) | Item . objects . filter ( Q ( creator__report__name = '<STR_LIT>' ) ) . order_by ( ) <EOL> self . assertQuerysetEqual ( q1 , [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( str ( q1 . query ) , str ( q2 . query ) ) <EOL> q1 = Item . objects . filter ( Q ( creator__report__name = '<STR_LIT>' ) | Q ( creator = self . a1 ) ) . order_by ( ) <EOL> q2 = Item . objects . filter ( Q ( creator__report__name = '<STR_LIT>' ) ) . order_by ( ) | Item . objects . filter ( Q ( creator = self . a1 ) ) . order_by ( ) <EOL> self . assertQuerysetEqual ( q1 , [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( str ( q1 . query ) , str ( q2 . query ) ) <EOL> def test_ticket7095 ( self ) : <EOL> ManagedModel . objects . create ( data = '<STR_LIT>' , tag = self . t1 , public = True ) <EOL> self . assertEqual ( ManagedModel . objects . update ( data = '<STR_LIT>' ) , <NUM_LIT:1> ) <EOL> if connection . features . interprets_empty_strings_as_nulls : <EOL> expected_null_charfield_repr = '<STR_LIT>' <EOL> else : <EOL> expected_null_charfield_repr = None <EOL> self . assertValueQuerysetEqual ( <EOL> Report . objects . values_list ( "<STR_LIT>" , flat = True ) . order_by ( "<STR_LIT:name>" ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , expected_null_charfield_repr ] , <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Report . objects . select_related ( "<STR_LIT>" , "<STR_LIT>" ) . order_by ( "<STR_LIT:name>" ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> d1 = Detail . objects . create ( data = "<STR_LIT>" ) <EOL> d2 = Detail . objects . create ( data = "<STR_LIT>" ) <EOL> m1 = Member . objects . create ( name = "<STR_LIT>" , details = d1 ) <EOL> m2 = Member . objects . create ( name = "<STR_LIT>" , details = d2 ) <EOL> Child . objects . create ( person = m2 , parent = m1 ) <EOL> obj = m1 . children . select_related ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . person . details . data , '<STR_LIT>' ) <EOL> def test_order_by_resetting ( self ) : <EOL> qs = Author . objects . order_by ( ) . order_by ( '<STR_LIT:name>' ) <EOL> self . assertTrue ( '<STR_LIT>' in qs . query . get_compiler ( qs . db ) . as_sql ( ) [ <NUM_LIT:0> ] ) <EOL> def test_ticket10181 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . filter ( id__in = Tag . objects . filter ( id__in = [ ] ) ) , <EOL> [ ] <EOL> ) <EOL> def test_ticket15316_filter_false ( self ) : <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> c3 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c1 ) <EOL> ci2 = CategoryItem . objects . create ( category = c2 ) <EOL> ci3 = CategoryItem . objects . create ( category = c3 ) <EOL> qs = CategoryItem . objects . filter ( category__specialcategory__isnull = False ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> self . assertQuerysetEqual ( qs , [ ci2 . pk , ci3 . pk ] , lambda x : x . pk , False ) <EOL> def test_ticket15316_exclude_false ( self ) : <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> c3 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c1 ) <EOL> ci2 = CategoryItem . objects . create ( category = c2 ) <EOL> ci3 = CategoryItem . objects . create ( category = c3 ) <EOL> qs = CategoryItem . objects . exclude ( category__specialcategory__isnull = False ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> self . assertQuerysetEqual ( qs , [ ci1 . pk ] , lambda x : x . pk ) <EOL> def test_ticket15316_filter_true ( self ) : <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> c3 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c1 ) <EOL> ci2 = CategoryItem . objects . create ( category = c2 ) <EOL> ci3 = CategoryItem . objects . create ( category = c3 ) <EOL> qs = CategoryItem . objects . filter ( category__specialcategory__isnull = True ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> self . assertQuerysetEqual ( qs , [ ci1 . pk ] , lambda x : x . pk ) <EOL> def test_ticket15316_exclude_true ( self ) : <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> c3 = SpecialCategory . objects . create ( name = "<STR_LIT>" , <EOL> special_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c1 ) <EOL> ci2 = CategoryItem . objects . create ( category = c2 ) <EOL> ci3 = CategoryItem . objects . create ( category = c3 ) <EOL> qs = CategoryItem . objects . exclude ( category__specialcategory__isnull = True ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> self . assertQuerysetEqual ( qs , [ ci2 . pk , ci3 . pk ] , lambda x : x . pk , False ) <EOL> def test_ticket15316_one2one_filter_false ( self ) : <EOL> c = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c0 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = OneToOneCategory . objects . create ( category = c1 , new_name = "<STR_LIT>" ) <EOL> c3 = OneToOneCategory . objects . create ( category = c0 , new_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c ) <EOL> ci2 = CategoryItem . objects . create ( category = c0 ) <EOL> ci3 = CategoryItem . objects . create ( category = c1 ) <EOL> qs = CategoryItem . objects . filter ( category__onetoonecategory__isnull = False ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> self . assertQuerysetEqual ( qs , [ ci2 . pk , ci3 . pk ] , lambda x : x . pk , False ) <EOL> def test_ticket15316_one2one_exclude_false ( self ) : <EOL> c = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c0 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = OneToOneCategory . objects . create ( category = c1 , new_name = "<STR_LIT>" ) <EOL> c3 = OneToOneCategory . objects . create ( category = c0 , new_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c ) <EOL> ci2 = CategoryItem . objects . create ( category = c0 ) <EOL> ci3 = CategoryItem . objects . create ( category = c1 ) <EOL> qs = CategoryItem . objects . exclude ( category__onetoonecategory__isnull = False ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> self . assertQuerysetEqual ( qs , [ ci1 . pk ] , lambda x : x . pk ) <EOL> def test_ticket15316_one2one_filter_true ( self ) : <EOL> c = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c0 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = OneToOneCategory . objects . create ( category = c1 , new_name = "<STR_LIT>" ) <EOL> c3 = OneToOneCategory . objects . create ( category = c0 , new_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c ) <EOL> ci2 = CategoryItem . objects . create ( category = c0 ) <EOL> ci3 = CategoryItem . objects . create ( category = c1 ) <EOL> qs = CategoryItem . objects . filter ( category__onetoonecategory__isnull = True ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> self . assertQuerysetEqual ( qs , [ ci1 . pk ] , lambda x : x . pk ) <EOL> def test_ticket15316_one2one_exclude_true ( self ) : <EOL> c = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c0 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c1 = SimpleCategory . objects . create ( name = "<STR_LIT>" ) <EOL> c2 = OneToOneCategory . objects . create ( category = c1 , new_name = "<STR_LIT>" ) <EOL> c3 = OneToOneCategory . objects . create ( category = c0 , new_name = "<STR_LIT>" ) <EOL> ci1 = CategoryItem . objects . create ( category = c ) <EOL> ci2 = CategoryItem . objects . create ( category = c0 ) <EOL> ci3 = CategoryItem . objects . create ( category = c1 ) <EOL> qs = CategoryItem . objects . exclude ( category__onetoonecategory__isnull = True ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> self . assertQuerysetEqual ( qs , [ ci2 . pk , ci3 . pk ] , lambda x : x . pk , False ) <EOL> class Queries5Tests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> n1 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:1> ) <EOL> n2 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:bar>' , id = <NUM_LIT:2> ) <EOL> e1 = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = n1 ) <EOL> e2 = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = n2 ) <EOL> a1 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e1 ) <EOL> a2 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e1 ) <EOL> a3 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e2 ) <EOL> self . rank1 = Ranking . objects . create ( rank = <NUM_LIT:2> , author = a2 ) <EOL> Ranking . objects . create ( rank = <NUM_LIT:1> , author = a3 ) <EOL> Ranking . objects . create ( rank = <NUM_LIT:3> , author = a1 ) <EOL> def test_ordering ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Ranking . objects . all ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Ranking . objects . all ( ) . order_by ( '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Ranking . objects . extra ( tables = [ '<STR_LIT>' ] , order_by = [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> qs = Ranking . objects . extra ( select = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( <EOL> [ o . good for o in qs . extra ( order_by = ( '<STR_LIT>' , ) ) ] , <EOL> [ True , False , False ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> qs . extra ( order_by = ( '<STR_LIT>' , '<STR_LIT:id>' ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> dicts = qs . values ( '<STR_LIT:id>' , '<STR_LIT>' ) . order_by ( '<STR_LIT:id>' ) <EOL> self . assertEqual ( <EOL> [ d [ '<STR_LIT>' ] for d in dicts ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:3> ] <EOL> ) <EOL> def test_ticket7256 ( self ) : <EOL> qs = Ranking . objects . extra ( select = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> dicts = qs . values ( ) . order_by ( '<STR_LIT:id>' ) <EOL> for d in dicts : del d [ '<STR_LIT:id>' ] ; del d [ '<STR_LIT>' ] <EOL> self . assertEqual ( <EOL> [ sorted ( d . items ( ) ) for d in dicts ] , <EOL> [ [ ( '<STR_LIT>' , <NUM_LIT:0> ) , ( '<STR_LIT>' , <NUM_LIT:2> ) ] , [ ( '<STR_LIT>' , <NUM_LIT:0> ) , ( '<STR_LIT>' , <NUM_LIT:1> ) ] , [ ( '<STR_LIT>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , <NUM_LIT:3> ) ] ] <EOL> ) <EOL> def test_ticket7045 ( self ) : <EOL> qs = Ranking . objects . extra ( tables = [ '<STR_LIT>' ] ) <EOL> qs . query . get_compiler ( qs . db ) . as_sql ( ) <EOL> qs . query . get_compiler ( qs . db ) . as_sql ( ) <EOL> def test_ticket9848 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Ranking . objects . filter ( author__name = '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertEqual ( <EOL> Ranking . objects . filter ( author__name = '<STR_LIT>' ) . update ( rank = '<STR_LIT:4>' ) , <EOL> <NUM_LIT:1> <EOL> ) <EOL> r = Ranking . objects . filter ( author__name = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . assertNotEqual ( r . id , r . author . id ) <EOL> self . assertEqual ( r . rank , <NUM_LIT:4> ) <EOL> r . rank = <NUM_LIT:3> <EOL> r . save ( ) <EOL> self . assertQuerysetEqual ( <EOL> Ranking . objects . all ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket5261 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . exclude ( Q ( ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . filter ( ~ Q ( ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . filter ( ~ Q ( ) | ~ Q ( ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . exclude ( ~ Q ( ) & ~ Q ( ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> class SelectRelatedTests ( TestCase ) : <EOL> def test_tickets_3045_3288 ( self ) : <EOL> self . assertQuerysetEqual ( X . objects . all ( ) , [ ] ) <EOL> self . assertQuerysetEqual ( X . objects . select_related ( ) , [ ] ) <EOL> class SubclassFKTests ( TestCase ) : <EOL> def test_ticket7778 ( self ) : <EOL> num_celebs = Celebrity . objects . count ( ) <EOL> tvc = TvChef . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertEqual ( Celebrity . objects . count ( ) , num_celebs + <NUM_LIT:1> ) <EOL> Fan . objects . create ( fan_of = tvc ) <EOL> Fan . objects . create ( fan_of = tvc ) <EOL> tvc . delete ( ) <EOL> self . assertEqual ( Celebrity . objects . count ( ) , num_celebs ) <EOL> class CustomPkTests ( TestCase ) : <EOL> def test_ticket7371 ( self ) : <EOL> self . assertQuerysetEqual ( Related . objects . order_by ( '<STR_LIT>' ) , [ ] ) <EOL> class NullableRelOrderingTests ( TestCase ) : <EOL> def test_ticket10028 ( self ) : <EOL> Plaything . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertQuerysetEqual ( <EOL> Plaything . objects . all ( ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_join_already_in_query ( self ) : <EOL> Plaything . objects . create ( name = "<STR_LIT>" ) <EOL> s = SingleObject . objects . create ( name = '<STR_LIT:s>' ) <EOL> r = RelatedObject . objects . create ( single = s ) <EOL> Plaything . objects . create ( name = "<STR_LIT>" , others = r ) <EOL> qs = Plaything . objects . all ( ) . filter ( others__isnull = False ) . order_by ( '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in str ( qs . query ) ) <EOL> qs = qs . order_by ( '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in str ( qs . query ) ) <EOL> self . assertTrue ( '<STR_LIT>' in str ( qs . query ) ) <EOL> self . assertQuerysetEqual ( <EOL> qs , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> class DisjunctiveFilterTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . n1 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:1> ) <EOL> ExtraInfo . objects . create ( info = '<STR_LIT>' , note = self . n1 ) <EOL> def test_ticket7872 ( self ) : <EOL> LeafA . objects . create ( data = '<STR_LIT>' ) <EOL> self . assertQuerysetEqual ( LeafA . objects . all ( ) , [ '<STR_LIT>' ] ) <EOL> self . assertQuerysetEqual ( <EOL> LeafA . objects . filter ( Q ( data = '<STR_LIT>' ) | Q ( join__b__data = '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket8283 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> ( ExtraInfo . objects . filter ( note = self . n1 ) | ExtraInfo . objects . filter ( info = '<STR_LIT>' ) ) . filter ( note = self . n1 ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> ( ExtraInfo . objects . filter ( info = '<STR_LIT>' ) | ExtraInfo . objects . filter ( note = self . n1 ) ) . filter ( note = self . n1 ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> class Queries6Tests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> generic = NamedCategory . objects . create ( name = "<STR_LIT>" ) <EOL> t1 = Tag . objects . create ( name = '<STR_LIT>' , category = generic ) <EOL> t2 = Tag . objects . create ( name = '<STR_LIT>' , parent = t1 , category = generic ) <EOL> t3 = Tag . objects . create ( name = '<STR_LIT>' , parent = t1 ) <EOL> t4 = Tag . objects . create ( name = '<STR_LIT>' , parent = t3 ) <EOL> t5 = Tag . objects . create ( name = '<STR_LIT>' , parent = t3 ) <EOL> n1 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:1> ) <EOL> ann1 = Annotation . objects . create ( name = '<STR_LIT>' , tag = t1 ) <EOL> ann1 . notes . add ( n1 ) <EOL> ann2 = Annotation . objects . create ( name = '<STR_LIT>' , tag = t4 ) <EOL> def test_slicing_and_cache_interaction ( self ) : <EOL> from django . db . models import query <EOL> query . ITER_CHUNK_SIZE = <NUM_LIT:2> <EOL> qs = Tag . objects . all ( ) <EOL> self . assertTrue ( bool ( qs ) ) <EOL> self . assertEqual ( len ( qs . _result_cache ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( repr ( qs [ <NUM_LIT:4> ] ) , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( qs . _result_cache ) , <NUM_LIT:5> ) <EOL> self . assertRaises ( IndexError , lambda : qs [ <NUM_LIT:100> ] ) <EOL> def test_parallel_iterators ( self ) : <EOL> qs = Tag . objects . all ( ) <EOL> i1 , i2 = iter ( qs ) , iter ( qs ) <EOL> self . assertEqual ( repr ( next ( i1 ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( next ( i1 ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( next ( i2 ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( next ( i2 ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( next ( i2 ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( next ( i1 ) ) , '<STR_LIT>' ) <EOL> qs = X . objects . all ( ) <EOL> self . assertEqual ( bool ( qs ) , False ) <EOL> self . assertEqual ( bool ( qs ) , False ) <EOL> def test_nested_queries_sql ( self ) : <EOL> qs = Annotation . objects . filter ( notes__in = Note . objects . filter ( note = "<STR_LIT>" ) ) <EOL> self . assertEqual ( <EOL> qs . query . get_compiler ( qs . db ) . as_sql ( ) [ <NUM_LIT:0> ] . count ( '<STR_LIT>' ) , <EOL> <NUM_LIT:2> <EOL> ) <EOL> def test_tickets_8921_9188 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> PointerA . objects . filter ( connection__pointerb__id = <NUM_LIT:1> ) , <EOL> [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> PointerA . objects . exclude ( connection__pointerb__id = <NUM_LIT:1> ) , <EOL> [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( children = None ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Tag . objects . exclude ( parent__annotation__name = "<STR_LIT>" ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Annotation . objects . exclude ( tag__children__name = "<STR_LIT>" ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Annotation . objects . filter ( notes__in = Note . objects . filter ( note = "<STR_LIT>" ) ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> def test_ticket3739 ( self ) : <EOL> q1 = Tag . objects . order_by ( '<STR_LIT:name>' ) <EOL> self . assertIsNot ( q1 , q1 . all ( ) ) <EOL> class RawQueriesTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> n1 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:1> ) <EOL> def test_ticket14729 ( self ) : <EOL> query = "<STR_LIT>" <EOL> params = [ '<STR_LIT>' ] <EOL> qs = Note . objects . raw ( query , params = params ) <EOL> self . assertEqual ( repr ( qs ) , str_prefix ( "<STR_LIT>" ) ) <EOL> query = "<STR_LIT>" <EOL> params = [ '<STR_LIT>' , '<STR_LIT:foo>' ] <EOL> qs = Note . objects . raw ( query , params = params ) <EOL> self . assertEqual ( repr ( qs ) , str_prefix ( "<STR_LIT>" ) ) <EOL> class GeneratorExpressionTests ( TestCase ) : <EOL> def test_ticket10432 ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Note . objects . filter ( pk__in = ( x for x in ( ) ) ) , <EOL> [ ] <EOL> ) <EOL> class ComparisonTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . n1 = Note . objects . create ( note = '<STR_LIT>' , misc = '<STR_LIT:foo>' , id = <NUM_LIT:1> ) <EOL> e1 = ExtraInfo . objects . create ( info = '<STR_LIT>' , note = self . n1 ) <EOL> self . a2 = Author . objects . create ( name = '<STR_LIT>' , num = <NUM_LIT> , extra = e1 ) <EOL> def test_ticket8597 ( self ) : <EOL> _ = Item . objects . create ( name = "<STR_LIT>" , created = datetime . datetime . now ( ) , creator = self . a2 , note = self . n1 ) <EOL> _ = Item . objects . create ( name = "<STR_LIT>" , created = datetime . datetime . now ( ) , creator = self . a2 , note = self . n1 ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( name__iexact = "<STR_LIT>" ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( name__iexact = "<STR_LIT>" ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( name__istartswith = "<STR_LIT>" ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . filter ( name__iendswith = "<STR_LIT>" ) , <EOL> [ '<STR_LIT>' ] <EOL> ) <EOL> class ExistsSql ( TestCase ) : <EOL> def setUp ( self ) : <EOL> settings . DEBUG = True <EOL> def test_exists ( self ) : <EOL> self . assertFalse ( Tag . objects . exists ( ) ) <EOL> self . assertTrue ( "<STR_LIT:id>" not in connection . queries [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] and "<STR_LIT:name>" not in connection . queries [ - <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> def tearDown ( self ) : <EOL> settings . DEBUG = False <EOL> class QuerysetOrderedTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_no_default_or_explicit_ordering ( self ) : <EOL> self . assertEqual ( Annotation . objects . all ( ) . ordered , False ) <EOL> def test_cleared_default_ordering ( self ) : <EOL> self . assertEqual ( Tag . objects . all ( ) . ordered , True ) <EOL> self . assertEqual ( Tag . objects . all ( ) . order_by ( ) . ordered , False ) <EOL> def test_explicit_ordering ( self ) : <EOL> self . assertEqual ( Annotation . objects . all ( ) . order_by ( '<STR_LIT:id>' ) . ordered , True ) <EOL> def test_order_by_extra ( self ) : <EOL> self . assertEqual ( Annotation . objects . all ( ) . extra ( order_by = [ '<STR_LIT:id>' ] ) . ordered , True ) <EOL> def test_annotated_ordering ( self ) : <EOL> qs = Annotation . objects . annotate ( num_notes = Count ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( qs . ordered , False ) <EOL> self . assertEqual ( qs . order_by ( '<STR_LIT>' ) . ordered , True ) <EOL> class SubqueryTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> DumbCategory . objects . create ( id = <NUM_LIT:1> ) <EOL> DumbCategory . objects . create ( id = <NUM_LIT:2> ) <EOL> DumbCategory . objects . create ( id = <NUM_LIT:3> ) <EOL> def test_ordered_subselect ( self ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> query = DumbCategory . objects . filter ( id__in = DumbCategory . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:2> ] ) <EOL> self . assertEqual ( set ( query . values_list ( '<STR_LIT:id>' , flat = True ) ) , set ( [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> query = DumbCategory . objects . filter ( id__in = DumbCategory . objects . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:2> ] ) <EOL> self . assertEqual ( set ( query . values_list ( '<STR_LIT:id>' , flat = True ) ) , set ( [ <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> query = DumbCategory . objects . filter ( id__in = DumbCategory . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:2> : ] ) <EOL> self . assertEqual ( set ( query . values_list ( '<STR_LIT:id>' , flat = True ) ) , set ( [ <NUM_LIT:1> ] ) ) <EOL> except DatabaseError : <EOL> self . assertFalse ( connections [ DEFAULT_DB_ALIAS ] . features . allow_sliced_subqueries ) <EOL> def test_sliced_delete ( self ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> DumbCategory . objects . filter ( id__in = DumbCategory . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> : <NUM_LIT:1> ] ) . delete ( ) <EOL> self . assertEqual ( set ( DumbCategory . objects . values_list ( '<STR_LIT:id>' , flat = True ) ) , set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> except DatabaseError : <EOL> self . assertFalse ( connections [ DEFAULT_DB_ALIAS ] . features . allow_sliced_subqueries ) <EOL> class CloneTests ( TestCase ) : <EOL> def test_evaluated_queryset_as_argument ( self ) : <EOL> "<STR_LIT>" <EOL> n = Note ( note = '<STR_LIT>' , misc = '<STR_LIT>' ) <EOL> n . save ( ) <EOL> e = ExtraInfo ( info = '<STR_LIT>' , note = n ) <EOL> e . save ( ) <EOL> n_list = Note . objects . all ( ) <EOL> list ( n_list ) <EOL> self . assertEqual ( ExtraInfo . objects . filter ( note__in = n_list ) [ <NUM_LIT:0> ] . info , '<STR_LIT>' ) <EOL> class EmptyQuerySetTests ( TestCase ) : <EOL> def test_emptyqueryset_values ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . none ( ) . values ( '<STR_LIT>' ) . order_by ( '<STR_LIT>' ) , [ ] <EOL> ) <EOL> def test_values_subquery ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( pk__in = Number . objects . none ( ) . values ( "<STR_LIT>" ) ) , <EOL> [ ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> Number . objects . filter ( pk__in = Number . objects . none ( ) . values_list ( "<STR_LIT>" ) ) , <EOL> [ ] <EOL> ) <EOL> def test_ticket_19151 ( self ) : <EOL> q = EmptyQuerySet ( ) <EOL> self . assertQuerysetEqual ( q . values ( ) , [ ] ) <EOL> self . assertQuerysetEqual ( q . values_list ( ) , [ ] ) <EOL> class ValuesQuerysetTests ( BaseQuerysetTest ) : <EOL> def test_flat_values_lits ( self ) : <EOL> Number . objects . create ( num = <NUM_LIT> ) <EOL> qs = Number . objects . values_list ( "<STR_LIT>" ) <EOL> qs = qs . values_list ( "<STR_LIT>" , flat = True ) <EOL> self . assertValueQuerysetEqual ( <EOL> qs , [ <NUM_LIT> ] <EOL> ) <EOL> class WeirdQuerysetSlicingTests ( BaseQuerysetTest ) : <EOL> def setUp ( self ) : <EOL> Number . objects . create ( num = <NUM_LIT:1> ) <EOL> Number . objects . create ( num = <NUM_LIT:2> ) <EOL> Article . objects . create ( name = '<STR_LIT>' , created = datetime . datetime . now ( ) ) <EOL> Article . objects . create ( name = '<STR_LIT>' , created = datetime . datetime . now ( ) ) <EOL> Article . objects . create ( name = '<STR_LIT>' , created = datetime . datetime . now ( ) ) <EOL> Article . objects . create ( name = '<STR_LIT>' , created = datetime . datetime . now ( ) ) <EOL> def test_tickets_7698_10202 ( self ) : <EOL> self . assertQuerysetEqual ( Article . objects . all ( ) [ <NUM_LIT:0> : <NUM_LIT:0> ] , [ ] ) <EOL> self . assertQuerysetEqual ( Article . objects . all ( ) [ <NUM_LIT:0> : <NUM_LIT:0> ] [ : <NUM_LIT:10> ] , [ ] ) <EOL> self . assertEqual ( Article . objects . all ( ) [ : <NUM_LIT:0> ] . count ( ) , <NUM_LIT:0> ) <EOL> self . assertRaisesMessage ( <EOL> AssertionError , <EOL> '<STR_LIT>' , <EOL> Article . objects . all ( ) [ : <NUM_LIT:0> ] . latest , '<STR_LIT>' <EOL> ) <EOL> def test_empty_resultset_sql ( self ) : <EOL> self . assertNumQueries ( <NUM_LIT:0> , lambda : list ( Number . objects . all ( ) [ <NUM_LIT:1> : <NUM_LIT:1> ] ) ) <EOL> class EscapingTests ( TestCase ) : <EOL> def test_ticket_7302 ( self ) : <EOL> _ = ReservedName . objects . create ( name = '<STR_LIT:a>' , order = <NUM_LIT> ) <EOL> ReservedName . objects . create ( name = '<STR_LIT:b>' , order = <NUM_LIT> ) <EOL> self . assertQuerysetEqual ( <EOL> ReservedName . objects . all ( ) . order_by ( '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> ReservedName . objects . extra ( select = { '<STR_LIT>' : '<STR_LIT:name>' } , order_by = ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> class ToFieldTests ( TestCase ) : <EOL> def test_in_query ( self ) : <EOL> apple = Food . objects . create ( name = "<STR_LIT>" ) <EOL> pear = Food . objects . create ( name = "<STR_LIT>" ) <EOL> lunch = Eaten . objects . create ( food = apple , meal = "<STR_LIT>" ) <EOL> dinner = Eaten . objects . create ( food = pear , meal = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> set ( Eaten . objects . filter ( food__in = [ apple , pear ] ) ) , <EOL> set ( [ lunch , dinner ] ) , <EOL> ) <EOL> def test_reverse_in ( self ) : <EOL> apple = Food . objects . create ( name = "<STR_LIT>" ) <EOL> pear = Food . objects . create ( name = "<STR_LIT>" ) <EOL> lunch_apple = Eaten . objects . create ( food = apple , meal = "<STR_LIT>" ) <EOL> lunch_pear = Eaten . objects . create ( food = pear , meal = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> set ( Food . objects . filter ( eaten__in = [ lunch_apple , lunch_pear ] ) ) , <EOL> set ( [ apple , pear ] ) <EOL> ) <EOL> def test_single_object ( self ) : <EOL> apple = Food . objects . create ( name = "<STR_LIT>" ) <EOL> lunch = Eaten . objects . create ( food = apple , meal = "<STR_LIT>" ) <EOL> dinner = Eaten . objects . create ( food = apple , meal = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> set ( Eaten . objects . filter ( food = apple ) ) , <EOL> set ( [ lunch , dinner ] ) <EOL> ) <EOL> def test_single_object_reverse ( self ) : <EOL> apple = Food . objects . create ( name = "<STR_LIT>" ) <EOL> lunch = Eaten . objects . create ( food = apple , meal = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> set ( Food . objects . filter ( eaten = lunch ) ) , <EOL> set ( [ apple ] ) <EOL> ) <EOL> def test_recursive_fk ( self ) : <EOL> node1 = Node . objects . create ( num = <NUM_LIT> ) <EOL> node2 = Node . objects . create ( num = <NUM_LIT:1> , parent = node1 ) <EOL> self . assertEqual ( <EOL> list ( Node . objects . filter ( parent = node1 ) ) , <EOL> [ node2 ] <EOL> ) <EOL> def test_recursive_fk_reverse ( self ) : <EOL> node1 = Node . objects . create ( num = <NUM_LIT> ) <EOL> node2 = Node . objects . create ( num = <NUM_LIT:1> , parent = node1 ) <EOL> self . assertEqual ( <EOL> list ( Node . objects . filter ( node = node2 ) ) , <EOL> [ node1 ] <EOL> ) <EOL> class ConditionalTests ( BaseQuerysetTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> generic = NamedCategory . objects . create ( name = "<STR_LIT>" ) <EOL> t1 = Tag . objects . create ( name = '<STR_LIT>' , category = generic ) <EOL> t2 = Tag . objects . create ( name = '<STR_LIT>' , parent = t1 , category = generic ) <EOL> t3 = Tag . objects . create ( name = '<STR_LIT>' , parent = t1 ) <EOL> t4 = Tag . objects . create ( name = '<STR_LIT>' , parent = t3 ) <EOL> t5 = Tag . objects . create ( name = '<STR_LIT>' , parent = t3 ) <EOL> @ unittest . skipIf ( sys . version_info [ : <NUM_LIT:2> ] == ( <NUM_LIT:2> , <NUM_LIT:6> ) , "<STR_LIT>" ) <EOL> def test_infinite_loop ( self ) : <EOL> self . assertRaisesMessage ( <EOL> FieldError , <EOL> '<STR_LIT>' , <EOL> lambda : list ( LoopX . objects . all ( ) ) <EOL> ) <EOL> self . assertRaisesMessage ( <EOL> FieldError , <EOL> '<STR_LIT>' , <EOL> lambda : list ( LoopZ . objects . all ( ) ) <EOL> ) <EOL> self . assertEqual ( len ( Tag . objects . order_by ( '<STR_LIT>' ) ) , <NUM_LIT:5> ) <EOL> self . assertQuerysetEqual ( <EOL> LoopX . objects . all ( ) . order_by ( '<STR_LIT>' ) , <EOL> [ ] <EOL> ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_null_ordering_added ( self ) : <EOL> query = Tag . objects . values_list ( '<STR_LIT>' , flat = True ) . order_by ( ) . query <EOL> query . group_by = [ '<STR_LIT>' ] <EOL> sql = query . get_compiler ( DEFAULT_DB_ALIAS ) . as_sql ( ) [ <NUM_LIT:0> ] <EOL> fragment = "<STR_LIT>" <EOL> pos = sql . find ( fragment ) <EOL> self . assertEqual ( sql . find ( fragment , pos + <NUM_LIT:1> ) , - <NUM_LIT:1> ) <EOL> self . assertEqual ( sql . find ( "<STR_LIT>" , pos + len ( fragment ) ) , pos + len ( fragment ) ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_ticket14244 ( self ) : <EOL> numbers = range ( <NUM_LIT> ) <EOL> Number . objects . all ( ) . delete ( ) <EOL> Number . objects . bulk_create ( Number ( num = num ) for num in numbers ) <EOL> self . assertEqual ( <EOL> Number . objects . filter ( num__in = numbers [ : <NUM_LIT:1000> ] ) . count ( ) , <EOL> <NUM_LIT:1000> <EOL> ) <EOL> self . assertEqual ( <EOL> Number . objects . filter ( num__in = numbers [ : <NUM_LIT> ] ) . count ( ) , <EOL> <NUM_LIT> <EOL> ) <EOL> self . assertEqual ( <EOL> Number . objects . filter ( num__in = numbers [ : <NUM_LIT> ] ) . count ( ) , <EOL> <NUM_LIT> <EOL> ) <EOL> self . assertEqual ( <EOL> Number . objects . filter ( num__in = numbers ) . count ( ) , <EOL> len ( numbers ) <EOL> ) <EOL> class UnionTests ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> objectas = [ ] <EOL> objectbs = [ ] <EOL> objectcs = [ ] <EOL> a_info = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for name in a_info : <EOL> o = ObjectA ( name = name ) <EOL> o . save ( ) <EOL> objectas . append ( o ) <EOL> b_info = [ ( '<STR_LIT>' , <NUM_LIT:1> , objectas [ <NUM_LIT:0> ] ) , ( '<STR_LIT>' , <NUM_LIT:2> , objectas [ <NUM_LIT:0> ] ) , ( '<STR_LIT>' , <NUM_LIT:3> , objectas [ <NUM_LIT:2> ] ) ] <EOL> for name , number , objecta in b_info : <EOL> o = ObjectB ( name = name , num = number , objecta = objecta ) <EOL> o . save ( ) <EOL> objectbs . append ( o ) <EOL> c_info = [ ( '<STR_LIT>' , objectas [ <NUM_LIT:2> ] , objectbs [ <NUM_LIT:2> ] ) , ( '<STR_LIT>' , objectas [ <NUM_LIT:1> ] , objectbs [ <NUM_LIT:1> ] ) ] <EOL> for name , objecta , objectb in c_info : <EOL> o = ObjectC ( name = name , objecta = objecta , objectb = objectb ) <EOL> o . save ( ) <EOL> objectcs . append ( o ) <EOL> def check_union ( self , model , Q1 , Q2 ) : <EOL> filter = model . objects . filter <EOL> self . assertEqual ( set ( filter ( Q1 ) | filter ( Q2 ) ) , set ( filter ( Q1 | Q2 ) ) ) <EOL> self . assertEqual ( set ( filter ( Q2 ) | filter ( Q1 ) ) , set ( filter ( Q1 | Q2 ) ) ) <EOL> def test_A_AB ( self ) : <EOL> Q1 = Q ( name = '<STR_LIT>' ) <EOL> Q2 = Q ( objectb__name = '<STR_LIT>' ) <EOL> self . check_union ( ObjectA , Q1 , Q2 ) <EOL> def test_A_AB2 ( self ) : <EOL> Q1 = Q ( name = '<STR_LIT>' ) <EOL> Q2 = Q ( objectb__name = '<STR_LIT>' , objectb__num = <NUM_LIT:2> ) <EOL> self . check_union ( ObjectA , Q1 , Q2 ) <EOL> def test_AB_ACB ( self ) : <EOL> Q1 = Q ( objectb__name = '<STR_LIT>' ) <EOL> Q2 = Q ( objectc__objectb__name = '<STR_LIT>' ) <EOL> self . check_union ( ObjectA , Q1 , Q2 ) <EOL> def test_BAB_BAC ( self ) : <EOL> Q1 = Q ( objecta__objectb__name = '<STR_LIT>' ) <EOL> Q2 = Q ( objecta__objectc__name = '<STR_LIT>' ) <EOL> self . check_union ( ObjectB , Q1 , Q2 ) <EOL> def test_BAB_BACB ( self ) : <EOL> Q1 = Q ( objecta__objectb__name = '<STR_LIT>' ) <EOL> Q2 = Q ( objecta__objectc__objectb__name = '<STR_LIT>' ) <EOL> self . check_union ( ObjectB , Q1 , Q2 ) <EOL> def test_BA_BCA__BAB_BAC_BCA ( self ) : <EOL> Q1 = Q ( objecta__name = '<STR_LIT>' , objectc__objecta__name = '<STR_LIT>' ) <EOL> Q2 = Q ( objecta__objectc__name = '<STR_LIT>' , objectc__objecta__name = '<STR_LIT>' , objecta__objectb__name = '<STR_LIT>' ) <EOL> self . check_union ( ObjectB , Q1 , Q2 ) <EOL> class DefaultValuesInsertTest ( TestCase ) : <EOL> def test_no_extra_params ( self ) : <EOL> try : <EOL> DumbCategory . objects . create ( ) <EOL> except TypeError : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class NullInExcludeTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> NullableName . objects . create ( name = '<STR_LIT>' ) <EOL> NullableName . objects . create ( ) <EOL> def test_null_in_exclude_qs ( self ) : <EOL> none_val = '<STR_LIT>' if connection . features . interprets_empty_strings_as_nulls else None <EOL> self . assertQuerysetEqual ( <EOL> NullableName . objects . exclude ( name__in = [ ] ) , <EOL> [ '<STR_LIT>' , none_val ] , attrgetter ( '<STR_LIT:name>' ) ) <EOL> self . assertQuerysetEqual ( <EOL> NullableName . objects . exclude ( name__in = [ '<STR_LIT>' ] ) , <EOL> [ none_val ] , attrgetter ( '<STR_LIT:name>' ) ) <EOL> self . assertQuerysetEqual ( <EOL> NullableName . objects . exclude ( name__in = [ '<STR_LIT>' ] ) , <EOL> [ '<STR_LIT>' , none_val ] , attrgetter ( '<STR_LIT:name>' ) ) <EOL> inner_qs = NullableName . objects . filter ( name = '<STR_LIT>' ) . values_list ( '<STR_LIT:name>' ) <EOL> self . assertQuerysetEqual ( <EOL> NullableName . objects . exclude ( name__in = inner_qs ) , <EOL> [ none_val ] , attrgetter ( '<STR_LIT:name>' ) ) <EOL> self . assertIs ( inner_qs . _result_cache , None ) <EOL> @ unittest . expectedFailure <EOL> def test_col_not_in_list_containing_null ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertQuerysetEqual ( <EOL> NullableName . objects . exclude ( name__in = [ None ] ) , <EOL> [ '<STR_LIT>' ] , attrgetter ( '<STR_LIT:name>' ) ) <EOL> class EmptyStringsAsNullTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . nc = NamedCategory . objects . create ( name = '<STR_LIT>' ) <EOL> def test_direct_exclude ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> NamedCategory . objects . exclude ( name__in = [ '<STR_LIT>' ] ) , <EOL> [ self . nc . pk ] , attrgetter ( '<STR_LIT>' ) <EOL> ) <EOL> def test_joined_exclude ( self ) : <EOL> self . assertQuerysetEqual ( <EOL> DumbCategory . objects . exclude ( namedcategory__name__in = [ '<STR_LIT>' ] ) , <EOL> [ self . nc . pk ] , attrgetter ( '<STR_LIT>' ) <EOL> ) <EOL> class ProxyQueryCleanupTest ( TestCase ) : <EOL> def test_evaluated_proxy_count ( self ) : <EOL> """<STR_LIT>""" <EOL> ProxyCategory . objects . create ( ) <EOL> qs = ProxyCategory . objects . all ( ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> str ( qs . query ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> class WhereNodeTest ( TestCase ) : <EOL> class DummyNode ( object ) : <EOL> def as_sql ( self , qn , connection ) : <EOL> return '<STR_LIT>' , [ ] <EOL> def test_empty_full_handling_conjunction ( self ) : <EOL> qn = connection . ops . quote_name <EOL> w = WhereNode ( children = [ EverythingNode ( ) ] ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w = WhereNode ( children = [ NothingNode ( ) ] ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w = WhereNode ( children = [ EverythingNode ( ) , EverythingNode ( ) ] ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w = WhereNode ( children = [ EverythingNode ( ) , self . DummyNode ( ) ] ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w = WhereNode ( children = [ self . DummyNode ( ) , self . DummyNode ( ) ] ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w = WhereNode ( children = [ NothingNode ( ) , self . DummyNode ( ) ] ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> def test_empty_full_handling_disjunction ( self ) : <EOL> qn = connection . ops . quote_name <EOL> w = WhereNode ( children = [ EverythingNode ( ) ] , connector = '<STR_LIT>' ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w = WhereNode ( children = [ NothingNode ( ) ] , connector = '<STR_LIT>' ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w = WhereNode ( children = [ EverythingNode ( ) , EverythingNode ( ) ] , connector = '<STR_LIT>' ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w = WhereNode ( children = [ EverythingNode ( ) , self . DummyNode ( ) ] , connector = '<STR_LIT>' ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> w = WhereNode ( children = [ self . DummyNode ( ) , self . DummyNode ( ) ] , connector = '<STR_LIT>' ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w = WhereNode ( children = [ NothingNode ( ) , self . DummyNode ( ) ] , connector = '<STR_LIT>' ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( '<STR_LIT>' , [ ] ) ) <EOL> def test_empty_nodes ( self ) : <EOL> qn = connection . ops . quote_name <EOL> empty_w = WhereNode ( ) <EOL> w = WhereNode ( children = [ empty_w , empty_w ] ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( None , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( None , [ ] ) ) <EOL> w . connector = '<STR_LIT>' <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( None , [ ] ) ) <EOL> w . negate ( ) <EOL> self . assertEqual ( w . as_sql ( qn , connection ) , ( None , [ ] ) ) <EOL> w = WhereNode ( children = [ empty_w , NothingNode ( ) ] , connector = '<STR_LIT>' ) <EOL> self . assertRaises ( EmptyResultSet , w . as_sql , qn , connection ) <EOL> class NullJoinPromotionOrTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> d = ModelD . objects . create ( name = '<STR_LIT:foo>' ) <EOL> ModelA . objects . create ( name = '<STR_LIT:bar>' , d = d ) <EOL> def test_ticket_17886 ( self ) : <EOL> q_obj = ( <EOL> Q ( d__name = '<STR_LIT:foo>' ) | <EOL> Q ( b__name = '<STR_LIT:foo>' ) | <EOL> Q ( b__c__name = '<STR_LIT:foo>' ) <EOL> ) <EOL> qset = ModelA . objects . filter ( q_obj ) <EOL> self . assertEqual ( len ( qset ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( str ( qset . query ) . count ( '<STR_LIT>' ) , <NUM_LIT:1> ) </s>
