Example #1
0
def test_check_single_model_access(mock, tmp_path, test_data_path):
    mock.when(
        "POST /access/list",
        body='.+"test_user".+',
        headers={
            "Authorization": "Bearer security-token"
        },
    ).reply("[true]",
            headers={"Content-Type": "application/json"},
            times=FOREVER)
    mock.when(
        "POST /access/list",
        body='.+"non_granted_user".+',
        headers={
            "Authorization": "Bearer security-token"
        },
    ).reply("[false]",
            headers={"Content-Type": "application/json"},
            times=FOREVER)

    test_props = create_test_platform(tmp_path,
                                      test_data_path,
                                      "access",
                                      auth_url=mock.pretend_url)

    mp = ixmp.Platform(backend="jdbc", dbprops=test_props)

    granted = mp.check_access("test_user", "test_model")
    assert granted

    granted = mp.check_access("non_granted_user", "test_model")
    assert not granted

    granted = mp.check_access("non_existing_user", "test_model")
    assert not granted
Example #2
0
def test_solve_legacy_scenario(tmp_path, test_data_path):
    db_path = create_test_platform(tmp_path, test_data_path, 'legacy')
    mp = Platform(backend='jdbc', driver='hsqldb', path=db_path)
    scen = Scenario(mp,
                    model='canning problem (MESSAGE scheme)',
                    scenario='standard')
    exp = scen.var('OBJ')['lvl']

    # solve scenario, assert that the new objective value is close to previous
    scen.remove_solution()
    scen.solve()
    assert np.isclose(exp, scen.var('OBJ')['lvl'])
Example #3
0
def test_solve_legacy_scenario(tmp_path, test_data_path):
    db_path = create_test_platform(tmp_path, test_data_path, "legacy")
    mp = Platform(backend="jdbc", driver="hsqldb", path=db_path)
    scen = Scenario(mp,
                    model="canning problem (MESSAGE scheme)",
                    scenario="standard")
    exp = scen.var("OBJ")["lvl"]

    # solve scenario, assert that the new objective value is close to previous
    scen = scen.clone(keep_solution=False)
    scen.solve()
    assert np.isclose(exp, scen.var("OBJ")["lvl"])