コード例 #1
0
    def test_policy_update(self):
        policy = self.fw_policies.first()
        policy_dict = self.api_fw_policies.first()

        policy.name = 'new name'
        policy.description = 'new desc'
        policy.shared = True
        policy.audited = False

        policy_dict['name'] = 'new name'
        policy_dict['description'] = 'new desc'
        policy_dict['shared'] = True
        policy_dict['audited'] = False

        form_data = {
            'name': policy.name,
            'description': policy.description,
            'shared': policy.shared,
            'audited': policy.audited
        }

        form_dict = {'firewall_policy': form_data}
        ret_dict = {'firewall_policy': policy_dict}

        neutronclient.update_firewall_policy(policy.id,
                                             form_dict).AndReturn(ret_dict)
        self.mox.ReplayAll()

        ret_val = api_fwaas.policy_update(self.request, policy.id, **form_data)
        self.assertIsInstance(ret_val, api_fwaas.Policy)
        self.assertEqual(policy.name, ret_val.name)
        self.assertTrue(ret_val.id)
コード例 #2
0
    def handle(self, request, context):
        policy_id = self.initial['id']
        name_or_id = context.get('name') or policy_id

        # Remove 'shared' from the context if the user is not allowed to
        # change this field
        if self.ignore_shared and 'shared' in context:
            del context['shared']

        try:
            policy = api_fwaas.policy_update(request, policy_id, **context)
            msg = _('Policy %s was successfully updated.') % name_or_id
            messages.success(request, msg)
            return policy
        except Exception as e:
            LOG.error('Failed to update policy %(id)s: %(reason)s', {
                'id': policy_id,
                'reason': e
            })
            msg = (_('Failed to update policy %(name)s: %(reason)s') % {
                'name': name_or_id,
                'reason': e
            })
            redirect = reverse(self.failure_url)
            exceptions.handle(request, msg, redirect=redirect)
コード例 #3
0
    def test_policy_update(self):
        policy = self.fw_policies.first()
        policy_dict = self.api_fw_policies.first()

        policy.name = 'new name'
        policy.description = 'new desc'
        policy.shared = True
        policy.audited = False

        policy_dict['name'] = 'new name'
        policy_dict['description'] = 'new desc'
        policy_dict['shared'] = True
        policy_dict['audited'] = False

        form_data = {'name': policy.name,
                     'description': policy.description,
                     'shared': policy.shared,
                     'audited': policy.audited
                     }

        form_dict = {'firewall_policy': form_data}
        ret_dict = {'firewall_policy': policy_dict}

        self.mock_update_firewall_policy.return_value = ret_dict

        ret_val = api_fwaas.policy_update(self.request,
                                          policy.id, **form_data)
        self.assertIsInstance(ret_val, api_fwaas.Policy)
        self.assertEqual(policy.name, ret_val.name)
        self.assertTrue(ret_val.id)
        self.mock_update_firewall_policy.assert_called_once_with(
            policy.id, form_dict)
コード例 #4
0
    def test_update_policy_post(self):
        policy = self.fw_policies.first()

        api_fwaas.policy_get(IsA(http.HttpRequest),
                             policy.id).AndReturn(policy)

        data = {'name': 'new name',
                'description': 'new desc',
                'shared': True,
                'audited': False
                }

        api_fwaas.policy_update(IsA(http.HttpRequest), policy.id, **data)\
            .AndReturn(policy)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse(self.UPDATEPOLICY_PATH, args=(policy.id,)), data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
コード例 #5
0
 def handle(self, request, context):
     policy_id = self.initial['policy_id']
     name_or_id = context.get('name') or policy_id
     try:
         policy = api_fwaas.policy_update(request, policy_id, **context)
         msg = _('Policy %s was successfully updated.') % name_or_id
         messages.success(request, msg)
         return policy
     except Exception as e:
         LOG.error('Failed to update policy %(id)s: %(reason)s', {
             'id': policy_id,
             'reason': e
         })
         msg = (_('Failed to update policy %(name)s: %(reason)s') % {
             'name': name_or_id,
             'reason': e
         })
         redirect = reverse(self.failure_url)
         exceptions.handle(request, msg, redirect=redirect)