Ejemplo n.º 1
0
    def test_error_handling(self, requests_mock, mock_kwargs,
                            expected_exception):
        """Test that various errors are handled as expected."""
        params = {'email': '*****@*****.**'}
        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('*****@*****.**')

        assert str(excinfo.value) == str(expected_exception)
Ejemplo n.º 2
0
    def test_returns_data_on_success(self, requests_mock):
        """Test that user data is returned on success."""
        params = {'email': '*****@*****.**'}
        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('*****@*****.**') == FAKE_SSO_USER_DATA
Ejemplo n.º 3
0
def _fetch_user_data_from_sso(email):
    try:
        return get_user_by_email_user_id(email)
    except SSOUserDoesNotExist:
        return get_user_by_email(email)