Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: versionning des variables applicatives #857

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: idealement faut utiliser urljoin, sinon ton os.path.join n'est pas très différent de juste une concaténation ! attention au comportement quand le SIB_URL contient déjà un path par contre.

pas grave du tout, je le dis en passant.


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", "[email protected]")

SIB_MAGIC_LINK_TEMPLATE = 31
Expand Down
7 changes: 7 additions & 0 deletions config/settings/dev.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Enable django-debug-toolbar with Docker.
import os
import socket

from lacommunaute.utils.enums import Environment
Expand All @@ -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")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi pas. après, j'aurais peut etre laissé vide en dev, et mis ça en test; comme ça ça crashe quand meme en dev et le dev sait qu'il faut MAJ la valeur, par contre les tests vont tourner en mode mock.


# Security.
# ------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions lacommunaute/notification/tests/tests_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
17 changes: 5 additions & 12 deletions lacommunaute/notification/tests/tests_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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


Expand Down Expand Up @@ -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):
Expand All @@ -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,
}
Expand Down Expand Up @@ -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

Expand Down
Loading