Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove username max_length constraint in ShareProjectSerializer #2311

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 35 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,38 @@ 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())
self.assertFalse(len(serializer.errors) > 0)