-
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.
Ensure PROJECT_INVITATION_URL setting works for multipe domains
- Loading branch information
1 parent
7f0c5d8
commit 3ae3e5c
Showing
4 changed files
with
61 additions
and
9 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
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 |
---|---|---|
|
@@ -2841,7 +2841,13 @@ def test_only_admins_allowed(self, mock_send_mail): | |
else: | ||
self.assertEqual(response.status_code, 403) | ||
|
||
@override_settings(PROJECT_INVITATION_URL="https://example.com/register") | ||
@override_settings( | ||
PROJECT_INVITATION_URL={ | ||
"*": "https://example.com/register", | ||
"onadata.com": "https://onadata.com/register", | ||
} | ||
) | ||
@override_settings(ALLOWED_HOSTS=["*"]) | ||
def test_create_invitation(self, mock_send_mail): | ||
"""Project invitation can be created""" | ||
post_data = { | ||
|
@@ -2882,6 +2888,31 @@ def test_create_invitation(self, mock_send_mail): | |
response = self.view(request, pk=self.project.pk) | ||
self.assertEqual(response.status_code, 400) | ||
|
||
# Project invitations are created for non-default host | ||
request = self.factory.post( | ||
"/", | ||
data=json.dumps(post_data), | ||
content_type="application/json", | ||
**self.extra, | ||
) | ||
request.META["HTTP_HOST"] = "onadata.com" | ||
response = self.view(request, pk=self.project.pk) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(self.project.invitations.count(), 1) | ||
invitation = self.project.invitations.first() | ||
self.assertEqual( | ||
response.data, | ||
{ | ||
"id": invitation.pk, | ||
"email": "[email protected]", | ||
"role": "editor", | ||
"status": 1, | ||
}, | ||
) | ||
mock_send_mail.assert_called_once_with( | ||
invitation.pk, "https://example.com/register" | ||
) | ||
|
||
def test_email_required(self, mock_send_mail): | ||
"""email is required""" | ||
# blank string | ||
|
@@ -3073,7 +3104,7 @@ def test_only_admins_allowed(self, mock_send_mail): | |
else: | ||
self.assertEqual(response.status_code, 403) | ||
|
||
@override_settings(PROJECT_INVITATION_URL="https://example.com/register") | ||
@override_settings(PROJECT_INVITATION_URL={"*": "https://example.com/register"}) | ||
def test_update(self, mock_send_mail): | ||
"""We can update an invitation""" | ||
payload = { | ||
|
@@ -3133,7 +3164,7 @@ def test_update_role_only(self, mock_send_mail): | |
) | ||
mock_send_mail.assert_not_called() | ||
|
||
@override_settings(PROJECT_INVITATION_URL="https://example.com/register") | ||
@override_settings(PROJECT_INVITATION_URL={"*": "https://example.com/register"}) | ||
def test_update_email_only(self, mock_send_mail): | ||
"""We can update email only""" | ||
payload = { | ||
|
@@ -3351,7 +3382,7 @@ def test_only_admins_allowed(self, mock_send_mail): | |
|
||
mock_send_mail.assert_not_called() | ||
|
||
@override_settings(PROJECT_INVITATION_URL="https://example.com/register") | ||
@override_settings(PROJECT_INVITATION_URL={"*": "https://example.com/register"}) | ||
def test_resend_invite(self, mock_send_mail): | ||
"""Invitation is revoked""" | ||
invitation = self.project.invitations.create( | ||
|
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
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