#NEWLINE# def test_model( ) : #NEWLINE# #INDENT# ( app , db , admin ) = setup ( ) #NEWLINE# ( Model1 , Model2 ) = create_models ( db ) #NEWLINE# db . create_all ( ) #NEWLINE# view = CustomModelView ( Model1 , db . session ) #NEWLINE# admin . add_view ( Model1 ) #NEWLINE# eq_ ( view . model , Model1 ) #NEWLINE# eq_ ( view . name , 'Model1' ) #NEWLINE# eq_ ( view . endpoint , 'model1' ) #NEWLINE# eq_ ( view . _primary_key , 'id' ) #NEWLINE# ok_ ( ( 'test1' in view . _sortable_columns ) ) #NEWLINE# ok_ ( ( 'test2' in view . _sortable_columns ) ) #NEWLINE# ok_ ( ( 'test3' in view . _sortable_columns ) ) #NEWLINE# ok_ ( ( 'test4' in view . _sortable_columns ) ) #NEWLINE# ok_ ( ( view . _create_form_class is not None ) ) #NEWLINE# ok_ ( ( view . _edit_form_class is not None ) ) #NEWLINE# eq_ ( view . _search_supported , False ) #NEWLINE# eq_ ( view . _filters , None ) #NEWLINE# eq_ ( view . _create_form_class . test1 . field_class , fields . StringField ) #NEWLINE# eq_ ( view . _create_form_class . test2 . field_class , fields . StringField ) #NEWLINE# eq_ ( view . _create_form_class . test3 . field_class , fields . TextAreaField ) #NEWLINE# eq_ ( view . _create_form_class . test4 . field_class , fields . TextAreaField ) #NEWLINE# client = app . test_client ( ) #NEWLINE# rv = client . get ( '/admin/model1/' ) #NEWLINE# eq_ ( rv . status_code , 200 ) #NEWLINE# rv = client . get ( '/admin/model1/new/' ) #NEWLINE# eq_ ( rv . status_code , 200 ) #NEWLINE# rv = client . post ( '/admin/model1/new/' , data = dict ( test1 = 'test1large' , test2 = 'test2' , time_field = time ( 0 , 0 , 0 ) ) ) #NEWLINE# eq_ ( rv . status_code , 302 ) #NEWLINE# model = db . session . query ( Model1 ) . first ( ) #NEWLINE# eq_ ( model . test1 , 'test1large' ) #NEWLINE# eq_ ( model . test2 , 'test2' ) #NEWLINE# eq_ ( model . test3 , '' ) #NEWLINE# eq_ ( model . test4 , '' ) #NEWLINE# rv = client . get ( '/admin/model1/' ) #NEWLINE# eq_ ( rv . status_code , 200 ) #NEWLINE# ok_ ( ( 'test1large' in rv . data . decode ( 'utf-8' ) ) ) #NEWLINE# url = ( '/admin/model1/edit/?id=%s' % model . id ) #NEWLINE# rv = client . get ( url ) #NEWLINE# eq_ ( rv . status_code , 200 ) #NEWLINE# ok_ ( ( '00:00:00' in rv . data . decode ( 'utf-8' ) ) ) #NEWLINE# rv = client . post ( url , data = dict ( test1 = 'test1small' , test2 = 'test2large' ) ) #NEWLINE# eq_ ( rv . status_code , 302 ) #NEWLINE# model = db . session . query ( Model1 ) . first ( ) #NEWLINE# eq_ ( model . test1 , 'test1small' ) #NEWLINE# eq_ ( model . test2 , 'test2large' ) #NEWLINE# eq_ ( model . test3 , '' ) #NEWLINE# eq_ ( model . test4 , '' ) #NEWLINE# url = ( '/admin/model1/delete/?id=%s' % model . id ) #NEWLINE# rv = client . post ( url ) #NEWLINE# eq_ ( rv . status_code , 302 ) #NEWLINE# eq_ ( db . session . query ( Model1 ) . count ( ) , 0 )