Skip to content

Commit 4900eaf

Browse files
committed
tests can now be skipped when configuration is absent
1 parent c2ea9a1 commit 4900eaf

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

tests/test_client.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ def load_conf(filename):
5252
logger.warning("Unable to open/read JSON configuration %s" % filename)
5353
raise
5454
openid_configuration = {}
55-
try:
56-
# The following line may duplicate a '/' at the joining point,
57-
# but requests.get(...) would still work.
58-
# Besides, standard urljoin(...) is picky on insisting oidp ends with '/'
59-
discovery_uri = conf["oidp"] + '/.well-known/openid-configuration'
60-
openid_configuration.update(requests.get(discovery_uri).json())
61-
except:
62-
logger.warning("openid-configuration uri not accesible: %s", discovery_uri)
55+
if "oidp" in conf:
56+
try:
57+
# The following line may duplicate a '/' at the joining point,
58+
# but requests.get(...) would still work.
59+
# Besides, standard urljoin(...) is picky on insisting oidp ends with '/'
60+
discovery_uri = conf["oidp"] + '/.well-known/openid-configuration'
61+
openid_configuration.update(requests.get(discovery_uri).json())
62+
except:
63+
logger.warning(
64+
"openid configuration uri not accesible: %s", discovery_uri)
6365
openid_configuration.update(conf.get("additional_openid_configuration", {}))
6466
if openid_configuration.get("device_authorization_endpoint"):
6567
# The following urljoin(..., ...) trick allows a "path_name" shorthand
@@ -100,13 +102,20 @@ def setUpClass(cls):
100102
CONFIG["openid_configuration"], CONFIG['client_id'],
101103
client_secret=CONFIG.get('client_secret'))
102104

103-
@unittest.skipUnless("client_secret" in CONFIG, "client_secret missing")
105+
@unittest.skipIf(
106+
"token_endpoint" not in CONFIG.get("openid_configuration", {}),
107+
"token_endpoint missing")
108+
@unittest.skipIf("client_secret" not in CONFIG, "client_secret missing")
104109
def test_client_credentials(self):
105110
result = self.client.obtain_token_for_client(CONFIG.get('scope'))
106111
self.assertIn('access_token', result)
107112

108-
@unittest.skipUnless(
109-
"username" in CONFIG and "password" in CONFIG, "username/password missing")
113+
@unittest.skipIf(
114+
"token_endpoint" not in CONFIG.get("openid_configuration", {}),
115+
"token_endpoint missing")
116+
@unittest.skipIf(
117+
not ("username" in CONFIG and "password" in CONFIG),
118+
"username/password missing")
110119
def test_username_password(self):
111120
result = self.client.obtain_token_by_username_password(
112121
CONFIG["username"], CONFIG["password"],

0 commit comments

Comments
 (0)