Skip to content

Commit 9d5f2fe

Browse files
committed
PEP8 code style
1 parent 2ac9e45 commit 9d5f2fe

File tree

1 file changed

+60
-32
lines changed

1 file changed

+60
-32
lines changed

tests/satosa/backends/test_orcid.py

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import json
2-
from unittest.mock import Mock
3-
from urllib.parse import urljoin, urlparse, parse_qsl
4-
52
import pytest
63
import responses
74

8-
from saml2.saml import NAMEID_FORMAT_TRANSIENT
9-
105
from satosa.backends.orcid import OrcidBackend
116
from satosa.context import Context
127
from satosa.internal import InternalData
138
from satosa.response import Response
9+
from unittest.mock import Mock
10+
from urllib.parse import urljoin, urlparse, parse_qsl
1411

1512
ORCID_PERSON_ID = "0000-0000-0000-0000"
1613
ORCID_PERSON_GIVEN_NAME = "orcid_given_name"
@@ -19,10 +16,17 @@
1916
ORCID_PERSON_EMAIL = "orcid_email"
2017
ORCID_PERSON_COUNTRY = "XX"
2118

19+
2220
class TestOrcidBackend(object):
2321
@pytest.fixture(autouse=True)
2422
def create_backend(self, internal_attributes, backend_config):
25-
self.orcid_backend = OrcidBackend(Mock(), internal_attributes, backend_config, backend_config["base_url"], "orcid")
23+
self.orcid_backend = OrcidBackend(
24+
Mock(),
25+
internal_attributes,
26+
backend_config,
27+
backend_config["base_url"],
28+
"orcid"
29+
)
2630

2731
@pytest.fixture
2832
def backend_config(self):
@@ -44,12 +48,12 @@ def backend_config(self):
4448
def internal_attributes(self):
4549
return {
4650
"attributes": {
47-
"address": { "orcid": ["address"] },
48-
"displayname": { "orcid": ["name"] },
51+
"address": {"orcid": ["address"]},
52+
"displayname": {"orcid": ["name"]},
4953
"edupersontargetedid": {"orcid": ["orcid"]},
5054
"givenname": {"orcid": ["givenname"]},
5155
"mail": {"orcid": ["mail"]},
52-
"name": { "orcid": ["name"] },
56+
"name": {"orcid": ["name"]},
5357
"surname": {"orcid": ["surname"]},
5458
}
5559
}
@@ -58,17 +62,21 @@ def internal_attributes(self):
5862
def userinfo(self):
5963
return {
6064
"name": {
61-
"given-names": { "value": ORCID_PERSON_GIVEN_NAME },
62-
"family-name": { "value": ORCID_PERSON_FAMILY_NAME },
65+
"given-names": {"value": ORCID_PERSON_GIVEN_NAME},
66+
"family-name": {"value": ORCID_PERSON_FAMILY_NAME},
6367
},
6468
"emails": {
6569
"email": [
66-
{ "email": ORCID_PERSON_EMAIL, "verified": True, "primary": True }
70+
{
71+
"email": ORCID_PERSON_EMAIL,
72+
"verified": True,
73+
"primary": True
74+
}
6775
]
6876
},
6977
"addresses": {
7078
"address": [
71-
{ "country": { "value": ORCID_PERSON_COUNTRY } }
79+
{"country": {"value": ORCID_PERSON_COUNTRY}}
7280
]
7381
}
7482
}
@@ -77,8 +85,8 @@ def userinfo(self):
7785
def userinfo_private(self):
7886
return {
7987
"name": {
80-
"given-names": { "value": ORCID_PERSON_GIVEN_NAME },
81-
"family-name": { "value": ORCID_PERSON_FAMILY_NAME },
88+
"given-names": {"value": ORCID_PERSON_GIVEN_NAME},
89+
"family-name": {"value": ORCID_PERSON_FAMILY_NAME},
8290
},
8391
"emails": {
8492
"email": [
@@ -90,7 +98,6 @@ def userinfo_private(self):
9098
}
9199
}
92100

93-
94101
def assert_expected_attributes(self, user_claims, actual_attributes):
95102
print(user_claims)
96103
print(actual_attributes)
@@ -116,18 +123,22 @@ def setup_token_endpoint(self, token_endpoint_url):
116123
"orcid": ORCID_PERSON_ID
117124
}
118125

119-
responses.add(responses.POST,
120-
token_endpoint_url,
121-
body=json.dumps(token_response),
122-
status=200,
123-
content_type="application/json")
126+
responses.add(
127+
responses.POST,
128+
token_endpoint_url,
129+
body=json.dumps(token_response),
130+
status=200,
131+
content_type="application/json"
132+
)
124133

125134
def setup_userinfo_endpoint(self, userinfo_endpoint_url, userinfo):
126-
responses.add(responses.GET,
127-
urljoin(userinfo_endpoint_url, '{}/person'.format(ORCID_PERSON_ID)),
128-
body=json.dumps(userinfo),
129-
status=200,
130-
content_type="application/json")
135+
responses.add(
136+
responses.GET,
137+
urljoin(userinfo_endpoint_url, '{}/person'.format(ORCID_PERSON_ID)),
138+
body=json.dumps(userinfo),
139+
status=200,
140+
content_type="application/json"
141+
)
131142

132143
@pytest.fixture
133144
def incoming_authn_response(self, context, backend_config):
@@ -149,7 +160,10 @@ def test_start_auth(self, context, backend_config):
149160
assert auth_params["scope"] == " ".join(backend_config["scope"])
150161
assert auth_params["response_type"] == backend_config["response_type"]
151162
assert auth_params["client_id"] == backend_config["client_config"]["client_id"]
152-
assert auth_params["redirect_uri"] == backend_config["base_url"] + "/" + backend_config["authz_page"]
163+
assert auth_params["redirect_uri"] == "{}/{}".format(
164+
backend_config["base_url"],
165+
backend_config["authz_page"]
166+
)
153167

154168
@responses.activate
155169
def test_authn_response(self, backend_config, userinfo, incoming_authn_response):
@@ -166,9 +180,16 @@ def test_authn_response(self, backend_config, userinfo, incoming_authn_response)
166180

167181
@responses.activate
168182
def test_user_information(self, context, backend_config, userinfo):
169-
self.setup_userinfo_endpoint(backend_config["server_info"]["user_info"], userinfo)
183+
self.setup_userinfo_endpoint(
184+
backend_config["server_info"]["user_info"],
185+
userinfo
186+
)
170187

171-
user_attributes = self.orcid_backend.user_information("orcid_access_token", ORCID_PERSON_ID, ORCID_PERSON_NAME)
188+
user_attributes = self.orcid_backend.user_information(
189+
"orcid_access_token",
190+
ORCID_PERSON_ID,
191+
ORCID_PERSON_NAME
192+
)
172193

173194
assert user_attributes["address"] == ORCID_PERSON_COUNTRY
174195
assert user_attributes["displayname"] == ORCID_PERSON_NAME
@@ -180,9 +201,16 @@ def test_user_information(self, context, backend_config, userinfo):
180201

181202
@responses.activate
182203
def test_user_information_private(self, context, backend_config, userinfo_private):
183-
self.setup_userinfo_endpoint(backend_config["server_info"]["user_info"], userinfo_private)
184-
185-
user_attributes = self.orcid_backend.user_information("orcid_access_token", ORCID_PERSON_ID, ORCID_PERSON_NAME)
204+
self.setup_userinfo_endpoint(
205+
backend_config["server_info"]["user_info"],
206+
userinfo_private
207+
)
208+
209+
user_attributes = self.orcid_backend.user_information(
210+
"orcid_access_token",
211+
ORCID_PERSON_ID,
212+
ORCID_PERSON_NAME
213+
)
186214

187215
assert user_attributes["address"] == ""
188216
assert user_attributes["mail"] == ""

0 commit comments

Comments
 (0)