Skip to content

Commit 8bb8c4f

Browse files
Henry Chanhenrylamchan
authored andcommitted
Blackfied code
1 parent b8dcdcf commit 8bb8c4f

File tree

12 files changed

+200
-168
lines changed

12 files changed

+200
-168
lines changed

setup.py

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,51 @@
44

55
base_dir = os.path.dirname(__file__)
66

7-
with open('README.md', 'r') as f:
7+
with open("README.md", "r") as f:
88
long_description = f.read()
99

1010
about = {}
11-
with open(os.path.join(base_dir, 'workos', '__about__.py')) as f:
11+
with open(os.path.join(base_dir, "workos", "__about__.py")) as f:
1212
exec(f.read(), about)
1313

1414
dev_requirements = [
15-
'flake8',
16-
'pytest==4.6.9',
17-
'pytest-cov==2.8.1',
18-
'six==1.13.0',
15+
"flake8",
16+
"pytest==4.6.9",
17+
"pytest-cov==2.8.1",
18+
"six==1.13.0",
1919
]
2020
if sys.version_info.major == 3:
21-
dev_requirements.extend([
22-
'black==19.10b0',
23-
'twine==3.1.1',
24-
])
21+
dev_requirements.extend(
22+
["black==19.10b0", "twine==3.1.1",]
23+
)
2524

2625
setup(
27-
name=about['__package_name__'],
28-
version=about['__version__'],
29-
author=about['__author__'],
30-
author_email=about['__author_email__'],
31-
url=about['__package_url__'],
32-
description=about['__description__'],
26+
name=about["__package_name__"],
27+
version=about["__version__"],
28+
author=about["__author__"],
29+
author_email=about["__author_email__"],
30+
url=about["__package_url__"],
31+
description=about["__description__"],
3332
long_description=long_description,
34-
long_description_content_type='text/markdown',
35-
packages=find_packages(exclude=['tests*', ]),
33+
long_description_content_type="text/markdown",
34+
packages=find_packages(exclude=["tests*",]),
3635
zip_safe=False,
37-
license=about['__license__'],
38-
install_requires=['requests>=2.22.0'],
39-
extras_require={
40-
'dev': dev_requirements,
41-
},
36+
license=about["__license__"],
37+
install_requires=["requests>=2.22.0"],
38+
extras_require={"dev": dev_requirements,},
4239
classifiers=[
43-
'Development Status :: 1 - Planning',
44-
'Intended Audience :: Developers',
45-
'License :: OSI Approved :: MIT License',
46-
'Operating System :: OS Independent',
47-
'Programming Language :: Python',
48-
'Programming Language :: Python :: 2',
49-
'Programming Language :: Python :: 2.7',
50-
'Programming Language :: Python :: 3',
51-
'Programming Language :: Python :: 3.4',
52-
'Programming Language :: Python :: 3.5',
53-
'Programming Language :: Python :: 3.6',
54-
'Programming Language :: Python :: 3.7',
55-
'Programming Language :: Python :: 3.8',
40+
"Development Status :: 1 - Planning",
41+
"Intended Audience :: Developers",
42+
"License :: OSI Approved :: MIT License",
43+
"Operating System :: OS Independent",
44+
"Programming Language :: Python",
45+
"Programming Language :: Python :: 2",
46+
"Programming Language :: Python :: 2.7",
47+
"Programming Language :: Python :: 3",
48+
"Programming Language :: Python :: 3.4",
49+
"Programming Language :: Python :: 3.5",
50+
"Programming Language :: Python :: 3.6",
51+
"Programming Language :: Python :: 3.7",
52+
"Programming Language :: Python :: 3.8",
5653
],
57-
)
54+
)

tests/conftest.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import workos
55

6+
67
class MockResponse(object):
78
def __init__(self, response_dict, status_code, headers=None):
89
self.response_dict = response_dict
@@ -12,18 +13,22 @@ def __init__(self, response_dict, status_code, headers=None):
1213
def json(self):
1314
return self.response_dict
1415

16+
1517
@pytest.fixture
1618
def set_api_key(monkeypatch):
17-
monkeypatch.setattr(workos, 'api_key', 'sk_abdsomecharactersm284')
19+
monkeypatch.setattr(workos, "api_key", "sk_abdsomecharactersm284")
20+
1821

1922
@pytest.fixture
2023
def set_project_id(monkeypatch):
21-
monkeypatch.setattr(workos, 'project_id', 'project_b27needthisforssotemxo')
24+
monkeypatch.setattr(workos, "project_id", "project_b27needthisforssotemxo")
25+
2226

2327
@pytest.fixture
2428
def set_api_key_and_project_id(set_api_key, set_project_id):
2529
pass
2630

31+
2732
@pytest.fixture
2833
def mock_request_method(monkeypatch):
2934
def inner(method, response_dict, status_code, headers=None):
@@ -34,6 +39,7 @@ def mock(*args, **kwargs):
3439

3540
return inner
3641

42+
3743
@pytest.fixture
3844
def capture_and_mock_requests(monkeypatch):
3945
def inner():
@@ -43,9 +49,9 @@ def capture(*args, **kwargs):
4349
captured_requests.append((args, kwargs))
4450
return MockResponse({}, 200)
4551

46-
monkeypatch.setattr(requests, 'get', capture)
47-
monkeypatch.setattr(requests, 'post', capture)
52+
monkeypatch.setattr(requests, "get", capture)
53+
monkeypatch.setattr(requests, "post", capture)
4854

4955
return captured_requests
5056

51-
return inner
57+
return inner

tests/test_client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from workos import client
44
from workos.exceptions import ConfigurationException
55

6+
67
class TestClient(object):
78
@pytest.fixture(autouse=True)
89
def setup(self):
@@ -17,22 +18,22 @@ def test_initialize_sso_missing_api_key(self, set_project_id):
1718

1819
message = str(ex)
1920

20-
assert 'api_key' in message
21-
assert 'project_id' not in message
21+
assert "api_key" in message
22+
assert "project_id" not in message
2223

2324
def test_initialize_sso_missing_project_id(self, set_api_key):
2425
with pytest.raises(ConfigurationException) as ex:
2526
client.sso
26-
27+
2728
message = str(ex)
2829

29-
assert 'project_id' in message
30-
assert 'api_key' not in message
31-
30+
assert "project_id" in message
31+
assert "api_key" not in message
32+
3233
def test_initialize_sso_missing_api_key_and_project_id(self):
3334
with pytest.raises(ConfigurationException) as ex:
3435
client.sso
3536

3637
message = str(ex)
3738

38-
assert all(setting in message for setting in ('api_key', 'project_id',))
39+
assert all(setting in message for setting in ("api_key", "project_id",))

tests/test_sso.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,62 @@
77
from workos.sso import SSO
88
from workos.utils.request import RESPONSE_TYPE_CODE
99

10+
1011
class TestSSO(object):
1112
@pytest.fixture(autouse=True)
1213
def setup(self, set_api_key_and_project_id):
13-
self.customer_domain = 'workos.com'
14-
self.redirect_uri = 'https://localhost/auth/callback'
15-
self.state = { 'things': 'with_stuff', }
14+
self.customer_domain = "workos.com"
15+
self.redirect_uri = "https://localhost/auth/callback"
16+
self.state = {
17+
"things": "with_stuff",
18+
}
1619

1720
self.sso = SSO()
1821

1922
@pytest.fixture
2023
def mock_profile(self):
2124
return {
22-
'id': 'prof_01DWAS7ZQWM70PV93BFV1V78QV',
23-
'email': '[email protected]',
24-
'first_name': 'WorkOS',
25-
'last_name': 'Demo',
26-
'connection_type': 'OktaSAML',
27-
'idp_id': '00u1klkowm8EGah2H357'
25+
"id": "prof_01DWAS7ZQWM70PV93BFV1V78QV",
26+
"email": "[email protected]",
27+
"first_name": "WorkOS",
28+
"last_name": "Demo",
29+
"connection_type": "OktaSAML",
30+
"idp_id": "00u1klkowm8EGah2H357",
2831
}
2932

3033
def test_authorization_url_has_expected_query_params(self):
3134
authorization_url = self.sso.get_authorization_url(
32-
self.customer_domain,
33-
self.redirect_uri,
34-
state=self.state
35+
self.customer_domain, self.redirect_uri, state=self.state
3536
)
3637

3738
parsed_url = urlparse(authorization_url)
3839

3940
assert dict(parse_qsl(parsed_url.query)) == {
40-
'domain': self.customer_domain,
41-
'client_id': workos.project_id,
42-
'redirect_uri': self.redirect_uri,
43-
'response_type': RESPONSE_TYPE_CODE,
44-
'state': json.dumps(self.state),
41+
"domain": self.customer_domain,
42+
"client_id": workos.project_id,
43+
"redirect_uri": self.redirect_uri,
44+
"response_type": RESPONSE_TYPE_CODE,
45+
"state": json.dumps(self.state),
4546
}
4647

47-
4848
def test_get_profile_returns_expected_workosprofile_object(
4949
self, mock_profile, mock_request_method
5050
):
5151
response_dict = {
52-
'profile': {
53-
'object': 'profile',
54-
'id': mock_profile['id'],
55-
'email': mock_profile['email'],
56-
'first_name': mock_profile['first_name'],
57-
'connection_type': mock_profile['connection_type'],
58-
'last_name': mock_profile['last_name'],
59-
'idp_id': mock_profile['idp_id'],
52+
"profile": {
53+
"object": "profile",
54+
"id": mock_profile["id"],
55+
"email": mock_profile["email"],
56+
"first_name": mock_profile["first_name"],
57+
"connection_type": mock_profile["connection_type"],
58+
"last_name": mock_profile["last_name"],
59+
"idp_id": mock_profile["idp_id"],
6060
},
61-
'access_token': '01DY34ACQTM3B1CSX1YSZ8Z00D',
61+
"access_token": "01DY34ACQTM3B1CSX1YSZ8Z00D",
6262
}
6363

64-
mock_request_method('post', response_dict, 200)
64+
mock_request_method("post", response_dict, 200)
6565

6666
profile = self.sso.get_profile(123)
6767

68-
assert profile.to_dict() == mock_profile
68+
assert profile.to_dict() == mock_profile

tests/utils/test_requests.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import pytest
22

33
from workos.exceptions import (
4-
AuthenticationException, AuthorizationException, BadRequestException,
4+
AuthenticationException,
5+
AuthorizationException,
6+
BadRequestException,
57
ServerException,
68
)
79
from workos.utils.request import RequestHelper, BASE_HEADERS
@@ -13,6 +15,7 @@
1315
500: ServerException,
1416
}
1517

18+
1619
class TestRequestHelper(object):
1720
def test_set_base_api_url(self):
1821
pass
@@ -23,29 +26,29 @@ def test_request_raises_expected_exception_for_status_code(
2326
request_helper = RequestHelper()
2427

2528
for status_code, exception in STATUS_CODE_TO_EXCEPTION_MAPPING.items():
26-
mock_request_method('get', {}, status_code)
29+
mock_request_method("get", {}, status_code)
2730

2831
with pytest.raises(exception):
29-
request_helper.request('bad_place')
32+
request_helper.request("bad_place")
3033

3134
def test_request_exceptions_include_expected_request_data(
3235
self, mock_request_method
3336
):
3437
request_helper = RequestHelper()
3538

36-
request_id = 'request-123'
37-
response_message = 'stuff happened'
39+
request_id = "request-123"
40+
response_message = "stuff happened"
3841

3942
for status_code, exception in STATUS_CODE_TO_EXCEPTION_MAPPING.items():
4043
mock_request_method(
41-
'get',
42-
{'message': response_message, },
44+
"get",
45+
{"message": response_message,},
4346
status_code,
44-
headers={'X-Request-ID': request_id}
47+
headers={"X-Request-ID": request_id},
4548
)
4649

4750
try:
48-
request_helper.request('bad_place')
51+
request_helper.request("bad_place")
4952
except exception as ex:
5053
assert ex.message == response_message
5154
assert ex.request_id == request_id
@@ -56,17 +59,14 @@ def test_request_exceptions_include_expected_request_data(
5659
def test_request_bad_body_raises_expected_exception_with_request_data(
5760
self, mock_request_method
5861
):
59-
request_id = 'request-123'
62+
request_id = "request-123"
6063

6164
mock_request_method(
62-
'get',
63-
'this_isnt_json',
64-
200,
65-
headers={'X-Request-ID': request_id}
65+
"get", "this_isnt_json", 200, headers={"X-Request-ID": request_id}
6666
)
6767

6868
try:
69-
RequestHelper().request('bad_place')
69+
RequestHelper().request("bad_place")
7070
except ServerException as ex:
7171
assert ex.message == None
7272
assert ex.request_id == request_id
@@ -77,11 +77,11 @@ def test_request_bad_body_raises_expected_exception_with_request_data(
7777
def test_request_includes_base_headers(self, capture_and_mock_requests):
7878
requests = capture_and_mock_requests()
7979

80-
RequestHelper().request('ok_place')
80+
RequestHelper().request("ok_place")
8181

8282
assert len(requests) == 1
8383

84-
base_headers = set(BASE_HEADERS.items())
85-
headers = set(requests[0][1]['headers'].items())
84+
base_headers = set(BASE_HEADERS.items())
85+
headers = set(requests[0][1]["headers"].items())
8686

87-
assert base_headers.issubset(headers)
87+
assert base_headers.issubset(headers)

0 commit comments

Comments
 (0)