Ejemplo n.º 1
0
    def test_remove_firewall_rule(self):
        # firewall-policy-remove-rule myid ruleid
        resource = 'firewall_policy'
        cmd = firewallpolicy.FirewallPolicyRemoveRule(
            test_cli20.MyApp(sys.stdout), None)
        myid = 'myid'
        args = ['myid', 'removerule']
        extrafields = {
            'firewall_rule_id': 'removerule',
        }

        body = extrafields
        path = getattr(self.client, resource + "_remove_path")
        cmd_parser = cmd.get_parser(resource + "_remove_rule")
        resp = (test_cli20.MyResp(204), None)

        with mock.patch.object(cmd, "get_client",
                               return_value=self.client) as mock_get_client, \
                mock.patch.object(self.client.httpclient, "request",
                                  return_value=resp) as mock_request:
            shell.run_command(cmd, cmd_parser, args)
        self.assert_mock_multiple_calls_with_same_arguments(
            mock_get_client, mock.call(), 2)
        mock_request.assert_called_once_with(
            test_cli20.MyUrlComparator(test_cli20.end_url(path % myid),
                                       self.client),
            'PUT',
            body=test_cli20.MyComparator(body, self.client),
            headers=test_cli20.ContainsKeyValue(
                {'X-Auth-Token': test_cli20.TOKEN}))
    def test_remove_firewall_rule(self):
        """firewall-policy-remove-rule myid ruleid
        """
        resource = 'firewall_policy'
        cmd = firewallpolicy.FirewallPolicyRemoveRule(
            test_cli20.MyApp(sys.stdout), None)
        myid = 'myid'
        args = ['myid', 'removerule']
        extrafields = {
            'firewall_rule_id': 'removerule',
        }

        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        body = extrafields
        path = getattr(self.client, resource + "_remove_path")
        self.client.httpclient.request(
            test_cli20.MyUrlComparator(
                test_cli20.end_url(path % myid, format=self.format),
                self.client),
            'PUT',
            body=test_cli20.MyComparator(body, self.client),
            headers=mox.ContainsKeyValue('X-Auth-Token',
                                         test_cli20.TOKEN)).AndReturn(
                                             (test_cli20.MyResp(204), None))
        args.extend(['--request-format', self.format])
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser(resource + "_remove_rule")
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()