示例#1
0
    # Verify engine is connected
    engine.connect()

    return engine


def check_mysql_fn():
    try:
        get_sqlalchemy_engine(config["root_database"])
    except sqlalchemy.exc.OperationalError:
        raise ContainerCheckFailed(
            "Unable to connect to a presumed MySQL test container via given config: {}".format(
                config
            )
        )


_mysql_container = pytest.fixture("session")(
    get_container_fn(
        "_mysql_container",
        config["image"],
        {3306: config["port"]},
        {
            "MYSQL_DATABASE": config["root_database"],
            "MYSQL_ROOT_PASSWORD": config["password"]
        },
        check_mysql_fn,
    )
)
示例#2
0
from pytest_mock_resources.container import (
    ContainerCheckFailed,
    get_container_fn,
    get_docker_host,
    IN_CI,
)

redis_config = {
    "port": 6379 if IN_CI else 6380,
    "image": "redis:5.0.7",
}


def check_redis_fn():
    try:
        client = redis.Redis(host=get_docker_host(), port=redis_config["port"])
        client.ping()
    except redis.ConnectionError:
        raise ContainerCheckFailed(
            "Unable to connect to a presumed Redis test container via given config: {}"
            .format(redis_config))


_redis_container = pytest.fixture(scope="session")(get_container_fn(
    name="pmr_redis_container",
    image=redis_config["image"],
    ports={6379: redis_config["port"]},
    environment={},
    check_fn=check_redis_fn,
))
示例#3
0
    "port": 27017 if IN_CI else 28017,
    "root_database": "dev-mongo",
    "image": "mongo:3.6",
}


def get_pymongo_client():
    uri = "mongodb://{}:{}".format(get_docker_host(), config["port"])

    return pymongo.MongoClient(uri)


def check_mongo_fn():
    try:
        client = get_pymongo_client()
        db = client[config["root_database"]]
        db.command("ismaster")
    except pymongo.errors.ConnectionFailure:
        raise ContainerCheckFailed(
            "Unable to connect to a presumed MongoDB test container via given config: {}".format(
                config
            )
        )


_mongo_container = pytest.fixture("session")(
    get_container_fn(
        "_mongo_container", config["image"], {27017: config["port"]}, {}, check_mongo_fn
    )
)
示例#4
0
    psycopg2.connect

    engine = sqlalchemy.create_engine(DB_URI, **options)

    # Verify engine is connected
    engine.connect()

    return engine


def check_postgres_fn():
    try:
        get_sqlalchemy_engine(config["root_database"])
    except sqlalchemy.exc.OperationalError:
        raise ContainerCheckFailed(
            "Unable to connect to a presumed Postgres test container via given config: {}"
            .format(config))


_postgres_container = pytest.fixture("session")(get_container_fn(
    "_postgres_container",
    config["image"],
    {5432: config["port"]},
    {
        "POSTGRES_DB": config["root_database"],
        "POSTGRES_USER": config["username"],
        "POSTGRES_PASSWORD": config["password"],
    },
    check_postgres_fn,
))
示例#5
0
    "port": 27017 if IN_CI else 28017,
    "root_database": "dev-mongo",
    "image": "mongo:3.6",
}


def get_pymongo_client():
    from pymongo import MongoClient

    uri = "mongodb://{}:{}".format(get_docker_host(), config["port"])

    return MongoClient(uri)


def check_mongo_fn():
    from pymongo.errors import ConnectionFailure

    try:
        client = get_pymongo_client()
        db = client[config["root_database"]]
        db.command("ismaster")
    except ConnectionFailure:
        raise ContainerCheckFailed(
            "Unable to connect to a presumed MongoDB test container via given config: {}"
            .format(config))


_mongo_container = pytest.fixture("session")(get_container_fn(
    "_mongo_container", config["image"], {27017: config["port"]}, {},
    check_mongo_fn))