diff --git a/config/settings/base.py b/config/settings/base.py index 15a5a00a..1e28b4df 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -357,13 +357,14 @@ MATOMO_SITE_ID = int(os.getenv("MATOMO_SITE_ID", "1")) MATOMO_AUTH_TOKEN = os.getenv("MATOMO_AUTH_TOKEN", None) -# SENDINBLUE +# SENDINBLUE / BREVO # --------------------------------------- -SIB_URL = os.getenv("SIB_URL", "http://test.com") -SIB_SMTP_URL = os.path.join(SIB_URL, "smtp/email") -SIB_CONTACTS_URL = os.path.join(SIB_URL, "contacts/import") +SIB_URL = os.getenv("SIB_URL") +if SIB_URL: + SIB_SMTP_URL = os.path.join(SIB_URL, "smtp/email") + SIB_CONTACTS_URL = os.path.join(SIB_URL, "contacts/import") -SIB_API_KEY = os.getenv("SIB_API_KEY", "set-sib-api-key") +SIB_API_KEY = os.getenv("SIB_API_KEY") DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", "noreply@inclusion.gouv.fr") SIB_MAGIC_LINK_TEMPLATE = 31 diff --git a/config/settings/dev.py b/config/settings/dev.py index 94f751e3..88b0e69e 100644 --- a/config/settings/dev.py +++ b/config/settings/dev.py @@ -1,4 +1,5 @@ # Enable django-debug-toolbar with Docker. +import os import socket from lacommunaute.utils.enums import Environment @@ -15,6 +16,12 @@ ENVIRONMENT = Environment.DEV ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", "192.168.0.1"] +# SENDINBLUE / BREVO +# --------------------------------------- +SIB_URL = os.getenv("SIB_URL", "https://test.com") +SIB_SMTP_URL = os.path.join(SIB_URL, "smtp/email") +SIB_CONTACTS_URL = os.path.join(SIB_URL, "contacts/import") +SIB_API_KEY = os.getenv("SIB_API_KEY", "key_to_be_set") # Security. # ------------------------------------------------------------------------------ diff --git a/lacommunaute/notification/tests/tests_emails.py b/lacommunaute/notification/tests/tests_emails.py index fc058476..ea9c52cc 100644 --- a/lacommunaute/notification/tests/tests_emails.py +++ b/lacommunaute/notification/tests/tests_emails.py @@ -2,10 +2,10 @@ import httpx import respx +from django.conf import settings from django.test import TestCase from faker import Faker -from config.settings.base import DEFAULT_FROM_EMAIL, SIB_CONTACTS_URL, SIB_SMTP_URL from lacommunaute.notification.emails import bulk_send_user_to_list, send_email from lacommunaute.notification.models import EmailSentTrack from lacommunaute.users.factories import UserFactory @@ -17,13 +17,13 @@ class SendEmailTestCase(TestCase): @classmethod def setUpTestData(cls): - respx.post(SIB_SMTP_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) + respx.post(settings.SIB_SMTP_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) cls.to = [{"email": faker.email()}] cls.params = faker.text() cls.template_id = faker.random_int() cls.kind = "first_reply" cls.payload = { - "sender": {"name": "La Communauté", "email": DEFAULT_FROM_EMAIL}, + "sender": {"name": "La Communauté", "email": settings.DEFAULT_FROM_EMAIL}, "to": cls.to, "params": cls.params, "templateId": cls.template_id, @@ -52,7 +52,7 @@ def test_send_email_with_bcc(self): class BulkSendUserToListTestCase(TestCase): @classmethod def setUpTestData(cls): - respx.post(SIB_CONTACTS_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) + respx.post(settings.SIB_CONTACTS_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) @respx.mock def test_bulk_send_user_to_list(self): diff --git a/lacommunaute/notification/tests/tests_tasks.py b/lacommunaute/notification/tests/tests_tasks.py index 3ddee86d..24ed8429 100644 --- a/lacommunaute/notification/tests/tests_tasks.py +++ b/lacommunaute/notification/tests/tests_tasks.py @@ -8,13 +8,6 @@ from django.urls import reverse from faker import Faker -from config.settings.base import ( - DEFAULT_FROM_EMAIL, - SIB_CONTACTS_URL, - SIB_ONBOARDING_LIST, - SIB_SMTP_URL, - SIB_UNANSWERED_QUESTION_TEMPLATE, -) from lacommunaute.forum_conversation.factories import ( TopicFactory, ) @@ -37,7 +30,7 @@ @pytest.fixture(name="mock_respx_post_to_sib_smtp_url") def mock_respx_post_to_sib_smtp_url_fixture(): with respx.mock: - respx.post(SIB_SMTP_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) + respx.post(settings.SIB_SMTP_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) yield @@ -115,7 +108,7 @@ def test_num_queries(self, db, django_assert_num_queries, mock_respx_post_to_sib class AddUserToListWhenRegister(TestCase): def setUp(self): super().setUp() - respx.post(SIB_CONTACTS_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) + respx.post(settings.SIB_CONTACTS_URL).mock(return_value=httpx.Response(200, json={"message": "OK"})) @respx.mock def test_add_user_to_list_when_register(self): @@ -128,7 +121,7 @@ def test_add_user_to_list_when_register(self): ], "emailBlacklist": False, "smsBlacklist": False, - "listIds": [SIB_ONBOARDING_LIST], + "listIds": [settings.SIB_ONBOARDING_LIST], "updateExistingContacts": True, "emptyContactsAttributes": True, } @@ -163,10 +156,10 @@ def payload_for_staff_user_to_notify_on_unanswered_topics_fixture(): ) params = {"count": 1, "link": "".join(url)} payload = { - "sender": {"name": "La Communauté", "email": DEFAULT_FROM_EMAIL}, + "sender": {"name": "La Communauté", "email": settings.DEFAULT_FROM_EMAIL}, "to": to, "params": params, - "templateId": SIB_UNANSWERED_QUESTION_TEMPLATE, + "templateId": settings.SIB_UNANSWERED_QUESTION_TEMPLATE, } yield payload