def test_multi_sources_multi_destinations(self, mock_put):
        client = AddACLAccess(self.fake_env, self.sources, self.destinations,
                              self.default_port)
        client.execute()

        expected_payload_first_call = {
            "kind":
            "object#acl",
            "rules": [{
                "action": "permit",
                "protocol": "tcp",
                "source": self.sources[0],
                "destination": self.destinations[0],
                "l4-options": {
                    "dest-port-op": "eq",
                    "dest-port-start": str(self.default_port)
                }
            }, {
                "action": "permit",
                "protocol": "tcp",
                "source": self.sources[0],
                "destination": self.destinations[1],
                "l4-options": {
                    "dest-port-op": "eq",
                    "dest-port-start": str(self.default_port)
                }
            }]
        }
        expected_payload_second_call = {
            "kind":
            "object#acl",
            "rules": [{
                "action": "permit",
                "protocol": "tcp",
                "source": self.sources[1],
                "destination": self.destinations[0],
                "l4-options": {
                    "dest-port-op": "eq",
                    "dest-port-start": str(self.default_port)
                }
            }, {
                "action": "permit",
                "protocol": "tcp",
                "source": self.sources[1],
                "destination": self.destinations[1],
                "l4-options": {
                    "dest-port-op": "eq",
                    "dest-port-start": str(self.default_port)
                }
            }]
        }
        self.assertTrue(mock_put.called)
        self.assertEqual(mock_put.call_count, 2)
        put_args_first, put_args_second = mock_put.call_args_list
        expected_endpoint = 'fake_endpoint/api/ipv4/acl/1.1.1.1/27'
        self._validate_call(put_args_first, expected_payload_first_call,
                            expected_endpoint)
        expected_endpoint = 'fake_endpoint/api/ipv4/acl/2.2.2.2/27'
        self._validate_call(put_args_second, expected_payload_second_call,
                            expected_endpoint)
 def test_resp_not_ok(self, mock_stdout, mock_put):
     mock_put.return_value = namedtuple(
         'FakeResp', 'ok status_code content')(False, 400, 'Some error')
     client = AddACLAccess(self.fake_env, self.sources[:1],
                           self.destinations[:1], self.default_port)
     client.execute()
     self.assertIn('FAIL Status: {} Error: {}!!'.format(400, 'Some error'),
                   mock_stdout.getvalue())
 def test_resp_ok(self, mock_stdout, mock_put):
     mock_put.return_value = namedtuple('FakeResp',
                                        'ok status_code content')(True, 200,
                                                                  '')
     client = AddACLAccess(self.fake_env, self.sources[:1],
                           self.destinations[:1], self.default_port)
     client.execute()
     self.assertIn("SUCCESS!!", mock_stdout.getvalue())
    def test_one_source(self, mock_put):
        client = AddACLAccess(self.fake_env, self.sources[:1],
                              self.destinations[:1], self.default_port)
        client.execute()

        expected_payload = {
            "kind":
            "object#acl",
            "rules": [{
                "action": "permit",
                "protocol": "tcp",
                "source": self.sources[0],
                "destination": self.destinations[0],
                "l4-options": {
                    "dest-port-op": "eq",
                    "dest-port-start": str(self.default_port)
                }
            }]
        }
        self.assertTrue(mock_put.called)
        self.assertEqual(mock_put.call_count, 1)
        put_args = mock_put.call_args
        expected_endpoint = 'fake_endpoint/api/ipv4/acl/1.1.1.1/27'
        self._validate_call(put_args, expected_payload, expected_endpoint)