Exemplo n.º 1
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest), user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest), user.id,
                                    self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest), user.id,
                                 IgnoreArg()).AndReturn(None)

        self.mox.ReplayAll()

        formData = {
            'method': 'UpdateUserForm',
            'id': user.id,
            'name': user.name,
            'email': user.email,
            'password': '******',
            'tenant_id': self.tenant.id,
            'confirm_password': '******'
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemplo n.º 2
0
    def test_update_with_keystone_can_edit_user_false(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone_can_edit_user().AndReturn(False)
        api.keystone_can_edit_user().AndReturn(False)
        api.user_update_tenant(IsA(http.HttpRequest), user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest), user.id,
                                    self.tenant.id).AndReturn(None)

        self.mox.ReplayAll()

        formData = {
            'method': 'UpdateUserForm',
            'id': user.id,
            'name': user.name,
            'tenant_id': self.tenant.id,
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemplo n.º 3
0
    def test_update_with_keystone_can_edit_user_false(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest),
                     '1',
                     admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone_can_edit_user().AndReturn(False)
        api.keystone_can_edit_user().AndReturn(False)
        api.user_update_tenant(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest),
                                    user.id,
                                    self.tenant.id).AndReturn(None)

        self.mox.ReplayAll()

        formData = {'method': 'UpdateUserForm',
                    'id': user.id,
                    'name': user.name,
                    'tenant_id': self.tenant.id, }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemplo n.º 4
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), "1", admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(
            IsA(http.HttpRequest), user.id, email=u"*****@*****.**", name=u"test_user"
        ).AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest), user.id, IgnoreArg()).AndReturn(None)

        self.mox.ReplayAll()

        formData = {
            "method": "UpdateUserForm",
            "id": user.id,
            "name": user.name,
            "email": user.email,
            "password": "******",
            "tenant_id": self.tenant.id,
            "confirm_password": "******",
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemplo n.º 5
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1',
                     admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(),
                        admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(None)
        api.keystone.roles_for_user(IsA(http.HttpRequest),
                                    user.id,
                                    self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest),
                                 user.id,
                                 IgnoreArg()).AndReturn(None)

        self.mox.ReplayAll()

        formData = {'method': 'UpdateUserForm',
                    'id': user.id,
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': '******'}

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Exemplo n.º 6
0
    def test_update_user_with_passwords_not_matching(self):
        api.user_get(IsA(http.HttpRequest), "1", admin=True).AndReturn(self.user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        self.mox.ReplayAll()

        self.selenium.get("%s%s" % (self.live_server_url, USER_UPDATE_URL))

        body = self.selenium.find_element_by_tag_name("body")
        self.assertFalse("Passwords do not match" in body.text, "Error message should not be visible at loading time")
        self.selenium.find_element_by_id("id_password").send_keys("test")
        self.selenium.find_element_by_id("id_confirm_password").send_keys("te")
        self.selenium.find_element_by_id("id_email").clear()
        body = self.selenium.find_element_by_tag_name("body")
        self.assertTrue("Passwords do not match" in body.text, "Error message not found in body")
Exemplo n.º 7
0
    def test_update_user_with_passwords_not_matching(self):
        api.user_get(IsA(http.HttpRequest), '1',
                     admin=True).AndReturn(self.user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        self.mox.ReplayAll()

        self.selenium.get("%s%s" % (self.live_server_url, USER_UPDATE_URL))

        body = self.selenium.find_element_by_tag_name("body")
        self.assertFalse(
            "Passwords do not match" in body.text,
            "Error message should not be visible at loading time")
        self.selenium.find_element_by_id("id_password").send_keys("test")
        self.selenium.find_element_by_id("id_confirm_password").send_keys("te")
        self.selenium.find_element_by_id("id_email").clear()
        body = self.selenium.find_element_by_tag_name("body")
        self.assertTrue("Passwords do not match" in body.text,
                        "Error message not found in body")
Exemplo n.º 8
0
 def get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = api.user_get(self.request,
                                         self.kwargs['user_id'],
                                         admin=True)
         except:
             redirect = reverse("horizon:admin:users:index")
             exceptions.handle(self.request,
                               _('Unable to update user.'),
                               redirect=redirect)
     return self._object
def update(request, user_id):
    user = api.user_get(request, user_id)
    form, handle = get_user_form(request, user).maybe_handle(request, is_create=False, initial={'id': user_id,
                             'email': user.email,
                             'is_hardadmin': "hardadmin" in user.global_roles,
                             'is_softadmin': "softadmin" in user.global_roles})
    if handle:
        return handle
    return render_to_response(
    topbar + '/user_update.html',{
        'form': form
    }, context_instance = template.RequestContext(request))
Exemplo n.º 10
0
    def test_update_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), "1", admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())

        self.mox.ReplayAll()

        formData = {
            "method": "UpdateUserForm",
            "id": user.id,
            "name": user.name,
            "email": user.email,
            "password": "******",
            "tenant_id": self.tenant.id,
            "confirm_password": "******",
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertFormError(res, "form", "password", ["Password must be between 8 and 18 characters."])
Exemplo n.º 11
0
 def get_object(self):
     if not hasattr(self, "_object"):
         try:
             self._object = api.user_get(self.request,
                                         self.kwargs['user_id'],
                                         admin=True)
         except:
             redirect = reverse("horizon:admin:users:index")
             exceptions.handle(self.request,
                               _('Unable to update user.'),
                               redirect=redirect)
     return self._object
Exemplo n.º 12
0
    def test_update_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())

        self.mox.ReplayAll()

        formData = {
            'method': 'UpdateUserForm',
            'id': user.id,
            'name': user.name,
            'email': user.email,
            'password': '******',
            'tenant_id': self.tenant.id,
            'confirm_password': '******'
        }

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertFormError(res, "form", 'password',
                             ['Password must be between 8 and 18 characters.'])
Exemplo n.º 13
0
    def test_update_validation_for_password_too_long(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1',
                     admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(),
                        admin=True).AndReturn(self.tenants.list())

        self.mox.ReplayAll()

        formData = {'method': 'UpdateUserForm',
                    'id': user.id,
                    'name': user.name,
                    'email': user.email,
                    'password': '******',
                    'tenant_id': self.tenant.id,
                    'confirm_password': '******'}

        res = self.client.post(USER_UPDATE_URL, formData)

        self.assertFormError(
                res, "form", 'password',
                ['Password must be between 8 and 18 characters.'])
 def _handle(self, request, data):
     self.user = self.clean()
     self.updated = []
     self.user_id = self.user['id']
     if self.is_create:
         self.orig_user = api.user_create(
             request, self.user['id'], self.user['email'], 
             self.user['password'], None, True)
         messages.success(request,
                          '%s was successfully created.'
                          % self.user_id)
     else:
         self.orig_user = api.user_get(request, self.user_id)
         if self.user['email'] != self.orig_user.email:
             self.updated.append('email')
             api.user_update_email(request, self.user['id'], self.user['email'])
         if self.user['password']:
             self.updated.append('password')
             api.user_update_password(request, self.user['id'], self.user['password'])