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())
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())
def test_product_and_app(): """Setup & Teardown an product and app for this api""" product = ApigeeApiProducts() app = ApigeeApiDeveloperApps() loop = asyncio.new_event_loop() loop.run_until_complete(product.create_new_product()) loop.run_until_complete(app.setup_app()) app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url) yield product, app loop.run_until_complete(app.destroy_app()) loop.run_until_complete(product.destroy_product())
def base_test_app(): """Setup & Teardown an app-restricted app for this api""" app = ApigeeApiDeveloperApps() loop = asyncio.new_event_loop() loop.run_until_complete( app.setup_app( api_products=[get_env("APIGEE_PRODUCT")], custom_attributes=_BASE_CUSTOM_ATTRIBUTES, )) app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url) yield app loop.run_until_complete(app.destroy_app())
def test_app(): """Setup & Teardown an app-restricted app for this api""" app = ApigeeApiDeveloperApps() loop = asyncio.new_event_loop() loop.run_until_complete( app.setup_app( api_products=[get_env("APIGEE_PRODUCT")], custom_attributes={ "jwks-resource-url": "https://raw.githubusercontent.com/NHSDigital/identity-service-jwks/main/jwks/internal-dev/9baed6f4-1361-4a8e-8531-1f8426e3aba8.json" # noqa }, ) ) app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url) yield app loop.run_until_complete(app.destroy_app())
def test_product_and_app(): """Setup & Teardown an product and app for this api""" product = ApigeeApiProducts() app = ApigeeApiDeveloperApps() loop = asyncio.new_event_loop() loop.run_until_complete(product.create_new_product()) loop.run_until_complete( product.update_scopes([ "urn:nhsd:apim:app:level3:immunisation-history", "urn:nhsd:apim:user-nhs-login:P9:immunisation-history", "urn:nhsd:apim:user-nhs-login:P5:immunisation-history" ])) loop.run_until_complete( app.setup_app( api_products=[product.name], custom_attributes=_BASE_CUSTOM_ATTRIBUTES, )) app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url) yield product, app loop.run_until_complete(app.destroy_app()) loop.run_until_complete(product.destroy_product())
def test_product_and_app(request): """Setup & Teardown an product and app for this api""" request_params = request.param product = ApigeeApiProducts() app = ApigeeApiDeveloperApps() loop = asyncio.new_event_loop() loop.run_until_complete(product.create_new_product()) loop.run_until_complete(product.update_scopes( request_params['scopes'] )) loop.run_until_complete( app.setup_app( api_products=[product.name], custom_attributes= { "jwks-resource-url": "https://raw.githubusercontent.com/NHSDigital/identity-service-jwks/main/jwks/internal-dev/9baed6f4-1361-4a8e-8531-1f8426e3aba8.json", "nhs-login-allowed-proofing-level": request_params.get('requested_proofing_level') }, ) ) app.oauth = OauthHelper(app.client_id, app.client_secret, app.callback_url) app.request_params = request_params yield product, app loop.run_until_complete(app.destroy_app()) loop.run_until_complete(product.destroy_product())