Exemplo n.º 1
0
def test_to_path_windows(patch_platform, patch_session):
    TEST_DIRNAME = Path("some title")
    cli = BaseCliApi(TEST_HOST,
                     TEST_APIKEY,
                     username=TEST_USER,
                     password=TEST_PASS)

    assert cli.to_path("some title") == TEST_DIRNAME
    assert cli.to_path("some /title") == TEST_DIRNAME
    assert cli.to_path("some: title") == TEST_DIRNAME
Exemplo n.º 2
0
def test_to_path_linux(patch_platform, patch_session):
    # For all unix based platforms (linux, bsd, osx...)
    TEST_DIRNAME = Path("some title")
    cli = BaseCliApi(TEST_HOST,
                     TEST_APIKEY,
                     username=TEST_USER,
                     password=TEST_PASS)

    assert cli.to_path("some title") == TEST_DIRNAME
    assert cli.to_path("some /title") == TEST_DIRNAME
    assert cli.to_path("some:title") == Path("some:title")
Exemplo n.º 3
0
def test_put(patch_session):
    cli = BaseCliApi(TEST_HOST,
                     TEST_APIKEY,
                     username=TEST_USER,
                     password=TEST_PASS)
    patch_session().request.return_value = mock_response(200, [TEST_JSON])
    rep = cli.request_put(TEST_PATH, {'param': 'value'})

    assert patch_session().headers == {"X-Api-Key": TEST_APIKEY}
    patch_session().request.assert_called_with("PUT",
                                               f"{TEST_HOST}{TEST_PATH}",
                                               params=None,
                                               json={'param': 'value'})
    assert rep == TEST_JSON
Exemplo n.º 4
0
def test_server_error(patch_session):
    cli = BaseCliApi(TEST_HOST,
                     TEST_APIKEY,
                     username=TEST_USER,
                     password=TEST_PASS)
    patch_session().request.return_value = mock_response(400, Exception)

    with pytest.raises(CliServerError):
        cli.request_get(TEST_PATH)

    assert patch_session().headers == {"X-Api-Key": TEST_APIKEY}
    patch_session().request.assert_called_with("GET",
                                               f"{TEST_HOST}{TEST_PATH}",
                                               params=None,
                                               json=None)
Exemplo n.º 5
0
def test_request_error(patch_session):
    cli = BaseCliApi(TEST_HOST,
                     TEST_APIKEY,
                     username=TEST_USER,
                     password=TEST_PASS)
    patch_session().request.side_effect = Exception

    with pytest.raises(CliArrError):
        cli.request_get(TEST_PATH)

    assert patch_session().headers == {"X-Api-Key": TEST_APIKEY}
    patch_session().request.assert_called_with("GET",
                                               f"{TEST_HOST}{TEST_PATH}",
                                               params=None,
                                               json=None)