Skip to content

Commit

Permalink
Add new test to make sure we don't invite deactivated user
Browse files Browse the repository at this point in the history
  • Loading branch information
jingcheng16 committed Sep 18, 2024
1 parent 7c02205 commit 2506997
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions corehq/apps/registration/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from testil import Regex

from ..forms import AdminInvitesUserForm
from corehq.apps.users.models import WebUser


patch_query = patch.object(
Expand All @@ -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)
Expand All @@ -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 {}))
Expand Down

0 comments on commit 2506997

Please sign in to comment.