Skip to content

Commit 36c92c5

Browse files
committed
chore(format): reformat with black
1 parent 0a9998a commit 36c92c5

2 files changed

Lines changed: 40 additions & 35 deletions

File tree

tests/test_handlers.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ def test_acs_handler_factory(appctx, db):
7676

7777
acs_handler = acs_handler_factory("test")
7878

79-
with appctx.test_request_context(), patch(
80-
"invenio_saml.utils.SAMLAuth"
81-
) as mock_saml_auth:
79+
with (
80+
appctx.test_request_context(),
81+
patch("invenio_saml.utils.SAMLAuth") as mock_saml_auth,
82+
):
8283
mock_saml_auth.get_attributes.return_value = attrs
8384
next_url = acs_handler(mock_saml_auth, "/foo")
8485

@@ -110,9 +111,10 @@ def test_acs_handler_factory_config(appctx, db):
110111

111112
acs_handler = acs_handler_factory("test")
112113

113-
with appctx.test_request_context(), patch(
114-
"invenio_saml.utils.SAMLAuth"
115-
) as mock_saml_auth:
114+
with (
115+
appctx.test_request_context(),
116+
patch("invenio_saml.utils.SAMLAuth") as mock_saml_auth,
117+
):
116118
mock_saml_auth.get_attributes.return_value = attrs
117119
acs_handler(mock_saml_auth, "/foo")
118120

@@ -131,11 +133,11 @@ def test_acs_handler_authetication_error(appctx, db):
131133

132134
acs_handler = acs_handler_factory("test")
133135

134-
with appctx.test_request_context(), patch(
135-
"invenio_saml.utils.SAMLAuth"
136-
) as mock_saml_auth, patch(
137-
"invenio_saml.handlers.account_authenticate"
138-
) as mock_authenticate:
136+
with (
137+
appctx.test_request_context(),
138+
patch("invenio_saml.utils.SAMLAuth") as mock_saml_auth,
139+
patch("invenio_saml.handlers.account_authenticate") as mock_authenticate,
140+
):
139141
mock_saml_auth.get_attributes.return_value = attrs
140142
mock_authenticate.return_value = False
141143
with pytest.raises(Unauthorized):
@@ -153,11 +155,11 @@ def test_acs_handler_user_creation_error(appctx, db):
153155

154156
acs_handler = acs_handler_factory("test")
155157

156-
with appctx.test_request_context(), patch(
157-
"invenio_saml.utils.SAMLAuth"
158-
) as mock_saml_auth, patch(
159-
"invenio_saml.handlers.account_register"
160-
) as mock_register:
158+
with (
159+
appctx.test_request_context(),
160+
patch("invenio_saml.utils.SAMLAuth") as mock_saml_auth,
161+
patch("invenio_saml.handlers.account_register") as mock_register,
162+
):
161163
mock_saml_auth.get_attributes.return_value = attrs
162164
mock_register.return_value = None
163165
with pytest.raises(Unauthorized):
@@ -200,9 +202,10 @@ def account_info(attributes, remote_app):
200202

201203
acs_handler = acs_handler_factory("test", account_info=account_info)
202204

203-
with appctx.test_request_context(), patch(
204-
"invenio_saml.utils.SAMLAuth"
205-
) as mock_saml_auth:
205+
with (
206+
appctx.test_request_context(),
207+
patch("invenio_saml.utils.SAMLAuth") as mock_saml_auth,
208+
):
206209
mock_saml_auth.get_attributes.return_value = attrs
207210
acs_handler(mock_saml_auth, "/")
208211

@@ -235,9 +238,10 @@ def test_custom_user_lookup(appctx, users):
235238

236239
acs_handler = acs_handler_factory("test", user_lookup=mock_user_lookup)
237240

238-
with appctx.test_request_context(), patch(
239-
"invenio_saml.utils.SAMLAuth"
240-
) as mock_saml_auth:
241+
with (
242+
appctx.test_request_context(),
243+
patch("invenio_saml.utils.SAMLAuth") as mock_saml_auth,
244+
):
241245
mock_saml_auth.get_attributes.return_value = attrs
242246
acs_handler(mock_saml_auth, "/")
243247

tests/test_views.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ def test_acs(appctx, base_client, sso_response):
5353
res = client.post(acs_url, data=dict(SAMLResponse=sso_response))
5454
assert res.status_code == 401
5555

56-
with patch(
57-
"onelogin.saml2.auth.OneLogin_Saml2_Response.is_valid"
58-
) as mock_is_valid, patch(
59-
"invenio_saml.utils.SAMLAuth.is_authenticated"
60-
) as mock_is_authenticated:
56+
with (
57+
patch("onelogin.saml2.auth.OneLogin_Saml2_Response.is_valid") as mock_is_valid,
58+
patch("invenio_saml.utils.SAMLAuth.is_authenticated") as mock_is_authenticated,
59+
):
6160
mock_is_valid.return_value = True
6261
mock_is_authenticated.return_value = False
6362
res = client.post(acs_url, data=dict(SAMLResponse=sso_response))
@@ -98,9 +97,10 @@ def test_sls(appctx, base_client, slo_query_string):
9897
res = client.get(sls_url, query_string=slo_query_string)
9998
assert res.status_code == 302
10099

101-
with patch("invenio_saml.utils.SAMLAuth.get_errors") as mock_get_erros, patch(
102-
"invenio_saml.utils.SAMLAuth.get_last_error_reason"
103-
) as mock_get_reason:
100+
with (
101+
patch("invenio_saml.utils.SAMLAuth.get_errors") as mock_get_erros,
102+
patch("invenio_saml.utils.SAMLAuth.get_last_error_reason") as mock_get_reason,
103+
):
104104
mock_get_erros.return_value = ["bad error"]
105105
mock_get_reason.return_value = "Test reason"
106106
res = client.get(sls_url, query_string=slo_query_string)
@@ -117,11 +117,12 @@ def test_metadata(appctx, base_client, metadata_response):
117117
assert res.status_code == 200
118118
assert res.data == metadata_response
119119

120-
with patch(
121-
"onelogin.saml2.settings.OneLogin_Saml2_Settings.validate_metadata"
122-
) as mock_validate_metadata, patch(
123-
"invenio_saml.utils.SAMLAuth.get_last_error_reason"
124-
) as mock_get_reason:
120+
with (
121+
patch(
122+
"onelogin.saml2.settings.OneLogin_Saml2_Settings.validate_metadata"
123+
) as mock_validate_metadata,
124+
patch("invenio_saml.utils.SAMLAuth.get_last_error_reason") as mock_get_reason,
125+
):
125126
mock_validate_metadata.return_value = ["bad error", "worst error"]
126127
mock_get_reason.return_value = "Test reason"
127128
res = client.get(metadata_url)

0 commit comments

Comments
 (0)