def setUp(self): super(ConsumerUnbindCommandTests, self).setUp() self.command = ConsumerUnbindCommand(self.context) self.mock_poll = mock.MagicMock() self.command.poll = self.mock_poll self.mock_unbind_binding = mock.MagicMock() self.mock_unbind_binding.return_value = task_simulator.create_fake_task_response() self.bindings.bind.unbind = self.mock_unbind_binding
def __init__(self, context, name=None, description=None): """ Create a new YumConsumerUnbindCommand :param context: The context to use for this command :type context: pulp.client.extensions.core.ClientContext :param name: The name to use for this command :type name: str :param description: The description for this command :type description: str """ ConsumerUnbindCommand.__init__(self, context, name, description) self.context.exception_handler = UnbindExceptionHandler(self.prompt, context.config)
def __init__(self, context, name=None, description=None): """ Create a new YumConsumerUnbindCommand :param context: The context to use for this command :type context: pulp.client.extensions.core.ClientContext :param name: The name to use for this command :type name: str :param description: The description for this command :type description: str """ ConsumerUnbindCommand.__init__(self, context, name, description) self.context.exception_handler = UnbindExceptionHandler( self.prompt, context.config)
class ConsumerUnbindCommandTests(base.PulpClientTests): def setUp(self): super(ConsumerUnbindCommandTests, self).setUp() self.command = ConsumerUnbindCommand(self.context) self.mock_poll = mock.MagicMock() self.command.poll = self.mock_poll self.mock_unbind_binding = mock.MagicMock() self.mock_unbind_binding.return_value = task_simulator.create_fake_task_response() self.bindings.bind.unbind = self.mock_unbind_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.assertTrue(FLAG_FORCE in self.command.options) self.assertEqual(5, 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('unbind --repo-id r1 --consumer-id c1 --distributor-id d1'.split()) # Verify self.mock_unbind_binding.assert_called_once_with('c1', 'r1', 'd1', False) # 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_unbind_binding.return_value.response_body) def test_task_header_unbind(self): # Setup sim = task_simulator.TaskSimulator() task = sim.add_task_state('1', responses.STATE_FINISHED) task.tags = [tags.action_tag(tags.ACTION_UNBIND)] # Test self.command.task_header(task) # Verify self.assertEqual(self.prompt.get_write_tags(), ['unbind-header']) def test_task_header_agent_unbind(self): # Setup sim = task_simulator.TaskSimulator() task = sim.add_task_state('2', responses.STATE_FINISHED) task.tags = [tags.action_tag(tags.ACTION_AGENT_UNBIND)] # Test self.command.task_header(task) # Verify self.assertEqual(self.prompt.get_write_tags(), ['agent-unbind-header']) def test_task_header_delete_binding(self): # Setup sim = task_simulator.TaskSimulator() task = sim.add_task_state('3', responses.STATE_FINISHED) task.tags = [tags.action_tag(tags.ACTION_DELETE_BINDING)] # Test self.command.task_header(task) # Verify self.assertEqual(self.prompt.get_write_tags(), ['delete-header'])