Ejemplo n.º 1
0
class TestPublishIsos(unittest.TestCase):
    """
    Tests the _publish_isos helper method in GroupISODistributor. This really just decides the correct
    http(s) publishing directories, cleans them up, and calls export_utils.publish_isos.
    """
    def setUp(self):
        self.distributor = GroupISODistributor()
        self.repo_group = RepositoryGroup('group_id', '', '', {}, [], '/working/dir')
        self.config = {PUBLISH_HTTP_KEYWORD: True, PUBLISH_HTTPS_KEYWORD: True}

        self.publish_iso = export_utils.publish_isos
        export_utils.publish_isos = mock.Mock()

    def tearDown(self):
        export_utils.publish_isos = self.publish_iso

    @mock.patch('shutil.rmtree', autospec=True)
    def test_publish_isos(self, mock_rmtree):
        # Setup. These are the expected http and https publishing directories
        http_publish_dir = os.path.join(GROUP_EXPORT_HTTP_DIR, self.repo_group.id)
        https_publish_dir = os.path.join(GROUP_EXPORT_HTTPS_DIR, self.repo_group.id)

        # Test
        self.distributor._publish_isos(self.repo_group, PluginCallConfiguration({}, self.config))
        self.assertEqual(2, mock_rmtree.call_count)
        self.assertEqual(http_publish_dir, mock_rmtree.call_args_list[0][0][0])
        self.assertEqual(https_publish_dir, mock_rmtree.call_args_list[1][0][0])
        export_utils.publish_isos.assert_called_once_with(self.repo_group.working_dir,
                                                          self.repo_group.id, http_publish_dir,
                                                          https_publish_dir, None, None)

    @mock.patch('shutil.rmtree', autospec=True)
    def test_publish_http_https_false(self, mock_rmtree):
        # Setup
        self.config[PUBLISH_HTTPS_KEYWORD] = False
        self.config[PUBLISH_HTTP_KEYWORD] = False
        self.distributor._publish_isos(self.repo_group, PluginCallConfiguration({}, self.config))
        http_publish_dir = os.path.join(GROUP_EXPORT_HTTP_DIR, self.repo_group.id)
        https_publish_dir = os.path.join(GROUP_EXPORT_HTTPS_DIR, self.repo_group.id)

        # Test that publish_isos was called with None for the http and https directories.
        export_utils.publish_isos.assert_called_once_with(self.repo_group.working_dir,
                                                          self.repo_group.id, None, None, None, None)
        self.assertEqual(2, mock_rmtree.call_count)
        self.assertEqual(http_publish_dir, mock_rmtree.call_args_list[0][0][0])
        self.assertEqual(https_publish_dir, mock_rmtree.call_args_list[1][0][0])