Skip to content

Commit b445127

Browse files
committed
adapt tests
1 parent 683d508 commit b445127

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

tests/test_api_keys.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
1+
# type: ignore
12
import pytest
23

34
from tests.utils.fixtures.mock_api_key import MockApiKey
45
from tests.utils.syncify import syncify
5-
from workos.api_key import ApiKey, AsyncApiKey
6+
from workos.api_keys import API_KEY_VALIDATION_PATH, ApiKeys, AsyncApiKeys
67
from workos.exceptions import AuthenticationException
78

89

9-
@pytest.mark.sync_and_async(ApiKey, AsyncApiKey)
10-
class TestApiKey:
10+
@pytest.mark.sync_and_async(ApiKeys, AsyncApiKeys)
11+
class TestApiKeys:
1112
@pytest.fixture
12-
def mock_api_key_details(self):
13-
api_key_details = MockApiKey()
14-
return api_key_details.model_dump()
13+
def mock_api_key(self):
14+
return MockApiKey().dict()
15+
16+
@pytest.fixture
17+
def api_key(self):
18+
return "sk_my_api_key"
1519

1620
def test_validate_api_key_with_valid_key(
1721
self,
1822
module_instance,
19-
mock_api_key_details,
23+
api_key,
24+
mock_api_key,
2025
capture_and_mock_http_client_request,
2126
):
27+
response_body = {"api_key": mock_api_key}
2228
request_kwargs = capture_and_mock_http_client_request(
23-
module_instance._http_client, mock_api_key_details, 200
29+
module_instance._http_client, response_body, 200
2430
)
2531

26-
api_key_details = syncify(module_instance.validate_api_key())
32+
api_key_details = syncify(module_instance.validate_api_key(value=api_key))
2733

28-
assert request_kwargs["url"].endswith("/api_keys/validate")
34+
assert request_kwargs["url"].endswith(API_KEY_VALIDATION_PATH)
2935
assert request_kwargs["method"] == "post"
30-
assert api_key_details.id == mock_api_key_details["id"]
31-
assert api_key_details.name == mock_api_key_details["name"]
36+
assert api_key_details.id == mock_api_key["id"]
37+
assert api_key_details.name == mock_api_key["name"]
3238
assert api_key_details.object == "api_key"
3339

3440
def test_validate_api_key_with_invalid_key(
@@ -43,4 +49,4 @@ def test_validate_api_key_with_invalid_key(
4349
)
4450

4551
with pytest.raises(AuthenticationException):
46-
syncify(module_instance.validate_api_key())
52+
syncify(module_instance.validate_api_key(value="invalid-key"))

0 commit comments

Comments
 (0)