def clean(self):

        try:
            user_dict = client.sso_search_user_by_email(self.cleaned_data["email"])
        except HTTPError as e:
            error_text = e.response.text
            if e.response.status_code == 404:
                msg = _("User with email %s not found")
                raise ValidationError({"email": msg % self.cleaned_data["email"]})
            logger.error("Error when searching user on the SSO: %s", error_text)
            raise ValidationError(error_text[:MAX_ERROR_MESSAGE_LENGTH])
        user = client.construct_user(user_dict)
        logger.info("Added SSO user %s locally", user)
Beispiel #2
0
    def test_search_user(self):

        def mock_get(url, params, timeout):
            result = mock.Mock()
            result.json.return_value = {'user': {'a': 'dict'}}
            return result

        def mock_server_url(what):
            return 'http:/some/where/'

        with mock.patch('requests.get', mock_get):
            with mock.patch('lizard_auth_client.client.sso_server_url',
                            mock_server_url):
                self.assertEquals(
                    {'a': 'dict'},
                    client.sso_search_user_by_email('*****@*****.**'))