Esempio n. 1
0
 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())
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
 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
Esempio n. 8
0
 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)
Esempio n. 9
0
 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
Esempio n. 10
0
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)