<s> from django . test import TestCase <EOL> from django_dynamic_fixture . models_test import EmptyModel , ModelWithRelationships , ModelForLibrary <EOL> from django_dynamic_fixture import N , G , F , C , P , look_up_alias , PRE_SAVE , POST_SAVE <EOL> class NShortcutTest ( TestCase ) : <EOL> def test_shortcut_N ( self ) : <EOL> instance = N ( EmptyModel ) <EOL> self . assertEquals ( None , instance . id ) <EOL> class GShortcutTest ( TestCase ) : <EOL> def test_shortcut_G ( self ) : <EOL> instance = G ( EmptyModel ) <EOL> self . assertNotEquals ( None , instance . id ) <EOL> class PShortcutTest ( TestCase ) : <EOL> def test_accept_model_instance ( self ) : <EOL> P ( N ( EmptyModel ) ) <EOL> P ( G ( EmptyModel ) ) <EOL> def test_accepts_list ( self ) : <EOL> P ( [ N ( EmptyModel ) , G ( EmptyModel ) ] ) <EOL> def test_accepts_tuple ( self ) : <EOL> P ( ( N ( EmptyModel ) , G ( EmptyModel ) ) ) <EOL> def test_accepts_queryset ( self ) : <EOL> P ( EmptyModel . objects . all ( ) ) <EOL> class FShortcutTest ( TestCase ) : <EOL> def test_fk ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = <NUM_LIT:1000> , foreignkey = F ( integer = <NUM_LIT> ) ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . foreignkey . integer ) <EOL> def test_self_fk ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = <NUM_LIT:1000> , selfforeignkey = F ( integer = <NUM_LIT> ) ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . selfforeignkey . integer ) <EOL> def test_o2o ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = <NUM_LIT:1000> , onetoone = F ( integer = <NUM_LIT> ) ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . onetoone . integer ) <EOL> def test_m2m_with_one_element ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = <NUM_LIT:1000> , manytomany = [ F ( integer = <NUM_LIT> ) ] ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:0> ] . integer ) <EOL> def test_m2m_with_many_elements ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = <NUM_LIT:1000> , manytomany = [ F ( integer = <NUM_LIT> ) , F ( integer = <NUM_LIT> ) ] ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:0> ] . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:1> ] . integer ) <EOL> def test_full_example ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = <NUM_LIT:1000> , <EOL> foreignkey = F ( integer = <NUM_LIT> ) , <EOL> selfforeignkey = F ( integer = <NUM_LIT> ) , <EOL> onetoone = F ( integer = <NUM_LIT> ) , <EOL> manytomany = [ F ( integer = <NUM_LIT> ) , F ( integer = <NUM_LIT> ) , F ( selfforeignkey = F ( integer = <NUM_LIT> ) ) ] ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . foreignkey . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . selfforeignkey . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . onetoone . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:0> ] . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:1> ] . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:2> ] . selfforeignkey . integer ) <EOL> def test_using_look_up_alias ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = <NUM_LIT:1000> , <EOL> foreignkey__integer = <NUM_LIT> , <EOL> selfforeignkey__integer = <NUM_LIT> , <EOL> onetoone__integer = <NUM_LIT> , <EOL> manytomany = [ F ( integer = <NUM_LIT> ) , F ( integer = <NUM_LIT> ) , F ( selfforeignkey__integer = <NUM_LIT> ) ] ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . foreignkey . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . selfforeignkey . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . onetoone . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:0> ] . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:1> ] . integer ) <EOL> self . assertEquals ( <NUM_LIT> , instance . manytomany . all ( ) [ <NUM_LIT:2> ] . selfforeignkey . integer ) <EOL> class CShortcutTest ( TestCase ) : <EOL> def test_copying_from_the_same_model ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = C ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( instance . integer , instance . integer_b ) <EOL> def test_copying_from_a_fk ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = C ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( instance . integer , instance . foreignkey . integer ) <EOL> def test_copying_from_a_one2one ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = C ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( instance . integer , instance . onetoone . integer ) <EOL> def test_copying_from_a_self_fk ( self ) : <EOL> instance = G ( ModelWithRelationships , integer = C ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( instance . integer , instance . selfforeignkey . integer_b ) <EOL> def test_copying_inside_fk ( self ) : <EOL> instance = G ( ModelWithRelationships , selfforeignkey = F ( integer = C ( '<STR_LIT>' ) ) ) <EOL> self . assertEquals ( instance . selfforeignkey . integer , instance . selfforeignkey . selfforeignkey . integer_b ) <EOL> def test_copying_inside_many_to_many ( self ) : <EOL> instance = G ( ModelWithRelationships , manytomany = [ F ( integer = C ( '<STR_LIT>' ) ) ] ) <EOL> instance1 = instance . manytomany . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEquals ( instance1 . integer , instance1 . integer_b ) <EOL> class ShelveAndLibraryTest ( TestCase ) : <EOL> def test_shelve ( self ) : <EOL> instance = G ( ModelForLibrary , integer = <NUM_LIT:1000> , shelve = True ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> instance = G ( ModelForLibrary , use_library = False ) <EOL> self . assertNotEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> instance = G ( ModelForLibrary , use_library = True ) <EOL> self . assertEquals ( <NUM_LIT:1000> , instance . integer ) <EOL> instance = G ( ModelForLibrary , integer = <NUM_LIT> , use_library = True ) <EOL> self . assertEquals ( <NUM_LIT> , instance . integer ) <EOL> class CreatingMultipleObjectsTest ( TestCase ) : <EOL> def test_new ( self ) : <EOL> self . assertEquals ( [ ] , N ( EmptyModel , n = <NUM_LIT:0> ) ) <EOL> self . assertEquals ( [ ] , N ( EmptyModel , n = - <NUM_LIT:1> ) ) <EOL> self . assertTrue ( isinstance ( N ( EmptyModel ) , EmptyModel ) ) <EOL> self . assertTrue ( isinstance ( N ( EmptyModel , n = <NUM_LIT:1> ) , EmptyModel ) ) <EOL> self . assertEquals ( <NUM_LIT:2> , len ( N ( EmptyModel , n = <NUM_LIT:2> ) ) ) <EOL> def test_get ( self ) : <EOL> self . assertEquals ( [ ] , G ( EmptyModel , n = <NUM_LIT:0> ) ) <EOL> self . assertEquals ( [ ] , G ( EmptyModel , n = - <NUM_LIT:1> ) ) <EOL> self . assertTrue ( isinstance ( G ( EmptyModel ) , EmptyModel ) ) <EOL> self . assertTrue ( isinstance ( G ( EmptyModel , n = <NUM_LIT:1> ) , EmptyModel ) ) <EOL> self . assertEquals ( <NUM_LIT:2> , len ( G ( EmptyModel , n = <NUM_LIT:2> ) ) ) <EOL> class LookUpSeparatorTest ( TestCase ) : <EOL> def test_look_up_alias_with_just_one_parameter ( self ) : <EOL> self . assertEquals ( { '<STR_LIT:a>' : <NUM_LIT:1> } , look_up_alias ( a = <NUM_LIT:1> ) ) <EOL> self . assertEquals ( { '<STR_LIT:a>' : F ( ) } , look_up_alias ( a = F ( ) ) ) <EOL> self . assertEquals ( { '<STR_LIT>' : <NUM_LIT:1> } , look_up_alias ( a_b = <NUM_LIT:1> ) ) <EOL> self . assertEquals ( { '<STR_LIT:a>' : F ( b = <NUM_LIT:1> ) } , look_up_alias ( a__b = <NUM_LIT:1> ) ) <EOL> self . assertEquals ( { '<STR_LIT>' : F ( c = <NUM_LIT:1> ) } , look_up_alias ( a_b__c = <NUM_LIT:1> ) ) <EOL> self . assertEquals ( { '<STR_LIT:a>' : F ( b = F ( c = <NUM_LIT:1> ) ) } , look_up_alias ( a__b__c = <NUM_LIT:1> ) ) <EOL> self . assertEquals ( { '<STR_LIT>' : F ( c_d = F ( e_f = <NUM_LIT:1> ) ) } , look_up_alias ( a_b__c_d__e_f = <NUM_LIT:1> ) ) <EOL> def test_look_up_alias_with_many_parameters ( self ) : <EOL> self . assertEquals ( { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:2> } , look_up_alias ( a = <NUM_LIT:1> , b = <NUM_LIT:2> ) ) <EOL> self . assertEquals ( { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> } , look_up_alias ( a = <NUM_LIT:1> , b_c = <NUM_LIT:2> ) ) <EOL> self . assertEquals ( { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : F ( c = <NUM_LIT:2> ) } , look_up_alias ( a = <NUM_LIT:1> , b__c = <NUM_LIT:2> ) ) <EOL> self . assertEquals ( { '<STR_LIT:a>' : F ( b = <NUM_LIT:1> ) , '<STR_LIT:c>' : F ( d = <NUM_LIT:2> ) } , look_up_alias ( a__b = <NUM_LIT:1> , c__d = <NUM_LIT:2> ) ) <EOL> class PreAndPostSaveTest ( TestCase ) : <EOL> def test_pre_save ( self ) : <EOL> PRE_SAVE ( EmptyModel , lambda x : x ) <EOL> def test_post_save ( self ) : <EOL> POST_SAVE ( EmptyModel , lambda x : x ) </s>
