class TestBindCommand(base.PulpClientTests): OPTION_NAMES = set(['--repo-id']) def setUp(self): super(TestBindCommand, self).setUp() self.command = BindCommand(self.context, 'bind', 'desc') def test_structure(self): # Ensure the correct method is wired up self.assertEqual(self.command.method, self.command.bind) def test_options_present(self): options_present = set([option.name for option in self.command.options]) self.assertEqual(self.OPTION_NAMES, options_present) def test_name(self): self.assertEqual(self.command.name, 'bind') self.assertEqual(self.command.description, 'desc') @mock.patch('pulp.bindings.consumer.BindingsAPI.bind') @mock.patch(LOAD_CONSUMER_API, return_value='c1') def test_bind_no_repo(self, mock_consumer, mock_bind): mock_bind.side_effect = BadRequestException({'property_names': ['repo_id']}) self.context.prompt = mock.MagicMock() # Test data = {'repo-id': 'repo1'} self.command.bind(**data) # Verify self.assertEqual(self.context.server.bind.bind.call_count, 1) self.assertEqual(self.context.prompt.render_success_message.call_count, 0) self.assertEqual(self.context.prompt.render_failure_message.call_count, 1) m = ('Repository [repo1] does not exist on the server') self.context.prompt.render_failure_message.assert_called_once_with(m, tag='not-found') @mock.patch('pulp.bindings.consumer.BindingsAPI.bind') @mock.patch(LOAD_CONSUMER_API, return_value='c1') def test_bind_no_dist(self, mock_consumer, mock_bind): mock_bind.side_effect = BadRequestException({'property_names': ['distributor_id']}) self.context.prompt = mock.MagicMock() # Test data = {'repo-id': 'repo1'} self.command.bind(**data) # Verify self.assertEqual(self.context.server.bind.bind.call_count, 1) self.assertEqual(self.context.prompt.render_success_message.call_count, 0) self.assertEqual(self.context.prompt.render_failure_message.call_count, 1) m = ('Repository [repo1] does not have a distributor') self.context.prompt.render_failure_message.assert_called_once_with(m, tag='not-found') @mock.patch(LOAD_CONSUMER_API, return_value=None) def test_unbind_no_registered_consumer(self, mock_consumer): self.command.prompt = mock.MagicMock() # Test data = {'repo-id': 'repo1'} self.command.bind(**data) # Verify self.assertEqual(self.command.prompt.render_success_message.call_count, 0) self.assertEqual(self.command.prompt.render_failure_message.call_count, 1) m = ('This consumer is not registered to the Pulp server') self.command.prompt.render_failure_message.assert_called_once_with(m)
class TestBindCommand(base.PulpClientTests): OPTION_NAMES = set(['--repo-id']) def setUp(self): super(TestBindCommand, self).setUp() self.command = BindCommand(self.context, 'bind', 'desc') def test_structure(self): # Ensure the correct method is wired up self.assertEqual(self.command.method, self.command.bind) def test_options_present(self): options_present = set([option.name for option in self.command.options]) self.assertEqual(self.OPTION_NAMES, options_present) def test_name(self): self.assertEqual(self.command.name, 'bind') self.assertEqual(self.command.description, 'desc') @mock.patch('pulp.bindings.consumer.BindingsAPI.bind') @mock.patch(LOAD_CONSUMER_API, return_value='c1') def test_bind_no_repo(self, mock_consumer, mock_bind): mock_bind.side_effect = BadRequestException( {'property_names': ['repo_id']}) self.context.prompt = mock.MagicMock() # Test data = {'repo-id': 'repo1'} self.command.bind(**data) # Verify self.assertEqual(self.context.server.bind.bind.call_count, 1) self.assertEqual(self.context.prompt.render_success_message.call_count, 0) self.assertEqual(self.context.prompt.render_failure_message.call_count, 1) m = ('Repository [repo1] does not exist on the server') self.context.prompt.render_failure_message.assert_called_once_with( m, tag='not-found') @mock.patch('pulp.bindings.consumer.BindingsAPI.bind') @mock.patch(LOAD_CONSUMER_API, return_value='c1') def test_bind_no_dist(self, mock_consumer, mock_bind): mock_bind.side_effect = BadRequestException( {'property_names': ['distributor_id']}) self.context.prompt = mock.MagicMock() # Test data = {'repo-id': 'repo1'} self.command.bind(**data) # Verify self.assertEqual(self.context.server.bind.bind.call_count, 1) self.assertEqual(self.context.prompt.render_success_message.call_count, 0) self.assertEqual(self.context.prompt.render_failure_message.call_count, 1) m = ('Repository [repo1] does not have a distributor') self.context.prompt.render_failure_message.assert_called_once_with( m, tag='not-found') @mock.patch(LOAD_CONSUMER_API, return_value=None) def test_unbind_no_registered_consumer(self, mock_consumer): self.command.prompt = mock.MagicMock() # Test data = {'repo-id': 'repo1'} self.command.bind(**data) # Verify self.assertEqual(self.command.prompt.render_success_message.call_count, 0) self.assertEqual(self.command.prompt.render_failure_message.call_count, 1) m = ('This consumer is not registered to the Pulp server') self.command.prompt.render_failure_message.assert_called_once_with(m)