1212from pytest_operator .plugin import OpsTest
1313from tenacity import Retrying , stop_after_attempt , wait_fixed
1414
15+ from constants import DATABASE_DEFAULT_NAME
16+
1517from ..helpers import (
1618 CHARM_BASE ,
1719 assert_sync_standbys ,
@@ -277,7 +279,10 @@ async def test_two_applications_doesnt_share_the_same_relation_data(ops_test: Op
277279 (another_application_app_name , f"{ APPLICATION_APP_NAME .replace ('-' , '_' )} _database" ),
278280 ]:
279281 connection_string = await build_connection_string (
280- ops_test , application , FIRST_DATABASE_RELATION_NAME , database = "postgres"
282+ ops_test ,
283+ application ,
284+ FIRST_DATABASE_RELATION_NAME ,
285+ database = DATABASE_DEFAULT_NAME ,
281286 )
282287 with pytest .raises (psycopg2 .Error ):
283288 psycopg2 .connect (connection_string )
@@ -487,7 +492,7 @@ async def test_admin_role(ops_test: OpsTest):
487492
488493 # Check that the user can access all the databases.
489494 for database in [
490- "postgres" ,
495+ DATABASE_DEFAULT_NAME ,
491496 f"{ APPLICATION_APP_NAME .replace ('-' , '_' )} _database" ,
492497 "another_application_database" ,
493498 ]:
@@ -511,11 +516,11 @@ async def test_admin_role(ops_test: OpsTest):
511516 )
512517 assert version == data
513518
514- # Write some data (it should fail in the "postgres" database).
519+ # Write some data (it should fail in the default database name ).
515520 random_name = (
516521 f"test_{ '' .join (secrets .choice (string .ascii_lowercase ) for _ in range (10 ))} "
517522 )
518- should_fail = database == "postgres"
523+ should_fail = database == DATABASE_DEFAULT_NAME
519524 cursor .execute (f"CREATE TABLE { random_name } (data TEXT);" )
520525 if should_fail :
521526 assert False , (
@@ -533,7 +538,7 @@ async def test_admin_role(ops_test: OpsTest):
533538
534539 # Test the creation and deletion of databases.
535540 connection_string = await build_connection_string (
536- ops_test , DATA_INTEGRATOR_APP_NAME , "postgresql" , database = "postgres"
541+ ops_test , DATA_INTEGRATOR_APP_NAME , "postgresql" , database = DATABASE_DEFAULT_NAME
537542 )
538543 connection = psycopg2 .connect (connection_string )
539544 connection .autocommit = True
@@ -542,8 +547,10 @@ async def test_admin_role(ops_test: OpsTest):
542547 cursor .execute (f"CREATE DATABASE { random_name } ;" )
543548 cursor .execute (f"DROP DATABASE { random_name } ;" )
544549 try :
545- cursor .execute ("DROP DATABASE postgres;" )
546- assert False , "the admin extra user role was able to drop the `postgres` system database"
550+ cursor .execute (f"DROP DATABASE { DATABASE_DEFAULT_NAME } ;" )
551+ assert False , (
552+ f"the admin extra user role was able to drop the `{ DATABASE_DEFAULT_NAME } ` system database"
553+ )
547554 except psycopg2 .errors .InsufficientPrivilege :
548555 # Ignore the error, as the admin extra user role mustn't be able to drop
549556 # the "postgres" system database.
0 commit comments