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
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")
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
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)
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)