Skip to main content

Pytest plugin accessing NHSDigital's APIM proxies

Project description

pytest-nhsd-apim

A pytest extension for NHSDigital's API Mangement suite.

Installation

In your project's virtual environment

poetry add pytest-nhsd-apim

or if using pip directly

python -m pip install pytest-nhsd-apim

Usage

  • create a python test file
  • write a test using our custom authentication markers!
  • enjoy!?

Testing

  • run make test to 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>

Available tools

When installing this library in your project you can access some very handy tools, including our platform authenticators and our apigee api wrapper library.

Autheticators

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(
        environment={APIGEE_ENVIRONMENT},
        identity_service_base_url={BASE_URL},
        client_id={CLIENT_ID},
        jwt_private_key={PRIVATE_KEY_PEM},
        jwt_kid={KEY_ID},
    )

    authenticator=ClientCredentialsAuthenticator(config=config)
    token=authenticator.get_token()

For a more detailed implementation on the rest of the authenticators please refer to the examples here.

Apigee APIs

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...
export APIGEE_NHSD_NONPROD_USERNAME={my_username}
export APIGEE_NHSD_NONPROD_PASSWORD={my_password}
export APIGEE_NHSD_NONPROD_OTP_KEY={my_otp}
# Or alternatively, if you already have a token you can pass it and the client will use it.
export APIGEE_ACCESS_TOKEN={access_token}

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

print(apps.list_aps('lucas.fantini@nhs.net'))

The APIs we offer at the moment are:

API Methods Documentation
DeveloperAppsAPI here Overview
ApiProductsAPI here Overview
DebugSessionsAPI here Overview
AccessTokensAPI here Overview
AppKeysAPI here Overview

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_nhsd_apim-6.0.10.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_nhsd_apim-6.0.10-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_nhsd_apim-6.0.10.tar.gz.

File metadata

  • Download URL: pytest_nhsd_apim-6.0.10.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pytest_nhsd_apim-6.0.10.tar.gz
Algorithm Hash digest
SHA256 3f2bece8f57ac976109c91d2a2391a77c7791bfa7ee4435e2c08b75005e4f961
MD5 dfa5f5daa7e3840ff523f2df6bc0c950
BLAKE2b-256 99c19e5fc6043780e3bc7d3e0865935997089fa6443974f3d6fca1c4fa5d2e1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_nhsd_apim-6.0.10.tar.gz:

Publisher: cd.yml on NHSDigital/pytest-nhsd-apim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_nhsd_apim-6.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_nhsd_apim-6.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 49364f43906bd1aa403576e69e49f33e97b1c81e24a6e25a61758784d4a55b37
MD5 322b4792d0d5cc01ee791dbc766b226b
BLAKE2b-256 67bfcd605a8eca2efe121eb24c30fae93fd4d781fdac29287e2f023d88dd1c85

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_nhsd_apim-6.0.10-py3-none-any.whl:

Publisher: cd.yml on NHSDigital/pytest-nhsd-apim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page