-
-
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.
Add new test to make sure we don't invite deactivated user
- Loading branch information
1 parent
7c02205
commit 2506997
Showing
1 changed file
with
20 additions
and
0 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from testil import Regex | ||
|
||
from ..forms import AdminInvitesUserForm | ||
from corehq.apps.users.models import WebUser | ||
|
||
|
||
patch_query = patch.object( | ||
|
@@ -12,6 +13,12 @@ | |
lambda *ignore: True, | ||
) | ||
|
||
mock_couch_user = WebUser( | ||
username="testuser", | ||
_id="user123", | ||
domain="test-domain", | ||
) | ||
|
||
|
||
@patch_query | ||
@patch("corehq.apps.users.models.WebUser.get_by_username", return_value=None) | ||
|
@@ -34,6 +41,19 @@ def test_form_is_invalid_when_invite_existing_email_with_case_mismatch(mock_web_ | |
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 {})) | ||
|