-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
send project invtation email when email is updated
- Loading branch information
1 parent
c3b2b0b
commit 2274a88
Showing
2 changed files
with
62 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3018,6 +3018,9 @@ def test_role_valid(self, mock_send_mail): | |
mock_send_mail.assert_not_called() | ||
|
||
|
||
@patch( | ||
"onadata.libs.serializers.project_invitation_serializer.send_project_invitation_email_async.delay" | ||
) | ||
class UpdateProjectInvitationTestCase(TestAbstractViewSet): | ||
"""Tests for update project invitation""" | ||
|
||
|
@@ -3031,25 +3034,25 @@ def setUp(self): | |
status=ProjectInvitation.Status.PENDING, | ||
) | ||
|
||
def test_authentication(self): | ||
def test_authentication(self, mock_send_mail): | ||
"""Authentication is required""" | ||
request = self.factory.put("/", data={}) | ||
response = self.view(request, pk=self.project.pk) | ||
self.assertEqual(response.status_code, 401) | ||
|
||
def test_invalid_project(self): | ||
def test_invalid_project(self, mock_send_mail): | ||
"""Invalid project is handled""" | ||
request = self.factory.put("/", data={}, **self.extra) | ||
response = self.view(request, pk=817) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_invalid_invitation_id(self): | ||
def test_invalid_invitation_id(self, mock_send_mail): | ||
"""Invalid project invitation is handled""" | ||
request = self.factory.put("/", data={}, **self.extra) | ||
response = self.view(request, pk=self.project.pk) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_only_admins_allowed(self): | ||
def test_only_admins_allowed(self, mock_send_mail): | ||
"""Only project admins are allowed to update project invitation""" | ||
# login as editor alice | ||
alice_data = {"username": "alice", "email": "[email protected]"} | ||
|
@@ -3070,7 +3073,8 @@ def test_only_admins_allowed(self): | |
else: | ||
self.assertEqual(response.status_code, 403) | ||
|
||
def test_update(self): | ||
@override_settings(PROJECT_INVITATION_URL="https://example.com/register") | ||
def test_update(self, mock_send_mail): | ||
"""We can update an invitation""" | ||
payload = { | ||
"email": "[email protected]", | ||
|
@@ -3097,8 +3101,11 @@ def test_update(self): | |
"status": 1, | ||
}, | ||
) | ||
mock_send_mail.assert_called_once_with( | ||
self.invitation.pk, "https://example.com/register" | ||
) | ||
|
||
def test_update_role_only(self): | ||
def test_update_role_only(self, mock_send_mail): | ||
"""We can update role only""" | ||
payload = { | ||
"email": self.invitation.email, | ||
|
@@ -3124,8 +3131,10 @@ def test_update_role_only(self): | |
"status": 1, | ||
}, | ||
) | ||
mock_send_mail.assert_not_called() | ||
|
||
def test_update_email_only(self): | ||
@override_settings(PROJECT_INVITATION_URL="https://example.com/register") | ||
def test_update_email_only(self, mock_send_mail): | ||
"""We can update email only""" | ||
payload = { | ||
"email": "[email protected]", | ||
|
@@ -3151,8 +3160,11 @@ def test_update_email_only(self): | |
"status": 1, | ||
}, | ||
) | ||
mock_send_mail.assert_called_once_with( | ||
self.invitation.pk, "https://example.com/register" | ||
) | ||
|
||
def test_only_pending_allowed(self): | ||
def test_only_pending_allowed(self, mock_send_mail): | ||
"""Only pending invitation can be updated""" | ||
for value, _ in ProjectInvitation.Status.choices: | ||
invitation = self.project.invitations.create( | ||
|
@@ -3174,6 +3186,28 @@ def test_only_pending_allowed(self): | |
else: | ||
self.assertEqual(response.status_code, 400) | ||
|
||
def test_user_unregistered(self, mock_send_mail): | ||
"""Email cannot be updated to that of an unregistered user""" | ||
alice_data = {"username": "alice", "email": "[email protected]"} | ||
self._create_user_profile(alice_data) | ||
post_data = { | ||
"email": alice_data["email"], | ||
"role": "editor", | ||
"invitation_id": self.invitation.id, | ||
} | ||
request = self.factory.put( | ||
"/", | ||
data=json.dumps(post_data), | ||
content_type="application/json", | ||
**self.extra, | ||
) | ||
response = self.view(request, pk=self.project.pk) | ||
print("Helleo", response.data) | ||
self.assertEqual(response.status_code, 400) | ||
self.invitation.refresh_from_db() | ||
# invitation email not updated | ||
self.assertEqual(self.invitation.email, "[email protected]") | ||
|
||
|
||
class RevokeInvitationTestCase(TestAbstractViewSet): | ||
"""Tests for revoke invitation""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters