def test_api_info_by_category(self): """ """ from max.routes import RESOURCES defined_categories = list(set([route.get('category') for name, route in RESOURCES.items() if route.get('category')])) res = self.testapp.get('/info/api?by_category=1', status=200) listed_categories = [category['name'] for category in res.json] self.assertIsInstance(res.json, list) self.assertItemsEqual(defined_categories, listed_categories) self.assertItemsEqual(res.json[0].keys(), [u'name', u'resources', u'id'])
def main(*args, **settings): """ This function returns a WSGI application. """ # App config authz_policy = ACLAuthorizationPolicy() authn_policy = MaxAuthenticationPolicy(['widgetcli']) # Read max settings max_settings = loadMAXSettings(settings) # IMPORTANT NOTE !! Order matters! First tween added will be the first to be invoked settings['pyramid.tweens'] = [ 'max.tweens.excview_tween_factory', 'max.tweens.compatibility_checker_factory', 'max.tweens.post_tunneling_factory', 'max.tweens.deprecation_wrapper_factory', ] debug.setup(settings) mongoprobe.setup(settings) config = Configurator( settings=settings, authentication_policy=authn_policy, authorization_policy=authz_policy, root_factory=Root) config.add_request_method(get_request_actor_username, name='actor_username', reify=True) config.add_request_method(get_request_actor, name='actor', reify=True) config.add_request_method(get_request_creator, name='creator', reify=True) config.add_request_method(get_database, name='db', reify=True) config.add_request_method(extract_post_data, name='decoded_payload', reify=True) config.add_request_method(get_oauth_headers, name='auth_headers', reify=True) # Mongodb connection initialization cluster_enabled = asbool(settings.get('mongodb.cluster', False)) auth_enabled = asbool(settings.get('mongodb.auth', False)) mongodb_uri = settings.get('mongodb.hosts') if cluster_enabled else settings['mongodb.url'] conn = mongodb.get_connection( mongodb_uri, use_greenlets=GEVENT_AVAILABLE, cluster=settings.get('mongodb.replica_set', None)) db = mongodb.get_database( conn, settings['mongodb.db_name'], username=settings.get('mongodb.username', None) if auth_enabled else None, password=settings.get('mongodb.password', None) if auth_enabled else None, authdb=settings.get('mongodb.authdb', None) if auth_enabled else None) config.registry.max_store = db # Set MAX settings config.registry.max_settings = max_settings # Set Twitter settings config.registry.cloudapis_settings = loadCloudAPISettings(config.registry) # Set security config.registry.max_security = loadMAXSecurity(config.registry) # Load cache settings set_cache_regions_from_settings(settings) # REST Resources # Configure routes based on resources defined in RESOURCES for name, properties in RESOURCES.items(): route_params = {param: value for param, value in properties.items() if param in ['traverse']} config.add_route(name, properties.get('route'), **route_params) config.scan('max', ignore=['max.tests']) set_signal() # Create exceptions log folfer if it doesnt exists exceptions_folder = config.registry.settings.get('exceptions_folder', '/tmp/exceptions/') if not os.path.exists(exceptions_folder): os.makedirs(exceptions_folder) return config.make_wsgi_app()