def test_get_runs_order(db_gateway: PyMongoDataAccess): runs = list(db_gateway.get_runs(sort_by="host.python_version")) assert len(runs) == 2 assert runs[0]["host"]["python_version"] == "3.4.3" assert runs[1]["host"]["python_version"] == "3.5.2" runs = list( db_gateway.get_runs(sort_by="host.python_version", sort_direction="desc")) assert len(runs) == 2 assert runs[0]["host"]["python_version"] == "3.5.2" assert runs[1]["host"]["python_version"] == "3.4.3"
def add_mongo_config_with_uri(app, connection_string_uri, database_name, collection_name): """ Configure PyMongo with a MongoDB connection string. :param app: Flask application :param connection_string_uri: MongoDB connection string :param database_name: Sacred database name :param collection_name: Sacred's collection with runs :return: """ app.config["data"] = PyMongoDataAccess.build_data_access_with_uri( connection_string_uri, database_name, collection_name)
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)
def test_get_run(db_gateway: PyMongoDataAccess): run = dict(db_gateway.get_run("57f9efb2e4b8490d19d7c30e")) assert run["host"]["hostname"] == "ntbacer"
def test_get_runs_filter_or(db_gateway: PyMongoDataAccess): filter = { "type": "and", "filters": [{ "field": "host.hostname", "operator": "==", "value": "ntbacer" }, { "type": "or", "filters": [{ "field": "result", "operator": "==", "value": 2403.52 }, { "field": "host.python_version", "operator": "==", "value": "3.5.2" }] }] } runs = list(db_gateway.get_runs(query=filter)) assert len(runs) == 1 assert runs[0]["host"]["hostname"] == "ntbacer" assert runs[0]["result"] == 2403.52 filter = { "type": "and", "filters": [{ "field": "host.hostname", "operator": "==", "value": "martin-virtual-machine" }, { "type": "or", "filters": [{ "field": "result", "operator": "==", "value": 2403.52 }, { "field": "host.python_version", "operator": "==", "value": "3.5.2" }] }] } runs = list(db_gateway.get_runs(query=filter)) assert len(runs) == 1 assert runs[0]["host"]["hostname"] == "martin-virtual-machine" assert runs[0]["host"]["python_version"] == "3.5.2" filter = { "type": "and", "filters": [{ "type": "or", "filters": [{ "field": "result", "operator": "==", "value": 2403.52 }, { "field": "host.python_version", "operator": "==", "value": "3.5.2" }] }] } runs = list(db_gateway.get_runs(query=filter)) assert len(runs) == 2 assert runs[0]["host"]["hostname"] == "ntbacer" assert runs[0]["host"]["python_version"] == "3.4.3" assert runs[1]["host"]["hostname"] == "martin-virtual-machine" assert runs[1]["host"]["python_version"] == "3.5.2"
def test_get_runs_filter(db_gateway: PyMongoDataAccess, query_filter): runs = list(db_gateway.get_runs(query=query_filter)) assert len(runs) == 1 assert runs[0]["host"]["hostname"] == "ntbacer"
def test_get_runs_limit(db_gateway: PyMongoDataAccess): runs = list(db_gateway.get_runs(limit=1)) assert len(runs) == 1 assert runs[0]["host"]["hostname"] == "ntbacer"
def test_get_runs(db_gateway: PyMongoDataAccess): runs = list(db_gateway.get_runs()) assert len(runs) == 2 assert runs[0]["host"]["hostname"] == "ntbacer" assert runs[1]["host"]["hostname"] == "martin-virtual-machine"
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
def add_mongo_config_with_uri(app, connection_string_uri, database_name, collection_name): app.config["data"] = PyMongoDataAccess.build_data_access_with_uri( connection_string_uri, database_name, collection_name)
def test_get_metrics_dao(db_gateway: PyMongoDataAccess): dao = db_gateway.get_metrics_dao() assert dao is not None assert isinstance(dao, MetricsDAO) assert isinstance(dao, MongoMetricsDAO) assert dao.generic_dao == db_gateway._generic_dao