Exemple #1
0
def test_user_check_grant_revoke_general_access(api_mock):
    koi.init()

    pool = koi.create_api_object_pool(host="http://base",
                                      username="******",
                                      password="******")

    roles = list(pool.get_all_general_roles())

    user = next(pool.get_all_users())

    helper_check_role(user, roles[1])

    koi.deinit()
Exemple #2
0
def test_get_roles(api_mock):
    koi.init()

    pool = koi.create_api_object_pool(host="http://base",
                                      username="******",
                                      password="******")

    general_roles = list(pool.get_all_general_roles())
    model_roles = list(pool.get_all_model_roles())
    instance_roles = list(pool.get_all_instance_roles())

    assert len(general_roles) == 2
    assert len(model_roles) == 2
    assert len(instance_roles) == 2

    koi.deinit()
Exemple #3
0
def test_user_check_grant_revoke_model_access(api_mock):
    koi.init()

    pool = koi.create_api_object_pool(host="http://base",
                                      username="******",
                                      password="******")

    roles = list(pool.get_all_model_roles())

    user = next(pool.get_all_users())

    model = next(pool.get_all_models())

    assert user.has_role(roles[0], model) is True

    helper_check_role(user, roles[1], model)

    koi.deinit()
def test_offline_authentication(offlineOrConnectionError, api_mock):
    koi_core.init()
    pool = koi_core.create_api_object_pool(host="http://base",
                                           username="******",
                                           password="******")

    # check that the api reports as online
    assert pool.api.online is True

    # check if the api detects the offline server when trying to authenticate
    if offlineOrConnectionError:
        api_mock.set_offline()
    else:
        api_mock.set_connectionError()
    with pytest.raises(KoiApiOfflineException):
        pool.api.authenticate()
    assert pool.api.online is False

    koi_core.deinit()
Exemple #5
0
def test_get_users(api_mock):
    koi.init()
    # create pool
    pool = koi.create_api_object_pool(host="http://base",
                                      username="******",
                                      password="******")

    users = list(pool.get_all_users())
    assert len(users) > 0

    user = users[0]

    assert user.name == "admin"

    user = users[2]
    assert user.name == "user2"
    user.name = "user2_new"
    assert user.name == "user2_new"

    koi.deinit()
def test_offline_detection(offlineOrConnectionError, api_mock):
    koi_core.init()
    pool = koi_core.create_api_object_pool(host="http://base",
                                           username="******",
                                           password="******")

    # check that the api reports as online and continous to do so after authentication
    assert pool.api.online is True
    pool.get_all_models()  # make sure the models are cached
    assert pool.api.online is True

    # check if the api detects the offline server when doing something
    if offlineOrConnectionError:
        api_mock.set_offline()
    else:
        api_mock.set_connectionError()
    pool.get_all_models(
    )  # just do something, so that the API can detect the absence of the server
    assert pool.api.online is False

    koi_core.deinit()
def run_all_models(persistence=None):
    koi.init()

    if persistence:
        pool = koi.create_api_object_pool(
            host="http://base",
            username="******",
            password="******",
            persistance_file=persistence,
        )
    else:
        pool = koi.create_api_object_pool(
            host="http://base",
            username="******",
            password="******"
        )
    models = pool.get_all_models()
    for model in models:
        instances = model.instances
        for instance in instances:
            koi.control.train(instance, dev=True)

    koi.deinit()
def test_offline_model_inference(offlineOrConnectionError, api_mock):
    persistence = io.BytesIO()

    koi_core.init()
    pool = koi_core.create_api_object_pool(
        host="http://base",
        username="******",
        password="******",
        persistance_file=persistence,
    )
    instance: Instance = pool.instance(
        InstanceId(
            uuid.UUID("00000000-0001-1000-8000-000000000000"),
            uuid.UUID("00000000-0002-1000-8000-000000000000"),
        ))
    koi_core.control.infer(instance, [], dev=True)
    koi_core.deinit()

    if offlineOrConnectionError:
        api_mock.set_offline()
    else:
        api_mock.set_connectionError()
    persistence.seek(0)
    koi_core.init()
    pool = koi_core.create_api_object_pool(
        host="http://base",
        username="******",
        password="******",
        persistance_file=persistence,
    )
    instance = pool.instance(
        InstanceId(
            uuid.UUID("00000000-0001-1000-8000-000000000000"),
            uuid.UUID("00000000-0002-1000-8000-000000000000"),
        ))
    koi_core.control.infer(instance, [], dev=True)
    koi_core.deinit()
def test_offline_api(offlineOrConnectionError, api_mock):
    persistence = io.BytesIO()

    koi_core.init()
    pool = koi_core.create_api_object_pool(
        host="http://base",
        username="******",
        password="******",
        persistance_file=persistence,
    )
    instance: Instance = pool.instance(
        InstanceId(
            uuid.UUID("00000000-0001-1000-8000-000000000000"),
            uuid.UUID("00000000-0002-1000-8000-000000000000"),
        ))
    koi_core.control.infer(instance, [], dev=True)
    koi_core.deinit()

    api_mock.requests_mock.reset_mock()
    persistence.seek(0)
    koi_core.init()
    pool = koi_core.create_offline_object_pool(persistance_file=persistence)
    instance = pool.instance(
        InstanceId(
            uuid.UUID("00000000-0001-1000-8000-000000000000"),
            uuid.UUID("00000000-0002-1000-8000-000000000000"),
        ))
    koi_core.control.infer(instance, [], dev=True)
    koi_core.deinit()
    assert api_mock.requests_mock.call_count == 0, "The Offline API should not make any HTTP Request"

    if offlineOrConnectionError:
        api_mock.set_offline()
    else:
        api_mock.set_connectionError()
    persistence.seek(0)
    koi_core.init()
    pool = koi_core.create_offline_object_pool(persistance_file=persistence)
    instance = pool.instance(
        InstanceId(
            uuid.UUID("00000000-0001-1000-8000-000000000000"),
            uuid.UUID("00000000-0002-1000-8000-000000000000"),
        ))
    koi_core.control.infer(instance, [], dev=True)
    koi_core.deinit()
Exemple #10
0
def cleanup():
    yield
    try:
        koi_core.deinit()
    except Exception:
        pass