def test_default_bind_is_assumed(self): app, client = self.create_test_app(OGM_GRAPH_HOST='localhost', OGM_GRAPH_USER='******', OGM_GRAPH_PASSWORD='******') with app.app_context(): ogm = OGM(app) assert 'localhost' in repr(ogm.get_connection())
def test_bound_connection_no_optional_params(self): app, client = self.create_test_app( OGM_GRAPH_CREDENTIALS={ 'SOME_CONN': dict(HOST='localhost', USER='******', PASSWORD='******'), }) with app.app_context(): ogm = OGM(app) assert isinstance(ogm.get_connection('SOME_CONN'), Graph)
def test_factory_method_creation(self): app, client = self.create_test_app( OGM_GRAPH_HOST='localhost', OGM_GRAPH_USER='******', OGM_GRAPH_PASSWORD='******', OGM_GRAPH_PROTOCOL='http', OGM_GRAPH_PORT='7474' ) ogm = OGM() with app.app_context(): ogm.init_app(app) assert isinstance(ogm.graph, Graph)
def test_default_connection_simple_no_optional_params(self): app, client = self.create_test_app(OGM_GRAPH_HOST='localhost', OGM_GRAPH_USER='******', OGM_GRAPH_PASSWORD='******') with app.app_context(): ogm = OGM(app) assert isinstance(ogm.graph, Graph)
def test_connection_graph_credentials_not_found(self): try: app, client = self.create_test_app() # no password with app.app_context(): ogm = OGM(app) assert isinstance(ogm.graph, Graph) except GraphCredentialsNotFoundError: assert True else: # pragma: no cover assert False
def test_connection_incomplete_graph_credentials(self): try: app, client = self.create_test_app( OGM_GRAPH_HOST='localhost', OGM_GRAPH_USER='******') # no password with app.app_context(): ogm = OGM(app) assert isinstance(ogm.graph, Graph) except GraphCredentialsIncompleteError: assert True else: # pragma: no cover assert False
def test_out_of_application_context_error(self): app, client = self.create_test_app(OGM_GRAPH_HOST='localhost', OGM_GRAPH_USER='******', OGM_GRAPH_PASSWORD='******') try: ogm = OGM(app) graph = ogm.graph assert graph except OutOfApplicationContextError: assert True else: # pragma: no cover assert False
def test_default_connection_bound_all_params(self): app, client = self.create_test_app( OGM_GRAPH_CREDENTIALS={ 'DEFAULT': dict(HOST='localhost', USER='******', PASSWORD='******', PORT='7687', PROTOCOL='bolt'), }) with app.app_context(): ogm = OGM(app) assert isinstance(ogm.graph, Graph)
def test_default_connection_unclear(self): try: app, client = self.create_test_app(OGM_GRAPH_HOST='localhost', OGM_GRAPH_USER='******', OGM_GRAPH_PASSWORD='******', OGM_GRAPH_CREDENTIALS={ 'DEFAULT': dict(HOST='localhost', USER='******', PASSWORD='******'), }) # no password with app.app_context(): ogm = OGM(app) assert isinstance(ogm.graph, Graph) except DefaultGraphCredentialsUnclearError: assert True else: # pragma: no cover assert False
Tiny app designed to demonstrate using the extension. """ from flask import Flask from py2neo.ogm import GraphObject try: from flask_ogm import OGM, ParamConverter # typical import except ImportError: # Path hack allows examples to be run without installation. import os parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.sys.path.insert(0, parentdir) from flask_ogm import OGM, ParamConverter app = Flask('Flask-OGM Example App') app.config.update(OGM_GRAPH_HOST='localhost', OGM_GRAPH_USER='******', OGM_GRAPH_PASSWORD='******') ogm = OGM(app) @app.route('/') def helloWorld(): return str(ogm.graph.run('MATCH (n) RETURN COUNT(n) AS c').evaluate()) if __name__ == '__main__': app.run(debug=True)