Skip to content

Commit

Permalink
Remove username max_length constraint in ShareProjectSerializer
Browse files Browse the repository at this point in the history
Signed-off-by: Kipchirchir Sigei <[email protected]>
  • Loading branch information
KipSigei committed Aug 29, 2022
1 parent 5fc11bf commit e9552e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion onadata/libs/serializers/share_project_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ShareProjectSerializer(serializers.Serializer):
"""

project = ProjectField()
username = serializers.CharField(max_length=255)
username = serializers.CharField(required=True)
role = serializers.CharField(max_length=50)

def create(self, validated_data):
Expand Down
34 changes: 34 additions & 0 deletions onadata/libs/tests/serializers/test_share_project_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,37 @@ def test_error_on_inactive_user(self):
self.assertFalse(serializer.is_valid())
self.assertEqual(str(serializer.errors['username'][0]),
"The following user(s) is/are not active: dave, john")

def test_no_username_char_limit(self):
"""
Test that the 255 char max_length constraint validation error is not
raised when trying to share a project with multiple users
"""
self._publish_xls_form_to_project()
project = Project.objects.last()

# Test that it can share to multiple users
users_list = [
"cowmirowlanchaharmonicabrownbreadokratea",
"harmonicaantlambchopdoggoatgarlicbread",
"pureenchantingjunopancakeshoagsobjectbat",
"toystoryshrimprhythmzebraaceventuraran",
"riversandwichnovaowlhighnoonstyxgiraffe",
"mayonnaiseearthyinceptionbatplanetarlog",
"fitnessleoiantgollumnotesmelodypinecone"
]
for user in users_list:
# create users
_user = self._create_user(user, user)
self.assertFalse(ReadOnlyRole.user_has_role(_user, project))
# check usernames length is > 255 chars
usernames = ','.join(users_list)
self.assertTrue(len(usernames) > 255)
data = {
'project': project.id,
'username': usernames,
'role': ReadOnlyRole.name
}

serializer = ShareProjectSerializer(data=data)
self.assertTrue(serializer.is_valid())

0 comments on commit e9552e7

Please sign in to comment.