示例#1
0
    def setUp(self):
        super(ConsumerBindCommandTests, self).setUp()

        self.command = ConsumerBindCommand(self.context)

        self.mock_poll = mock.MagicMock()
        self.command.poll = self.mock_poll

        self.mock_bind_binding = mock.MagicMock()
        self.mock_bind_binding.return_value = task_simulator.create_fake_task_response()
        self.bindings.bind.bind = self.mock_bind_binding
示例#2
0
class ConsumerBindCommandTests(base.PulpClientTests):

    def setUp(self):
        super(ConsumerBindCommandTests, self).setUp()

        self.command = ConsumerBindCommand(self.context)

        self.mock_poll = mock.MagicMock()
        self.command.poll = self.mock_poll

        self.mock_bind_binding = mock.MagicMock()
        self.mock_bind_binding.return_value = task_simulator.create_fake_task_response()
        self.bindings.bind.bind = self.mock_bind_binding

    def test_structure(self):
        self.assertTrue(isinstance(self.command, PollingCommand))

        self.assertTrue(OPTION_REPO_ID in self.command.options)
        self.assertTrue(OPTION_CONSUMER_ID in self.command.options)
        self.assertTrue(OPTION_DISTRIBUTOR_ID in self.command.options)
        self.assertEqual(4, len(self.command.options))  # these + background from PollingCommand

        self.assertEqual(self.command.method, self.command.run)

    def test_run(self):
        # Setup
        self.cli.add_command(self.command)

        # Test
        self.cli.run('bind --repo-id r1 --consumer-id c1 --distributor-id d1'.split())

        # Verify
        self.mock_bind_binding.assert_called_once_with('c1', 'r1', 'd1')

        # Poll call made with the correct value
        self.assertEqual(1, self.mock_poll.call_count)
        self.assertEqual(self.mock_poll.call_args[0][0],
                         self.mock_bind_binding.return_value.response_body)

    def test_task_header_bind(self):
        # Setup
        sim = task_simulator.TaskSimulator()

        task = sim.add_task_state('1', responses.STATE_FINISHED)
        task.tags = [tags.action_tag(tags.ACTION_BIND)]

        # Test
        self.command.task_header(task)

        # Verify
        self.assertEqual(self.prompt.get_write_tags(), ['bind-header'])

    def test_task_header_agent_bind(self):
        # Setup
        sim = task_simulator.TaskSimulator()

        task = sim.add_task_state('2', responses.STATE_FINISHED)
        task.tags = [tags.action_tag(tags.ACTION_AGENT_BIND)]

        # Test
        self.command.task_header(task)

        # Verify
        self.assertEqual(self.prompt.get_write_tags(), ['agent-bind-header'])