|
1 | 1 | import uuid |
2 | 2 | import pytest |
| 3 | +import os |
3 | 4 |
|
4 | 5 | from labelbox.schema.timeunit import TimeUnit |
5 | 6 | from labelbox.schema.api_key import ApiKey |
6 | 7 | from lbox.exceptions import LabelboxError |
7 | 8 | # The creation of API keys requires a feature flag to be enabled. |
8 | 9 |
|
9 | 10 |
|
10 | | -def test_create_api_key_success(admin_client): |
| 11 | +@pytest.mark.skipif( |
| 12 | + condition=os.environ["LABELBOX_TEST_ENVIRON"] != "prod", |
| 13 | + reason="Admin permissions are required to create API keys", |
| 14 | +) |
| 15 | +def test_create_api_key_success(client): |
11 | 16 | # Create a test API key |
12 | 17 | key_name = f"Test Key {uuid.uuid4()}" |
13 | | - user_email = admin_client.get_user().email |
| 18 | + user_email = client.get_user().email |
14 | 19 |
|
15 | 20 | assert ( |
16 | | - admin_client.get_user().org_role().name == "Admin" |
| 21 | + client.get_user().org_role().name == "Admin" |
17 | 22 | ), "User must be an admin to create API keys" |
18 | 23 |
|
19 | 24 | # Get available roles and use the first one |
20 | | - available_roles = ApiKey._get_available_api_key_roles(admin_client) |
| 25 | + available_roles = ApiKey._get_available_api_key_roles(client) |
21 | 26 | assert ( |
22 | 27 | len(available_roles) > 0 |
23 | 28 | ), "No available roles found for API key creation" |
24 | 29 |
|
25 | 30 | # Create the API key with a short validity period |
26 | | - api_key_result = admin_client.create_api_key( |
| 31 | + api_key_result = client.create_api_key( |
27 | 32 | name=key_name, |
28 | 33 | user=user_email, |
29 | 34 | role=available_roles[0], |
@@ -223,7 +228,10 @@ def test_create_api_key_invalid_time_unit(client): |
223 | 228 | ) |
224 | 229 | assert "valid TimeUnit" in str(excinfo.value) |
225 | 230 |
|
226 | | - |
| 231 | +@pytest.mark.skipif( |
| 232 | + condition=os.environ["LABELBOX_TEST_ENVIRON"] == "prod", |
| 233 | + reason="Accounts with sdmin permission can create API keys", |
| 234 | +) |
227 | 235 | def test_create_api_key_insufficient_permissions(client): |
228 | 236 | """Test that creating an API key fails when the user has insufficient permissions.""" |
229 | 237 | user_email = client.get_user().email |
|
0 commit comments