-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for changes in the model and serializer
- Loading branch information
José Redrejo
committed
Oct 17, 2023
1 parent
b2e2c2e
commit 57c6aa3
Showing
2 changed files
with
46 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 |
---|---|---|
|
@@ -751,6 +751,32 @@ def test_creating_user_same_username_case_insensitive(self): | |
response.data[0]["id"], error_constants.USERNAME_ALREADY_EXISTS | ||
) | ||
|
||
def test_do_not_allow_emails_in_usernames(self): | ||
data = { | ||
"username": "[email protected]", | ||
"password": DUMMY_PASSWORD, | ||
"facility": self.facility.id, | ||
} | ||
response = self.client.post( | ||
reverse("kolibri:core:facilityuser-list"), data, format="json" | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(response.data[0]["id"], error_constants.INVALID) | ||
self.assertEqual(response.data[0]["metadata"]["field"], "username") | ||
|
||
def test_max_length_username_in_api(self): | ||
data = { | ||
"username": 32 * "gh", | ||
"password": DUMMY_PASSWORD, | ||
"facility": self.facility.id, | ||
} | ||
response = self.client.post( | ||
reverse("kolibri:core:facilityuser-list"), data, format="json" | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(response.data[0]["id"], error_constants.MAX_LENGTH) | ||
self.assertEqual(response.data[0]["metadata"]["field"], "username") | ||
|
||
|
||
class UserUpdateTestCase(APITestCase): | ||
@classmethod | ||
|
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 |
---|---|---|
|
@@ -680,6 +680,26 @@ def test_deserialize_empty_password(self): | |
self.assertEqual("bob", user.username) | ||
self.assertEqual(NOT_SPECIFIED, user.password) | ||
|
||
def test_username_validation(self): | ||
self.facility = Facility.objects.create() | ||
self.device_settings = DeviceSettings.objects.create() | ||
user1 = FacilityUser.objects.create( | ||
username="[email protected]", | ||
password="password", | ||
facility=self.facility, | ||
) | ||
user1.full_clean() | ||
user2 = FacilityUser.objects.create( | ||
username="@bob", password="password", facility=self.facility | ||
) | ||
with self.assertRaises(ValidationError): | ||
user2.full_clean() | ||
user3 = FacilityUser.objects.create( | ||
username=32 * "gh", password="password", facility=self.facility | ||
) | ||
with self.assertRaises(ValidationError): | ||
user3.full_clean() | ||
|
||
|
||
class CollectionHierarchyTestCase(TestCase): | ||
def test_facility_with_parent(self): | ||
|