Skip to content

Commit a728a20

Browse files
committed
Change helper function
1 parent 71f86ac commit a728a20

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

tests/integration/helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def check_database_users_existence(
3030
"""
3131
unit = ops_test.model.applications[DATABASE_APP_NAME].units[0]
3232
unit_address = await get_unit_address(ops_test, unit.name)
33-
password = await get_operator_password(ops_test)
33+
password = await get_password(ops_test)
3434

3535
# Retrieve all users in the database.
3636
output = await execute_query_on_unit(
@@ -61,7 +61,7 @@ async def check_database_creation(ops_test: OpsTest, database: str) -> None:
6161
ops_test: The ops test framework
6262
database: Name of the database that should have been created
6363
"""
64-
password = await get_operator_password(ops_test)
64+
password = await get_password(ops_test)
6565

6666
for unit in ops_test.model.applications[DATABASE_APP_NAME].units:
6767
unit_address = await get_unit_address(ops_test, unit.name)
@@ -196,12 +196,12 @@ def get_application_units(ops_test: OpsTest, application_name: str) -> List[str]
196196
]
197197

198198

199-
async def get_operator_password(ops_test: OpsTest):
200-
"""Retrieve the operator user password using the action."""
199+
async def get_password(ops_test: OpsTest, username: str = "operator"):
200+
"""Retrieve a user password using the action."""
201201
unit = ops_test.model.units.get(f"{DATABASE_APP_NAME}/0")
202-
action = await unit.run_action("get-password")
202+
action = await unit.run_action("get-password", **{"username": username})
203203
result = await action.wait()
204-
return result.results["operator-password"]
204+
return result.results[f"{username}-password"]
205205

206206

207207
async def get_primary(ops_test: OpsTest, unit_id=0) -> str:

tests/integration/test_charm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
convert_records_to_dict,
1919
get_application_units,
2020
get_cluster_members,
21-
get_operator_password,
21+
get_password,
2222
get_unit_address,
2323
scale_application,
2424
)
@@ -74,7 +74,7 @@ async def test_database_is_up(ops_test: OpsTest, unit_id: int):
7474

7575
@pytest.mark.parametrize("unit_id", UNIT_IDS)
7676
async def test_settings_are_correct(ops_test: OpsTest, unit_id: int):
77-
password = await get_operator_password(ops_test)
77+
password = await get_password(ops_test)
7878

7979
# Connect to PostgreSQL.
8080
host = await get_unit_address(ops_test, f"{APP_NAME}/{unit_id}")
@@ -162,7 +162,7 @@ async def test_scale_down_and_up(ops_test: OpsTest):
162162
async def test_persist_data_through_graceful_restart(ops_test: OpsTest):
163163
"""Test data persists through a graceful restart."""
164164
primary = await get_primary(ops_test)
165-
password = await get_operator_password(ops_test)
165+
password = await get_password(ops_test)
166166
address = await get_unit_address(ops_test, primary)
167167

168168
# Write data to primary IP.
@@ -190,7 +190,7 @@ async def test_persist_data_through_graceful_restart(ops_test: OpsTest):
190190
async def test_persist_data_through_failure(ops_test: OpsTest):
191191
"""Test data persists through a failure."""
192192
primary = await get_primary(ops_test)
193-
password = await get_operator_password(ops_test)
193+
password = await get_password(ops_test)
194194
address = await get_unit_address(ops_test, primary)
195195

196196
# Write data to primary IP.

0 commit comments

Comments
 (0)