Esempio n. 1
0
 def setUp(self):
     super(TestRefreshContentSourcesCommand, self).setUp()
     self.context = MagicMock(
         config={'output': {
             'poll_frequency_in_seconds': 1
         }})
     self.prompt = Mock()
     self.context.prompt = self.prompt
     self.renderer = PublishStepStatusRenderer(self.context)
     self.command = RefreshContentSourcesCommand(self.context,
                                                 self.renderer)
     step_details = {
         'source_id': '1',
         'succeeded': None,
         'url': 'mock-url',
         'added_count': '2',
         'deleted_count': '0',
         'errors': []
     }
     self.step = {
         reporting_constants.PROGRESS_STEP_TYPE_KEY: u'foo_step',
         reporting_constants.PROGRESS_STEP_UUID: u'abcde',
         reporting_constants.PROGRESS_DESCRIPTION_KEY: u'foo description',
         reporting_constants.PROGRESS_DETAILS_KEY: [step_details],
         reporting_constants.PROGRESS_STATE_KEY:
         reporting_constants.STATE_NOT_STARTED,
         reporting_constants.PROGRESS_ITEMS_TOTAL_KEY: 1,
         reporting_constants.PROGRESS_NUM_PROCESSED_KEY: 0,
         reporting_constants.PROGRESS_ERROR_DETAILS_KEY: []
     }
Esempio n. 2
0
 def setUp(self):
     super(TestRefreshContentSourcesCommand, self).setUp()
     self.context = MagicMock(config={"output": {"poll_frequency_in_seconds": 1}})
     self.prompt = Mock()
     self.context.prompt = self.prompt
     self.renderer = PublishStepStatusRenderer(self.context)
     self.command = RefreshContentSourcesCommand(self.context, self.renderer)
     step_details = {
         "source_id": "1",
         "succeeded": None,
         "url": "mock-url",
         "added_count": "2",
         "deleted_count": "0",
         "errors": [],
     }
     self.step = {
         reporting_constants.PROGRESS_STEP_TYPE_KEY: u"foo_step",
         reporting_constants.PROGRESS_STEP_UUID: u"abcde",
         reporting_constants.PROGRESS_DESCRIPTION_KEY: u"foo description",
         reporting_constants.PROGRESS_DETAILS_KEY: [step_details],
         reporting_constants.PROGRESS_STATE_KEY: reporting_constants.STATE_NOT_STARTED,
         reporting_constants.PROGRESS_ITEMS_TOTAL_KEY: 1,
         reporting_constants.PROGRESS_NUM_PROCESSED_KEY: 0,
         reporting_constants.PROGRESS_ERROR_DETAILS_KEY: [],
     }
Esempio n. 3
0
class TestRefreshContentSourcesCommand(base.PulpClientTests):
    def setUp(self):
        super(TestRefreshContentSourcesCommand, self).setUp()
        self.context = MagicMock(config={"output": {"poll_frequency_in_seconds": 1}})
        self.prompt = Mock()
        self.context.prompt = self.prompt
        self.renderer = PublishStepStatusRenderer(self.context)
        self.command = RefreshContentSourcesCommand(self.context, self.renderer)
        step_details = {
            "source_id": "1",
            "succeeded": None,
            "url": "mock-url",
            "added_count": "2",
            "deleted_count": "0",
            "errors": [],
        }
        self.step = {
            reporting_constants.PROGRESS_STEP_TYPE_KEY: u"foo_step",
            reporting_constants.PROGRESS_STEP_UUID: u"abcde",
            reporting_constants.PROGRESS_DESCRIPTION_KEY: u"foo description",
            reporting_constants.PROGRESS_DETAILS_KEY: [step_details],
            reporting_constants.PROGRESS_STATE_KEY: reporting_constants.STATE_NOT_STARTED,
            reporting_constants.PROGRESS_ITEMS_TOTAL_KEY: 1,
            reporting_constants.PROGRESS_NUM_PROCESSED_KEY: 0,
            reporting_constants.PROGRESS_ERROR_DETAILS_KEY: [],
        }

    @patch("pulp.client.commands.polling.PollingCommand.poll")
    def test_run_one(self, mock_poll):
        """
        Test run() when there are no refresh content source tasks on the server.
        """
        content_source_id = "test-content"
        data = {options.OPTION_CONTENT_SOURCE_ID.keyword: content_source_id}
        # No tasks are running
        self.command.run(**data)
        self.assertEqual(1, mock_poll.call_count)

    @patch("pulp.client.commands.polling.PollingCommand.poll")
    def test_run_all(self, mock_poll):
        """
        Test run() when there are no refresh content source tasks on the server.
        """
        data = {options.OPTION_CONTENT_SOURCE_ID.keyword: None}
        # No tasks are running
        self.command.run(**data)
        self.assertEqual(1, mock_poll.call_count)

    def test_progress(self):
        """
        Test the progress() method with a progress_report.
        """
        task = responses.Task({"progress_report": {"Refresh Content Sources": self.step}})
        spinner = MagicMock()
        self.renderer.display_report = MagicMock()
        self.command.progress(task, spinner)

        self.renderer.display_report.assert_called_once_with({"Refresh Content Sources": self.step})
Esempio n. 4
0
class TestRefreshContentSourcesCommand(base.PulpClientTests):
    def setUp(self):
        super(TestRefreshContentSourcesCommand, self).setUp()
        self.context = MagicMock(
            config={'output': {
                'poll_frequency_in_seconds': 1
            }})
        self.prompt = Mock()
        self.context.prompt = self.prompt
        self.renderer = PublishStepStatusRenderer(self.context)
        self.command = RefreshContentSourcesCommand(self.context,
                                                    self.renderer)
        step_details = {
            'source_id': '1',
            'succeeded': None,
            'url': 'mock-url',
            'added_count': '2',
            'deleted_count': '0',
            'errors': []
        }
        self.step = {
            reporting_constants.PROGRESS_STEP_TYPE_KEY: u'foo_step',
            reporting_constants.PROGRESS_STEP_UUID: u'abcde',
            reporting_constants.PROGRESS_DESCRIPTION_KEY: u'foo description',
            reporting_constants.PROGRESS_DETAILS_KEY: [step_details],
            reporting_constants.PROGRESS_STATE_KEY:
            reporting_constants.STATE_NOT_STARTED,
            reporting_constants.PROGRESS_ITEMS_TOTAL_KEY: 1,
            reporting_constants.PROGRESS_NUM_PROCESSED_KEY: 0,
            reporting_constants.PROGRESS_ERROR_DETAILS_KEY: []
        }

    @patch('pulp.client.commands.polling.PollingCommand.poll')
    def test_run_one(self, mock_poll):
        """
        Test run() when there are no refresh content source tasks on the server.
        """
        content_source_id = 'test-content'
        data = {options.OPTION_CONTENT_SOURCE_ID.keyword: content_source_id}
        # No tasks are running
        self.command.run(**data)
        self.assertEqual(1, mock_poll.call_count)

    @patch('pulp.client.commands.polling.PollingCommand.poll')
    def test_run_all(self, mock_poll):
        """
        Test run() when there are no refresh content source tasks on the server.
        """
        data = {options.OPTION_CONTENT_SOURCE_ID.keyword: None}
        # No tasks are running
        self.command.run(**data)
        self.assertEqual(1, mock_poll.call_count)

    def test_progress(self):
        """
        Test the progress() method with a progress_report.
        """
        task = responses.Task(
            {'progress_report': {
                'Refresh Content Sources': self.step
            }})
        spinner = MagicMock()
        self.renderer.display_report = MagicMock()
        self.command.progress(task, spinner)

        self.renderer.display_report.assert_called_once_with(
            {'Refresh Content Sources': self.step})