mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +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()
|
self.send_emails()
|
||||||
logger.info("done sending emails")
|
logger.info("done sending emails")
|
||||||
|
|
||||||
self.update_domains_as_sent()
|
|
||||||
|
|
||||||
logger.info("done sending emails and updating transition_domains")
|
logger.info("done sending emails and updating transition_domains")
|
||||||
else:
|
else:
|
||||||
logger.info("not sending emails")
|
logger.info("not sending emails")
|
||||||
|
@ -143,11 +141,13 @@ class Command(BaseCommand):
|
||||||
# to True
|
# to True
|
||||||
for domain in email_data["domains"]:
|
for domain in email_data["domains"]:
|
||||||
self.domains_with_errors.append(domain)
|
self.domains_with_errors.append(domain)
|
||||||
|
else:
|
||||||
def update_domains_as_sent(self):
|
# email was sent no exception, mark all these transition domains
|
||||||
"""set email_sent to True in all transition_domains which have
|
# as email_sent.
|
||||||
been processed successfully"""
|
this_email = email_data["email"]
|
||||||
for transition_domain in self.transition_domains:
|
for domain_name in email_data["domains"]:
|
||||||
if transition_domain.domain_name not in self.domains_with_errors:
|
# self.transition_domains is a queryset so we can sub-select
|
||||||
transition_domain.email_sent = True
|
# from it and use the objects to mark them as sent
|
||||||
transition_domain.save()
|
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,
|
UserDomainRole,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import boto3_mocking # type: ignore
|
||||||
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
@ -413,3 +415,15 @@ class TestMigrations(TestCase):
|
||||||
self.assertIn("Found 2 transition domains", output)
|
self.assertIn("Found 2 transition domains", output)
|
||||||
self.assertTrue("would send email to testuser@gmail.com", output)
|
self.assertTrue("would send email to testuser@gmail.com", output)
|
||||||
self.assertTrue("would send email to agustina.wyman7@test.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