Example #1
0
class TestPublishIsos(unittest.TestCase):
    """
    Tests the _publish_isos method in GroupISODistributor. This method decides what the publishing
    directories should be, cleans them up, and hands everything off to the publish_iso method in
    export_utils.
    """
    def setUp(self):
        self.distributor = ISODistributor()
        self.repo = Repository('repo_id', working_dir='/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):
        """
        Test that publish_isos is called with the expected arguments
        """
        # Setup
        http_publish_dir = os.path.join(EXPORT_HTTP_DIR, self.repo.id)
        https_publish_dir = os.path.join(EXPORT_HTTPS_DIR, self.repo.id)

        # Test
        self.distributor._publish_isos(self.repo, 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.working_dir, self.repo.id,
                                                          http_publish_dir, https_publish_dir, None,
                                                          None)

    @mock.patch('shutil.rmtree', autospec=True)
    def test_publish_http_https_false(self, mock_rmtree):
        """
        Test that when the config has publishing http and https set to false, publish_isos is called
        with None for https_dir and http_dir
        """
        # Setup
        self.config[PUBLISH_HTTPS_KEYWORD] = False
        self.config[PUBLISH_HTTP_KEYWORD] = False
        self.distributor._publish_isos(self.repo, PluginCallConfiguration({}, self.config))
        http_publish_dir = os.path.join(EXPORT_HTTP_DIR, self.repo.id)
        https_publish_dir = os.path.join(EXPORT_HTTPS_DIR, self.repo.id)

        # Test
        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.working_dir, self.repo.id, None,
                                                          None, None, None)