<s> import stdnet <EOL> from stdnet import odm , FieldError <EOL> from stdnet . utils import test <EOL> from examples . models import Parent , Child <EOL> class TestForeignKey ( test . TestCase ) : <EOL> models = ( Parent , Child ) <EOL> def test_custom_pk ( self ) : <EOL> models = self . mapper <EOL> parent = yield models . parent . new ( name = '<STR_LIT:test>' ) <EOL> self . assertEqual ( parent . pkvalue ( ) , '<STR_LIT:test>' ) <EOL> self . assertEqual ( parent . pk ( ) . name , '<STR_LIT:name>' ) <EOL> def test_add_parent_and_child ( self ) : <EOL> models = self . mapper <EOL> with models . session ( ) . begin ( ) as t : <EOL> parent = models . parent ( name = '<STR_LIT>' ) <EOL> child = models . child ( parent = parent , name = '<STR_LIT:foo>' ) <EOL> self . assertEqual ( child . parent , parent ) <EOL> self . assertEqual ( child . parent_id , parent . pkvalue ( ) ) <EOL> t . add ( parent ) <EOL> t . add ( child ) <EOL> yield t . on_result <EOL> class TestQuery ( test . TestCase ) : <EOL> models = ( Parent , Child ) <EOL> def test_non_id_pk ( self ) : <EOL> '''<STR_LIT>''' <EOL> models = self . mapper <EOL> with models . session ( ) . begin ( ) as t : <EOL> parent = models . parent ( name = '<STR_LIT>' ) <EOL> child = models . child ( parent = parent , name = '<STR_LIT:foo>' ) <EOL> t . add ( parent ) <EOL> t . add ( child ) <EOL> yield t . on_result <EOL> with models . session ( ) . begin ( ) as t : <EOL> parents = t . query ( Parent ) . all ( ) <EOL> self . assertEqual ( len ( parents ) , <NUM_LIT:1> ) <EOL> yield t . on_result <EOL> class TestManyToMany ( test . TestCase ) : <EOL> models = ( Parent , Child ) <EOL> def test_non_id_pk ( self ) : <EOL> '''<STR_LIT>''' <EOL> models = self . mapper <EOL> with models . session ( ) . begin ( ) as t : <EOL> parent = models . parent ( name = '<STR_LIT>' ) <EOL> uncle = models . parent ( name = '<STR_LIT>' ) <EOL> child = models . child ( parent = parent , name = '<STR_LIT:foo>' ) <EOL> t . add ( parent ) <EOL> t . add ( uncle ) <EOL> t . add ( child ) <EOL> yield t . on_result <EOL> with models . session ( ) . begin ( ) as t : <EOL> child . uncles . add ( uncle ) <EOL> self . assertEqual ( len ( child . uncles . all ( ) ) , <NUM_LIT:1> ) <EOL> yield t . on_result </s>
