<s> import eve <EOL> import os <EOL> from eve . flaskapp import RegexConverter <EOL> from eve . flaskapp import Eve <EOL> from eve . io . base import DataLayer <EOL> from eve . tests import TestBase <EOL> from eve . exceptions import ConfigException , SchemaException <EOL> from eve . io . mongo import Mongo , Validator <EOL> class TestConfig ( TestBase ) : <EOL> def test_allow_unknown_with_soft_delete ( self ) : <EOL> my_settings = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : { '<STR_LIT>' : { } } <EOL> } <EOL> try : <EOL> self . app = Eve ( settings = my_settings ) <EOL> except TypeError : <EOL> self . fail ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def test_default_import_name ( self ) : <EOL> self . assertEqual ( self . app . import_name , eve . __package__ ) <EOL> def test_custom_import_name ( self ) : <EOL> self . app = Eve ( '<STR_LIT>' , settings = self . settings_file ) <EOL> self . assertEqual ( self . app . import_name , '<STR_LIT>' ) <EOL> def test_custom_kwargs ( self ) : <EOL> self . app = Eve ( '<STR_LIT>' , static_folder = '<STR_LIT:/>' , <EOL> settings = self . settings_file ) <EOL> self . assertEqual ( self . app . static_folder , '<STR_LIT:/>' ) <EOL> def test_regexconverter ( self ) : <EOL> regex_converter = self . app . url_map . converters . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( regex_converter , RegexConverter ) <EOL> def test_default_validator ( self ) : <EOL> self . assertEqual ( self . app . validator , Validator ) <EOL> def test_default_datalayer ( self ) : <EOL> self . assertEqual ( type ( self . app . data ) , Mongo ) <EOL> def test_default_settings ( self ) : <EOL> self . assertEqual ( self . app . settings , self . settings_file ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT:localhost>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , { '<STR_LIT:w>' : <NUM_LIT:1> } ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , False ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , True ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , [ '<STR_LIT>' , <EOL> '<STR_LIT:POST>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , False ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , False ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , True ) <EOL> def test_settings_as_dict ( self ) : <EOL> my_settings = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : { } } } <EOL> self . app = Eve ( settings = my_settings ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( self . app . config [ '<STR_LIT>' ] , { '<STR_LIT:w>' : <NUM_LIT:1> } ) <EOL> def test_unexisting_env_config ( self ) : <EOL> env = os . environ <EOL> try : <EOL> os . environ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertRaises ( IOError , Eve ) <EOL> finally : <EOL> os . environ = env <EOL> def test_custom_validator ( self ) : <EOL> class MyTestValidator ( Validator ) : <EOL> pass <EOL> self . app = Eve ( validator = MyTestValidator , <EOL> settings = self . settings_file ) <EOL> self . assertEqual ( self . app . validator , MyTestValidator ) <EOL> def test_custom_datalayer ( self ) : <EOL> class MyTestDataLayer ( DataLayer ) : <EOL> def init_app ( self , app ) : <EOL> pass <EOL> self . app = Eve ( data = MyTestDataLayer , settings = self . settings_file ) <EOL> self . assertEqual ( type ( self . app . data ) , MyTestDataLayer ) <EOL> def test_validate_domain_struct ( self ) : <EOL> del self . app . config [ '<STR_LIT>' ] <EOL> self . assertValidateConfigFailure ( '<STR_LIT>' ) <EOL> self . app . config [ '<STR_LIT>' ] = [ ] <EOL> self . assertValidateConfigFailure ( '<STR_LIT>' ) <EOL> self . app . config [ '<STR_LIT>' ] = { } <EOL> self . assertValidateConfigSuccess ( ) <EOL> def test_validate_resource_methods ( self ) : <EOL> self . app . config [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT:POST>' ] <EOL> self . assertValidateConfigFailure ( '<STR_LIT>' ) <EOL> def test_validate_item_methods ( self ) : <EOL> self . app . config [ '<STR_LIT>' ] = [ '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' ] <EOL> self . assertValidateConfigFailure ( [ '<STR_LIT:POST>' , '<STR_LIT>' ] ) <EOL> def test_validate_schema_methods ( self ) : <EOL> test = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT:POST>' ] , <EOL> } <EOL> self . app . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] = test <EOL> self . assertValidateConfigFailure ( '<STR_LIT>' ) <EOL> def test_validate_schema_item_methods ( self ) : <EOL> test = { <EOL> '<STR_LIT>' : [ '<STR_LIT:GET>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:POST>' ] , <EOL> } <EOL> self . app . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] = test <EOL> self . assertValidateConfigFailure ( '<STR_LIT>' ) <EOL> def test_validate_datecreated_in_schema ( self ) : <EOL> self . assertUnallowedField ( eve . DATE_CREATED ) <EOL> def test_validate_lastupdated_in_schema ( self ) : <EOL> self . assertUnallowedField ( eve . LAST_UPDATED ) <EOL> def assertUnallowedField ( self , field , field_type = '<STR_LIT>' ) : <EOL> self . domain . clear ( ) <EOL> schema = { field : { '<STR_LIT:type>' : field_type } } <EOL> self . domain [ '<STR_LIT>' ] = { '<STR_LIT>' : schema } <EOL> self . app . set_defaults ( ) <EOL> self . assertValidateSchemaFailure ( '<STR_LIT>' , schema , field ) <EOL> def test_validate_schema ( self ) : <EOL> schema = self . domain [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> del ( schema [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> self . assertValidateSchemaFailure ( '<STR_LIT>' , schema , '<STR_LIT>' ) <EOL> def test_validate_invalid_field_names ( self ) : <EOL> schema = self . domain [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> schema [ '<STR_LIT>' ] = { '<STR_LIT:type>' : '<STR_LIT:string>' } <EOL> self . assertValidateSchemaFailure ( '<STR_LIT>' , schema , '<STR_LIT>' ) <EOL> del ( schema [ '<STR_LIT>' ] ) <EOL> schema [ '<STR_LIT>' ] = { '<STR_LIT:type>' : '<STR_LIT:string>' } <EOL> self . assertValidateSchemaFailure ( '<STR_LIT>' , schema , '<STR_LIT>' ) <EOL> del ( schema [ '<STR_LIT>' ] ) <EOL> schema [ '<STR_LIT>' ] = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } } <EOL> } <EOL> self . assertValidateSchemaFailure ( '<STR_LIT>' , schema , '<STR_LIT>' ) <EOL> schema [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } } <EOL> self . assertValidateSchemaFailure ( '<STR_LIT>' , schema , '<STR_LIT>' ) <EOL> def test_set_schema_defaults ( self ) : <EOL> schema = self . domain [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> data_relation = schema [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT>' in data_relation ) <EOL> self . assertEqual ( data_relation [ '<STR_LIT>' ] , <EOL> self . domain [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> id_field = self . domain [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> self . assertTrue ( id_field in schema ) <EOL> self . assertEqual ( schema [ id_field ] , { '<STR_LIT:type>' : '<STR_LIT>' } ) <EOL> def test_set_defaults ( self ) : <EOL> self . domain . clear ( ) <EOL> resource = '<STR_LIT>' <EOL> self . domain [ resource ] = { } <EOL> self . app . set_defaults ( ) <EOL> self . _test_defaults_for_resource ( resource ) <EOL> settings = self . domain [ resource ] <EOL> self . assertEqual ( len ( settings [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> def _test_defaults_for_resource ( self , resource ) : <EOL> settings = self . domain [ resource ] <EOL> self . assertEqual ( settings [ '<STR_LIT:url>' ] , resource ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> resource . rstrip ( '<STR_LIT:s>' ) . capitalize ( ) ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , settings [ '<STR_LIT:url>' ] ) <EOL> self . assertNotEqual ( settings [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( type ( settings [ '<STR_LIT>' ] ) , dict ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , None ) <EOL> def test_datasource ( self ) : <EOL> self . _test_datasource_for_resource ( '<STR_LIT>' ) <EOL> def _test_datasource_for_resource ( self , resource ) : <EOL> datasource = self . domain [ resource ] [ '<STR_LIT>' ] <EOL> schema = self . domain [ resource ] [ '<STR_LIT>' ] <EOL> compare = [ key for key in datasource [ '<STR_LIT>' ] if key in schema ] <EOL> compare . extend ( [ self . domain [ resource ] [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( datasource [ '<STR_LIT>' ] , <EOL> dict ( ( field , <NUM_LIT:1> ) for ( field ) in compare ) ) <EOL> self . assertEqual ( datasource [ '<STR_LIT:source>' ] , resource ) <EOL> self . assertEqual ( datasource [ '<STR_LIT>' ] , None ) <EOL> self . assertEqual ( datasource [ '<STR_LIT>' ] , None ) <EOL> def test_validate_roles ( self ) : <EOL> for resource in self . domain : <EOL> self . assertValidateRoles ( resource , '<STR_LIT>' ) <EOL> self . assertValidateRoles ( resource , '<STR_LIT>' ) <EOL> self . assertValidateRoles ( resource , '<STR_LIT>' ) <EOL> self . assertValidateRoles ( resource , '<STR_LIT>' ) <EOL> self . assertValidateRoles ( resource , '<STR_LIT>' ) <EOL> self . assertValidateRoles ( resource , '<STR_LIT>' ) <EOL> def assertValidateRoles ( self , resource , directive ) : <EOL> prev = self . domain [ resource ] [ directive ] <EOL> self . domain [ resource ] [ directive ] = '<STR_LIT>' <EOL> self . assertValidateConfigFailure ( directive ) <EOL> self . domain [ resource ] [ directive ] = [ ] <EOL> self . assertValidateConfigSuccess ( ) <EOL> self . domain [ resource ] [ directive ] = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertValidateConfigSuccess ( ) <EOL> self . domain [ resource ] [ directive ] = None <EOL> self . assertValidateConfigFailure ( directive ) <EOL> self . domain [ resource ] [ directive ] = prev <EOL> def assertValidateConfigSuccess ( self ) : <EOL> try : <EOL> self . app . validate_domain_struct ( ) <EOL> self . app . validate_config ( ) <EOL> except ConfigException as e : <EOL> self . fail ( '<STR_LIT>' % e ) <EOL> def assertValidateConfigFailure ( self , expected ) : <EOL> try : <EOL> self . app . validate_domain_struct ( ) <EOL> self . app . validate_config ( ) <EOL> except ConfigException as e : <EOL> if isinstance ( expected , str ) : <EOL> expected = [ expected ] <EOL> for exp in expected : <EOL> self . assertTrue ( exp . lower ( ) in str ( e ) . lower ( ) ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def assertValidateSchemaFailure ( self , resource , schema , expected ) : <EOL> try : <EOL> self . app . validate_schema ( resource , schema ) <EOL> except SchemaException as e : <EOL> self . assertTrue ( expected . lower ( ) in str ( e ) . lower ( ) ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_schema_defaults ( self ) : <EOL> self . domain . clear ( ) <EOL> self . domain [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:title>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:default>' : <NUM_LIT:100> <EOL> } , <EOL> } <EOL> } <EOL> self . app . set_defaults ( ) <EOL> settings = self . domain [ '<STR_LIT>' ] <EOL> self . assertEqual ( { '<STR_LIT:title>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:100> } , settings [ '<STR_LIT>' ] ) <EOL> def test_url_helpers ( self ) : <EOL> self . assertNotEqual ( self . app . config . get ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( type ( self . app . config [ '<STR_LIT>' ] ) , dict ) <EOL> self . assertNotEqual ( self . app . config . get ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( type ( self . app . config [ '<STR_LIT>' ] ) , dict ) <EOL> del ( self . domain [ '<STR_LIT>' ] ) <EOL> for resource , settings in self . domain . items ( ) : <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , <EOL> self . app . config [ '<STR_LIT>' ] [ resource ] ) <EOL> def test_pretty_resource_urls ( self ) : <EOL> """<STR_LIT>""" <EOL> resource_url = self . app . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> pretty_url = '<STR_LIT>' <EOL> self . assertEqual ( resource_url , pretty_url ) <EOL> resource_url = self . app . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> pretty_url = '<STR_LIT>' <EOL> self . assertEqual ( resource_url , pretty_url ) <EOL> def test_url_rules ( self ) : <EOL> map_adapter = self . app . url_map . bind ( '<STR_LIT>' ) <EOL> del ( self . domain [ '<STR_LIT>' ] ) <EOL> del ( self . domain [ '<STR_LIT>' ] ) <EOL> del ( self . domain [ '<STR_LIT>' ] ) <EOL> del ( self . domain [ '<STR_LIT>' ] ) <EOL> del ( self . domain [ '<STR_LIT>' ] ) <EOL> for _ , settings in self . domain . items ( ) : <EOL> for method in settings [ '<STR_LIT>' ] : <EOL> self . assertTrue ( map_adapter . test ( '<STR_LIT>' % settings [ '<STR_LIT:url>' ] , <EOL> method ) ) <EOL> def test_register_resource ( self ) : <EOL> resource = '<STR_LIT>' <EOL> settings = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:title>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT:default>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:default>' : <NUM_LIT:100> <EOL> } , <EOL> } <EOL> } <EOL> self . app . register_resource ( resource , settings ) <EOL> self . _test_defaults_for_resource ( resource ) <EOL> self . _test_datasource_for_resource ( resource ) <EOL> self . test_validate_roles ( ) <EOL> def test_auth_field_as_idfield ( self ) : <EOL> resource = '<STR_LIT>' <EOL> settings = { <EOL> '<STR_LIT>' : self . app . config [ '<STR_LIT>' ] , <EOL> } <EOL> self . assertRaises ( ConfigException , self . app . register_resource , <EOL> resource , settings ) <EOL> def test_auth_field_as_custom_idfield ( self ) : <EOL> resource = '<STR_LIT>' <EOL> settings = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT:id>' , <EOL> '<STR_LIT>' : '<STR_LIT:id>' <EOL> } <EOL> self . assertRaises ( ConfigException , self . app . register_resource , <EOL> resource , settings ) <EOL> def test_oplog_config ( self ) : <EOL> self . app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . app . _init_oplog ( ) <EOL> self . assertOplog ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> del ( self . domain [ '<STR_LIT>' ] ) <EOL> oplog = '<STR_LIT>' <EOL> self . app . config [ '<STR_LIT>' ] = oplog <EOL> self . app . _init_oplog ( ) <EOL> self . assertOplog ( oplog , '<STR_LIT>' ) <EOL> del ( self . domain [ oplog ] ) <EOL> self . domain [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : [ '<STR_LIT:POST>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { '<STR_LIT:source>' : '<STR_LIT>' } <EOL> } <EOL> self . app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> settings = self . domain [ '<STR_LIT>' ] <EOL> self . app . _init_oplog ( ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , [ '<STR_LIT:GET>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , [ '<STR_LIT:GET>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT:url>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] [ '<STR_LIT:source>' ] , '<STR_LIT>' ) <EOL> def assertOplog ( self , key , endpoint ) : <EOL> self . assertTrue ( key in self . domain ) <EOL> settings = self . domain [ key ] <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , [ '<STR_LIT:GET>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] , [ '<STR_LIT:GET>' ] ) <EOL> self . assertEqual ( settings [ '<STR_LIT:url>' ] , endpoint ) <EOL> self . assertEqual ( settings [ '<STR_LIT>' ] [ '<STR_LIT:source>' ] , key ) <EOL> def test_create_indexes ( self ) : <EOL> settings = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:list>' } <EOL> } , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : [ ( '<STR_LIT:name>' , <NUM_LIT:1> ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT:name>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , <NUM_LIT:1> ) ] , <EOL> '<STR_LIT>' : ( [ ( '<STR_LIT>' , "<STR_LIT>" ) ] , { "<STR_LIT>" : True } ) <EOL> } <EOL> } <EOL> self . app . register_resource ( '<STR_LIT>' , settings ) <EOL> self . assertEqual ( <EOL> self . app . config [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] <EOL> ) <EOL> from pymongo import MongoClient <EOL> db_name = self . app . config [ '<STR_LIT>' ] <EOL> db = MongoClient ( ) [ db_name ] <EOL> for coll in [ db [ '<STR_LIT>' ] , db [ '<STR_LIT>' ] ] : <EOL> indexes = coll . index_information ( ) <EOL> self . assertTrue ( len ( indexes ) > len ( settings [ '<STR_LIT>' ] ) ) <EOL> for key , value in settings [ '<STR_LIT>' ] . items ( ) : <EOL> if isinstance ( value , tuple ) : <EOL> fields , args = value <EOL> else : <EOL> fields = value <EOL> args = None <EOL> self . assertTrue ( key in indexes ) <EOL> self . assertEqual ( indexes [ key ] [ '<STR_LIT:key>' ] , fields ) <EOL> for arg in args or ( ) : <EOL> self . assertTrue ( arg in indexes [ key ] ) <EOL> self . assertEqual ( args [ arg ] , indexes [ key ] [ arg ] ) <EOL> def test_custom_error_handlers ( self ) : <EOL> """<STR_LIT>""" <EOL> codes = self . app . config [ '<STR_LIT>' ] <EOL> handlers = self . app . error_handler_spec [ None ] <EOL> challenge = lambda code : self . assertTrue ( code in handlers ) <EOL> map ( challenge , codes ) </s>
