diff --git a/testsuite/mailhog.py b/testsuite/mailhog.py index e4198cad5..646975caa 100644 --- a/testsuite/mailhog.py +++ b/testsuite/mailhog.py @@ -44,8 +44,9 @@ def url(self) -> str: """Url of the mailhog app""" return self._url + @backoff.on_exception(backoff.expo, requests.exceptions.RequestException, max_tries=3) def request(self, method: str = "GET", params: dict = None, endpoint: str = None): - """Requests the mailhog API""" + """Requests the mailhog API with automatic retry on connection errors""" params = params or {} full_url = f"{self._url}/{endpoint}" diff --git a/testsuite/tests/system/messages/conftest.py b/testsuite/tests/system/messages/conftest.py new file mode 100644 index 000000000..4c420740a --- /dev/null +++ b/testsuite/tests/system/messages/conftest.py @@ -0,0 +1,31 @@ +""" +Conftest for messages tests. + +These tests require email notifications to be enabled. +""" + +import pytest + +NOTIFICATIONS = [ + "account_created", + "application_created", + "service_contract_created", + "account_deleted", + "service_deleted", +] + + +@pytest.fixture(scope="session", autouse=True) +def enable_notifications(threescale): + """ + Enable notification preferences for the current provider's admin user. + + After porta PR #4039, notifications use a per-user NotificationPreferences model + instead of account-level settings. In fresh deployments, notifications default to disabled. + """ + params = {f"notification_preferences[{n}]": "true" for n in NOTIFICATIONS} + threescale.rest.patch(path="/admin/api/personal/notification_preferences", data=params) + # Enable service_plans_ui_visible which defaults to false, gating service_contract_created + threescale.rest.put(path="/admin/api/settings", data={"service_plans_ui_visible": "true"}) + + yield diff --git a/testsuite/tests/system/messages/mail_templates.yml b/testsuite/tests/system/messages/mail_templates.yml index 360ba31a4..4928ad09b 100644 --- a/testsuite/tests/system/messages/mail_templates.yml +++ b/testsuite/tests/system/messages/mail_templates.yml @@ -4,7 +4,7 @@ subject_templates: Headers: '{"unique_args":{"event_name":"Accounts::AccountCreatedEvent","event_id":".*","user_id":[0-9]+,"account_id":[0-9]+},"category":\["notification","accounts/account_created_event"\]}' Body: '----==_mimepart_.+Content-Type: text/plain; charset=UTF-8Content-Transfer-Encoding: 7bitDear , from has signed-up for: .+New - user details: Username: Email: @New + user details: Username: Email: @.*New account details: Organization/Group Name: To view new signup in your 3scale Admin Portal, follow this link: https://3scale-admin./buyers/accounts/[0-9]+You are receiving this because you subscribed to this notification.View notification @@ -13,7 +13,7 @@ subject_templates: html>

Dear ,

from has signed-up for: .+

New user details:

  • Username: -
  • Email: @

New +

  • Email: @
  • .*

    New account details:

    • Organization/Group Name:

    /buyers/accounts/[0-9]+">View new signup in your 3scale Admin Portal

    =E2=80=94
    You are receiving diff --git a/testsuite/tests/system/messages/test_email_accounts.py b/testsuite/tests/system/messages/test_email_accounts.py index ae0f3de5b..9caf68f3a 100644 --- a/testsuite/tests/system/messages/test_email_accounts.py +++ b/testsuite/tests/system/messages/test_email_accounts.py @@ -97,7 +97,7 @@ def test_emails_content_after_account_creation(mailhog_client, mail_template): for m in mailhog_client.all_messages() if message_match(tpl, "Headers", headers(m).get("X-SMTPAPI", "DO NOT MATCH")) ] - assert messages, f"Didn't find assumed X-SMTPAPI: {tpl['Headers']}" + assert messages, "Didn't find any messages with expected X-SMTPAPI headers" messages = [ m