Skip to content

[PLT-1205] More defensive programming on input #1720

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

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions libs/labelbox/src/labelbox/schema/user_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def get(self) -> "UserGroup":

Raises:
ResourceNotFoundError: If the query fails to fetch the group information.
ValueError: If the group ID is not provided.
"""
if not self.id:
raise ValueError("Group id is required")
query = """
query GetUserGroupPyApi($id: ID!) {
userGroup(where: {id: $id}) {
Expand Down Expand Up @@ -156,7 +159,12 @@ def update(self) -> "UserGroup":
Raises:
ResourceNotFoundError: If the update fails due to unknown user group
UnprocessableEntityError: If the update fails due to a malformed input
ValueError: If the group id or name is not provided
"""
if not self.id:
raise ValueError("Group id is required")
if not self.name:
raise ValueError("Group name is required")
query = """
mutation UpdateUserGroupPyApi($id: ID!, $name: String!, $color: String!, $projectIds: [String!]!, $userIds: [String!]!) {
updateUserGroup(
Expand Down
21 changes: 21 additions & 0 deletions libs/labelbox/tests/unit/schema/test_user_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def test_constructor(self):
assert len(group.projects) == 0
assert len(group.users) == 0

def test_update_with_exception_name(self):
group = self.group
group.id = ""

with pytest.raises(ValueError):
group.get()

def test_get(self):
projects = [
{
Expand Down Expand Up @@ -170,6 +177,20 @@ def test_update_resource_error_unknown_id(self):
with pytest.raises(ResourceNotFoundError) as e:
group.update()

def test_update_with_exception_name(self):
group = self.group
group.name = ""

with pytest.raises(ValueError):
group.update()

def test_update_with_exception_name(self):
group = self.group
group.id = ""

with pytest.raises(ValueError):
group.update()

def test_create_with_exception_id(self):
group = self.group
group.id = "group_id"
Expand Down
Loading