Skip to content

Commit 15ffe77

Browse files
committed
Skipping tests when no OIDC configuration is available
1 parent 977e5ec commit 15ffe77

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

tests/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def oidc_token(config: Dict, scope: Optional[List]):
111111

112112

113113
@pytest.fixture
114-
def oidc_token_read(test_config) -> Dict:
114+
def oidc_token_read(test_config) -> Optional[Dict]:
115115
""" Return an OIDC token with scope 'mrmat-python-api-flask-resource-read'
116116
117117
Args:
@@ -120,13 +120,16 @@ def oidc_token_read(test_config) -> Dict:
120120
Returns:
121121
A Dict containing the desired token structure
122122
"""
123+
if test_config is None:
124+
LOGGER.info('Missing OIDC test client configuration. Tests will be limited')
125+
return None
123126
token = oidc_token(test_config, ['mrmat-python-api-flask-resource-read'])
124127
token['jwt'] = jwt.decode(token['access_token'], options={"verify_signature": False})
125128
return token
126129

127130

128131
@pytest.fixture
129-
def oidc_token_write(test_config) -> Dict:
132+
def oidc_token_write(test_config) -> Optional[Dict]:
130133
""" Return an OIDC token with scope 'mrmat-python-api-flask-resource-write'
131134
132135
Args:
@@ -135,6 +138,9 @@ def oidc_token_write(test_config) -> Dict:
135138
Returns:
136139
A Dict containing the desired token structure
137140
"""
141+
if test_config is None:
142+
LOGGER.info('Missing OIDC test client configuration. Tests will be limited')
143+
return None
138144
token = oidc_token(test_config, ['mrmat-python-api-flask-resource-write'])
139145
token['jwt'] = jwt.decode(token['access_token'], options={"verify_signature": False})
140146
return token

tests/test_resource_v1.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23+
import pytest
24+
2325
from typing import Dict
2426
from flask.testing import FlaskClient
2527

2628
from resource_api_client import ResourceAPIClient
2729

2830

2931
def test_create(client: FlaskClient, oidc_token_write: Dict):
32+
if oidc_token_write is None:
33+
pytest.skip('No OIDC configuration is available')
3034
rac = ResourceAPIClient(client, token=oidc_token_write)
3135
(resp, resp_body) = rac.create(name='Test Resource 1')
3236
assert resp.status_code == 201
@@ -36,6 +40,8 @@ def test_create(client: FlaskClient, oidc_token_write: Dict):
3640

3741

3842
def test_modify(client: FlaskClient, oidc_token_write):
43+
if oidc_token_write is None:
44+
pytest.skip('No OIDC configuration is available')
3945
rac = ResourceAPIClient(client, token=oidc_token_write)
4046

4147
(resp, resp_body) = rac.create(name='Test Resource Original')
@@ -52,6 +58,8 @@ def test_modify(client: FlaskClient, oidc_token_write):
5258

5359

5460
def test_remove(client: FlaskClient, oidc_token_write):
61+
if oidc_token_write is None:
62+
pytest.skip('No OIDC configuration is available')
5563
rac = ResourceAPIClient(client, token=oidc_token_write)
5664
(resp, resp_body) = rac.create(name='Short-lived Test Resource')
5765
assert resp.status_code == 201
@@ -63,6 +71,8 @@ def test_remove(client: FlaskClient, oidc_token_write):
6371

6472

6573
def test_get_all(client: FlaskClient, oidc_token_read, oidc_token_write):
74+
if oidc_token_read is None or oidc_token_write is None:
75+
pytest.skip('No OIDC configuration is available')
6676
rac_read = ResourceAPIClient(client, token=oidc_token_read)
6777
rac_write = ResourceAPIClient(client, token=oidc_token_write)
6878

@@ -81,6 +91,8 @@ def test_get_all(client: FlaskClient, oidc_token_read, oidc_token_write):
8191

8292

8393
def test_get_one(client: FlaskClient, oidc_token_read, oidc_token_write):
94+
if oidc_token_read is None or oidc_token_write is None:
95+
pytest.skip('No OIDC configuration is available')
8496
rac_read = ResourceAPIClient(client, token=oidc_token_read)
8597
rac_write = ResourceAPIClient(client, token=oidc_token_write)
8698

0 commit comments

Comments
 (0)