def test_error_handling(self, requests_mock, mock_kwargs, expected_exception): """Test that various errors are handled as expected.""" params = {'email_user_id': '*****@*****.**'} request_url = f'{settings.STAFF_SSO_BASE_URL}api/v1/user/introspect/?{urlencode(params)}' requests_mock.get(request_url, **mock_kwargs) with pytest.raises(expected_exception.__class__) as excinfo: get_user_by_email_user_id('*****@*****.**') assert str(excinfo.value) == str(expected_exception)
def test_returns_data_on_success(self, requests_mock): """Test that user data is returned on success.""" params = {'email_user_id': '*****@*****.**'} request_url = f'{settings.STAFF_SSO_BASE_URL}api/v1/user/introspect/?{urlencode(params)}' requests_mock.get(request_url, json=FAKE_SSO_USER_DATA) assert get_user_by_email_user_id('*****@*****.**') == FAKE_SSO_USER_DATA
def _fetch_user_data_from_sso(email): try: return get_user_by_email_user_id(email) except SSOUserDoesNotExist: return get_user_by_email(email)