From 42ee333283e26f829d0e347449157978a467e05f Mon Sep 17 00:00:00 2001 From: Arturo Seijas Date: Tue, 19 Mar 2024 14:39:35 +0100 Subject: [PATCH] Fix integration tests --- tests/integration/conftest.py | 20 ++++++++++++++++++++ tests/integration/test_charm.py | 17 ++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 486a8272..e5db8340 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -108,3 +108,23 @@ async def app( await ops_test.model.wait_for_idle(status="active", raise_on_error=False) yield application + + +@pytest_asyncio.fixture(scope="module", name="saml_integrator") +async def saml_integrator_fixture(ops_test: OpsTest): + """SAML integrator charm used for integration testing. + + Builds the charm and deploys it. + """ + assert ops_test.model + saml_config = { + "metadata_url": "https://login.staging.ubuntu.com/saml/metadata", + "entity_id": "https://login.staging.ubuntu.com", + } + saml_integrator = await ops_test.model.deploy( + "saml-integrator", channel="latest/stable", config=saml_config, trust=True + ) + await ops_test.model.wait_for_idle( + apps=[saml_integrator.name], status="active", raise_on_error=False + ) + yield saml_integrator diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index 4ea0dbf6..7cf9bf20 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -186,27 +186,22 @@ async def test_anonymize_user_fail(app: Application): @pytest.mark.asyncio @pytest.mark.abort_on_fail -async def test_saml_auth( +async def test_saml_auth( # pylint: disable=too-many-arguments ops_test: OpsTest, app: Application, saml_email: str, saml_password: str, requests_timeout: float, + saml_integrator: Application, ): """ arrange: given charm in its initial state - act: configure a SAML target url and fire SAML authentication + act: configure and integrate the SAML integrator fire SAML authentication assert: The SAML authentication process is executed successfully. """ - # The linter does not recognize set_config as a method, so this errors must be ignored. - await app.set_config( # type: ignore[attr-defined] # pylint: disable=W0106 - { - "site_url": "https://events.staging.canonical.com", - } - ) - # The linter does not recognize wait_for_idle as a method, - # since ops_test has a model as Optional, so this error must be ignored. - await ops_test.model.wait_for_idle(status="active") # type: ignore[union-attr] + assert ops_test.model + ops_test.model.add_relation(app.name, saml_integrator.name) + await ops_test.model.wait_for_idle(status="active") urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) host = "events.staging.canonical.com"