mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-21 10:16:13 +02:00
Set transition domain's email_sent flag as the emails are sent
This commit is contained in:
parent
dcbb54f799
commit
4402dfd90d
2 changed files with 24 additions and 10 deletions
|
@ -65,8 +65,6 @@ class Command(BaseCommand):
|
|||
self.send_emails()
|
||||
logger.info("done sending emails")
|
||||
|
||||
self.update_domains_as_sent()
|
||||
|
||||
logger.info("done sending emails and updating transition_domains")
|
||||
else:
|
||||
logger.info("not sending emails")
|
||||
|
@ -143,11 +141,13 @@ class Command(BaseCommand):
|
|||
# to True
|
||||
for domain in email_data["domains"]:
|
||||
self.domains_with_errors.append(domain)
|
||||
|
||||
def update_domains_as_sent(self):
|
||||
"""set email_sent to True in all transition_domains which have
|
||||
been processed successfully"""
|
||||
for transition_domain in self.transition_domains:
|
||||
if transition_domain.domain_name not in self.domains_with_errors:
|
||||
transition_domain.email_sent = True
|
||||
transition_domain.save()
|
||||
else:
|
||||
# email was sent no exception, mark all these transition domains
|
||||
# as email_sent.
|
||||
this_email = email_data["email"]
|
||||
for domain_name in email_data["domains"]:
|
||||
# self.transition_domains is a queryset so we can sub-select
|
||||
# from it and use the objects to mark them as sent
|
||||
this_transition_domain = self.transition_domains.get(username=this_email, domain_name=domain_name)
|
||||
this_transition_domain.email_sent = True
|
||||
this_transition_domain.save()
|
||||
|
|
|
@ -13,6 +13,8 @@ from registrar.models import (
|
|||
UserDomainRole,
|
||||
)
|
||||
|
||||
import boto3_mocking # type: ignore
|
||||
|
||||
from django.core.management import call_command
|
||||
from unittest.mock import patch
|
||||
|
||||
|
@ -413,3 +415,15 @@ class TestMigrations(TestCase):
|
|||
self.assertIn("Found 2 transition domains", output)
|
||||
self.assertTrue("would send email to testuser@gmail.com", output)
|
||||
self.assertTrue("would send email to agustina.wyman7@test.com", output)
|
||||
|
||||
# this tries to actually send an email, so mock it out
|
||||
@boto3_mocking.patching
|
||||
def test_send_domain_invitations_email_sent(self):
|
||||
"""A transition domain is marked email_sent."""
|
||||
with less_console_noise():
|
||||
self.run_load_domains()
|
||||
self.run_transfer_domains()
|
||||
call_command("send_domain_invitations", "-s", "testuser@gmail.com")
|
||||
|
||||
self.assertTrue(TransitionDomain.objects.get(username="testuser@gmail.com").email_sent)
|
||||
self.assertFalse(TransitionDomain.objects.get(username="agustina.wyman7@test.com").email_sent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue