def test_create_security_groups_post(self): SECGROUP_NAME = 'fakegroup' SECGROUP_DESC = 'fakegroup_desc' new_group = self.mox.CreateMock(api.SecurityGroup) new_group.name = SECGROUP_NAME formData = { 'method': 'CreateGroup', 'tenant_id': self.TEST_TENANT, 'name': SECGROUP_NAME, 'description': SECGROUP_DESC, } self.mox.StubOutWithMock(api, 'security_group_create') api.security_group_create(IsA(http.HttpRequest), SECGROUP_NAME, SECGROUP_DESC).AndReturn(new_group) self.mox.ReplayAll() res = self.client.post( reverse('dash_security_groups_create', args=[self.TEST_TENANT]), formData) self.assertRedirectsNoFollow( res, reverse('dash_security_groups', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_create_security_groups_post(self): SECGROUP_NAME = 'fakegroup' SECGROUP_DESC = 'fakegroup_desc' new_group = self.mox.CreateMock(api.SecurityGroup) new_group.name = SECGROUP_NAME formData = {'method': 'CreateGroup', 'tenant_id': self.TEST_TENANT, 'name': SECGROUP_NAME, 'description': SECGROUP_DESC, } self.mox.StubOutWithMock(api, 'security_group_create') api.security_group_create(IsA(http.HttpRequest), SECGROUP_NAME, SECGROUP_DESC).AndReturn(new_group) self.mox.ReplayAll() res = self.client.post(reverse('dash_security_groups_create', args=[self.TEST_TENANT]), formData) self.assertRedirectsNoFollow(res, reverse('dash_security_groups', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_create_security_groups_post_exception(self): SECGROUP_NAME = 'fakegroup' SECGROUP_DESC = 'fakegroup_desc' exception = novaclient_exceptions.ClientException( 'ClientException', message='ClientException') formData = { 'method': 'CreateGroup', 'tenant_id': self.TEST_TENANT, 'name': SECGROUP_NAME, 'description': SECGROUP_DESC, } self.mox.StubOutWithMock(api, 'security_group_create') api.security_group_create(IsA(http.HttpRequest), SECGROUP_NAME, SECGROUP_DESC).AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('dash_security_groups_create', args=[self.TEST_TENANT]), formData) self.assertTemplateUsed( res, 'django_openstack/dash/security_groups/create.html') self.mox.VerifyAll()
def test_create_security_groups_post_exception(self): SECGROUP_NAME = 'fakegroup' SECGROUP_DESC = 'fakegroup_desc' exception = novaclient_exceptions.ClientException('ClientException', message='ClientException') formData = {'method': 'CreateGroup', 'tenant_id': self.TEST_TENANT, 'name': SECGROUP_NAME, 'description': SECGROUP_DESC, } self.mox.StubOutWithMock(api, 'security_group_create') api.security_group_create(IsA(http.HttpRequest), SECGROUP_NAME, SECGROUP_DESC).AndRaise(exception) self.mox.ReplayAll() res = self.client.post(reverse('dash_security_groups_create', args=[self.TEST_TENANT]), formData) self.assertTemplateUsed(res, 'django_openstack/dash/security_groups/create.html') self.mox.VerifyAll()
def handle(self, request, data): try: LOG.info('Add security_group: "%s"' % data) security_group = api.security_group_create(request, data["name"], data["description"]) messages.info(request, "Successfully created security_group: %s" % data["name"]) return shortcuts.redirect("dash_security_groups", data["tenant_id"]) except novaclient_exceptions.ClientException, e: LOG.exception("ClientException in CreateGroup") messages.error(request, "Error creating security group: %s" % e.message)
def handle(self, request, data): try: LOG.info('Add security_group: "%s"' % data) security_group = api.security_group_create(request, data['name'], data['description']) messages.info(request, 'Successfully created security_group: %s' \ % data['name']) return shortcuts.redirect('dash_security_groups', data['tenant_id']) except novaclient_exceptions.ClientException, e: LOG.error("ClientException in CreateGroup", exc_info=True) messages.error(request, 'Error creating security group: %s' % e.message)
def test_create_security_groups_post_exception(self): SECGROUP_NAME = "fakegroup" SECGROUP_DESC = "fakegroup_desc" exception = novaclient_exceptions.ClientException("ClientException", message="ClientException") formData = { "method": "CreateGroup", "tenant_id": self.TEST_TENANT, "name": SECGROUP_NAME, "description": SECGROUP_DESC, } self.mox.StubOutWithMock(api, "security_group_create") api.security_group_create(IsA(http.HttpRequest), SECGROUP_NAME, SECGROUP_DESC).AndRaise(exception) self.mox.ReplayAll() res = self.client.post(reverse("dash_security_groups_create", args=[self.TEST_TENANT]), formData) self.assertTemplateUsed(res, "django_openstack/dash/security_groups/create.html") self.mox.VerifyAll()
def handle(self, request, data): try: LOG.info('Add security_group: "%s"' % data) security_group = api.security_group_create(request, data['name'], data['description']) messages.info(request, _('Successfully created security_group: %s') % data['name']) return shortcuts.redirect('dash_security_groups', data['tenant_id']) except novaclient_exceptions.ClientException, e: LOG.exception("ClientException in CreateGroup") messages.error(request, _('Error creating security group: %s') % e.message)
def test_create_security_groups_post(self): SECGROUP_NAME = "fakegroup" SECGROUP_DESC = "fakegroup_desc" new_group = self.mox.CreateMock(api.SecurityGroup) new_group.name = SECGROUP_NAME formData = { "method": "CreateGroup", "tenant_id": self.TEST_TENANT, "name": SECGROUP_NAME, "description": SECGROUP_DESC, } self.mox.StubOutWithMock(api, "security_group_create") api.security_group_create(IsA(http.HttpRequest), SECGROUP_NAME, SECGROUP_DESC).AndReturn(new_group) self.mox.ReplayAll() res = self.client.post(reverse("dash_security_groups_create", args=[self.TEST_TENANT]), formData) self.assertRedirectsNoFollow(res, reverse("dash_security_groups", args=[self.TEST_TENANT])) self.mox.VerifyAll()