Skip to content

Commit

Permalink
Update test case: Show expected error message
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Sep 19, 2024
1 parent 7427d35 commit 4b8e4fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions oidc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"JWT_ALGORITHM": "HS256",
"FIELD_VALIDATION_REGEX": {
"username": {
"regex": "^(?!\d+$)[a-zA-Z0-9_]{3,}$", # noqa
"help_text": "Username should only contain alpha numeric characters",
"regex": r"^(?!\d+$)[a-zA-Z0-9_]{3,}$", # noqa
"help_text": "Username should only contain alpha numeric characters and should be at least 3 characters",
}
},
"REPLACE_USERNAME_CHARACTERS": "-.",
Expand Down
11 changes: 8 additions & 3 deletions tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"REPLACE_USERNAME_CHARACTERS": "-.",
"FIELD_VALIDATION_REGEX": {
"username": {
"regex": "^(?!\d+$)[a-zA-Z0-9_]{3,}$",
"help_text": "Username should only contain word characters & numbers i.e datatester23",
"regex": r"^(?!\d+$)[a-zA-Z0-9_]{3,}$",
"help_text": "Username should only contain word characters & numbers and should have 3 or more characters",
},
},
}
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_returns_data_entry_template_on_invalid_username(self):
def test_returns_data_entry_template_on_invalid_username_and_bad_email(self):
"""
Test that users are redirected to the data entry
page when username is not present in decoded token and
page when username provided in decoded token is invalid and
provided email also does not provide a valid username
"""
view = UserModelOpenIDConnectViewset.as_view({"post": "callback"})
Expand All @@ -154,6 +154,11 @@ def test_returns_data_entry_template_on_invalid_username_and_bad_email(self):
request = self.factory.post("/", data=data)
response = view(request, auth_server="default")
self.assertEqual(response.status_code, 400)
self.assertTrue(
response.rendered_content.startswith(
b'{"error":"Username should only contain word characters & numbers and should have 3 or more characters"'
)
)
self.assertEqual(response.template_name, "oidc/oidc_user_data_entry.html")

def test_unrecoverable_error_on_missing_claim(self):
Expand Down

0 comments on commit 4b8e4fd

Please sign in to comment.