Пример #1
0
def test_add(tmp_path, caplog):
    caplog.set_level(logging.INFO)
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger()
    uid = str(uuid.uuid4())
    data = {"id": uid, "type": t_add, "status": "test_2"}
    logger.info(data)
    all_logs = logger.list(uid).get("data")
    print("all_logs", all_logs)
    assert len(all_logs) == 1
    log = all_logs[0]
    assert log["levelname"] == "INFO"
    assert log["id"] == uid
    assert log["type"] == t_add
    assert log["status"] == "test_2"
Пример #2
0
async def test_init(tmp_path):
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = str(path_srv_root)
    logger = Logger()
    uid = str(uuid.uuid4())
    jobs = Jobs(logger, clean, init_data)
    list_job = await jobs.list(uid)
    assert len(list_job) == 0
Пример #3
0
def test_add(tmp_path, caplog):
    caplog.set_level(logging.INFO)
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger()
    uid = str(uuid.uuid4())
    # print('logs', list(logger.list(uid).get('data')))
    data = {'id': uid, 'type': t_add, "status": 'test_2'}
    logger.info(data)
    all_logs = logger.list(uid).get('data')
    print('all_logs', all_logs)
    assert len(all_logs) == 1
    log = all_logs[0]
    assert log['levelname'] == 'INFO'
    assert log['id'] == uid
    assert log['type'] == t_add
    assert log['status'] == 'test_2'
Пример #4
0
def test_init(tmp_path):
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = str(path_srv_root)
    logger = Logger()
    path_naas = os.path.join(path_srv_root, '.naas', 'jobs.json')
    uid = str(uuid.uuid4())
    jobs = Jobs(logger, clean, init_data)
    assert len(jobs.list(uid)) == 0
Пример #5
0
async def test_delete(tmp_path):
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger()
    uid = str(uuid.uuid4())
    jobs = Jobs(logger, clean, init_data)
    path =  os.path.join(os.getcwd(), 'test_delete.py')
    target_type = t_notebook
    value = user_folder_name
    params = {}
    runTime = 0
    await jobs.update(uid, path, target_type, value, params, t_add, runTime)
    assert len(jobs.list(uid)) == 1
    await jobs.update(uid, path, target_type, value, params, t_delete, runTime)
    assert len(jobs.list(uid)) == 0
Пример #6
0
async def test_add(tmp_path):
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger()
    uid = str(uuid.uuid4())
    jobs = Jobs(logger, clean, init_data)
    path =  os.path.join(os.getcwd(), 'test_add.py')
    target_type = t_notebook
    value = user_folder_name
    params = {}
    runTime = 0
    await jobs.update(uid, path, target_type, value, params, t_add, runTime)
    assert len(jobs.list(uid)) == 1
    data = jobs.find_by_path(uid, path, target_type)
    assert data.get('value') == value
    assert data['params'] == params
    assert data['lastRun'] == runTime
Пример #7
0
async def test_scheduler(tmp_path, event_loop):
    recur = "* * * * *"
    test_notebook = "tests/demo/demo_scheduler.ipynb"
    cur_path = os.path.join(os.getcwd(), test_notebook)
    new_path = os.path.join(tmp_path, test_notebook)
    os.makedirs(os.path.dirname(new_path))
    logger = Logger()
    notebooks = Notebooks(logger)
    jobs = Jobs(logger, True, [])
    scheduler = Scheduler(logger, jobs, notebooks, event_loop)
    uid = str(uuid.uuid4())
    copy2(cur_path, new_path)
    job = {
        "type": t_scheduler,
        "path": new_path,
        "params": {},
        "value": recur,
        "status": t_add,
    }
    await jobs.update(
        uid,
        job["path"],
        job["type"],
        job["value"],
        job["params"],
        job["status"],
    )
    resp_json = await jobs.list(uid)
    assert len(resp_json) == 1
    res_job = resp_json[0]
    assert res_job.get("type") == t_scheduler
    assert res_job.get("path") == new_path
    assert res_job.get("value") == recur
    assert res_job.get("status") == t_add
    await scheduler.start(test_mode=True)
    resp_json = await jobs.list(uid)
    assert len(resp_json) == 1
    res_job = resp_json[0]
    assert res_job.get("type") == t_scheduler
    assert res_job.get("path") == new_path
    assert res_job.get("value") == recur
    assert res_job.get("status") == t_health
Пример #8
0
async def test_notebook(test_cli, tmp_path):
    test_notebook = "tests/demo/demo_scheduler.ipynb"
    cur_path = os.path.join(os.getcwd(), test_notebook)
    new_path = os.path.join(tmp_path, test_notebook)
    os.makedirs(os.path.dirname(new_path))
    copy2(cur_path, new_path)
    logger = Logger()
    notebook = Notebooks(logger)
    job = {
        "type": t_notebook,
        "path": new_path,
        "params": {},
        "value": "any",
        "status": t_add,
    }
    uid = str(uuid.uuid4())
    res = await notebook.exec(uid, job)
    print("\n\n\nres\n\n", res, "\n\n\n END")
    assert res is not None
    assert res.get("cells") is not None
Пример #9
0
def test_init(tmp_path, caplog):
    caplog.set_level(logging.INFO)
    path_srv_root = os.path.join(os.getcwd(), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger(clear=True)
    uid = str(uuid.uuid4())
    data = logger.list(uid).get("data")
    assert len(data) == 0
    logger.info({"id": uid, "status": "inited", "type": t_add})
    data = logger.list(uid).get("data")
    assert len(data) == 1
    log = data[0]
    assert log["levelname"] == "INFO"
    assert log["status"] == "inited"
    assert log["id"] == uid
Пример #10
0
def test_init(tmp_path, caplog):
    caplog.set_level(logging.INFO)
    path_srv_root = os.path.join(os.getcwd(), user_folder_name)
    # path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger(clear=True)
    uid = str(uuid.uuid4())
    data = logger.list(uid).get('data')
    assert len(data) == 0
    logger.info({'id': uid, 'status': 'inited', 'type': t_add})
    data = logger.list(uid).get('data')
    assert len(data) == 1
    log = data[0]
    assert log['levelname'] == 'INFO'
    assert log['status'] == 'inited'
    assert log['id'] == uid
Пример #11
0
async def test_update(tmp_path):
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger()
    uid = str(uuid.uuid4())
    jobs = Jobs(logger, clean, init_data)
    path = os.path.join(os.getcwd(), "test_update.py")
    target_type = t_notebook
    value = user_folder_name
    new_value = "value_changed"
    params = {}
    run_time = 0
    await jobs.update(uid, path, target_type, value, params, t_add, run_time)
    list_job = await jobs.list(uid)
    assert len(list_job) == 1
    await jobs.update(uid, path, target_type, new_value, params, t_update, run_time)
    list_job = await jobs.list(uid)
    assert len(list_job) == 1
    data = await jobs.find_by_path(uid, path, target_type)
    assert data["value"] == new_value
    await jobs.update(uid, path, target_type, value, params, t_delete, run_time)
    list_job = await jobs.list(uid)
    assert len(list_job) == 0
Пример #12
0
def test_list(tmp_path, caplog):
    caplog.set_level(logging.INFO)
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger()
    uid = str(uuid.uuid4())
    data = {'id': uid, 'type': t_add, "status": 'test_1'}
    data_two = {'id': uid, 'type': t_delete, "status": 'test_2'}
    data_tree = {'id': uid, 'type': t_update, "status": 'test_2'}
    logger.info(data)
    logger.info(data_two)
    logger.info(data_tree)
    all_logs = logger.list(uid).get('data')
    assert len(all_logs) == 3
    assert len(logger.list(uid, skip=1).get('data')) == 2
    assert len(logger.list(uid, skip=0, limit=1).get('data')) == 1
    assert len(logger.list(uid, skip=1, limit=1).get('data')) == 1
    assert len(logger.list(uid, skip=0, limit=0,
                           search='test_2').get('data')) == 2
    assert len(logger.list(uid, skip=0, limit=0,
                           search='test_2').get('data')) == 2
    assert len(
        logger.list(uid,
                    skip=0,
                    limit=0,
                    search=None,
                    filters=[t_delete, t_add]).get('data')) == 2
Пример #13
0
def test_clean(tmp_path, caplog):
    caplog.set_level(logging.INFO)
    path_srv_root = os.path.join(str(tmp_path), user_folder_name)
    os.environ["JUPYTER_SERVER_ROOT"] = path_srv_root
    logger = Logger(clear=True)
    uid = str(uuid.uuid4())
    data = logger.list(uid).get('data')
    assert len(data) == 0
    logger.info({'id': uid, 'type': t_add, "status": 'test_1'})
    data = logger.list(uid).get('data')
    assert len(data) == 1
    logger_new = Logger()
    assert len(logger_new.list(uid).get('data')) == 1
    logger_new.clear()
    assert len(logger_new.list(uid).get('data')) == 0