By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
### Certificate validation
The library attempts to validate TLS on HTTPS endpoints by default. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
```python
```python
client=AuthenticatedClient(
client=AuthenticatedClient(
...
@@ -51,7 +72,7 @@ client = AuthenticatedClient(
...
@@ -51,7 +72,7 @@ client = AuthenticatedClient(
)
)
```
```
You can also disable certificate validation altogether, but beware that **this is a security risk**.
You can also disable certificate validation altogether. This is a **security risk** and **is not recommended**.
```python
```python
client=AuthenticatedClient(
client=AuthenticatedClient(
...
@@ -61,47 +82,58 @@ client = AuthenticatedClient(
...
@@ -61,47 +82,58 @@ client = AuthenticatedClient(
)
)
```
```
Things to know:
## Contribute to development
1. Every path/method combo becomes a Python module with four functions:
1.`sync`: Blocking request that returns parsed data (if successful) or `None`
The Funkwhale API client is generated from the Funkwhale OpenAPI schema. If you notice an issue with the API itself, consider contributing to [Funkwhale](https://dev.funkwhale.audio/funkwhale/funkwhale).
1.`sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
1.`asyncio`: Like `sync` but async instead of blocking
### Build / publish the client
1.`asyncio_detailed`: Like `sync_detailed` but async instead of blocking
This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Make sure you have it installed before you start.
1. All path/query params, and bodies become method arguments.
1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
To publish a new version of the client:
1. Any endpoint which did not have a tag will be in `funkwhale_api_client.api.default`
1. Update the metadata in `pyproject.toml` (e.g. authors, version)
## Building / publishing this Client
2. If you're using a private repository, configure it with Poetry
This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
1. Update the metadata in pyproject.toml (e.g. authors, version)
```sh
1. If you're using a private repository, configure it with Poetry
poetry config repositories.<your-repository-name> <url-to-your-repository> # Set up your repository
1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
3. Publish the client:
1. Publish to PyPI with `poetry publish --build`
2. Publish to a private repository with `poetry publish --build -r <your-repository-name>`.
If you want to install this client into another project without publishing it (e.g. for development) then:
If you want to install this client into another project without publishing it (e.g. for development) then:
1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
1. If that project is not using Poetry:
1. If the project **uses Poetry**, add the client using `poetry add <path-to-this-client>`.
2. If the project doesn't use Poetry:
1. Build a wheel with `poetry build -f wheel`
1. Build a wheel with `poetry build -f wheel`
1. Install that wheel from the other project `pip install <path-to-wheel>`
2. Install that wheel from the target project `pip install <path-to-wheel>`
### Create tests
## Contributing
Tests are split into two types: **integration tests** and **model tests**.
### Run tests
#### Integration tests
To run the tests, run `poetry run pytest`.
You can test methods by calling them with a `Client` or `AuthenticatedClient` and expecting a specific result. Check `tests/integration/test_albums.py` for an example.
### How to write test cases
#### Model tests
There are two things to test: The models and the API functions.
You can test models by asserting equality with a response from a Funkwhale server. For example, to test the `/api/v1/albums` endpoint:
Lets imagine you want to write a test case for the endpoint `/api/v1/albums`
1. Find the API call in `api/albums/albums_list.py`
focusing on the models for now. Since this endpoint lists the Albums, the
2. Check which model is used in the `_parse_response()` method. In this case `PaginatedAlbumList`
correct API call is in `api/albums/albums_list.py`. Check the function called
3. Fetch data from the `/api/v1/albums` endpoint using [cURL](https://curl.se/) and save the output to `tests/data/paginated_album_list.json`
`_parse_response()`. The model used to parse the response is called
4. Create a test to assert equality between the resulting JSON and the `PaginatedAlbumList` model using the model's `from_dict()` method
`PaginatedAlbumList`, which we will run tests against. Now curl the endpoint you
want to write tests for and put the response into `tests/data/albums.json`. Now
An example test can be found in `tests/unit/test_model_paginated_album_list.py`.
we can load this json file, load it with the model and do some assertions. The
example is available in `tests/unit/test_model_paginated_album_list.py`.
### Run tests
You can run the whole suite of tests with the following command: