Skip to content

Commit

Permalink
make rel test checks more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed May 3, 2024
1 parent 7e51f4b commit 227afc7
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions tests/integration/relation_tests/test_charm_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
from tenacity import RetryError

from ..ha_tests.helpers import get_replica_set_primary as replica_set_primary
from ..helpers import (
check_or_scale_app,
get_address_of_unit,
get_app_name,
run_mongo_op,
)
from ..helpers import check_or_scale_app, get_app_name, run_mongo_op
from .helpers import (
get_application_relation_data,
get_connection_string,
Expand Down Expand Up @@ -295,7 +290,6 @@ async def test_app_relation_metadata_change(ops_test: OpsTest) -> None:
await verify_crud_operations(ops_test, scaled_down_string)


@pytest.mark.group(1)
async def test_user_with_extra_roles(ops_test: OpsTest):
"""Test superuser actions (ie creating a new user and creating a new database)."""
connection_string = await get_connection_string(
Expand All @@ -309,14 +303,17 @@ async def test_user_with_extra_roles(ops_test: OpsTest):
result = await run_mongo_op(
ops_test, cmd, f'"{connection_string}"', stringify=False, expect_json_load=False
)
addresses = [await get_address_of_unit(ops_test, unit_id) for unit_id in range(REQUIRED_UNITS)]
hosts = ",".join(addresses)
mongo_uri = f"mongodb://newTestUser:Test123@{hosts}/new_database"
cmd = "db.getUsers();"

result = await run_mongo_op(
ops_test, f'"{cmd}"', f'"{connection_string}"', stringify=False, expect_json_load=False
)
assert "application_first_database.newTestUser" in str(result)
cmd = 'db = db.getSiblingDB("new_database"); db.test_collection.insertOne({"test": "one"});'
result = await run_mongo_op(
ops_test, cmd, f'"{mongo_uri}"', stringify=False, expect_json_load=False
ops_test, cmd, f'"{connection_string}"', stringify=False, expect_json_load=False
)
assert '"acknowledged" : true' in result.data
assert "acknowledged: true" in str(result.data)


@pytest.mark.group(1)
Expand Down

0 comments on commit 227afc7

Please sign in to comment.