def test_index(self): self.mox.StubOutWithMock(api, 'user_list') api.user_list(IgnoreArg()).AndReturn(self.users) self.mox.ReplayAll() res = self.client.get(USERS_INDEX_URL) self.assertTemplateUsed(res, 'syspanel/users/index.html') self.assertItemsEqual(res.context['table'].data, self.users)
def get_data(self): users = [] try: users = api.user_list(self.request) except api_exceptions.AuthorizationFailure, e: LOG.exception("Unauthorized attempt to list users.") messages.error(self.request, _('Unable to get user info: %s') % e.message)
def users(request, tenant_id): for f in (AddUser, RemoveUser,): form, handled = f.maybe_handle(request) if handled: return handled add_user_form = AddUser() remove_user_form = RemoveUser() users = api.user_list(request, tenant_id) all_users = api.user_list(request) user_ids = [u.id for u in users] new_users = [u for u in all_users if not u.id in user_ids] return shortcuts.render(request, 'syspanel/tenants/users.html', { 'add_user_form': add_user_form, 'remove_user_form': remove_user_form, 'tenant_id': tenant_id, 'users': users, 'new_users': new_users})
def test_shoot_yourself_in_the_foot(self): self.mox.StubOutWithMock(api, 'user_list') # Four times... one for each post and one for each followed redirect api.user_list(IgnoreArg()).AndReturn(self.users) api.user_list(IgnoreArg()).AndReturn(self.users) api.user_list(IgnoreArg()).AndReturn(self.users) api.user_list(IgnoreArg()).AndReturn(self.users) self.mox.ReplayAll() formData = {'action': 'users__disable__%s' % self.request.user.id} res = self.client.post(USERS_INDEX_URL, formData, follow=True) self.assertEqual(list(res.context['messages'])[0].message, 'You cannot disable the user you are currently ' 'logged in as.') formData = {'action': 'users__delete__%s' % self.request.user.id} res = self.client.post(USERS_INDEX_URL, formData, follow=True) self.assertEqual(list(res.context['messages'])[0].message, 'You cannot delete the user you are currently ' 'logged in as.')
def test_shoot_yourself_in_the_foot(self): self.mox.StubOutWithMock(api, 'user_list') # Four times... one for each post and one for each followed redirect api.user_list(IgnoreArg()).AndReturn(self.users) api.user_list(IgnoreArg()).AndReturn(self.users) api.user_list(IgnoreArg()).AndReturn(self.users) api.user_list(IgnoreArg()).AndReturn(self.users) self.mox.ReplayAll() formData = {'action': 'users__disable__%s' % self.request.user.id} res = self.client.post(USERS_INDEX_URL, formData, follow=True) self.assertEqual( list(res.context['messages'])[0].message, 'You cannot disable the user you are currently ' 'logged in as.') formData = {'action': 'users__delete__%s' % self.request.user.id} res = self.client.post(USERS_INDEX_URL, formData, follow=True) self.assertEqual( list(res.context['messages'])[0].message, 'You cannot delete the user you are currently ' 'logged in as.')