Skip to content

Commit 49e2879

Browse files
committed
Fix test_create_api_key_insufficient_permissions so it is not run by an admin account
1 parent c6463a5 commit 49e2879

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

libs/labelbox/tests/integration/test_api_keys.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,16 @@ def test_create_api_key_insufficient_permissions(client, project_based_user):
237237
"""Test that creating an API key fails when the user has insufficient permissions."""
238238
user_email = project_based_user.email
239239

240-
assert project_based_user.org_role().name == "None"
241-
242-
# Create a client using the project-based user's API key
243-
# This requires creating an API key for the user first, which we can't do with their permissions
244-
# Instead, we'll test with the admin client but use the project-based user's email
245-
with pytest.raises(LabelboxError) as excinfo:
246-
client.create_api_key(
247-
name=f"Test Key {uuid.uuid4()}",
248-
user=user_email,
249-
role="Admin",
250-
validity=5,
251-
time_unit=TimeUnit.MINUTE,
252-
)
253-
254-
assert "192" in str(excinfo.value)
240+
if client.get_user().org_role().name == "Admin":
241+
# Attempt to create another API key using the limited permissions client
242+
# This should fail due to insufficient permissions
243+
with pytest.raises(LabelboxError) as excinfo:
244+
client.create_api_key(
245+
name=f"Test Key {uuid.uuid4()}",
246+
user=user_email,
247+
role="Admin",
248+
validity=5,
249+
time_unit=TimeUnit.MINUTE,
250+
)
251+
252+
assert "192" in str(excinfo.value)

0 commit comments

Comments
 (0)