Pytest plugin accessing NHSDigital's APIM proxies
A pytest extension for NHSDigital's API Mangement suite.
In your project's virtual environment
poetry add pytest-nhsd-apim
or if using pip directly
python -m pip install pytest-nhsd-apim
- create a python test file
- write a test using our custom authentication markers!
make testto run test examples, located in this repo
- after creating your file you can use the plugin as:
python -m pytest -p pytest_nhsd_apim test_nhsd_apim.py -s --apigee-proxy-name=<your-proxy-name>
When installing this library in your project you can access some very handy tools, including our platform authenticators and our apigee api wrapper library.
We present a variety of authenticators including AuthorizationCodeAuthenticator, ClientCredentialsAuthenticator and TokenExchangeAuthenticator. The way of using them is simple. First you create the configuration object which will validate that your coniguration is correct on creation using pydantic, then pass the config to the authenticator and call get_token() on it.
from pytest_nhsd_apim.identity_service import ClientCredentialsConfig, ClientCredentialsAuthenticator
config = ClientCredentialsConfig(
For a more detailed implementation on the rest of the authenticators please refer to the examples here.
We also present a variety off Apigee APIs with the benefit of a fully authenticated Apigee client ready to use. Just remember to export the following variables
# If you want the client to authenticate you...
# Or alternatively, if you already have a token you can pass it and the client will use it.
#NOTE: in case both sets of credentials are defined, the username and password take presedence, this is so the Apigee client can keep itself authenticated all the time.
from pytest_nhsd_apim.apigee_apis import ApigeeNonProdCredentials, DeveloperAppsAPI
config = ApigeeNonProdCredentials()
client = ApigeeClient(config=config)
apps = DeveloperAppsAPI(client=client)
The APIs we offer at the moment are:
For a more detailed implementation of the available APIs please refer to the tests here. We will keep adding APIs with time, if you are looking for a particular APIs not listed above please feel free to open a pull request and send it to us.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for pytest_nhsd_apim-3.3.12-py3-none-any.whl