<s> from nose . tools import eq_ , ok_ , raises <EOL> from . import setup <EOL> from . test_basic import CustomModelView , create_models <EOL> from flask . ext . admin . form import rules <EOL> def test_form_rules ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , _ = create_models ( db ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model1 , db . session , <EOL> form_rules = ( '<STR_LIT>' , '<STR_LIT>' , rules . Field ( '<STR_LIT>' ) ) ) <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> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> pos1 = data . find ( '<STR_LIT>' ) <EOL> pos2 = data . find ( '<STR_LIT>' ) <EOL> pos3 = data . find ( '<STR_LIT>' ) <EOL> pos4 = data . find ( '<STR_LIT>' ) <EOL> ok_ ( pos1 > pos2 ) <EOL> ok_ ( pos4 > pos1 ) <EOL> ok_ ( pos3 == - <NUM_LIT:1> ) <EOL> def test_rule_macro ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , _ = create_models ( db ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model1 , db . session , <EOL> create_template = '<STR_LIT>' , <EOL> form_create_rules = ( rules . Macro ( '<STR_LIT:test>' , arg = '<STR_LIT>' ) , <EOL> rules . Macro ( '<STR_LIT>' ) ) ) <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> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> def test_rule_container ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , _ = create_models ( db ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model1 , db . session , <EOL> create_template = '<STR_LIT>' , <EOL> form_create_rules = ( rules . Container ( '<STR_LIT>' , rules . Macro ( '<STR_LIT>' ) ) , ) ) <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> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> pos1 = data . find ( '<STR_LIT>' ) <EOL> pos2 = data . find ( '<STR_LIT>' ) <EOL> pos3 = data . find ( '<STR_LIT>' ) <EOL> ok_ ( pos1 != - <NUM_LIT:1> ) <EOL> ok_ ( pos2 != - <NUM_LIT:1> ) <EOL> ok_ ( pos3 != - <NUM_LIT:1> ) <EOL> ok_ ( pos1 < pos2 < pos3 ) <EOL> def test_rule_header ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , _ = create_models ( db ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model1 , db . session , <EOL> form_create_rules = ( rules . Header ( '<STR_LIT:hello>' ) , ) ) <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> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> def test_rule_field_set ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , _ = create_models ( db ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model1 , db . session , <EOL> form_create_rules = ( rules . FieldSet ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) , ) ) <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> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' in data ) <EOL> pos1 = data . find ( '<STR_LIT>' ) <EOL> pos2 = data . find ( '<STR_LIT>' ) <EOL> pos3 = data . find ( '<STR_LIT>' ) <EOL> pos4 = data . find ( '<STR_LIT>' ) <EOL> ok_ ( pos1 > pos2 ) <EOL> ok_ ( pos4 > pos1 ) <EOL> ok_ ( pos3 == - <NUM_LIT:1> ) <EOL> def test_rule_inlinefieldlist ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , Model2 = create_models ( db ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model1 , db . session , <EOL> inline_models = ( Model2 , ) , <EOL> form_create_rules = ( '<STR_LIT>' , '<STR_LIT>' ) ) <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> def test_inline_model_rules ( ) : <EOL> app , db , admin = setup ( ) <EOL> Model1 , Model2 = create_models ( db ) <EOL> db . create_all ( ) <EOL> view = CustomModelView ( Model1 , db . session , <EOL> inline_models = [ ( Model2 , dict ( form_rules = ( '<STR_LIT>' , '<STR_LIT>' ) ) ) ] ) <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> data = rv . data . decode ( '<STR_LIT:utf-8>' ) <EOL> ok_ ( '<STR_LIT>' not in data ) </s>
