(tests) update tests to look for dimail secret in settings

Update back-end tests to match 'secret' field being moved to settings.
This commit is contained in:
Marie PUPO JEAMMET
2024-08-30 17:05:23 +02:00
committed by Marie
parent ba30b1d3ee
commit 29904ef7b6
4 changed files with 10 additions and 6 deletions

View File

@@ -31,7 +31,6 @@ class MailDomainFactory(factory.django.DjangoModelFactory):
name = factory.Faker("domain_name")
slug = factory.LazyAttribute(lambda o: slugify(o.name))
secret = factory.Faker("password")
@factory.post_generation
def users(self, create, extracted, **kwargs):

View File

@@ -438,7 +438,7 @@ def test_api_mailboxes__secret_unrelated_to_domain():
assert response.status_code == status.HTTP_403_FORBIDDEN
assert response.json() == {
"detail": f"Secret not valid for this domain {access.domain.name}"
"detail": "Permission denied. Please check your MAIL_PROVISIONING_API_CREDENTIALS."
}
assert not models.Mailbox.objects.exists()

View File

@@ -8,6 +8,7 @@ from logging import Logger
from unittest import mock
from django.core import exceptions
from django.test.utils import override_settings
import pytest
import responses
@@ -143,13 +144,17 @@ def test_models_mailboxes__cannot_be_created_for_pending_maildomain():
### SYNC TO DIMAIL-API
@override_settings(MAIL_PROVISIONING_API_CREDENTIALS=None)
def test_models_mailboxes__no_secret():
"""If no secret is declared on the domain, the function should raise an error."""
domain = factories.MailDomainEnabledFactory(secret=None)
"""
If MAIL_PROVISIONING_API_CREDENTIALS setting is not configured,
trying to create a mailbox should raise an error.
"""
domain = factories.MailDomainEnabledFactory()
with pytest.raises(
exceptions.ValidationError,
match="Please configure your domain's secret before creating any mailbox.",
match="Please configure MAIL_PROVISIONING_API_CREDENTIALS before creating any mailbox.",
):
factories.MailboxFactory(domain=domain)

View File

@@ -581,7 +581,7 @@ class Test(Base):
CELERY_TASK_ALWAYS_EAGER = values.BooleanValue(True)
# this is a dev credentials for mail provisioning API
MAIL_PROVISIONING_API_CREDENTIALS = "bGFfcmVnaWU6cGFzc3dvcmQ"
MAIL_PROVISIONING_API_CREDENTIALS = "bGFfcmVnaWU6cGFzc3dvcmQ="
class ContinuousIntegration(Test):