def test_add_project_missing_field_error(self): project = self.tenants.first() quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() # init api.tenant_quota_defaults(IsA(http.HttpRequest), self.tenant.id) \ .AndReturn(quota) api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) # contribute api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) self.mox.ReplayAll() workflow_data = self._get_workflow_data(project, quota) workflow_data["name"] = "" url = reverse('horizon:admin:projects:create') res = self.client.post(url, workflow_data) self.assertContains(res, "field is required")
def test_add_project_get(self): quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() api.tenant_quota_defaults(IsA(http.HttpRequest), self.tenant.id) \ .AndReturn(quota) # init api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) self.mox.ReplayAll() url = reverse('horizon:admin:projects:create') res = self.client.get(url) self.assertTemplateUsed(res, 'admin/projects/create.html') workflow = res.context['workflow'] self.assertEqual(res.context['workflow'].name, CreateProject.name) step = workflow.get_step("createprojectinfoaction") self.assertEqual(step.action.initial['ram'], quota.ram) self.assertEqual(step.action.initial['injected_files'], quota.injected_files) self.assertQuerysetEqual(workflow.steps, [ '<CreateProjectInfo: createprojectinfoaction>', '<UpdateProjectMembers: update_members>', '<UpdateProjectQuota: update_quotas>' ])
def test_add_project_tenant_create_error(self): project = self.tenants.first() quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() # init api.tenant_quota_defaults(IsA(http.HttpRequest), self.tenant.id) \ .AndReturn(quota) api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) # contribute api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) # handle project_details = self._get_project_info(project) api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \ .AndRaise(self.exceptions.keystone) self.mox.ReplayAll() workflow_data = self._get_workflow_data(project, quota) url = reverse('horizon:admin:projects:create') res = self.client.post(url, workflow_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL)
def test_add_project_get(self): quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() api.tenant_quota_defaults(IsA(http.HttpRequest), self.tenant.id) \ .AndReturn(quota) # init api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) self.mox.ReplayAll() url = reverse('horizon:admin:projects:create') res = self.client.get(url) self.assertTemplateUsed(res, 'admin/projects/create.html') workflow = res.context['workflow'] self.assertEqual(res.context['workflow'].name, CreateProject.name) step = workflow.get_step("createprojectinfoaction") self.assertEqual(step.action.initial['ram'], quota.ram) self.assertEqual(step.action.initial['injected_files'], quota.injected_files) self.assertQuerysetEqual(workflow.steps, ['<CreateProjectInfo: createprojectinfoaction>', '<UpdateProjectMembers: update_members>', '<UpdateProjectQuota: update_quotas>'])
def test_add_project_user_update_error(self): project = self.tenants.first() quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() # init api.tenant_quota_defaults(IsA(http.HttpRequest), self.tenant.id) \ .AndReturn(quota) api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) # contribute api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) # handle project_details = self._get_project_info(project) quota_data = self._get_quota_info(quota) api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \ .AndReturn(project) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) workflow_data = {} for role in roles: if "role_" + role.id in workflow_data: ulist = workflow_data["role_" + role.id] for user in ulist: api.add_tenant_user_role(IsA(http.HttpRequest), tenant_id=self.tenant.id, user_id=user, role_id=role.id) \ .AndRaise(self.exceptions.keystone) break break api.nova.tenant_quota_update(IsA(http.HttpRequest), project.id, **quota_data) self.mox.ReplayAll() workflow_data.update(self._get_workflow_data(project, quota)) url = reverse('horizon:admin:projects:create') res = self.client.post(url, workflow_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL)
def get_data(self): try: quota_set = api.tenant_quota_defaults(self.request, self.request.user.tenant_id) data = quota_set.items except: data = [] exceptions.handle(self.request, _('Unable to get quota info.')) return data
def test_add_project_quota_defaults_error(self): default_role = self.roles.first() users = self.users.list() roles = self.roles.list() # init api.tenant_quota_defaults(IsA(http.HttpRequest), self.tenant.id) \ .AndRaise(self.exceptions.nova) api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) self.mox.ReplayAll() url = reverse('horizon:admin:projects:create') res = self.client.get(url) self.assertTemplateUsed(res, 'admin/projects/create.html') self.assertContains(res, "Unable to retrieve default quota values")
def get_initial(self): initial = super(CreateProjectView, self).get_initial() # get initial quota defaults try: quota_defaults = api.tenant_quota_defaults( self.request, self.request.user.tenant_id) for field in QUOTA_FIELDS: initial[field] = getattr(quota_defaults, field, None) except: error_msg = _('Unable to retrieve default quota values.') self.add_error_to_step(error_msg, 'update_quotas') return initial
def get_initial(self): initial = super(CreateProjectView, self).get_initial() # get initial quota defaults try: quota_defaults = api.tenant_quota_defaults(self.request, self.request.user.tenant_id) for field in QUOTA_FIELDS: initial[field] = getattr(quota_defaults, field, None) except: error_msg = _('Unable to retrieve default quota values.') self.add_error_to_step(error_msg, 'update_quotas') return initial