Esempio n. 1
0
def add_mongo_config_simple(app, connection_string, collection_name):
    """
    Configure the app to use MongoDB.

    :param app: Flask Application
    :type app: Flask
    :param connection_string: in format host:port:database or database
            (default: sacred)
    :type connection_string: str

    :param collection_name: Name of the collection
    :type collection_name: str
    """
    split_string = connection_string.split(":")
    config = {"host": "localhost", "port": 27017, "db": "sacred"}
    if len(split_string) > 0 and len(split_string[-1]) > 0:
        config["db"] = split_string[-1]
    if len(split_string) > 1:
        config["port"] = int(split_string[-2])
    if len(split_string) > 2:
        config["host"] = split_string[-3]
    app.config["data"] = PyMongoDataAccess.build_data_access(
        config["host"], config["port"], config["db"], collection_name)
Esempio n. 2
0
def db_gateway() -> PyMongoDataAccess:
    db_gw = PyMongoDataAccess.build_data_access("n/a", 0, "testdb", "runs")
    # Use MongoMockClient with MongoMock
    db_gw._create_client = create_mongomock_client
    db_gw.connect()
    return db_gw