Skip to content

Commit c317415

Browse files
committed
fix unit test. change db endpoint(mailman3_core) to db endpoint(postgresql_test_app)
1 parent 84d039a commit c317415

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

src/relations/postgresql_provider.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,6 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None:
226226
if self._check_multiple_endpoints():
227227
self.charm.unit.status = BlockedStatus(ENDPOINT_SIMULTANEOUSLY_BLOCKING_MESSAGE)
228228
return
229-
# Check which data has changed to emit customs events.
230-
_diff = diff(event, self.charm.unit)
231-
232-
# Emit a database requested event if the setup key (database name and optional
233-
# extra user roles) was added to the relation databag by the application.
234-
if "database" in _diff.added:
235-
getattr(self.database_provides.on, "database_requested").emit(
236-
event.relation, app=event.app, unit=event.unit
237-
)
238229

239230
def _update_unit_status_on_blocking_endpoint_simultaneously(self):
240231
"""Clean up Blocked status if this is due related of multiple endpoints."""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Copyright 2023 Canonical Ltd.
1+
# Copyright 2024 Canonical Ltd.
22
# See LICENSE file for licensing details.

tests/integration/relations/test_relations.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
logger = logging.getLogger(__name__)
1717

1818
APP_NAME = METADATA["name"]
19-
MAILMAN3_CORE_APP_NAME = "mailman3-core"
19+
# MAILMAN3_CORE_APP_NAME = "mailman3-core"
2020
DB_RELATION = "db"
2121
DATABASE_RELATION = "database"
2222
FIRST_DATABASE_RELATION = "first-database"
23-
APP_NAMES = [APP_NAME, APPLICATION_APP_NAME, MAILMAN3_CORE_APP_NAME]
23+
DATABASE_APP_NAME = "database-app"
24+
DB_APP_NAME = "db-app"
25+
APP_NAMES = [APP_NAME, DATABASE_APP_NAME, DB_APP_NAME]
2426

2527

2628
@pytest.mark.group(1)
@@ -33,7 +35,7 @@ async def test_deploy_charms(ops_test: OpsTest, charm):
3335
await asyncio.gather(
3436
ops_test.model.deploy(
3537
APPLICATION_APP_NAME,
36-
application_name=APPLICATION_APP_NAME,
38+
application_name=DATABASE_APP_NAME,
3739
num_units=1,
3840
series=CHARM_SERIES,
3941
channel="edge",
@@ -43,14 +45,14 @@ async def test_deploy_charms(ops_test: OpsTest, charm):
4345
application_name=APP_NAME,
4446
num_units=1,
4547
series=CHARM_SERIES,
46-
config={"profile": "testing"},
48+
config={"profile": "testing", "plugin_unaccent_enable": "True", "plugin_pg_trgm_enable": "True"},
4749
),
4850
ops_test.model.deploy(
49-
MAILMAN3_CORE_APP_NAME,
50-
application_name=MAILMAN3_CORE_APP_NAME,
51-
channel="stable",
52-
series="focal",
53-
config={"hostname": "example.org"},
51+
APPLICATION_APP_NAME,
52+
application_name=DB_APP_NAME,
53+
num_units=1,
54+
series=CHARM_SERIES,
55+
channel="edge",
5456
),
5557
)
5658

@@ -59,8 +61,8 @@ async def test_deploy_charms(ops_test: OpsTest, charm):
5961

6062
@pytest.mark.group(1)
6163
async def test_legacy_endpoint_with_multiple_related_endpoints(ops_test: OpsTest):
62-
await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}")
63-
await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}")
64+
await ops_test.model.relate(f"{DB_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}")
65+
await ops_test.model.relate(APP_NAME, f"{DATABASE_APP_NAME}:{FIRST_DATABASE_RELATION}")
6466

6567
app = ops_test.model.applications[APP_NAME]
6668
await ops_test.model.block_until(
@@ -70,7 +72,7 @@ async def test_legacy_endpoint_with_multiple_related_endpoints(ops_test: OpsTest
7072

7173
logger.info(" remove relation with modern endpoints")
7274
await ops_test.model.applications[APP_NAME].remove_relation(
73-
f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}"
75+
f"{APP_NAME}:{DATABASE_RELATION}", f"{DATABASE_APP_NAME}:{FIRST_DATABASE_RELATION}"
7476
)
7577
async with ops_test.fast_forward():
7678
await ops_test.model.wait_for_idle(
@@ -80,27 +82,27 @@ async def test_legacy_endpoint_with_multiple_related_endpoints(ops_test: OpsTest
8082
)
8183

8284
legacy_interface_connect = await get_legacy_db_connection_str(
83-
ops_test, MAILMAN3_CORE_APP_NAME, DB_RELATION, remote_unit_name=f"{APP_NAME}/0"
85+
ops_test, DB_APP_NAME, DB_RELATION, remote_unit_name=f"{APP_NAME}/0"
8486
)
8587
logger.info(f" check connect to = {legacy_interface_connect}")
8688
for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)):
8789
with attempt:
8890
with psycopg2.connect(legacy_interface_connect) as connection:
8991
assert connection.status == psycopg2.extensions.STATUS_READY
9092

91-
logger.info(" remove relation mailman3-core")
93+
logger.info(f" remove relation {DB_APP_NAME}:{DB_RELATION}")
9294
async with ops_test.fast_forward():
9395
await ops_test.model.applications[APP_NAME].remove_relation(
94-
f"{APP_NAME}:{DB_RELATION}", f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}"
96+
f"{APP_NAME}:{DB_RELATION}", f"{DB_APP_NAME}:{DB_RELATION}"
9597
)
9698
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)
9799
with pytest.raises(psycopg2.OperationalError):
98100
psycopg2.connect(legacy_interface_connect)
99101

100102

101103
async def test_modern_endpoint_with_multiple_related_endpoints(ops_test: OpsTest):
102-
await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}")
103-
await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}")
104+
await ops_test.model.relate(f"{DB_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}")
105+
await ops_test.model.relate(APP_NAME, f"{DATABASE_APP_NAME}:{FIRST_DATABASE_RELATION}")
104106

105107
app = ops_test.model.applications[APP_NAME]
106108
await ops_test.model.block_until(
@@ -110,24 +112,24 @@ async def test_modern_endpoint_with_multiple_related_endpoints(ops_test: OpsTest
110112

111113
logger.info(" remove relation with legacy endpoints")
112114
await ops_test.model.applications[APP_NAME].remove_relation(
113-
f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}"
115+
f"{DB_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}"
114116
)
115117
async with ops_test.fast_forward():
116118
await ops_test.model.wait_for_idle(status="active", timeout=3000, raise_on_error=False)
117119

118120
modern_interface_connect = await build_connection_string(
119-
ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION
121+
ops_test, DATABASE_APP_NAME, FIRST_DATABASE_RELATION
120122
)
121-
logger.info(f" check connect to = {modern_interface_connect}")
123+
logger.info(f"check connect to = {modern_interface_connect}")
122124
for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)):
123125
with attempt:
124126
with psycopg2.connect(modern_interface_connect) as connection:
125127
assert connection.status == psycopg2.extensions.STATUS_READY
126128

127-
logger.info(f" remove relation {APPLICATION_APP_NAME}")
129+
logger.info(f"remove relation {DATABASE_APP_NAME}:{FIRST_DATABASE_RELATION}")
128130
async with ops_test.fast_forward():
129131
await ops_test.model.applications[APP_NAME].remove_relation(
130-
f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}"
132+
f"{APP_NAME}:{DATABASE_RELATION}", f"{DATABASE_APP_NAME}:{FIRST_DATABASE_RELATION}"
131133
)
132134
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)
133135
for attempt in Retrying(stop=stop_after_delay(60 * 5), wait=wait_fixed(10)):

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ allowlist_externals =
2626
charmcraft
2727
charmcraftcache
2828
mv
29+
psycopg2-binary
2930
commands_pre =
3031
poetry export --only main,charm-libs --output requirements.txt
3132
commands =

0 commit comments

Comments
 (0)