Esempio n. 1
0
    def test_import_modules_failed(self, *mocks):
        """
        Test that when there was some failure in a previous step, _import_modules does not
        overwrite the failed state
        """
        mock_conduit = Mock()
        mock_conduit.get_units.return_value = []

        method = SynchronizeWithDirectory(mock_conduit, Mock())
        method.started_fetch_modules = 0
        metadata = {'name': 'j-p', 'author': 'J', 'version': '1.1'}
        method._extract_metadata = Mock(return_value=metadata)
        method.report = Mock()
        method.report.modules_total_count = 1
        method.report.modules_finished_count = 0
        method.report.modules_state = constants.STATE_FAILED

        # test
        method._import_modules(['/path1'])

        # validation
        self.assertEquals(constants.STATE_FAILED, method.report.modules_state)
        self.assertEquals(2, method.report.update_progress.call_count)
        self.assertEquals(1, method.report.modules_total_count)
        self.assertEquals(1, method.report.modules_finished_count)
Esempio n. 2
0
    def test_import_modules_failed(self, *mocks):
        """
        Test that when there was some failure in a previous step, _import_modules does not
        overwrite the failed state
        """
        mock_conduit = Mock()
        mock_conduit.get_units.return_value = []

        method = SynchronizeWithDirectory(mock_conduit, Mock())
        method.started_fetch_modules = 0
        metadata = {'name': 'j-p', 'author': 'J', 'version': '1.1'}
        method._extract_metadata = Mock(return_value=metadata)
        method.report = Mock()
        method.report.modules_total_count = 1
        method.report.modules_finished_count = 0
        method.report.modules_state = constants.STATE_FAILED

        # test
        method._import_modules(['/path1'])

        # validation
        self.assertEquals(constants.STATE_FAILED, method.report.modules_state)
        self.assertEquals(2, method.report.update_progress.call_count)
        self.assertEquals(1, method.report.modules_total_count)
        self.assertEquals(1, method.report.modules_finished_count)
Esempio n. 3
0
    def test_import_modules(self, mock_extract, mock_add, mock_remove_missing):
        # These manifests represent the parsed metadata.json file. These contain a 'name'
        # field, where we retrieve both the unit key's 'name' and 'author' field.
        manifest = [{'name': 'john-pulp1', 'author': 'Johnathon', 'version': '1.0'}]
        mock_extract.side_effect = manifest
        module_paths = ['/tmp/module_1']
        mock_pulp1, mock_pulp2 = (Mock(), Mock())
        mock_pulp1.unit_key = {'name': 'pulp1', 'author': 'john', 'version': '1.0'}
        mock_pulp2.unit_key = {'name': 'pulp2', 'author': 'john', 'version': '2.0'}
        conduit = Mock()
        conduit.get_units.return_value = [mock_pulp1, mock_pulp2]
        config = Mock()
        config.get_boolean.return_value = True

        # test
        method = SynchronizeWithDirectory(conduit, config)
        method.started_fetch_modules = 10
        method.report = Mock()
        method.report.modules_total_count = 2
        method.report.modules_finished_count = 0
        method._import_modules(module_paths)

        # validation
        config.get_boolean.assert_called_once_with(constants.CONFIG_REMOVE_MISSING)
        mock_remove_missing.assert_called_once_with([mock_pulp1, mock_pulp2], [mock_pulp1.unit_key])
Esempio n. 4
0
    def test_import_modules_cancelled(self, mock_extract):
        config = {}
        mock_conduit = Mock()
        mock_conduit.get_units.return_value = []

        # test
        method = SynchronizeWithDirectory(mock_conduit, config)
        method.canceled = True
        method._import_modules(['/path1', '/path2'])

        # validation
        self.assertFalse(mock_extract.called)
Esempio n. 5
0
    def test_import_modules_cancelled(self, mock_extract):
        config = {}
        mock_conduit = Mock()
        mock_conduit.get_units.return_value = []

        # test
        method = SynchronizeWithDirectory(mock_conduit, config)
        method.canceled = True
        method._import_modules(['/path1', '/path2'])

        # validation
        self.assertFalse(mock_extract.called)
Esempio n. 6
0
    def test_import_modules(self, mock_extract, mock_add, mock_remove_missing):
        # These manifests represent the parsed metadata.json file. These contain a 'name'
        # field, where we retrieve both the unit key's 'name' and 'author' field.
        manifests = [
            {'name': 'john-pulp1', 'author': 'Johnathon', 'version': '1.0'},
            {'name': 'john-pulp2', 'author': 'Johnathon', 'version': '2.0'},
            {'name': 'john/pulp3', 'author': 'Johnathon', 'version': '3.0'},
        ]
        mock_extract.side_effect = manifests
        unit_keys = [
            {'name': 'pulp1', 'author': 'john', 'version': '1.0'},
            {'name': 'pulp2', 'author': 'john', 'version': '2.0'},
            {'name': 'pulp3', 'author': 'john', 'version': '3.0'},
        ]
        module_paths = [
            '/tmp/module_1',
            '/tmp/module_2',
            '/tmp/module_3',
        ]
        mock_pulp2 = Mock()
        mock_pulp2.unit_key = unit_keys[1]
        conduit = Mock()
        conduit.get_units.return_value = [mock_pulp2]
        config = Mock()
        config.get_boolean.return_value = False

        # test
        method = SynchronizeWithDirectory(conduit, config)
        method.started_fetch_modules = 10
        method.report = Mock()
        method.report.modules_total_count = 3
        method.report.modules_finished_count = 0
        method._import_modules(module_paths)

        # validation
        self.assertEqual(3, mock_extract.call_count)
        self.assertEqual(mock_extract.mock_calls[0][1][0], module_paths[0])
        self.assertEqual(mock_extract.mock_calls[1][1][0], module_paths[1])
        self.assertEqual(mock_extract.mock_calls[2][1][0], module_paths[2])

        self.assertEqual(2, mock_add.call_count)
        self.assertEqual(mock_add.mock_calls[0][1][0], module_paths[0])
        self.assertEqual(mock_add.mock_calls[1][1][0], module_paths[2])

        config.get_boolean.assert_called_once_with(constants.CONFIG_REMOVE_MISSING)
        self.assertEqual(0, mock_remove_missing.call_count)

        # Check that the progress reporting was called as expected
        self.assertEquals(3, method.report.update_progress.call_count)
        self.assertEquals(2, method.report.modules_finished_count)
        self.assertEquals(2, method.report.modules_total_count)
Esempio n. 7
0
    def test_import_modules(self, mock_extract, mock_add, mock_remove_missing):
        # These manifests represent the parsed metadata.json file. These contain a 'name'
        # field, where we retrieve both the unit key's 'name' and 'author' field.
        manifest = [{
            'name': 'john-pulp1',
            'author': 'Johnathon',
            'version': '1.0'
        }]
        mock_extract.side_effect = manifest
        module_paths = ['/tmp/module_1']
        mock_pulp1, mock_pulp2 = (Mock(), Mock())
        mock_pulp1.unit_key = {
            'name': 'pulp1',
            'author': 'john',
            'version': '1.0'
        }
        mock_pulp2.unit_key = {
            'name': 'pulp2',
            'author': 'john',
            'version': '2.0'
        }
        conduit = Mock()
        conduit.get_units.return_value = [mock_pulp1, mock_pulp2]
        config = Mock()
        config.get_boolean.return_value = True

        # test
        method = SynchronizeWithDirectory(conduit, config)
        method.started_fetch_modules = 10
        method.report = Mock()
        method.report.modules_total_count = 2
        method.report.modules_finished_count = 0
        method._import_modules(module_paths)

        # validation
        config.get_boolean.assert_called_once_with(
            constants.CONFIG_REMOVE_MISSING)
        mock_remove_missing.assert_called_once_with([mock_pulp1, mock_pulp2],
                                                    [mock_pulp1.unit_key])
Esempio n. 8
0
    def test_import_modules(self, mock_extract, mock_add):
        feed_url = 'http://host/root/PULP_MANAFEST'

        conduit = Mock()
        config = {constants.CONFIG_FEED: feed_url}

        mock_inventory = Mock()
        mock_inventory.already_associated.side_effect = [False, True, False]

        # These manifests represent the parsed metadata.json file. These contain a 'name'
        # field, where we retrieve both the unit key's 'name' and 'author' field.
        manifests = [
            {'name': 'john-pulp1', 'author': 'Johnathon', 'version': '1.0'},
            {'name': 'john-pulp2', 'author': 'Johnathon', 'version': '2.0'},
            {'name': 'john/pulp3', 'author': 'Johnathon', 'version': '3.0'},
        ]
        mock_extract.side_effect = manifests

        unit_keys = [
            {'name': 'pulp1', 'author': 'john', 'version': '1.0'},
            {'name': 'pulp2', 'author': 'john', 'version': '2.0'},
            {'name': 'pulp3', 'author': 'john', 'version': '3.0'},
        ]

        module_paths = [
            '/tmp/module_1',
            '/tmp/module_2',
            '/tmp/module_3',
        ]

        # test
        method = SynchronizeWithDirectory(conduit, config)
        method.started_fetch_modules = 10
        method.report = Mock()
        method.report.modules_total_count = 3
        method.report.modules_finished_count = 0
        imported_modules = method._import_modules(mock_inventory, module_paths)

        # validation
        mock_add.assert_any_with(module_paths[0], ANY)
        mock_add.assert_any_with(module_paths[2], ANY)

        # should only be modules 1 and 3.  2 already associated.
        self.assertEqual(len(imported_modules), 2)
        self.assertEqual(imported_modules[0], unit_keys[0])
        self.assertEqual(imported_modules[1], unit_keys[2])

        # Check that the progress reporting was called as expected
        self.assertEquals(3, method.report.update_progress.call_count)
        self.assertEquals(2, method.report.modules_finished_count)
        self.assertEquals(2, method.report.modules_total_count)
Esempio n. 9
0
    def test_import_modules_cancelled(self, mock_extract):
        config = {}
        mock_conduit = Mock()
        mock_inventory = Mock()

        # test

        method = SynchronizeWithDirectory(mock_conduit, config)
        method.canceled = True
        imported_modules = method._import_modules(mock_inventory, ['/path1', '/path2'])

        # validation

        self.assertFalse(mock_extract.called)
        self.assertEqual(imported_modules, [])
Esempio n. 10
0
    def test_import_modules(self, mock_extract, mock_add):
        feed_url = 'http://host/root/PULP_MANAFEST'

        conduit = Mock()
        config = {constants.CONFIG_FEED: feed_url}

        mock_inventory = Mock()
        mock_inventory.already_associated.side_effect = [False, True, False]

        manifests = [
            {'name': 'pulp1', 'author': 'john', 'version': '1.0'},
            {'name': 'pulp2', 'author': 'john', 'version': '2.0'},
            {'name': 'pulp3', 'author': 'john', 'version': '3.0'},
        ]

        mock_extract.side_effect = manifests

        module_paths = [
            '/tmp/module_1',
            '/tmp/module_2',
            '/tmp/module_3',
        ]

        # test

        method = SynchronizeWithDirectory(conduit, config)
        imported_modules = method._import_modules(mock_inventory, module_paths)

        # validation

        mock_add.assert_any_with(module_paths[0], ANY)
        mock_add.assert_any_with(module_paths[2], ANY)

        # should only be modules 1 and 3.  2 already associated.
        self.assertEqual(len(imported_modules), 2)
        self.assertEqual(imported_modules[0], manifests[0])
        self.assertEqual(imported_modules[1], manifests[2])
Esempio n. 11
0
    def test_import_modules(self, mock_extract, mock_add, mock_remove_missing):
        # These manifests represent the parsed metadata.json file. These contain a 'name'
        # field, where we retrieve both the unit key's 'name' and 'author' field.
        manifests = [
            {
                'name': 'john-pulp1',
                'author': 'Johnathon',
                'version': '1.0'
            },
            {
                'name': 'john-pulp2',
                'author': 'Johnathon',
                'version': '2.0'
            },
            {
                'name': 'john/pulp3',
                'author': 'Johnathon',
                'version': '3.0'
            },
        ]
        mock_extract.side_effect = manifests
        unit_keys = [
            {
                'name': 'pulp1',
                'author': 'john',
                'version': '1.0'
            },
            {
                'name': 'pulp2',
                'author': 'john',
                'version': '2.0'
            },
            {
                'name': 'pulp3',
                'author': 'john',
                'version': '3.0'
            },
        ]
        module_paths = [
            '/tmp/module_1',
            '/tmp/module_2',
            '/tmp/module_3',
        ]
        mock_pulp2 = Mock()
        mock_pulp2.unit_key = unit_keys[1]
        conduit = Mock()
        conduit.get_units.return_value = [mock_pulp2]
        config = Mock()
        config.get_boolean.return_value = False

        # test
        method = SynchronizeWithDirectory(conduit, config)
        method.started_fetch_modules = 10
        method.report = Mock()
        method.report.modules_total_count = 3
        method.report.modules_finished_count = 0
        method._import_modules(module_paths)

        # validation
        self.assertEqual(3, mock_extract.call_count)
        self.assertEqual(mock_extract.mock_calls[0][1][0], module_paths[0])
        self.assertEqual(mock_extract.mock_calls[1][1][0], module_paths[1])
        self.assertEqual(mock_extract.mock_calls[2][1][0], module_paths[2])

        self.assertEqual(2, mock_add.call_count)
        self.assertEqual(mock_add.mock_calls[0][1][0], module_paths[0])
        self.assertEqual(mock_add.mock_calls[1][1][0], module_paths[2])

        config.get_boolean.assert_called_once_with(
            constants.CONFIG_REMOVE_MISSING)
        self.assertEqual(0, mock_remove_missing.call_count)

        # Check that the progress reporting was called as expected
        self.assertEquals(3, method.report.update_progress.call_count)
        self.assertEquals(2, method.report.modules_finished_count)
        self.assertEquals(2, method.report.modules_total_count)