<s> from django . test import TestCase <EOL> from regressiontests . select_related_regress . models import * <EOL> class SelectRelatedRegressTests ( TestCase ) : <EOL> def test_regression_7110 ( self ) : <EOL> """<STR_LIT>""" <EOL> b = Building . objects . create ( name = '<STR_LIT>' ) <EOL> dev1 = Device . objects . create ( name = "<STR_LIT>" , building = b ) <EOL> dev2 = Device . objects . create ( name = "<STR_LIT>" , building = b ) <EOL> dev3 = Device . objects . create ( name = "<STR_LIT>" , building = b ) <EOL> port1 = Port . objects . create ( port_number = '<STR_LIT:4>' , device = dev1 ) <EOL> port2 = Port . objects . create ( port_number = '<STR_LIT>' , device = dev2 ) <EOL> port3 = Port . objects . create ( port_number = '<STR_LIT:1>' , device = dev3 ) <EOL> c1 = Connection . objects . create ( start = port1 , end = port2 ) <EOL> c2 = Connection . objects . create ( start = port2 , end = port3 ) <EOL> connections = Connection . objects . filter ( start__device__building = b , end__device__building = b ) . order_by ( '<STR_LIT:id>' ) <EOL> self . assertEqual ( [ ( c . id , unicode ( c . start ) , unicode ( c . end ) ) for c in connections ] , <EOL> [ ( c1 . id , u'<STR_LIT>' , u'<STR_LIT>' ) , ( c2 . id , u'<STR_LIT>' , u'<STR_LIT>' ) ] ) <EOL> connections = Connection . objects . filter ( start__device__building = b , end__device__building = b ) . select_related ( ) . order_by ( '<STR_LIT:id>' ) <EOL> self . assertEqual ( [ ( c . id , unicode ( c . start ) , unicode ( c . end ) ) for c in connections ] , <EOL> [ ( c1 . id , u'<STR_LIT>' , u'<STR_LIT>' ) , ( c2 . id , u'<STR_LIT>' , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( connections . query . count_active_tables ( ) , <NUM_LIT:7> ) <EOL> def test_regression_8106 ( self ) : <EOL> """<STR_LIT>""" <EOL> us = TUser . objects . create ( name = "<STR_LIT>" ) <EOL> usp = Person . objects . create ( user = us ) <EOL> uo = TUser . objects . create ( name = "<STR_LIT>" ) <EOL> uop = Person . objects . create ( user = uo ) <EOL> s = Student . objects . create ( person = usp ) <EOL> o = Organizer . objects . create ( person = uop ) <EOL> c = Class . objects . create ( org = o ) <EOL> e = Enrollment . objects . create ( std = s , cls = c ) <EOL> e_related = Enrollment . objects . all ( ) . select_related ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( e_related . std . person . user . name , u"<STR_LIT>" ) <EOL> self . assertEqual ( e_related . cls . org . person . user . name , u"<STR_LIT>" ) <EOL> def test_regression_8036 ( self ) : <EOL> """<STR_LIT>""" <EOL> australia = Country . objects . create ( name = '<STR_LIT>' ) <EOL> active = ClientStatus . objects . create ( name = '<STR_LIT>' ) <EOL> client = Client . objects . create ( name = '<STR_LIT>' , status = active ) <EOL> self . assertEqual ( client . status , active ) <EOL> self . assertEqual ( Client . objects . select_related ( ) [ <NUM_LIT:0> ] . status , active ) <EOL> self . assertEqual ( Client . objects . select_related ( '<STR_LIT:state>' ) [ <NUM_LIT:0> ] . status , active ) <EOL> self . assertEqual ( Client . objects . select_related ( '<STR_LIT:state>' , '<STR_LIT:status>' ) [ <NUM_LIT:0> ] . status , active ) <EOL> self . assertEqual ( Client . objects . select_related ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . status , active ) <EOL> self . assertEqual ( Client . objects . select_related ( '<STR_LIT>' , '<STR_LIT:status>' ) [ <NUM_LIT:0> ] . status , active ) <EOL> self . assertEqual ( Client . objects . select_related ( '<STR_LIT:status>' ) [ <NUM_LIT:0> ] . status , active ) <EOL> def test_multi_table_inheritance ( self ) : <EOL> """<STR_LIT>""" <EOL> c1 = Child . objects . create ( name = "<STR_LIT>" , value = <NUM_LIT> ) <EOL> i1 = Item . objects . create ( name = "<STR_LIT>" , child = c1 ) <EOL> i2 = Item . objects . create ( name = "<STR_LIT>" ) <EOL> self . assertQuerysetEqual ( <EOL> Item . objects . select_related ( "<STR_LIT>" ) . order_by ( "<STR_LIT:name>" ) , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> ) <EOL> def test_regression_12851 ( self ) : <EOL> """<STR_LIT>""" <EOL> australia = Country . objects . create ( name = '<STR_LIT>' ) <EOL> active = ClientStatus . objects . create ( name = '<STR_LIT>' ) <EOL> wa = State . objects . create ( name = "<STR_LIT>" , country = australia ) <EOL> c1 = Client . objects . create ( name = '<STR_LIT>' , state = wa , status = active ) <EOL> burke = Client . objects . select_related ( '<STR_LIT:state>' ) . defer ( '<STR_LIT>' ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( burke . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( burke . state . name , u'<STR_LIT>' ) <EOL> sc1 = SpecialClient . objects . create ( name = '<STR_LIT>' , state = wa , status = active , value = <NUM_LIT> ) <EOL> troy = SpecialClient . objects . select_related ( '<STR_LIT:state>' ) . defer ( '<STR_LIT>' ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( troy . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( troy . value , <NUM_LIT> ) <EOL> self . assertEqual ( troy . state . name , u'<STR_LIT>' ) <EOL> troy = SpecialClient . objects . select_related ( '<STR_LIT:state>' ) . defer ( '<STR_LIT:value>' , '<STR_LIT>' ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( troy . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( troy . value , <NUM_LIT> ) <EOL> self . assertEqual ( troy . state . name , u'<STR_LIT>' ) <EOL> troy = SpecialClient . objects . select_related ( '<STR_LIT:state>' ) . only ( '<STR_LIT:name>' ) . get ( name = '<STR_LIT>' ) <EOL> self . assertEqual ( troy . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( troy . value , <NUM_LIT> ) <EOL> self . assertEqual ( troy . state . name , u'<STR_LIT>' ) </s>
