<s> from __future__ import absolute_import <EOL> from django . db . models import Q <EOL> from django . test import TestCase <EOL> from . models import ( SystemDetails , Item , PropertyValue , SystemInfo , Forum , <EOL> Post , Comment ) <EOL> class NullFkTests ( TestCase ) : <EOL> def test_null_fk ( self ) : <EOL> d = SystemDetails . objects . create ( details = '<STR_LIT>' ) <EOL> s = SystemInfo . objects . create ( system_name = '<STR_LIT>' , system_details = d ) <EOL> f = Forum . objects . create ( system_info = s , forum_name = '<STR_LIT>' ) <EOL> p = Post . objects . create ( forum = f , title = '<STR_LIT>' ) <EOL> c1 = Comment . objects . create ( post = p , comment_text = '<STR_LIT>' ) <EOL> c2 = Comment . objects . create ( comment_text = '<STR_LIT>' ) <EOL> c = Comment . objects . select_related ( ) . get ( id = c1 . id ) <EOL> self . assertEqual ( c . post , p ) <EOL> self . assertEqual ( Comment . objects . select_related ( ) . get ( id = c2 . id ) . post , None ) <EOL> self . assertQuerysetEqual ( <EOL> Comment . objects . select_related ( '<STR_LIT>' ) . all ( ) , <EOL> [ <EOL> ( c1 . id , u'<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( c2 . id , u'<STR_LIT>' , '<STR_LIT:None>' ) <EOL> ] , <EOL> transform = lambda c : ( c . id , c . comment_text , repr ( c . post ) ) <EOL> ) <EOL> self . assertTrue ( Comment . objects . select_related ( '<STR_LIT>' ) . filter ( post__isnull = True ) [ <NUM_LIT:0> ] . post is None ) <EOL> self . assertQuerysetEqual ( <EOL> Comment . objects . select_related ( '<STR_LIT>' ) , <EOL> [ <EOL> ( c1 . id , u'<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( c2 . id , u'<STR_LIT>' , '<STR_LIT:None>' ) <EOL> ] , <EOL> transform = lambda c : ( c . id , c . comment_text , repr ( c . post ) ) <EOL> ) <EOL> def test_combine_isnull ( self ) : <EOL> item = Item . objects . create ( title = '<STR_LIT>' ) <EOL> pv = PropertyValue . objects . create ( label = '<STR_LIT>' ) <EOL> item . props . create ( key = '<STR_LIT:a>' , value = pv ) <EOL> item . props . create ( key = '<STR_LIT:b>' ) <EOL> q1 = Q ( props__key = '<STR_LIT:a>' , props__value = pv ) <EOL> q2 = Q ( props__key = '<STR_LIT:b>' , props__value__isnull = True ) <EOL> self . assertEqual ( Item . objects . get ( q1 ) , item ) <EOL> self . assertEqual ( Item . objects . get ( q2 ) , item ) <EOL> qs1 = Item . objects . filter ( q1 ) & Item . objects . filter ( q2 ) <EOL> qs2 = Item . objects . filter ( q2 ) & Item . objects . filter ( q1 ) <EOL> qs3 = Item . objects . filter ( q1 ) | Item . objects . filter ( q2 ) <EOL> qs4 = Item . objects . filter ( q2 ) | Item . objects . filter ( q1 ) <EOL> self . assertEqual ( list ( qs1 ) , list ( qs2 ) ) <EOL> self . assertEqual ( list ( qs3 ) , list ( qs4 ) ) </s>
