-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35144 from dimagi/jc/disable-inviting-deactivated…
…-user Disabling invite a deactivated user
- Loading branch information
Showing
2 changed files
with
28 additions
and
3 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from testil import Regex | ||
|
||
from ..forms import AdminInvitesUserForm | ||
from corehq.apps.users.models import WebUser | ||
|
||
|
||
patch_query = patch.object( | ||
|
@@ -12,16 +13,24 @@ | |
lambda *ignore: True, | ||
) | ||
|
||
mock_couch_user = WebUser( | ||
username="testuser", | ||
_id="user123", | ||
domain="test-domain", | ||
) | ||
|
||
|
||
@patch_query | ||
def test_minimal_valid_form(): | ||
@patch("corehq.apps.users.models.WebUser.get_by_username", return_value=None) | ||
def test_minimal_valid_form(mock_web_user): | ||
form = create_form() | ||
|
||
assert form.is_valid(), form.errors | ||
|
||
|
||
@patch_query | ||
def test_form_is_invalid_when_invite_existing_email_with_case_mismatch(): | ||
@patch("corehq.apps.users.models.WebUser.get_by_username", return_value=None) | ||
def test_form_is_invalid_when_invite_existing_email_with_case_mismatch(mock_web_user): | ||
form = create_form( | ||
{"email": "[email protected]"}, | ||
excluded_emails=["[email protected]"], | ||
|
@@ -32,6 +41,19 @@ def test_form_is_invalid_when_invite_existing_email_with_case_mismatch(): | |
assert form.errors["email"] == [Regex(msg)], form.errors | ||
|
||
|
||
@patch_query | ||
@patch("corehq.apps.users.models.WebUser.get_by_username", return_value=mock_couch_user) | ||
def test_form_is_invalid_when_invite_deactivated_user(mock_web_user): | ||
mock_web_user.is_active = False | ||
form = create_form( | ||
{"email": "[email protected]"}, | ||
) | ||
|
||
msg = "A user with this email address is deactivated." | ||
assert not form.is_valid() | ||
assert form.errors["email"] == [Regex(msg)], form.errors | ||
|
||
|
||
def create_form(data=None, **kw): | ||
form_defaults = {"email": "[email protected]", "role": "admin"} | ||
request = RequestFactory().post("/", form_defaults | (data or {})) | ||
|