<s> from nose . tools import eq_ , ok_ <EOL> from . import setup <EOL> from . test_basic import CustomModelView <EOL> from flask_sqlalchemy import Model <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> def test_multiple_pk ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Model ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> id2 = db . Column ( db . String ( <NUM_LIT:20> ) , primary_key = True ) <EOL> test = db . Column ( db . String ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model , db . session , form_columns = [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT:test>' ] ) <EOL> admin . add_view ( view ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . post ( '<STR_LIT>' , <EOL> data = dict ( id = <NUM_LIT:1> , id2 = '<STR_LIT>' , test = '<STR_LIT>' ) ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> def test_joined_inheritance ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Parent ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> test = db . Column ( db . String ) <EOL> discriminator = db . Column ( '<STR_LIT:type>' , db . String ( <NUM_LIT:50> ) ) <EOL> __mapper_args__ = { '<STR_LIT>' : discriminator } <EOL> class Child ( Parent ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> __mapper_args__ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> id = db . Column ( db . ForeignKey ( Parent . id ) , primary_key = True ) <EOL> name = db . Column ( db . String ( <NUM_LIT:100> ) ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Child , db . session , form_columns = [ '<STR_LIT:id>' , '<STR_LIT:test>' , '<STR_LIT:name>' ] ) <EOL> admin . add_view ( view ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . post ( '<STR_LIT>' , <EOL> data = dict ( id = <NUM_LIT:1> , test = '<STR_LIT:foo>' , name = '<STR_LIT:bar>' ) ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT:foo>' in data ) <EOL> ok_ ( '<STR_LIT:bar>' in data ) <EOL> def test_single_table_inheritance ( ) : <EOL> app , db , admin = setup ( ) <EOL> CustomModel = declarative_base ( Model , name = '<STR_LIT>' ) <EOL> class Parent ( CustomModel ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> test = db . Column ( db . String ) <EOL> discriminator = db . Column ( '<STR_LIT:type>' , db . String ( <NUM_LIT:50> ) ) <EOL> __mapper_args__ = { '<STR_LIT>' : discriminator } <EOL> class Child ( Parent ) : <EOL> __mapper_args__ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> name = db . Column ( db . String ( <NUM_LIT:100> ) ) <EOL> CustomModel . metadata . create_all ( db . engine ) <EOL> view = CustomModelView ( Child , db . session , form_columns = [ '<STR_LIT:id>' , '<STR_LIT:test>' , '<STR_LIT:name>' ] ) <EOL> admin . add_view ( view ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . post ( '<STR_LIT>' , <EOL> data = dict ( id = <NUM_LIT:1> , test = '<STR_LIT:foo>' , name = '<STR_LIT:bar>' ) ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT:foo>' in data ) <EOL> ok_ ( '<STR_LIT:bar>' in data ) <EOL> def test_concrete_table_inheritance ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Parent ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> test = db . Column ( db . String ) <EOL> class Child ( Parent ) : <EOL> __mapper_args__ = { '<STR_LIT>' : True } <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> name = db . Column ( db . String ( <NUM_LIT:100> ) ) <EOL> test = db . Column ( db . String ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Child , db . session , form_columns = [ '<STR_LIT:id>' , '<STR_LIT:test>' , '<STR_LIT:name>' ] ) <EOL> admin . add_view ( view ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . post ( '<STR_LIT>' , <EOL> data = dict ( id = <NUM_LIT:1> , test = '<STR_LIT:foo>' , name = '<STR_LIT:bar>' ) ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT:foo>' in data ) <EOL> ok_ ( '<STR_LIT:bar>' in data ) <EOL> def test_concrete_multipk_inheritance ( ) : <EOL> app , db , admin = setup ( ) <EOL> class Parent ( db . Model ) : <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> test = db . Column ( db . String ) <EOL> class Child ( Parent ) : <EOL> __mapper_args__ = { '<STR_LIT>' : True } <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> id2 = db . Column ( db . Integer , primary_key = True ) <EOL> name = db . Column ( db . String ( <NUM_LIT:100> ) ) <EOL> test = db . Column ( db . String ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Child , db . session , form_columns = [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT:test>' , '<STR_LIT:name>' ] ) <EOL> admin . add_view ( view ) <EOL> client = app . test_client ( ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = client . post ( '<STR_LIT>' , <EOL> data = dict ( id = <NUM_LIT:1> , id2 = <NUM_LIT:2> , test = '<STR_LIT:foo>' , name = '<STR_LIT:bar>' ) ) <EOL> eq_ ( rv . status_code , <NUM_LIT> ) <EOL> rv = client . get ( '<STR_LIT>' ) <EOL> eq_ ( rv . status_code , <NUM_LIT:200> ) <EOL> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT:foo>' in data ) <EOL> ok_ ( '<STR_LIT:bar>' in data ) </s>
