Skip to content

Commit

Permalink
Use integrate() instead of add_relation() (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielArndt authored Oct 20, 2023
1 parent 3855a14 commit 1c7ea1d
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

async def _deploy_database(ops_test: OpsTest):
"""Deploy a MongoDB."""
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
DATABASE_APP_NAME,
application_name=DATABASE_APP_NAME,
channel="5/edge",
Expand All @@ -31,7 +32,8 @@ async def _deploy_database(ops_test: OpsTest):

async def _deploy_nrf(ops_test: OpsTest):
"""Deploy a NRF."""
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
NRF_APP_NAME,
application_name=NRF_APP_NAME,
channel="edge",
Expand All @@ -41,7 +43,8 @@ async def _deploy_nrf(ops_test: OpsTest):

async def _deploy_tls_provider(ops_test: OpsTest):
"""Deploy a TLS provider."""
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
TLS_PROVIDER_APP_NAME,
application_name=TLS_PROVIDER_APP_NAME,
channel="beta",
Expand All @@ -52,11 +55,12 @@ async def _deploy_tls_provider(ops_test: OpsTest):
@pytest.mark.abort_on_fail
async def build_and_deploy(ops_test: OpsTest):
"""Build the charm-under-test and deploy it."""
assert ops_test.model
charm = await ops_test.build_charm(".")
resources = {
"smf-image": METADATA["resources"]["smf-image"]["upstream-source"],
}
await ops_test.model.deploy( # type: ignore[union-attr]
await ops_test.model.deploy(
charm,
resources=resources,
application_name=APP_NAME,
Expand All @@ -71,7 +75,8 @@ async def build_and_deploy(ops_test: OpsTest):
async def test_given_charm_is_built_when_deployed_then_status_is_blocked(
ops_test: OpsTest, build_and_deploy
):
await ops_test.model.wait_for_idle( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="blocked",
timeout=1000,
Expand All @@ -80,16 +85,17 @@ async def test_given_charm_is_built_when_deployed_then_status_is_blocked(

@pytest.mark.abort_on_fail
async def test_relate_and_wait_for_active_status(ops_test: OpsTest, build_and_deploy):
await ops_test.model.add_relation( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.integrate(
relation1=f"{NRF_APP_NAME}:database", relation2=f"{DATABASE_APP_NAME}"
)
await ops_test.model.add_relation( # type: ignore[union-attr]
await ops_test.model.integrate(
relation1=f"{APP_NAME}:database", relation2=f"{DATABASE_APP_NAME}"
)
await ops_test.model.add_relation(relation1=NRF_APP_NAME, relation2=TLS_PROVIDER_APP_NAME) # type: ignore[union-attr] # noqa: E501
await ops_test.model.add_relation(relation1=APP_NAME, relation2=NRF_APP_NAME) # type: ignore[union-attr] # noqa: E501
await ops_test.model.add_relation(relation1=APP_NAME, relation2=TLS_PROVIDER_APP_NAME) # type: ignore[union-attr] # noqa: E501
await ops_test.model.wait_for_idle( # type: ignore[union-attr]
await ops_test.model.integrate(relation1=NRF_APP_NAME, relation2=TLS_PROVIDER_APP_NAME)
await ops_test.model.integrate(relation1=APP_NAME, relation2=NRF_APP_NAME)
await ops_test.model.integrate(relation1=APP_NAME, relation2=TLS_PROVIDER_APP_NAME)
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
timeout=1000,
Expand All @@ -98,41 +104,43 @@ async def test_relate_and_wait_for_active_status(ops_test: OpsTest, build_and_de

@pytest.mark.abort_on_fail
async def test_remove_nrf_and_wait_for_blocked_status(ops_test: OpsTest, build_and_deploy):
await ops_test.model.remove_application(NRF_APP_NAME, block_until_done=True) # type: ignore[union-attr] # noqa: E501
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="blocked", timeout=60) # type: ignore[union-attr] # noqa: E501
assert ops_test.model
await ops_test.model.remove_application(NRF_APP_NAME, block_until_done=True)
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="blocked", timeout=60)


@pytest.mark.abort_on_fail
async def test_restore_nrf_and_wait_for_active_status(ops_test: OpsTest, build_and_deploy):
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
NRF_APP_NAME,
application_name=NRF_APP_NAME,
channel="edge",
trust=True,
)
await ops_test.model.add_relation( # type: ignore[union-attr]
await ops_test.model.integrate(
relation1=f"{NRF_APP_NAME}:database", relation2=DATABASE_APP_NAME
)
await ops_test.model.add_relation(relation1=NRF_APP_NAME, relation2=TLS_PROVIDER_APP_NAME) # type: ignore[union-attr] # noqa: E501
await ops_test.model.add_relation(relation1=APP_NAME, relation2=NRF_APP_NAME) # type: ignore[union-attr] # noqa: E501
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000) # type: ignore[union-attr] # noqa: E501
await ops_test.model.integrate(relation1=NRF_APP_NAME, relation2=TLS_PROVIDER_APP_NAME)
await ops_test.model.integrate(relation1=APP_NAME, relation2=NRF_APP_NAME)
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)


@pytest.mark.abort_on_fail
async def test_remove_tls_and_wait_for_blocked_status(ops_test: OpsTest, build_and_deploy):
await ops_test.model.remove_application(TLS_PROVIDER_APP_NAME, block_until_done=True) # type: ignore[union-attr] # noqa: E501
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="blocked", timeout=60) # type: ignore[union-attr] # noqa: E501
assert ops_test.model
await ops_test.model.remove_application(TLS_PROVIDER_APP_NAME, block_until_done=True)
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="blocked", timeout=60)


@pytest.mark.abort_on_fail
async def test_restore_tls_and_wait_for_active_status(ops_test: OpsTest, build_and_deploy):
await ops_test.model.deploy( # type: ignore[union-attr]
assert ops_test.model
await ops_test.model.deploy(
TLS_PROVIDER_APP_NAME,
application_name=TLS_PROVIDER_APP_NAME,
channel="beta",
trust=True,
)
await ops_test.model.add_relation( # type: ignore[union-attr]
relation1=APP_NAME, relation2=TLS_PROVIDER_APP_NAME
)
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000) # type: ignore[union-attr] # noqa: E501
await ops_test.model.integrate(relation1=APP_NAME, relation2=TLS_PROVIDER_APP_NAME)
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)

0 comments on commit 1c7ea1d

Please sign in to comment.