def test_resource_publish_endpoint2(self): discoverer = Discoverer() discoverer.init_app( self.app, DISCOVERER_PUBLISH_ENDPOINT='/non-default-resources2') self.assertEqual(self.app.config['DISCOVERER_PUBLISH_ENDPOINT'], '/non-default-resources2') r = self.client.get('/resources') self.assertStatus(r, 404) r = self.client.get('/non-default-resources2') self.assertStatus(r, 200) self.assertIn('/foo', r.json)
def create_app(**config): app = ADSFlask(__name__, static_folder=None, local_config=config or {}) app.url_map.strict_slashes = False ## pysqlite driver breaks transactions, we have to apply some hacks as per ## http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable if 'sqlite' in app.config.get('SQLALCHEMY_DATABASE_URI', None): from sqlalchemy import event engine = app.db.engine @event.listens_for(engine, "connect") def do_connect(dbapi_connection, connection_record): # disable pysqlite's emitting of the BEGIN statement entirely. # also stops it from emitting COMMIT before any DDL. dbapi_connection.isolation_level = None @event.listens_for(engine, "begin") def do_begin(conn): # emit our own BEGIN conn.execute("BEGIN") app.register_blueprint(bp) discoverer = Discoverer(app) class JsonResponse(Response): default_mimetype = 'application/json' app.response_class = JsonResponse return app
def create_app(**config): """ Create the application and return it to the user :return: flask.Flask application """ if config: app = ADSFlask(__name__, local_config=config) else: app = ADSFlask(__name__) app.url_map.strict_slashes = False # Add end points api = Api(app) api.add_resource(IndexView, '/tugboat/index') api.add_resource(ClassicSearchRedirectView, '/tugboat/classicSearchRedirect') api.add_resource(BumblebeeView, '/tugboat/redirect') api.add_resource(SimpleClassicView, '/tugboat/ads') api.add_resource(ComplexClassicView, '/tugboat/adsabs') api.add_resource(ComplexClassicArXivView, '/tugboat/arxiv') api.add_resource(ComplexClassicPhysicsView, '/tugboat/physics') Discoverer(app) return app
def create_app(self): app = Flask(__name__, static_folder=None) @app.route('/default', methods=['POST', 'PUT']) def default(): '''Default route docstring''' return "default route" @advertise(scopes=['default']) @app.route('/scoped') def scoped(): '''Scoped route docstring''' return "scoped route" self.expected_resources = { '/scoped': { 'scopes': ['default'], 'description': 'Scoped route docstring', 'methods': ['HEAD', 'OPTIONS', 'GET'], }, '/default': { 'description': 'Default route docstring', 'methods': ['PUT', 'POST', 'OPTIONS'], }, } discoverer = Discoverer(app) return app
def create_app(): """ Create the application and return it to the user :return: application """ app = Flask(__name__, static_folder=None) app.url_map.strict_slashes = False load_config(app) logging.config.dictConfig(app.config['WEBHOOKS_LOGGING']) # Register extensions api = Api(app) Discoverer(app) db.init_app(app) # Add the end resource end points api.add_resource(Account, '/account', methods=['POST']) api.add_resource(Subscription, '/subscribe', methods=['POST']) api.add_resource(Triggering, '/trigger', methods=['POST']) return app
def create_app(): """ Create the application and return it to the user :return: application """ app = Flask(__name__, static_folder=None) app.url_map.strict_slashes = False load_config(app) logging.config.dictConfig(app.config['WEBHOOKS_LOGGING']) # Register extensions api = Api(app) Discoverer(app) db.init_app(app) # Add the end resource end points # The account end-point supports interactions with user accounts api.add_resource(Account, '/account', methods=['POST']) # The subscribe end-point allows users to suubscribe to events api.add_resource(Subscription, '/subscribe', methods=['POST']) # The trigger endpoint is where event-producing entities send their data to api.add_resource(Triggering, '/trigger', methods=['POST']) return app
def create_app(self): class DefaultView(MethodView): '''Default route docstring''' def put(self): return "put on default route" def post(self): return "post on default route" class ScopedView(MethodView): '''Scoped route docstring''' scopes = ['default'] decorators = [advertise('scopes')] def get(self): return "scoped route" app = Flask(__name__, static_folder=None) app.add_url_rule('/default', view_func=DefaultView.as_view('default')) app.add_url_rule('/scoped', view_func=ScopedView.as_view('scoped')) discoverer = Discoverer(app) self.expected_resources = { '/scoped': { 'scopes': ['default'], 'description': 'Scoped route docstring', 'methods': ['HEAD', 'OPTIONS', 'GET'], }, '/default': { 'description': 'Default route docstring', 'methods': ['PUT', 'POST', 'OPTIONS'], }, } return app
def create_app(**config): opath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if opath not in sys.path: sys.path.insert(0, opath) if config: app = ADSFlask(__name__, static_folder=None, local_config=config) else: app = ADSFlask(__name__, static_folder=None) app.url_map.strict_slashes = False ## pysqlite driver breaks transactions, we have to apply some hacks as per ## http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable if 'sqlite' in app.config.get('SQLALCHEMY_DATABASE_URI', None): from sqlalchemy import event engine = app.db.engine @event.listens_for(engine, "connect") def do_connect(dbapi_connection, connection_record): # disable pysqlite's emitting of the BEGIN statement entirely. # also stops it from emitting COMMIT before any DDL. dbapi_connection.isolation_level = None @event.listens_for(engine, "begin") def do_begin(conn): # emit our own BEGIN conn.execute("BEGIN") # Note about imports being here rather than at the top level # I want to enclose the import into the scope of the create_app() # and not advertise any of the views; and yes, i'm importing # everything from inside views (everything in __all__) from . import views for o in inspect.getmembers(views, predicate=lambda x: inspect.ismodule(x)): for blueprint in inspect.getmembers( o[1], predicate=lambda x: isinstance(x, Blueprint)): app.register_blueprint(blueprint[1]) discoverer = Discoverer(app) class JsonResponse(Response): default_mimetype = 'application/json' app.response_class = JsonResponse """ @app.after_request def after_request_func(response): # by default (almost all our) responses are # mimetype application/json if 'Content-Type' not in response.headers: response.headers['Content-Type'] = 'application/json' return response """ return app
def create_app(**config): """ Create the application and return it to the user :return: flask.Flask application """ app = TurboBeeADSFlask('turbobee', local_config=config, static_folder=None) Discoverer(app) app.url_map.strict_slashes = False app.register_blueprint(bp) return app
def create_app(**config): """ Create the application and return it to the user :return: application """ if config: app = ADSFlask(__name__, static_folder=None, local_config=config) else: app = ADSFlask(__name__, static_folder=None) app.url_map.strict_slashes = False load_s3(app) # Register extensions watchman = Watchman(app, version=dict(scopes=[''])) api = Api(app) Discoverer(app) # Add the end resource end points api.add_resource(AuthenticateUserClassic, '/auth/classic', methods=['POST']) api.add_resource(AuthenticateUserTwoPointOh, '/auth/twopointoh', methods=['POST']) api.add_resource( ClassicLibraries, '/libraries/classic/<int:uid>', methods=['GET'] ) api.add_resource( TwoPointOhLibraries, '/libraries/twopointoh/<int:uid>', methods=['GET'] ) api.add_resource( ExportTwoPointOhLibraries, '/export/twopointoh/<export>', methods=['GET'] ) api.add_resource( ClassicMyADS, '/myads/classic/<int:uid>', methods=['GET'] ) api.add_resource(ClassicUser, '/user', methods=['GET']) api.add_resource(AllowedMirrors, '/mirrors', methods=['GET']) return app
def create_app(): """Application factory""" app = Flask(__name__, static_folder=None) app.url_map.strict_slashes = False load_config(app) logging.config.dictConfig(app.config['VIS_LOGGING']) Discoverer(app) api = Api(app) api.add_resource(WordCloud, '/word-cloud') api.add_resource(AuthorNetwork, '/author-network') api.add_resource(PaperNetwork, '/paper-network') return app
def create_app(**config): """Application factory""" app = ADSFlask(__name__, static_folder=None, local_config=config or {}) app.url_map.strict_slashes = False api = Api(app) api.add_resource(WordCloud, '/word-cloud') api.add_resource(AuthorNetwork, '/author-network') api.add_resource(PaperNetwork, '/paper-network') discoverer = Discoverer(app) return app
def create_app(**config): """ Create the application and return it to the user :return: flask.Flask application """ if config: app = ADSFlask(__name__, static_folder=None, local_config=config) else: app = ADSFlask(__name__, static_folder=None) app.url_map.strict_slashes = False Discoverer(app) app.register_blueprint(bp) return app
def create_app(): """ Create the application and return it to the user :return: flask.Flask application """ app = ADSFlask(__name__, static_folder=None) app.url_map.strict_slashes = False api = Api(app) api.add_resource(ObjectSearch, '/', '/<string:objects>', '/<string:objects>/<string:source>') api.add_resource(QuerySearch, '/query') api.add_resource(ClassicObjectSearch, '/nedsrv') discoverer = Discoverer(app) return app
def create_app(**config): """ Create the application and return it to the user :return: flask.Flask application """ if config: app = ADSFlask(__name__, static_folder=None, local_config=config) else: app = ADSFlask(__name__, static_folder=None) app.url_map.strict_slashes = False api = Api(app) api.add_resource(Graphics, '/<string:bibcode>') Discoverer(app) return app
def create_app(): """ Create the application and return it to the user :return: application """ app = Flask(__name__, static_folder=None) app.url_map.strict_slashes = False load_config(app) logging.config.dictConfig(app.config['BIBLIB_LOGGING']) # Register extensions api = Api(app) Discoverer(app) db.init_app(app) # Add the end resource end points api.add_resource(UserView, '/libraries', methods=['GET', 'POST']) api.add_resource(LibraryView, '/libraries/<string:library>', methods=['GET']) api.add_resource(DocumentView, '/documents/<string:library>', methods=['POST', 'DELETE', 'PUT']) api.add_resource(PermissionView, '/permissions/<string:library>', methods=['GET', 'POST']) api.add_resource(TransferView, '/transfer/<string:library>', methods=['POST']) api.add_resource(ClassicView, '/classic', methods=['GET']) api.add_resource(TwoPointOhView, '/twopointoh', methods=['GET']) return app
def create_app(): """ Create the application and return it to the user :return: flask.Flask application """ app = Flask(__name__, static_folder=None) app.url_map.strict_slashes = False load_config(app) logging.config.dictConfig(app.config['RECOMMENDER_LOGGING']) api = Api(app) api.add_resource(Recommender, '/<string:bibcode>') db.init_app(app) discoverer = Discoverer(app) return app
def create_app(self): from flask_restful import Resource, Api app = Flask(__name__, static_folder=None) class DefaultView(Resource): '''Default route docstring''' def put(self): return "put on default route" def post(self): return "post on default route" class ScopedView(Resource): '''Scoped route docstring''' scopes = ['default'] decorators = [advertise('scopes')] def get(self): return "scoped route" self.expected_resources = { '/scoped': { 'scopes': ['default'], 'description': 'Scoped route docstring', 'methods': ['HEAD', 'OPTIONS', 'GET'], }, '/default': { 'description': 'Default route docstring', 'methods': ['PUT', 'POST', 'OPTIONS'], }, } api = Api(app) api.add_resource(DefaultView, '/default') api.add_resource(ScopedView, '/scoped') discoverer = Discoverer(app) return app
def create_app(**config): opath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if opath not in sys.path: sys.path.insert(0, opath) app = Flask(__name__, static_folder=None) app.url_map.strict_slashes = False app.config.from_pyfile('config.py') # and finally from the local_config.py try: app.config.from_pyfile('local_config.py') except IOError: pass if config: app.config.update(config) db.init_app(app) logging.config.dictConfig(app.config['MYADS_LOGGING']) ## pysqlite driver breaks transactions, we have to apply some hacks as per ## http://docs.sqlalchemy.org/en/rel_0_9/dialects/sqlite.html#pysqlite-serializable if 'sqlite' in (app.config.get('SQLALCHEMY_BINDS') or { 'myads': '' })['myads']: from sqlalchemy import event binds = app.config.get('SQLALCHEMY_BINDS') if binds and 'myads' in binds: engine = db.get_engine(app, bind=(app.config.get('SQLALCHEMY_BINDS') and 'myads')) else: engine = db.get_engine(app) @event.listens_for(engine, "connect") def do_connect(dbapi_connection, connection_record): # disable pysqlite's emitting of the BEGIN statement entirely. # also stops it from emitting COMMIT before any DDL. dbapi_connection.isolation_level = None @event.listens_for(engine, "begin") def do_begin(conn): # emit our own BEGIN conn.execute("BEGIN") # Note about imports being here rather than at the top level # I want to enclose the import into the scope of the create_app() # and not advertise any of the views; and yes, i'm importing # everything from inside views (everything in __all__) from . import views for o in inspect.getmembers(views, predicate=lambda x: inspect.ismodule(x)): for blueprint in inspect.getmembers( o[1], predicate=lambda x: isinstance(x, Blueprint)): app.register_blueprint(blueprint[1]) discoverer = Discoverer(app) return app
zeroconf = Zeroconf() listener = MyListener() browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener) try: input("Press enter to exit...\n\n") finally: zeroconf.close() header = { "Authorization": "Bearer 4511~hNgxEqiPIYBBsV6jwwogaa1Jit4cBsPhFKOzPFjRpzws7qhhZd2PP5MUlt2uPhLI" } app = Flask(__name__) discoverer = Discoverer(app) mongoClient = MongoClient('localhost', 27017) db = mongoClient.grades collection = db.users user_credentials = [{ "username": "******", "password": "******" }, { "username": "******", "password": "******" }, { "username": "******", "password": "******" }]
def test_selfpublish_false(self): discoverer = Discoverer(self.app, DISCOVERER_SELF_PUBLISH=False) r = self.client.get(self.app.config['DISCOVERER_PUBLISH_ENDPOINT']) self.assertStatus(r, 200) self.assertNotIn(self.app.config['DISCOVERER_PUBLISH_ENDPOINT'], r.json)