def test_edit_rules_get(self):
        SECGROUP_ID = "1"

        self.mox.StubOutWithMock(api, "security_group_get")
        api.security_group_get(IsA(http.HttpRequest), SECGROUP_ID).AndReturn(self.security_groups[0])

        self.mox.ReplayAll()

        res = self.client.get(reverse("dash_security_groups_edit_rules", args=[self.TEST_TENANT, SECGROUP_ID]))

        self.assertTemplateUsed(res, "django_openstack/dash/security_groups/edit_rules.html")
        self.assertItemsEqual(res.context["security_group"].name, self.security_groups[0].name)

        self.mox.VerifyAll()
    def test_edit_rules_get_exception(self):
        SECGROUP_ID = "1"

        exception = novaclient_exceptions.ClientException("ClientException", message="ClientException")

        self.mox.StubOutWithMock(api, "security_group_get")
        api.security_group_get(IsA(http.HttpRequest), SECGROUP_ID).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.get(reverse("dash_security_groups_edit_rules", args=[self.TEST_TENANT, SECGROUP_ID]))

        self.assertRedirectsNoFollow(res, reverse("dash_security_groups", args=[self.TEST_TENANT]))

        self.mox.VerifyAll()
Пример #3
0
def edit_rules(request, tenant_id, security_group_id):
    add_form, handled = AddRule.maybe_handle(request,
                                             initial={
                                                 'tenant_id':
                                                 tenant_id,
                                                 'security_group_id':
                                                 security_group_id
                                             })
    if handled:
        return handled

    delete_form, handled = DeleteRule.maybe_handle(request,
                                                   initial={
                                                       'tenant_id':
                                                       tenant_id,
                                                       'security_group_id':
                                                       security_group_id
                                                   })
    if handled:
        return handled

    try:
        security_group = api.security_group_get(request, security_group_id)
    except novaclient_exceptions.ClientException, e:
        LOG.error("ClientException in security_groups rules edit",
                  exc_info=True)
        messages.error(request, 'Error getting security_group: %s' % e.message)
        return shortcuts.redirect('dash_security_groups', tenant_id)
Пример #4
0
    def test_edit_rules_get(self):
        SECGROUP_ID = '1'

        self.mox.StubOutWithMock(api, 'security_group_get')
        api.security_group_get(IsA(http.HttpRequest),
                               SECGROUP_ID).AndReturn(self.security_groups[0])

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('dash_security_groups_edit_rules',
                    args=[self.TEST_TENANT, SECGROUP_ID]))

        self.assertTemplateUsed(
            res, 'django_openstack/dash/security_groups/edit_rules.html')
        self.assertItemsEqual(res.context['security_group'].name,
                              self.security_groups[0].name)

        self.mox.VerifyAll()
Пример #5
0
    def test_edit_rules_get_exception(self):
        SECGROUP_ID = '1'

        exception = novaclient_exceptions.ClientException(
            'ClientException', message='ClientException')

        self.mox.StubOutWithMock(api, 'security_group_get')
        api.security_group_get(IsA(http.HttpRequest),
                               SECGROUP_ID).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.get(
            reverse('dash_security_groups_edit_rules',
                    args=[self.TEST_TENANT, SECGROUP_ID]))

        self.assertRedirectsNoFollow(
            res, reverse('dash_security_groups', args=[self.TEST_TENANT]))

        self.mox.VerifyAll()
def edit_rules(request, tenant_id, security_group_id):
    add_form, handled = AddRule.maybe_handle(
        request, initial={"tenant_id": tenant_id, "security_group_id": security_group_id}
    )
    if handled:
        return handled

    delete_form, handled = DeleteRule.maybe_handle(
        request, initial={"tenant_id": tenant_id, "security_group_id": security_group_id}
    )
    if handled:
        return handled

    try:
        security_group = api.security_group_get(request, security_group_id)
    except novaclient_exceptions.ClientException, e:
        LOG.exception("ClientException in security_groups rules edit")
        messages.error(request, "Error getting security_group: %s" % e.message)
        return shortcuts.redirect("dash_security_groups", tenant_id)
def edit_rules(request, tenant_id, security_group_id):
    add_form, handled = AddRule.maybe_handle(request,
                           initial={'tenant_id': tenant_id,
                                      'security_group_id': security_group_id})
    if handled:
        return handled

    delete_form, handled = DeleteRule.maybe_handle(request,
                              initial={'tenant_id': tenant_id,
                                       'security_group_id': security_group_id})
    if handled:
        return handled

    try:
        security_group = api.security_group_get(request, security_group_id)
    except novaclient_exceptions.ClientException, e:
        LOG.error("ClientException in security_groups rules edit", exc_info=True)
        messages.error(request, 'Error getting security_group: %s' % e.message)
        return shortcuts.redirect('dash_security_groups', tenant_id)