Skip to content

Commit

Permalink
feat: enable mailing for testing (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Oct 4, 2023
1 parent 10cdb80 commit 5759481
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 8 deletions.
1 change: 1 addition & 0 deletions basedosdados_api/account/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AccountCreationForm(forms.ModelForm):
is_active = forms.BooleanField(
label="Está ativo?",
initial=True,
required=False,
help_text="Marque ativo para não enviar email de confirmação",
)

Expand Down
4 changes: 1 addition & 3 deletions basedosdados_api/account/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from basedosdados_api.account.models import Account
from basedosdados_api.account.token import token_generator
from basedosdados_api.settings import EMAIL_HOST_USER
from basedosdados_api.utils import is_prod


@receiver(post_save, sender=Account)
Expand All @@ -20,9 +19,8 @@ def send_activation_email(sender, instance, created, raw, **kwargs):
- The account is new
- The account isn't active
- The account isn't a fixture
- The account is in production environment
"""
if created and not raw and not instance.is_active and is_prod():
if created and not raw and not instance.is_active:
to_email = instance.email
from_email = EMAIL_HOST_USER
subject = "Bem Vindo à Base dos Dados!"
Expand Down
5 changes: 0 additions & 5 deletions basedosdados_api/account/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


@pytest.mark.django_db
@patch("basedosdados_api.account.signals.is_prod", new=lambda: True)
def test_account_create():
account = Account.objects.create(
username="john.doe",
Expand All @@ -22,7 +21,6 @@ def test_account_create():

@pytest.mark.django_db
@patch("basedosdados_api.account.signals.EmailMultiAlternatives")
@patch("basedosdados_api.account.signals.is_prod", new=lambda: True)
def test_activate_account_signal(mock: MagicMock):
Account.objects.create(
username="john.doe",
Expand All @@ -35,7 +33,6 @@ def test_activate_account_signal(mock: MagicMock):

@pytest.mark.django_db
@patch("basedosdados_api.account.signals.render_to_string")
@patch("basedosdados_api.account.signals.is_prod", new=lambda: True)
def test_activate_account_confirmation(mock: MagicMock, client: Client):
account = Account.objects.create(
username="john.doe",
Expand All @@ -55,7 +52,6 @@ def test_activate_account_confirmation(mock: MagicMock, client: Client):

@pytest.mark.django_db
@patch("basedosdados_api.account.views.EmailMultiAlternatives")
@patch("basedosdados_api.account.signals.is_prod", new=lambda: True)
def test_password_reset_request(mock: MagicMock, client: Client):
account = Account.objects.create(
username="john.doe",
Expand All @@ -76,7 +72,6 @@ def test_password_reset_request(mock: MagicMock, client: Client):
@pytest.mark.django_db
@patch("basedosdados_api.account.views.render_to_string")
@patch("basedosdados_api.account.signals.render_to_string")
@patch("basedosdados_api.account.signals.is_prod", new=lambda: True)
def test_password_reset_confirmation(mock_signal: MagicMock, mock_view: MagicMock, client: Client):
# Create account
account = Account.objects.create(
Expand Down

0 comments on commit 5759481

Please sign in to comment.