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

Adds session helpers #384

Merged
merged 18 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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 LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 WorkOS
Copyright (c) 2024 WorkOS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 9 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
flake8
pytest==8.3.2
pytest-asyncio==0.23.8
pytest-cov==5.0.0
six==1.16.0
black==24.4.2
twine==5.1.1
mypy==1.12.0
httpx>=0.27.0
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
httpx>=0.27.0
pydantic==2.9.2
PyJWT==2.9.0
cryptography==43.0.3
20 changes: 8 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
with open(os.path.join(base_dir, "workos", "__about__.py")) as f:
exec(f.read(), about)


def read_requirements(filename):
with open(filename) as f:
return [line.strip() for line in f if line.strip() and not line.startswith("#")]


setup(
name=about["__package_name__"],
version=about["__version__"],
Expand All @@ -27,19 +33,9 @@
),
zip_safe=False,
license=about["__license__"],
install_requires=["httpx>=0.27.0", "pydantic==2.9.2"],
install_requires=read_requirements("requirements.txt"),
extras_require={
"dev": [
"flake8",
"pytest==8.3.2",
"pytest-asyncio==0.23.8",
"pytest-cov==5.0.0",
"six==1.16.0",
"black==24.4.2",
"twine==5.1.1",
"mypy==1.12.0",
"httpx>=0.27.0",
],
"dev": read_requirements("requirements-dev.txt"),
":python_version<'3.4'": ["enum34"],
},
classifiers=[
Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
from workos.utils.http_client import AsyncHTTPClient, HTTPClient, SyncHTTPClient
from workos.utils.request_helper import DEFAULT_LIST_RESPONSE_LIMIT

from jwt import PyJWKClient
from unittest.mock import Mock, patch
from functools import wraps


def _get_test_client_setup(
http_client_class_name: str,
Expand Down Expand Up @@ -302,3 +306,19 @@ def inner(
assert request_kwargs["params"][param] == params[param]

return inner


def with_jwks_mock(func):
@wraps(func)
def wrapper(*args, **kwargs):
# Create mock JWKS client
mock_jwks = Mock(spec=PyJWKClient)
mock_signing_key = Mock()
mock_signing_key.key = kwargs["TEST_CONSTANTS"]["PUBLIC_KEY"]
mock_jwks.get_signing_key_from_jwt.return_value = mock_signing_key

# Apply the mock
with patch("workos.session.PyJWKClient", return_value=mock_jwks):
return func(*args, **kwargs)

return wrapper
Loading
Loading