示例#1
0
    def clean(self):

        try:
            user_dict = client.sso_create_user(
                self.cleaned_data["first_name"],
                self.cleaned_data["last_name"],
                self.cleaned_data["email"],
                self.cleaned_data["username"],
            )
        except HTTPError as e:
            error_text = e.response.text
            if "duplicate username" in error_text:
                raise ValidationError({"username": (_("Username %s already used") % self.cleaned_data["username"])})
            logger.error("Error when creating user on the SSO: %s", error_text)
            raise ValidationError(error_text[:MAX_ERROR_MESSAGE_LENGTH])
        user = client.construct_user(user_dict)
        logger.info("Created user %s on the SSO and added it locally", user)
示例#2
0
    def test_create_user(self):

        def mock_post(url, data, 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.post', mock_post):
            with mock.patch('lizard_auth_client.client.sso_server_url',
                            mock_server_url):
                self.assertEquals(
                    {'a': 'dict'},
                    client.sso_create_user('some', 'name',
                                           '*****@*****.**',
                                           'somename'))