You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/12/12 23:18:47 UTC
[airavata-django-portal] 07/07: AIRAVATA-3243 Set Reply-To to
PORTAL_ADMINS
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch airavata-3243
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit 0a7ba8ddba454f92ef575292956af50e8dcfcc73
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Dec 12 18:01:01 2019 -0500
AIRAVATA-3243 Set Reply-To to PORTAL_ADMINS
---
django_airavata/apps/auth/tests.py | 64 ++++++++++++++++----------------------
django_airavata/apps/auth/utils.py | 12 ++++---
2 files changed, 34 insertions(+), 42 deletions(-)
diff --git a/django_airavata/apps/auth/tests.py b/django_airavata/apps/auth/tests.py
index 50d4faa..330a18c 100644
--- a/django_airavata/apps/auth/tests.py
+++ b/django_airavata/apps/auth/tests.py
@@ -11,82 +11,72 @@ from . import signals # noqa
GATEWAY_ID = "test-gateway"
SERVER_EMAIL = "admin@test-gateway.com"
PORTAL_TITLE = "Test Gateway"
-
+PORTAL_ADMINS = [('Portal Admin', 'admin@test-gateway.com')]
@override_settings(
GATEWAY_ID=GATEWAY_ID,
SERVER_EMAIL=SERVER_EMAIL,
- PORTAL_TITLE=PORTAL_TITLE
+ PORTAL_TITLE=PORTAL_TITLE,
+ PORTAL_ADMINS=PORTAL_ADMINS
)
class EmailUserAddedToGroupSignalReceiverTests(TestCase):
- def test(self):
+ def setUp(self):
factory = RequestFactory()
- request = factory.get("/")
- user = UserProfile(
+ self.request = factory.get("/")
+ self.user = UserProfile(
airavataInternalUserId=f"testuser@{GATEWAY_ID}",
userId="testuser",
gatewayId=GATEWAY_ID,
emails=["testuser@example.com"],
firstName="Test",
lastName="User")
+
+ def test(self):
group = GroupModel(id="abc123", name="Test Group")
user_added_to_group.send(None,
- user=user,
+ user=self.user,
groups=[group],
- request=request)
+ request=self.request)
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
+ self._assert_common_email_attributes(msg)
self.assertEqual(msg.subject,
f"You've been added to group "
f"[{group.name}] in {PORTAL_TITLE}")
- self.assertEqual(msg.from_email,
- f"{PORTAL_TITLE} <{SERVER_EMAIL}>")
- self.assertSequenceEqual(
- msg.to, [f"{user.firstName} {user.lastName} <{user.emails[0]}>"])
- self.assertIn(
- request.build_absolute_uri(
- reverse("django_airavata_workspace:dashboard")),
- msg.body)
- self.assertIn(
- request.build_absolute_uri(
- reverse("django_airavata_workspace:experiments")),
- msg.body)
- self.assertIn(user.userId, msg.body)
def test_multiple_groups(self):
- factory = RequestFactory()
- request = factory.get("/")
- user = UserProfile(
- airavataInternalUserId=f"testuser@{GATEWAY_ID}",
- userId="testuser",
- gatewayId=GATEWAY_ID,
- emails=["testuser@example.com"],
- firstName="Test",
- lastName="User")
group1 = GroupModel(id="abc123", name="Test Group")
group2 = GroupModel(id="group2", name="Group 2")
user_added_to_group.send(None,
- user=user,
+ user=self.user,
groups=[group1, group2],
- request=request)
+ request=self.request)
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
+ self._assert_common_email_attributes(msg)
self.assertEqual(msg.subject,
f"You've been added to groups "
f"[{group1.name}] and [{group2.name}] "
f"in {PORTAL_TITLE}")
+ self.assertIn("groups Test Group and Group 2", msg.body)
+
+ def _assert_common_email_attributes(self, msg):
self.assertEqual(msg.from_email,
- f"{PORTAL_TITLE} <{SERVER_EMAIL}>")
+ f"\"{PORTAL_TITLE}\" <{SERVER_EMAIL}>")
+ self.assertEqual(
+ msg.reply_to,
+ [f"\"{PORTAL_ADMINS[0][0]}\" <{PORTAL_ADMINS[0][1]}>"])
self.assertSequenceEqual(
- msg.to, [f"{user.firstName} {user.lastName} <{user.emails[0]}>"])
+ msg.to, [f"\"{self.user.firstName} {self.user.lastName}\" "
+ f"<{self.user.emails[0]}>"])
self.assertIn(
- request.build_absolute_uri(
+ self.request.build_absolute_uri(
reverse("django_airavata_workspace:dashboard")),
msg.body)
self.assertIn(
- request.build_absolute_uri(
+ self.request.build_absolute_uri(
reverse("django_airavata_workspace:experiments")),
msg.body)
- self.assertIn(user.userId, msg.body)
- self.assertIn("groups Test Group and Group 2", msg.body)
+ self.assertIn(self.user.userId, msg.body)
+
diff --git a/django_airavata/apps/auth/utils.py b/django_airavata/apps/auth/utils.py
index 50a1e16..0c35a3b 100644
--- a/django_airavata/apps/auth/utils.py
+++ b/django_airavata/apps/auth/utils.py
@@ -109,10 +109,12 @@ def send_email_to_user(template_id, context):
msg = EmailMessage(
subject=subject,
body=body,
- from_email="{} <{}>".format(settings.PORTAL_TITLE,
- settings.SERVER_EMAIL),
- to=["{} {} <{}>".format(context['first_name'],
- context['last_name'],
- context['email'])])
+ from_email="\"{}\" <{}>".format(settings.PORTAL_TITLE,
+ settings.SERVER_EMAIL),
+ to=["\"{} {}\" <{}>".format(context['first_name'],
+ context['last_name'],
+ context['email'])],
+ reply_to=[f"\"{a[0]}\" <{a[1]}>" for a in settings.PORTAL_ADMINS]
+ )
msg.content_subtype = 'html'
msg.send()