<s> """<STR_LIT>""" <EOL> from sqlalchemy . orm import * <EOL> from sqlalchemy import * <EOL> from elixir import * <EOL> class TestSQLAlchemyToElixir ( object ) : <EOL> def setup ( self ) : <EOL> metadata . bind = "<STR_LIT>" <EOL> def teardown ( self ) : <EOL> cleanup_all ( True ) <EOL> def test_simple ( self ) : <EOL> class A ( Entity ) : <EOL> name = Field ( String ( <NUM_LIT> ) ) <EOL> setup_all ( True ) <EOL> b_table = Table ( '<STR_LIT:b>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT> ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( A . id ) ) <EOL> ) <EOL> b_table . create ( ) <EOL> class B ( object ) : <EOL> pass <EOL> mapper ( B , b_table , properties = { <EOL> '<STR_LIT:a>' : relation ( A ) <EOL> } ) <EOL> b1 = B ( ) <EOL> b1 . name = '<STR_LIT>' <EOL> b1 . a = A ( name = '<STR_LIT>' ) <EOL> session . add ( b1 ) <EOL> session . commit ( ) <EOL> session . expunge_all ( ) <EOL> b = session . query ( B ) . one ( ) <EOL> assert b . a . name == '<STR_LIT>' <EOL> class TestElixirToSQLAlchemy ( object ) : <EOL> def setup ( self ) : <EOL> metadata . bind = "<STR_LIT>" <EOL> def teardown ( self ) : <EOL> cleanup_all ( True ) <EOL> def test_m2o ( self ) : <EOL> a_table = Table ( '<STR_LIT:a>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT> ) ) , <EOL> ) <EOL> a_table . create ( ) <EOL> class A ( object ) : <EOL> pass <EOL> mapper ( A , a_table ) <EOL> class B ( Entity ) : <EOL> name = Field ( String ( <NUM_LIT> ) ) <EOL> a = ManyToOne ( A ) <EOL> setup_all ( True ) <EOL> a1 = A ( ) <EOL> a1 . name = '<STR_LIT>' <EOL> b1 = B ( name = '<STR_LIT>' , a = a1 ) <EOL> session . add ( b1 ) <EOL> session . commit ( ) <EOL> session . expunge_all ( ) <EOL> b = B . query . one ( ) <EOL> assert b . a . name == '<STR_LIT>' <EOL> def test_m2o_non_pk_target ( self ) : <EOL> a_table = Table ( '<STR_LIT:a>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT> ) , unique = True ) <EOL> ) <EOL> a_table . create ( ) <EOL> class A ( object ) : <EOL> pass <EOL> mapper ( A , a_table ) <EOL> class B ( Entity ) : <EOL> name = Field ( String ( <NUM_LIT> ) ) <EOL> a = ManyToOne ( A , target_column = [ '<STR_LIT:name>' ] ) <EOL> setup_all ( True ) <EOL> a1 = A ( ) <EOL> a1 . name = '<STR_LIT>' <EOL> b1 = B ( name = '<STR_LIT>' , a = a1 ) <EOL> session . commit ( ) <EOL> session . expunge_all ( ) <EOL> b = B . query . one ( ) <EOL> assert b . a . name == '<STR_LIT>' </s>
