Пример #1
0
def pytest_sessionstart(session):
    """
    Provides initial connection to the database and sets up the rest of the test suite
    
    :param session: The session object. Please see <https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_sessionstart>`_
    :type Session object: For more information please see <https://docs.pytest.org/en/latest/reference.html#session>`_
    """
    
    warnings.simplefilter('default')
    
    config.DATABASE_URL = os.environ.get('NEO4J_BOLT_URL', 'bolt://*****:*****@localhost:7687')
    config.AUTO_INSTALL_LABELS = True

    try:
        # Clear the database if required
        database_is_populated, _ = db.cypher_query("MATCH (a) return count(a)>0 as database_is_populated")
        if database_is_populated[0][0] and not session.config.getoption("resetdb"):
            raise SystemError("Please note: The database seems to be populated.\n\tEither delete all nodes and edges manually, or set the --resetdb parameter when calling pytest\n\n\tpytest --resetdb.")
        else:
            clear_neo4j_database(db)        
    except CypherError as ce:
        # Handle instance without password being changed
        if 'The credentials you provided were valid, but must be changed before you can use this instance' in str(ce):
            warnings.warn("New database with no password set, setting password to 'test'")
            change_neo4j_password(db, 'test')
            db.set_connection('bolt://*****:*****@localhost:7687')            
            warnings.warn("Please 'export NEO4J_BOLT_URL=bolt://neo4j:test@localhost:7687' for subsequent test runs")
        else:
            raise ce
Пример #2
0
    def handle(self, *args, **options):
        password = options.get("password")
        if not password:
            self.stdout.write('No password provided, quitting..\n')
            return

        self.stdout.write('Changing password..\n')
        change_neo4j_password(db, password)
        self.stdout.write('Done.\n')
Пример #3
0
def pytest_sessionstart(session):
    """
    Provides initial connection to the database and sets up the rest of the test suite
    
    :param session: The session object. Please see <https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_sessionstart>`_
    :type Session object: For more information please see <https://docs.pytest.org/en/latest/reference.html#session>`_
    """

    warnings.simplefilter("default")

    config.DATABASE_URL = os.environ.get(
        "NEO4J_BOLT_URL", "bolt://*****:*****@localhost:7687")
    config.AUTO_INSTALL_LABELS = True

    try:
        # Clear the database if required
        database_is_populated, _ = db.cypher_query(
            "MATCH (a) return count(a)>0 as database_is_populated")
        if database_is_populated[0][0] and not session.config.getoption(
                "resetdb"):
            raise SystemError(
                "Please note: The database seems to be populated.\n\tEither delete all nodes and edges manually, or set the --resetdb parameter when calling pytest\n\n\tpytest --resetdb."
            )
        else:
            clear_neo4j_database(db,
                                 clear_constraints=True,
                                 clear_indexes=True)
    except (Neo4jError, ClientError) as ce:
        # Handle instance without password being changed
        if ("The credentials you provided were valid, but must be changed before you can use this instance"
                in str(ce)):
            warnings.warn(
                "New database with no password set, setting password to 'test'"
            )
            try:
                change_neo4j_password(db, "test")
                # Ensures that multiprocessing tests can use the new password
                config.DATABASE_URL = "bolt://*****:*****@localhost:7687"
                db.set_connection("bolt://*****:*****@localhost:7687")
                warnings.warn(
                    "Please 'export NEO4J_BOLT_URL=bolt://neo4j:test@localhost:7687' for subsequent test runs"
                )
            except (Neo4jError, ClientError) as e:
                if ("The credentials you provided were valid, but must be changed before you can use this instance"
                        in str(e)):
                    warnings.warn(
                        "You appear to be running on version 4.0+ of Neo4j, without having changed the password."
                        "Please manually log in, change your password, then update the config.DATABASE_URL call at line 32 in this file"
                    )
                else:
                    raise e
        else:
            raise ce
Пример #4
0
def pytest_sessionstart(session):
    """
    Provides initial connection to the database and sets up the rest of the test suite
    
    :param session: The session object. Please see
    <https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_sessionstart>`_
    :type Session object: For more information please see
    <https://docs.pytest.org/en/latest/reference.html#session>`_
    """

    warnings.simplefilter('default')

    config.DATABASE_URL = os.environ.get('NEO4J_BOLT_URL',
                                         'bolt://*****:*****@localhost:7687')
    config.AUTO_INSTALL_LABELS = True

    reset_db = session.config.getoption("resetdb")

    try:
        database_is_populated, _ = db.cypher_query(
            "MATCH (a) return count(a)>0 as database_is_populated")
    except CypherError as ce:
        # Handle instance without password being changed
        if 'The credentials you provided were valid, but must be changed before you can use this instance' in str(
                ce):
            warnings.warn(
                "New database with no password set, setting password to 'test'"
            )
            change_neo4j_password(db, 'test')
            db.set_connection('bolt://*****:*****@localhost:7687')
            warnings.warn(
                "Please 'export NEO4J_BOLT_URL=bolt://neo4j:test@localhost:7687' for subsequent test runs"
            )
            database_is_populated, _ = db.cypher_query(
                "MATCH (a) return count(a)>0 as database_is_populated")
        else:
            raise ce

    # If database is populated and user has not requested to clear the db, terminate test run with a SystemError
    if database_is_populated[0][0] and not reset_db:
        raise SystemError(DATABASE_POPULATED)

    # Clear the database if requested
    if reset_db:
        print("Clearing Neo4j database.")
        clear_neo4j_database(db)
Пример #5
0
from __future__ import print_function

from neomodel import db, change_neo4j_password, clear_neo4j_database
from neo4j.v1 import CypherError

# Travis default password dance
try:
    clear_neo4j_database(db)
except CypherError as ce:
    # handle instance without password being changed
    if 'The credentials you provided were valid, but must be changed before you can use this instance' in str(
            ce):
        change_neo4j_password(db, 'test')
        db.set_connection('bolt://*****:*****@localhost:7687')

        print("New database with no password set, setting password to 'test'")
        print(
            "Please 'export NEO4J_BOLT_URL=bolt://neo4j:test@localhost:7687' for subsequent test runs"
        )
    else:
        raise ce
Пример #6
0
from __future__ import print_function
import warnings
import os

from neomodel import config, db, clear_neo4j_database, change_neo4j_password
from neo4j.v1 import CypherError

warnings.simplefilter('default')

config.DATABASE_URL = os.environ.get('NEO4J_BOLT_URL', 'bolt://*****:*****@localhost:7687')
config.AUTO_INSTALL_LABELS = True

try:
    clear_neo4j_database(db)
except CypherError as ce:
    # handle instance without password being changed
    if 'The credentials you provided were valid, but must be changed before you can use this instance' in str(ce):
        change_neo4j_password(db, 'test')
        db.set_connection('bolt://*****:*****@localhost:7687')

        print("New database with no password set, setting password to 'test'")
        print("Please 'export NEO4J_BOLT_URL=bolt://neo4j:test@localhost:7687' for subsequent test runs")
    else:
        raise ce