Skip to content

Commit

Permalink
Add test for failing get_api_session
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Jul 3, 2024
1 parent adbe4e5 commit 0025b34
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_search_identities_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,22 @@ def test_search_identities_cache_hit_stale(provider, mock_data, freeze_time):
assert mock_data[data_key] == identities[0][0].data.get(identities_key)
assert isinstance(identities[0][0], IdentityInfo)
assert identities[1] == 1


@pytest.mark.usefixtures('httpretty_enabled')
def test_search_identities_cache_hit_broken_sso(mocker, provider, mock_data, freeze_time):
get_api_session = mocker.patch('flask_multipass_cern.CERNIdentityProvider._get_api_session')
get_api_session.side_effect = RequestException()

test_uri = f'{provider.settings.get("authz_api")}/api/v1.0/Identity'
httpretty.register_uri(httpretty.GET, test_uri, status=401)
cache_key = 'flask-multipass-cern:cip:email-identities:test@cern.ch'
provider.cache.set(cache_key, ([mock_data], 1), 2000, 10)
freeze_time(datetime.now() + timedelta(seconds=100))

identities = provider.search_identities_ex({'primaryAccountEmail': {'test@cern.ch'}}, True)

for identities_key, data_key in provider.settings.get('mapping').items():
assert mock_data[data_key] == identities[0][0].data.get(identities_key)
assert isinstance(identities[0][0], IdentityInfo)
assert identities[1] == 1

0 comments on commit 0025b34

Please sign in to comment.