def parse(cls, body: Dict): return cls( Recipient.parse_optional(body.get("author")), [Recipient.parse(reviewer) for reviewer in body["reviewers"]], body["commentCount"], body["transactionLink"], )
def parse(cls, body: dict): return cls( Recipient.parse_many(body["reviewers"]), Recipient.parse_many(body["subscribers"]), body["commentCount"], body["transactionLink"], )
def parse(cls, body: dict): return cls( Recipient.parse_optional(body.get("author")), Recipient.parse_many(body["reviewers"]), Recipient.parse_many(body["subscribers"]), body["transactionLink"], )
def parse(cls, body: Dict): return cls( body.get("mainComment"), InlineComment.parse_many(body["inlineComments"]), body["transactionLink"], Recipient.parse_optional(body.get("author")), [Recipient.parse(reviewer) for reviewer in body["reviewers"]], )
def test_target(): batch = MailBatch(MockTemplateStore()) batch.target(Recipient("1@mail", "1", timezone.utc, False), "template-author") batch.target(Recipient("2@mail", "2", timezone.utc, False), "template-reviewer") emails = batch.process(PUBLIC_REVISION, "actor", 0, 0, EVENT) assert len(emails) == 2 assert emails[0].to == "1@mail" assert emails[1].to == "2@mail"
def parse(cls, body: dict): return cls( body.get("landoLink"), body["isReadyToLand"], Recipient.parse_optional(body.get("author")), Recipient.parse_many(body["reviewers"]), Recipient.parse_many(body["subscribers"]), body["commentCount"], body["transactionLink"], )
def test_only_sends_to_each_recipient_once(): batch = MailBatch(MockTemplateStore()) batch.target(Recipient("1@mail", "1", timezone.utc, False), "template-author") batch.target_many( [ Recipient("1@mail", "1", timezone.utc, False), Recipient("2@mail", "2", timezone.utc, False), ], "template-reviewer", ) emails = batch.process(PUBLIC_REVISION, ACTOR, 0, 0, EVENT) assert len(emails) == 2 assert emails[0].to == "1@mail" assert emails[1].to == "2@mail"
def process_event_to_emails_with_minimal_context( self, timestamp: int, context: dict, thread_store: ThreadStore): """Turn the minimal Phabricator context into outgoing emails.""" revision = MinimalRevision.parse(context["revision"]) recipients = Recipient.parse_many(context["recipients"]) thread = thread_store.get_or_create(revision.id) thread.email_count += 1 emails = [] for recipient in recipients: if recipient.is_actor: continue template = self._template_store.get("minimal") html_email, text_email = template.render({ "revision": revision, "recipient_username": recipient.username, "unique_number": thread.email_count, "event": context, }) emails.append( OutgoingEmail( "minimal", f"D{revision.id}", recipient.email, timestamp, html_email, text_email, )) return emails
def parse(cls, body: dict): return cls( body["isReadyToLand"], body["newChangesLink"], Reviewer.parse_many(body["reviewers"]), Recipient.parse_many(body["subscribers"]), )
def parse(cls, body: Dict): return cls( Recipient.parse(body["recipient"]), body.get("pingedMainComment"), InlineComment.parse_many(body["pingedInlineComments"]), body["transactionLink"], )
def parse(cls, body: Dict): return cls( body["isReadyToLand"], body["isTitleChanged"], body["isBugChanged"], Recipient.parse_optional(body.get("author")), MetadataEditedReviewer.parse_many(body["reviewers"]), )
def parse(cls, reviewer: Dict): return cls( reviewer["name"], reviewer["isActionable"], ReviewerStatus(reviewer["status"]), ExistenceChange(reviewer["metadataChange"]), Recipient.parse_many(reviewer["recipients"]), )
def test_target_many(): batch = MailBatch(MockTemplateStore()) batch.target_many( [ Recipient("1@mail", "1", timezone.utc, False), Recipient("2@mail", "2", timezone.utc, False), ], "template-reviewer", ) batch.target_many( [ Recipient("3@mail", "3", timezone.utc, False), Recipient("4@mail", "4", timezone.utc, False), ], "template-reviewer", ) emails = batch.process(PUBLIC_REVISION, "actor", 0, 0, EVENT) assert len(emails) == 4 assert emails[0].to == "1@mail" assert emails[1].to == "2@mail" assert emails[2].to == "3@mail" assert emails[3].to == "4@mail"
def test_integration_templates(): template_store = TemplateStore("", "", False) template = template_store.get(PUBLIC_TEMPLATE_PATH_PREFIX + "pinged") html, text = template.render( { "revision": Revision(1, "revision", "link", None), "actor_name": "actor", "recipient_username": "******", "unique_number": 0, "event": RevisionCommentPinged( Recipient("1@mail", "1", timezone.utc, False), "you've been pinged", [], "link", ), } ) assert "actor mentioned you" in html assert "you've been pinged" in html assert "actor mentioned you" in text assert "you've been pinged" in text
def parse(cls, body: Dict): return cls( [Recipient.parse(reviewer) for reviewer in body["reviewers"]], body["commentCount"], body["transactionLink"], )
def parse(cls, body: dict): return cls( Reviewer.parse_many(body["reviewers"]), Recipient.parse_many(body["subscribers"]), )
def test_filter_target_is_actor(): batch = MailBatch(MockTemplateStore()) batch.target(Recipient("1@mail", "1", timezone.utc, True), "template-author") emails = batch.process(PUBLIC_REVISION, "actor", 0, 0, EVENT) assert len(emails) == 0
def parse(cls, body: Dict): return cls( Recipient.parse(body["recipient"]), body["transactionLink"], )
# License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. from datetime import timezone from phabricatoremails.render.events.common import Recipient from phabricatoremails.render.events.phabricator import Revision, RevisionCreated from phabricatoremails.render.events.phabricator_secure import SecureRevision, SecureBug from phabricatoremails.render.mailbatch import ( MailBatch, PUBLIC_TEMPLATE_PATH_PREFIX, SECURE_TEMPLATE_PATH_PREFIX, ) from tests.render.mock_template import MockTemplateStore NON_ACTOR_RECIPIENT = Recipient("1@mail", "1", timezone.utc, False) PUBLIC_REVISION = Revision(1, "revision", "link", None) EVENT = RevisionCreated([], []) def test_target(): batch = MailBatch(MockTemplateStore()) batch.target(Recipient("1@mail", "1", timezone.utc, False), "template-author") batch.target(Recipient("2@mail", "2", timezone.utc, False), "template-reviewer") emails = batch.process(PUBLIC_REVISION, "actor", 0, 0, EVENT) assert len(emails) == 2 assert emails[0].to == "1@mail" assert emails[1].to == "2@mail" def test_target_many():