def test_publish_group(self, mock_validate, export_publisher):
        mock_validate.return_value = (True, None)
        distributor = GroupISODistributor()
        export_publisher.return_value = mock.Mock()
        export_publisher.return_value.publish.return_value = 'foo'

        self.assertEquals('foo', distributor.publish_group(self.repo, self.conduit, self.config))
Ejemplo n.º 2
0
    def test_publish_group(self, mock_validate, export_publisher, mock_ensure_downloaded):
        mock_validate.return_value = (True, None)
        distributor = GroupISODistributor()
        export_publisher.return_value = mock.Mock()
        export_publisher.return_value.process_lifecycle.return_value = 'foo'

        self.assertEquals('foo', distributor.publish_group(self.repo, self.conduit, self.config))
Ejemplo n.º 3
0
    def test_publish_group(self, mock_validate, export_publisher):
        mock_validate.return_value = (True, None)
        distributor = GroupISODistributor()
        export_publisher.return_value = mock.Mock()
        export_publisher.return_value.publish.return_value = 'foo'

        self.assertEquals(
            'foo',
            distributor.publish_group(self.repo, self.conduit, self.config))
Ejemplo n.º 4
0
    def test_publish_group(self, mock_validate, export_publisher,
                           mock_ensure_downloaded):
        mock_validate.return_value = (True, None)
        distributor = GroupISODistributor()
        export_publisher.return_value = mock.Mock()
        export_publisher.return_value.process_lifecycle.return_value = 'foo'

        self.assertEquals(
            'foo',
            distributor.publish_group(self.repo, self.conduit, self.config))
Ejemplo n.º 5
0
class TestPublishGroup(unittest.TestCase):
    """
    Tests publish_group in GroupISODistributor
    """
    def setUp(self):
        """
        The distributor retrieves a lot of stuff from the database. It also creates and removes
        directories and files. This class does not test the functionality of the methods that handle
        any of that, so many are replaced with mocks here
        """
        self.group_distributor = GroupISODistributor()
        # Create arguments to be handed to the distributor
        self.config_dict = {
            PUBLISH_HTTP_KEYWORD: False,
            PUBLISH_HTTPS_KEYWORD: True
        }
        self.config = PluginCallConfiguration({}, self.config_dict)
        self.mock_conduit = mock.MagicMock(spec=RepoGroupPublishConduit)
        self.mock_conduit.distributor_id = 'mock_distributor_idq'
        self.repo_group = RepositoryGroup('test-group', '', '', {}, ['repo_id'], '/dir')

        # We aren't testing _publish_isos here, so let's not call it
        self.group_distributor._publish_isos = mock.MagicMock(
            spec=GroupISODistributor._publish_isos)

        self.patches = []
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'util.generate_listing_files')
        self.patches.append(patcher)
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'export_utils.cleanup_working_dir')
        self.patches.append(patcher)
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'export_utils.validate_export_config', return_value=(True, None))
        self.patches.append(patcher)
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'export_utils.export_complete_repo', return_value=({}, {'errors': []}))
        self.patches.append(patcher)
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'export_utils.export_incremental_content',
                             return_value=({}, {'errors': {}}))
        self.patches.append(patcher)
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'export_utils.retrieve_group_export_config',
                             return_value=([('repo_id', '/dir')], None))
        self.patches.append(patcher)
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'shutil.rmtree')
        self.patches.append(patcher)
        patcher = mock.patch('pulp_rpm.plugins.distributors.export_distributor.groupdistributor.'
                             'os.makedirs')
        self.patches.append(patcher)

        for patch_handler in self.patches:
            patch_handler.start()

    def tearDown(self):
        for patch_handler in self.patches:
            patch_handler.stop()

    def test_failed_override_config(self):
        """
        Tests that when invalid override configuration is given, an exception is raised.
        """
        # Setup
        export_utils.validate_export_config.return_value = (False, 'failed validation')

        # Test
        self.assertRaises(PulpDataException, self.group_distributor.publish_group, self.repo_group,
                          self.mock_conduit, self.config)

    def test_clean_working_dir(self):
        """
        Check that the working directory is cleaned before use. This is done because the ISOs are
        currently stored there
        """
        self.group_distributor.publish_group(self.repo_group, self.mock_conduit, self.config)
        shutil.rmtree.assert_called_once_with(self.repo_group.working_dir, ignore_errors=True)
        os.makedirs.assert_called_once_with(self.repo_group.working_dir)

    def test_export_iso_publish(self):
        """
        Test exporting a repository to ISO images. This happens when there is no export directory
        """
        # Call publish_group
        self.group_distributor.publish_group(self.repo_group, self.mock_conduit, self.config)

        # Test that _publish_isos is called with the correct arguments
        self.assertEqual(1, self.group_distributor._publish_isos.call_count)
        self.assertEqual(self.repo_group, self.group_distributor._publish_isos.call_args[0][0])
        self.assertEqual(self.config, self.group_distributor._publish_isos.call_args[0][1])

    def test_export_complete_repo_call(self):
        """
        Test that the export_complete_repo method is called with the correct arguments
        """
        self.group_distributor.publish_group(self.repo_group, self.mock_conduit, self.config)
        self.assertEqual(1, export_utils.export_complete_repo.call_count)
        self.assertEqual('repo_id', export_utils.export_complete_repo.call_args[0][0])
        self.assertEqual('/dir', export_utils.export_complete_repo.call_args[0][1])
        self.assertEqual(self.config, export_utils.export_complete_repo.call_args[0][3])

    def test_incremental_export_call(self):
        """
        Test the the export_incremental_content method is called with the correct arguments
        """
        # Setup retrieve_group_export_config return value to return a date filter
        export_utils.retrieve_group_export_config.return_value = ([('repo_id', '/dir')], 'filter')

        # Test that export_incremental_content was called correctly
        self.group_distributor.publish_group(self.repo_group, self.mock_conduit, self.config)
        self.assertEqual(1, export_utils.export_incremental_content.call_count)
        self.assertEqual('/dir', export_utils.export_incremental_content.call_args[0][0])
        self.assertEqual('filter', export_utils.export_incremental_content.call_args[0][2])

    def test_export_dir(self):
        """
        Test that when an export directory is in the config, ISOs are not created
        """
        # Setup
        self.config_dict[EXPORT_DIRECTORY_KEYWORD] = '/export/dir'
        config = PluginCallConfiguration({}, self.config_dict)

        # Test that _publish_isos is not called
        self.group_distributor.publish_group(self.repo_group, self.mock_conduit, config)
        self.assertEqual(0, self.group_distributor._publish_isos.call_count)

    def test_failed_publish(self):
        """
        Test that when errors are reported, a failure report is generated
        """
        # Setup. Insert an error in the details
        export_utils.export_complete_repo.return_value = ({}, {'errors': ['error_list']})

        # Test
        self.group_distributor.publish_group(self.repo_group, self.mock_conduit, self.config)
        self.mock_conduit.build_failure_report.assert_called_once_with(self.group_distributor.summary,
                                                                       self.group_distributor.details)