Example #1
0
def setup_session(request):
    """This fixture is automatically called once at the start of pytest execution.
    The default app created here should be modified by your tests.
    If your test requires specific app config then please create your own using
    the fixture test_app"""
    product = asyncio.run(_product_with_full_access())
    app = ApigeeApiDeveloperApps()

    print("\nCreating Default App..")
    asyncio.run(
        app.create_new_app(
            callback_url=
            "https://nhsd-apim-testing-internal-dev.herokuapp.com/callback"))
    asyncio.run(app.add_api_product([product.name]))

    # Set default JWT Testing resource url
    asyncio.run(
        app.set_custom_attributes({
            'jwks-resource-url':
            'https://raw.githubusercontent.com/NHSDigital/'
            'identity-service-jwks/main/jwks/internal-dev/'
            '9baed6f4-1361-4a8e-8531-1f8426e3aba8.json'
        }))

    oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    for item in request.node.items:
        setattr(item.cls, "oauth", oauth)

    yield

    # Teardown
    print("\nDestroying Default App..")
    asyncio.run(app.destroy_app())
    asyncio.run(product.destroy_product())
Example #2
0
def setup_session(request):
    """This fixture is called at a function level.
    The default app created here should be modified by your tests.
    """
    product = asyncio.run(_product_with_full_access())
    print("\nCreating Default App..")
    # Create a new app
    app = ApigeeApiDeveloperApps()

    asyncio.run(
        app.create_new_app(callback_url="https://example.org/callback"))
    # Assign the new product to the app
    asyncio.run(app.add_api_product([product.name]))

    # Set default JWT Testing resource url
    asyncio.run(
        app.set_custom_attributes({
            'jwks-resource-url':
            'https://raw.githubusercontent.com/NHSDigital/'
            'identity-service-jwks/main/jwks/internal-dev/'
            '9baed6f4-1361-4a8e-8531-1f8426e3aba8.json'
        }))

    asyncio.run(product.update_environments([config.ENVIRONMENT]))
    oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url)
    resp = asyncio.run(
        oauth.get_token_response(grant_type="authorization_code"))
    token = resp["body"]["access_token"]

    yield product, app, token

    # Teardown
    print("\nDestroying Default App..")
    asyncio.run(app.destroy_app())
    asyncio.run(product.destroy_product())