def send_mentions_bg(task): """Run sending email mentions for specified comments list in bg.""" from ggrc.notifications import people_mentions error_msg = None try: with utils.benchmark("Send people mentions"): people_mentions.send_mentions( comments_data=task.parameters.get("comments_data"), object_name=task.parameters.get("object_name"), href=task.parameters.get("href"), ) except Exception as exp: # pylint: disable=broad-except error_msg = ("Sending of people mentions has failed " "with the following error {}".format(exp.message)) logger.exception(error_msg) return utils.make_simple_response(error_msg)
def test_send_mentions(self, send_email_mock): """Test sending mentions emails.""" comments_data = set() comments_data.add( people_mentions.CommentData( author="*****@*****.**", created_at=datetime.datetime(2018, 1, 10, 7, 31, 42), comment_text=u"One <a href=\"mailto:[email protected]\"></a>", ) ) comments_data.add( people_mentions.CommentData( author="*****@*****.**", created_at=datetime.datetime(2018, 1, 10, 7, 31, 50), comment_text=u"Two <a href=\"mailto:[email protected]\"></a>", ) ) with mock.patch("ggrc.utils.user_generator.find_user", return_value=True): people_mentions.send_mentions( object_name="Object", href="api/objects/1", comments_data=comments_data ) expected_title = (u"[email protected] mentioned you " u"on a comment within Object") body = settings.EMAIL_MENTIONED_PERSON.render(person_mention={ "comments": [ (u"[email protected] mentioned you on a comment within Object " u"at 01/09/2018 23:31:42 PST:\n" u"One <a href=\"mailto:[email protected]\"></a>\n"), (u"[email protected] mentioned you on a comment within Object " u"at 01/09/2018 23:31:50 PST:\n" u"Two <a href=\"mailto:[email protected]\"></a>\n"), ], "url": "api/objects/1", }) send_email_mock.assert_called_once_with(u"*****@*****.**", expected_title, body)
def test_send_mentions(self, send_email_mock): """Test sending mentions emails.""" comments_data = set() comments_data.add( people_mentions.CommentData( author="*****@*****.**", created_at=datetime.datetime(2018, 1, 10, 7, 31, 42), comment_text=u"One <a href=\"mailto:[email protected]\"></a>", )) comments_data.add( people_mentions.CommentData( author="*****@*****.**", created_at=datetime.datetime(2018, 1, 10, 7, 31, 50), comment_text=u"Two <a href=\"mailto:[email protected]\"></a>", )) with mock.patch("ggrc.utils.user_generator.find_user", return_value=True): people_mentions.send_mentions(object_name="Object", href="api/objects/1", comments_data=comments_data) expected_title = (u"[email protected] mentioned you " u"on a comment within Object") body = settings.EMAIL_MENTIONED_PERSON.render( person_mention={ "comments": [ (u"[email protected] mentioned you on a comment within Object " u"at 01/09/2018 23:31:42 PST:\n" u"One <a href=\"mailto:[email protected]\"></a>\n"), (u"[email protected] mentioned you on a comment within Object " u"at 01/09/2018 23:31:50 PST:\n" u"Two <a href=\"mailto:[email protected]\"></a>\n"), ], "url": "api/objects/1", }) send_email_mock.assert_called_once_with(u"*****@*****.**", expected_title, body)