<s> import django <EOL> from django . db import connection <EOL> from django . db . models import Count <EOL> from django . db . models . query_utils import Q <EOL> from django . utils import translation <EOL> from hvad . test_utils . data import NORMAL , STANDARD <EOL> from hvad . test_utils . testcase import HvadTestCase , minimumDjangoVersion <EOL> from hvad . test_utils . project . app . models import Normal , AggregateModel , Standard , SimpleRelated <EOL> from hvad . test_utils . fixtures import NormalFixture , StandardFixture <EOL> class FilterTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_simple_filter ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . filter ( shared_field__contains = '<STR_LIT:2>' ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . shared_field , NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . filter ( shared_field__contains = '<STR_LIT:1>' ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_translated_filter ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . filter ( translated_field__contains = '<STR_LIT>' ) <EOL> self . assertEqual ( qs . count ( ) , self . normal_count ) <EOL> obj1 , obj2 = qs <EOL> self . assertEqual ( obj1 . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( obj1 . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( obj2 . shared_field , NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> self . assertEqual ( obj2 . translated_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_fallbacks_filter ( self ) : <EOL> ( Normal . objects . language ( '<STR_LIT>' ) <EOL> . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> . delete_translations ( ) ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) . fallbacks ( ) <EOL> with self . assertNumQueries ( <NUM_LIT:2> ) : <EOL> self . assertEqual ( qs . count ( ) , self . normal_count ) <EOL> self . assertEqual ( len ( qs ) , self . normal_count ) <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> self . assertCountEqual ( ( obj . pk for obj in qs ) , tuple ( self . normal_id . values ( ) ) ) <EOL> self . assertCountEqual ( ( obj . language_code for obj in qs ) , self . translations ) <EOL> def test_all_languages_filter ( self ) : <EOL> with self . assertNumQueries ( <NUM_LIT:2> ) : <EOL> qs = Normal . objects . language ( '<STR_LIT:all>' ) . filter ( shared_field__contains = '<STR_LIT>' ) <EOL> self . assertEqual ( qs . count ( ) , self . normal_count * len ( self . translations ) ) <EOL> self . assertCountEqual ( ( obj . shared_field for obj in qs ) , <EOL> ( NORMAL [ <NUM_LIT:1> ] . shared_field , <EOL> NORMAL [ <NUM_LIT:2> ] . shared_field ) * <NUM_LIT:2> ) <EOL> self . assertCountEqual ( ( obj . translated_field for obj in qs ) , <EOL> ( NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] , <EOL> NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] , <EOL> NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] , <EOL> NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) ) <EOL> with self . assertNumQueries ( <NUM_LIT:2> ) : <EOL> qs = Normal . objects . language ( '<STR_LIT:all>' ) . filter ( translated_field__contains = '<STR_LIT>' ) <EOL> self . assertEqual ( qs . count ( ) , self . normal_count ) <EOL> self . assertCountEqual ( ( obj . shared_field for obj in qs ) , <EOL> ( NORMAL [ <NUM_LIT:1> ] . shared_field , <EOL> NORMAL [ <NUM_LIT:2> ] . shared_field ) ) <EOL> self . assertCountEqual ( ( obj . translated_field for obj in qs ) , <EOL> ( NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] , <EOL> NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) ) <EOL> with self . assertNumQueries ( <NUM_LIT:2> ) : <EOL> qs = Normal . objects . language ( '<STR_LIT:all>' ) . filter ( translated_field__contains = '<STR_LIT:1>' ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_deferred_language_filter ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) . filter ( translated_field__contains = '<STR_LIT>' ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> self . assertEqual ( qs . count ( ) , self . normal_count ) <EOL> obj1 , obj2 = qs <EOL> self . assertEqual ( obj1 . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( obj1 . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( obj2 . shared_field , NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> self . assertEqual ( obj2 . translated_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> class ExtraTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_simple_extra ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . extra ( select = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( qs . count ( ) , self . normal_count ) <EOL> self . assertEqual ( int ( qs [ <NUM_LIT:0> ] . test_extra ) , <NUM_LIT:4> ) <EOL> class QueryCachingTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def _try_all_cache_using_methods ( self , qs , length ) : <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> x = <NUM_LIT:0> <EOL> for obj in qs : x += <NUM_LIT:1> <EOL> self . assertEqual ( x , length ) <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> qs [ <NUM_LIT:0> ] <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> self . assertEqual ( qs . exists ( ) , length != <NUM_LIT:0> ) <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> self . assertEqual ( qs . count ( ) , length ) <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> self . assertEqual ( len ( qs ) , length ) <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> self . assertEqual ( bool ( qs ) , length != <NUM_LIT:0> ) <EOL> def test_iter_caches ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> index = <NUM_LIT:0> <EOL> qs = Normal . objects . language ( ) . filter ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> for obj in qs : <EOL> index += <NUM_LIT:1> <EOL> self . assertEqual ( index , <NUM_LIT:1> ) <EOL> self . _try_all_cache_using_methods ( qs , <NUM_LIT:1> ) <EOL> def test_pickling_caches ( self ) : <EOL> import pickle <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) . filter ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> pickle . dumps ( qs ) <EOL> self . _try_all_cache_using_methods ( qs , <NUM_LIT:1> ) <EOL> def test_len_caches ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) . filter ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( len ( qs ) , <NUM_LIT:1> ) <EOL> self . _try_all_cache_using_methods ( qs , <NUM_LIT:1> ) <EOL> def test_bool_caches ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) . filter ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> self . assertTrue ( qs ) <EOL> self . _try_all_cache_using_methods ( qs , <NUM_LIT:1> ) <EOL> class IterTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_simple_iter ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> for index , obj in enumerate ( Normal . objects . language ( ) , <NUM_LIT:1> ) : <EOL> self . assertEqual ( obj . shared_field , NORMAL [ index ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ index ] . translated_field [ '<STR_LIT>' ] ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> for index , obj in enumerate ( Normal . objects . language ( ) , <NUM_LIT:1> ) : <EOL> self . assertEqual ( obj . shared_field , NORMAL [ index ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ index ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_iter_unique_reply ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> self . assertEqual ( len ( Normal . objects . all ( ) ) , len ( Normal . objects . untranslated ( ) ) ) <EOL> def test_iter_deferred_language ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> for index , obj in enumerate ( qs , <NUM_LIT:1> ) : <EOL> self . assertEqual ( obj . shared_field , NORMAL [ index ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ index ] . translated_field [ '<STR_LIT>' ] ) <EOL> class UpdateTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_update_shared ( self ) : <EOL> NEW_SHARED = '<STR_LIT>' <EOL> n1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> n2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> ja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> ja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> with self . assertNumQueries ( <NUM_LIT:1> if connection . features . update_can_self_select else <NUM_LIT:2> ) : <EOL> Normal . objects . language ( '<STR_LIT>' ) . update ( shared_field = NEW_SHARED ) <EOL> new1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> new2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( new1 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( new1 . translated_field , n1 . translated_field ) <EOL> self . assertEqual ( new2 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( new2 . translated_field , n2 . translated_field ) <EOL> newja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> newja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( newja1 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( newja2 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( newja1 . translated_field , ja1 . translated_field ) <EOL> self . assertEqual ( newja2 . translated_field , ja2 . translated_field ) <EOL> def test_update_translated ( self ) : <EOL> NEW_TRANSLATED = '<STR_LIT>' <EOL> n1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> n2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> ja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> ja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> Normal . objects . language ( '<STR_LIT>' ) . update ( translated_field = NEW_TRANSLATED ) <EOL> new1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> new2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( new1 . shared_field , n1 . shared_field ) <EOL> self . assertEqual ( new2 . shared_field , n2 . shared_field ) <EOL> self . assertEqual ( new1 . translated_field , NEW_TRANSLATED ) <EOL> self . assertEqual ( new2 . translated_field , NEW_TRANSLATED ) <EOL> newja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> newja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( newja1 . shared_field , ja1 . shared_field ) <EOL> self . assertEqual ( newja2 . shared_field , ja2 . shared_field ) <EOL> self . assertEqual ( newja1 . translated_field , ja1 . translated_field ) <EOL> self . assertEqual ( newja2 . translated_field , ja2 . translated_field ) <EOL> def test_update_mixed ( self ) : <EOL> NEW_SHARED = '<STR_LIT>' <EOL> NEW_TRANSLATED = '<STR_LIT>' <EOL> ja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> ja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> with self . assertNumQueries ( <NUM_LIT:2> if connection . features . update_can_self_select else <NUM_LIT:3> ) : <EOL> Normal . objects . language ( '<STR_LIT>' ) . update ( <EOL> shared_field = NEW_SHARED , translated_field = NEW_TRANSLATED <EOL> ) <EOL> new1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> new2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( new1 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( new1 . translated_field , NEW_TRANSLATED ) <EOL> self . assertEqual ( new2 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( new2 . translated_field , NEW_TRANSLATED ) <EOL> newja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> newja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( newja1 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( newja2 . shared_field , NEW_SHARED ) <EOL> self . assertEqual ( newja1 . translated_field , ja1 . translated_field ) <EOL> self . assertEqual ( newja2 . translated_field , ja2 . translated_field ) <EOL> def test_update_deferred_language ( self ) : <EOL> NEW_TRANSLATED = '<STR_LIT>' <EOL> n1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> n2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> ja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> ja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> qs . update ( translated_field = NEW_TRANSLATED ) <EOL> new1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> new2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( new1 . shared_field , n1 . shared_field ) <EOL> self . assertEqual ( new2 . shared_field , n2 . shared_field ) <EOL> self . assertEqual ( new1 . translated_field , NEW_TRANSLATED ) <EOL> self . assertEqual ( new2 . translated_field , NEW_TRANSLATED ) <EOL> newja1 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:1> ] ) <EOL> newja2 = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = self . normal_id [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( newja1 . shared_field , ja1 . shared_field ) <EOL> self . assertEqual ( newja2 . shared_field , ja2 . shared_field ) <EOL> self . assertEqual ( newja1 . translated_field , ja1 . translated_field ) <EOL> self . assertEqual ( newja2 . translated_field , ja2 . translated_field ) <EOL> def test_update_fallbacks ( self ) : <EOL> qs = Normal . objects . language ( ) . fallbacks ( ) <EOL> with self . assertNumQueries ( <NUM_LIT:1> if connection . features . update_can_self_select else <NUM_LIT:2> ) : <EOL> qs . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) . update ( shared_field = '<STR_LIT>' ) <EOL> self . assertEqual ( Normal . objects . language ( '<STR_LIT>' ) . get ( shared_field = '<STR_LIT>' ) . pk , self . normal_id [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( Normal . objects . language ( '<STR_LIT>' ) . get ( shared_field = '<STR_LIT>' ) . pk , self . normal_id [ <NUM_LIT:1> ] ) <EOL> class ValuesListTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_values_list_translated ( self ) : <EOL> values = Normal . objects . language ( '<STR_LIT>' ) . values_list ( '<STR_LIT>' , flat = True ) <EOL> values_list = list ( values ) <EOL> self . assertCountEqual ( values_list , [ NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] , <EOL> NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ] ) <EOL> def test_values_list_shared ( self ) : <EOL> values = Normal . objects . language ( '<STR_LIT>' ) . values_list ( '<STR_LIT>' , flat = True ) <EOL> values_list = list ( values ) <EOL> self . assertCountEqual ( values_list , [ NORMAL [ <NUM_LIT:1> ] . shared_field , <EOL> NORMAL [ <NUM_LIT:2> ] . shared_field ] ) <EOL> def test_values_list_mixed ( self ) : <EOL> values = Normal . objects . language ( '<STR_LIT>' ) . values_list ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> ( NORMAL [ <NUM_LIT:1> ] . shared_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) , <EOL> ( NORMAL [ <NUM_LIT:2> ] . shared_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_list_deferred_language ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> values = qs . values_list ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> ( NORMAL [ <NUM_LIT:1> ] . shared_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) , <EOL> ( NORMAL [ <NUM_LIT:2> ] . shared_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_list_language_all ( self ) : <EOL> values = ( Normal . objects . language ( '<STR_LIT:all>' ) . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> . values_list ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> ( NORMAL [ <NUM_LIT:1> ] . shared_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) , <EOL> ( NORMAL [ <NUM_LIT:1> ] . shared_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> class ValuesTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_values_shared ( self ) : <EOL> values = Normal . objects . language ( '<STR_LIT>' ) . values ( '<STR_LIT>' ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . shared_field } , <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:2> ] . shared_field } , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_translated ( self ) : <EOL> values = Normal . objects . language ( '<STR_LIT>' ) . values ( '<STR_LIT>' ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] } , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_mixed ( self ) : <EOL> values = Normal . objects . language ( '<STR_LIT>' ) . values ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . shared_field } , <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : NORMAL [ <NUM_LIT:2> ] . shared_field } , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_post_language ( self ) : <EOL> values = Normal . objects . language ( ) . values ( '<STR_LIT>' ) . language ( '<STR_LIT>' ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . shared_field } , <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:2> ] . shared_field } , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_post_filter ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . values ( '<STR_LIT>' ) <EOL> values = qs . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . shared_field } , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_deferred_language ( self ) : <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> values = qs . values ( '<STR_LIT>' ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] } , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> def test_values_language_all ( self ) : <EOL> values = ( Normal . objects . language ( '<STR_LIT:all>' ) . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> . values ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> values_list = list ( values ) <EOL> check = [ <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . shared_field , <EOL> '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] } , <EOL> { '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . shared_field , <EOL> '<STR_LIT>' : NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] } , <EOL> ] <EOL> self . assertCountEqual ( values_list , check ) <EOL> class InBulkTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_empty_in_bulk ( self ) : <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> result = Normal . objects . language ( '<STR_LIT>' ) . in_bulk ( [ ] ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:0> ) <EOL> def test_in_bulk ( self ) : <EOL> pk1 , pk2 = self . normal_id [ <NUM_LIT:1> ] , self . normal_id [ <NUM_LIT:2> ] <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> result = Normal . objects . language ( '<STR_LIT>' ) . in_bulk ( [ pk1 , pk2 ] ) <EOL> self . assertCountEqual ( ( pk1 , pk2 ) , result ) <EOL> self . assertEqual ( result [ pk1 ] . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( result [ pk1 ] . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ pk1 ] . language_code , '<STR_LIT>' ) <EOL> self . assertEqual ( result [ pk2 ] . shared_field , NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> self . assertEqual ( result [ pk2 ] . translated_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ pk2 ] . language_code , '<STR_LIT>' ) <EOL> def test_untranslated_in_bulk ( self ) : <EOL> pk1 = self . normal_id [ <NUM_LIT:1> ] <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> with self . assertNumQueries ( <NUM_LIT:2> ) : <EOL> result = Normal . objects . untranslated ( ) . in_bulk ( [ pk1 ] ) <EOL> self . assertCountEqual ( ( pk1 , ) , result ) <EOL> self . assertEqual ( result [ pk1 ] . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( result [ pk1 ] . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ pk1 ] . language_code , '<STR_LIT>' ) <EOL> def test_fallbacks_in_bulk ( self ) : <EOL> ( Normal . objects . language ( '<STR_LIT>' ) <EOL> . filter ( shared_field = NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> . delete_translations ( ) ) <EOL> with self . assertNumQueries ( <NUM_LIT:1> ) : <EOL> pk1 , pk2 = self . normal_id [ <NUM_LIT:1> ] , self . normal_id [ <NUM_LIT:2> ] <EOL> result = Normal . objects . language ( '<STR_LIT>' ) . fallbacks ( '<STR_LIT>' , '<STR_LIT>' ) . in_bulk ( [ pk1 , pk2 ] ) <EOL> self . assertCountEqual ( ( pk1 , pk2 ) , result ) <EOL> self . assertEqual ( result [ pk1 ] . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( result [ pk1 ] . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ pk1 ] . language_code , '<STR_LIT>' ) <EOL> self . assertEqual ( result [ pk2 ] . shared_field , NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> self . assertEqual ( result [ pk2 ] . translated_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ pk2 ] . language_code , '<STR_LIT>' ) <EOL> def test_all_languages_in_bulk ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> Normal . objects . language ( '<STR_LIT:all>' ) . in_bulk ( [ self . normal_id [ <NUM_LIT:1> ] ] ) <EOL> def test_in_bulk_deferred_language ( self ) : <EOL> pk1 = self . normal_id [ <NUM_LIT:1> ] <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> result = qs . in_bulk ( [ pk1 ] ) <EOL> self . assertCountEqual ( ( pk1 , ) , result ) <EOL> self . assertEqual ( result [ pk1 ] . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( result [ pk1 ] . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ pk1 ] . language_code , '<STR_LIT>' ) <EOL> class DeleteTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> def test_delete_all ( self ) : <EOL> Normal . objects . all ( ) . delete ( ) <EOL> self . assertEqual ( Normal . objects . count ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_delete_translation ( self ) : <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:4> ) <EOL> Normal . objects . language ( '<STR_LIT>' ) . delete_translations ( ) <EOL> self . assertEqual ( Normal . objects . untranslated ( ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:2> ) <EOL> Normal . objects . language ( '<STR_LIT>' ) . delete_translations ( ) <EOL> self . assertEqual ( Normal . objects . untranslated ( ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_filtered_delete_translation ( self ) : <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:4> ) <EOL> ( Normal . objects . language ( '<STR_LIT>' ) <EOL> . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> . delete_translations ( ) ) <EOL> self . assertEqual ( Normal . objects . untranslated ( ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:3> ) <EOL> ( Normal . objects . language ( '<STR_LIT>' ) <EOL> . filter ( translated_field = NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> . delete_translations ( ) ) <EOL> self . assertEqual ( Normal . objects . untranslated ( ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:2> ) <EOL> def test_delete_translation_deferred_language ( self ) : <EOL> self . assertEqual ( Normal . _meta . translations_model . objects . count ( ) , <NUM_LIT:4> ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = Normal . objects . language ( ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs . delete_translations ( ) <EOL> self . assertEqual ( Normal . objects . language ( '<STR_LIT>' ) . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( Normal . objects . language ( '<STR_LIT>' ) . count ( ) , <NUM_LIT:0> ) <EOL> def test_delete_fallbacks ( self ) : <EOL> qs = Normal . objects . language ( ) . fallbacks ( ) <EOL> qs . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) . delete ( ) <EOL> self . assertEqual ( Normal . objects . language ( '<STR_LIT>' ) . count ( ) , self . normal_count - <NUM_LIT:1> ) <EOL> self . assertEqual ( Normal . objects . language ( '<STR_LIT>' ) . count ( ) , self . normal_count - <NUM_LIT:1> ) <EOL> class GetTranslationFromInstanceTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:1> <EOL> def test_simple ( self ) : <EOL> en = Normal . objects . language ( '<STR_LIT>' ) . get ( ) <EOL> ja_trans = en . translations . get_language ( '<STR_LIT>' ) <EOL> ja = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = en . pk ) <EOL> self . assertEqual ( en . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( en . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( AttributeError , getattr , ja_trans , '<STR_LIT>' ) <EOL> self . assertEqual ( ja_trans . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( ja . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( ja . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_cached ( self ) : <EOL> en = Normal . objects . untranslated ( ) . prefetch_related ( '<STR_LIT>' ) . get ( ) <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> ja_trans = en . translations . get_language ( '<STR_LIT>' ) <EOL> ja = Normal . objects . language ( '<STR_LIT>' ) . get ( pk = en . pk ) <EOL> self . assertEqual ( en . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( en . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( AttributeError , getattr , ja_trans , '<STR_LIT>' ) <EOL> self . assertEqual ( ja_trans . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( ja . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( ja . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_not_exist ( self ) : <EOL> en = Normal . objects . untranslated ( ) . get ( ) <EOL> with self . assertRaises ( Normal . DoesNotExist ) : <EOL> en . translations . get_language ( '<STR_LIT>' ) <EOL> en = Normal . objects . untranslated ( ) . prefetch_related ( '<STR_LIT>' ) . get ( ) <EOL> with self . assertRaises ( Normal . DoesNotExist ) : <EOL> en . translations . get_language ( '<STR_LIT>' ) <EOL> class AggregateTests ( HvadTestCase ) : <EOL> def test_aggregate ( self ) : <EOL> from django . db . models import Avg <EOL> AggregateModel . objects . language ( "<STR_LIT>" ) . create ( number = <NUM_LIT:10> , translated_number = <NUM_LIT:20> ) <EOL> AggregateModel . objects . language ( "<STR_LIT>" ) . create ( number = <NUM_LIT:0> , translated_number = <NUM_LIT:0> ) <EOL> self . assertEqual ( AggregateModel . objects . language ( "<STR_LIT>" ) . aggregate ( Avg ( "<STR_LIT>" ) ) , { '<STR_LIT>' : <NUM_LIT:5> } ) <EOL> self . assertEqual ( AggregateModel . objects . language ( "<STR_LIT>" ) . aggregate ( Avg ( "<STR_LIT>" ) ) , { '<STR_LIT>' : <NUM_LIT:10> } ) <EOL> self . assertEqual ( AggregateModel . objects . language ( "<STR_LIT>" ) . aggregate ( num = Avg ( "<STR_LIT>" ) ) , { '<STR_LIT>' : <NUM_LIT:5> } ) <EOL> self . assertEqual ( AggregateModel . objects . language ( "<STR_LIT>" ) . aggregate ( tnum = Avg ( "<STR_LIT>" ) ) , { '<STR_LIT>' : <NUM_LIT:10> } ) <EOL> class AnnotateTests ( HvadTestCase , StandardFixture , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> standard_count = <NUM_LIT:4> <EOL> def test_annotate ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . annotate ( Count ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( qs ) , self . normal_count ) <EOL> self . assertEqual ( qs [ <NUM_LIT:0> ] . standards__count , <NUM_LIT:2> ) <EOL> self . assertEqual ( qs [ <NUM_LIT:1> ] . standards__count , <NUM_LIT:2> ) <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . annotate ( foo = Count ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( qs ) , self . normal_count ) <EOL> self . assertEqual ( qs [ <NUM_LIT:0> ] . foo , <NUM_LIT:2> ) <EOL> self . assertEqual ( qs [ <NUM_LIT:1> ] . foo , <NUM_LIT:2> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . annotate ( Count ( '<STR_LIT>' ) , standards__count = Count ( '<STR_LIT>' ) ) <EOL> class NotImplementedTests ( HvadTestCase ) : <EOL> def test_notimplemented ( self ) : <EOL> baseqs = SimpleRelated . objects . language ( '<STR_LIT>' ) <EOL> self . assertRaises ( NotImplementedError , baseqs . defer , '<STR_LIT>' ) <EOL> self . assertRaises ( NotImplementedError , baseqs . only ) <EOL> self . assertRaises ( NotImplementedError , baseqs . bulk_create , [ ] ) <EOL> self . assertRaises ( NotImplementedError , baseqs . select_related ) <EOL> if django . VERSION >= ( <NUM_LIT:1> , <NUM_LIT:7> ) : <EOL> self . assertRaises ( NotImplementedError , baseqs . update_or_create ) <EOL> class MinimumVersionTests ( HvadTestCase ) : <EOL> def test_versions ( self ) : <EOL> qs = SimpleRelated . objects . language ( '<STR_LIT>' ) <EOL> if django . VERSION < ( <NUM_LIT:1> , <NUM_LIT:7> ) : <EOL> self . assertRaises ( AttributeError , getattr , qs , '<STR_LIT>' ) <EOL> class ExcludeTests ( HvadTestCase , NormalFixture ) : <EOL> normal_count = <NUM_LIT:1> <EOL> def test_defer ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . exclude ( translated_field = NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:0> ) <EOL> def test_fallbacks_exclude ( self ) : <EOL> ( Normal . objects . language ( '<STR_LIT>' ) <EOL> . filter ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> . delete_translations ( ) ) <EOL> qs = ( Normal . objects . language ( '<STR_LIT>' ) <EOL> . fallbacks ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> . exclude ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:0> ) <EOL> def test_all_languages_exclude ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT:all>' ) . exclude ( translated_field = NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( qs [ <NUM_LIT:0> ] . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_invalid_all_languages_exclude ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> Normal . objects . language ( ) . exclude ( language_code = '<STR_LIT:all>' ) <EOL> class ComplexFilterTests ( HvadTestCase , StandardFixture , NormalFixture ) : <EOL> normal_count = <NUM_LIT:2> <EOL> standard_count = <NUM_LIT:2> <EOL> def test_qobject_filter ( self ) : <EOL> shared_contains_one = Q ( shared_field__contains = '<STR_LIT:1>' ) <EOL> shared_contains_two = Q ( shared_field__contains = '<STR_LIT:2>' ) <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . filter ( shared_contains_two ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . shared_field , NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> qs = ( Normal . objects . language ( '<STR_LIT>' ) . filter ( Q ( shared_contains_one | shared_contains_two ) ) <EOL> . order_by ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . shared_field , NORMAL [ <NUM_LIT:1> ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ <NUM_LIT:1> ] . translated_field [ '<STR_LIT>' ] ) <EOL> obj = qs [ <NUM_LIT:1> ] <EOL> self . assertEqual ( obj . shared_field , NORMAL [ <NUM_LIT:2> ] . shared_field ) <EOL> self . assertEqual ( obj . translated_field , NORMAL [ <NUM_LIT:2> ] . translated_field [ '<STR_LIT>' ] ) <EOL> def test_aware_qobject_filter ( self ) : <EOL> from hvad . utils import get_translation_aware_manager <EOL> manager = get_translation_aware_manager ( Standard ) <EOL> normal_one = Q ( normal_field = STANDARD [ <NUM_LIT:1> ] . normal_field ) <EOL> normal_two = Q ( normal_field = STANDARD [ <NUM_LIT:2> ] . normal_field ) <EOL> shared_one = Q ( normal__shared_field = NORMAL [ STANDARD [ <NUM_LIT:1> ] . normal ] . shared_field ) <EOL> translated_one_en = Q ( normal__translated_field = NORMAL [ STANDARD [ <NUM_LIT:1> ] . normal ] . translated_field [ '<STR_LIT>' ] ) <EOL> translated_two_en = Q ( normal__translated_field = NORMAL [ STANDARD [ <NUM_LIT:2> ] . normal ] . translated_field [ '<STR_LIT>' ] ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> qs = manager . filter ( shared_one ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . normal_field , STANDARD [ <NUM_LIT:1> ] . normal_field ) <EOL> qs = manager . filter ( translated_one_en ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . normal_field , STANDARD [ <NUM_LIT:1> ] . normal_field ) <EOL> qs = manager . filter ( Q ( normal_one & shared_one & translated_one_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> self . assertEqual ( obj . normal_field , STANDARD [ <NUM_LIT:1> ] . normal_field ) <EOL> qs = manager . filter ( Q ( normal_one & translated_two_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:0> ) <EOL> qs = manager . filter ( Q ( shared_one & translated_two_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:0> ) <EOL> qs = manager . filter ( Q ( translated_one_en & translated_two_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:0> ) <EOL> qs = manager . filter ( Q ( normal_one | translated_one_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> qs = manager . filter ( Q ( shared_one | translated_one_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> qs = manager . filter ( Q ( normal_one | translated_two_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> qs = manager . filter ( Q ( shared_one | translated_two_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> qs = manager . filter ( Q ( translated_one_en | translated_two_en ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:2> ) <EOL> qs = manager . filter ( Q ( normal_one & ( translated_one_en | translated_two_en ) ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> qs = manager . filter ( Q ( normal_two & ( translated_one_en | translated_two_en ) ) ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> qs = manager . filter ( shared_one & ~ translated_one_en ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:0> ) <EOL> qs = manager . filter ( shared_one & ~ translated_two_en ) <EOL> self . assertEqual ( qs . count ( ) , <NUM_LIT:1> ) <EOL> def test_defer ( self ) : <EOL> qs = Normal . objects . language ( '<STR_LIT>' ) . complex_filter ( { } ) <EOL> self . assertEqual ( qs . count ( ) , self . normal_count ) <EOL> self . assertRaises ( NotImplementedError , <EOL> Normal . objects . language ( '<STR_LIT>' ) . complex_filter , <EOL> Q ( shared_field = NORMAL [ <NUM_LIT:1> ] . shared_field ) ) </s>
