Beispiel #1
0
    def test_import_units__units_none(self):
        """
        Make sure that when units=None, we import all units from the import_conduit.
        """
        source_units = [
            Unit(ids.TYPE_ID_ISO, {"name": "test.iso"}, {}, "/path/test.iso"),
            Unit(ids.TYPE_ID_ISO, {"name": "test2.iso"}, {}, "/path/test2.iso"),
            Unit(ids.TYPE_ID_ISO, {"name": "test3.iso"}, {}, "/path/test3.iso"),
        ]
        import_conduit = importer_mocks.get_import_conduit(source_units=source_units)
        # source_repo, dest_repo, and config aren't used by import_units, so we'll just set them to
        # None for simplicity.
        imported_units = self.iso_importer.import_units(None, None, import_conduit, None, units=None)

        # There should have been four calls to the import_conduit. One to get_source_units(), and
        # three to associate units.
        # get_source_units should have a UnitAssociationCriteria that specified ISOs, so we'll
        # assert that behavior.
        self.assertEqual(len(import_conduit.get_source_units.call_args_list), 1)
        get_source_units_args = tuple(import_conduit.get_source_units.call_args_list[0])[1]
        self.assertEqual(get_source_units_args["criteria"]["type_ids"], [ids.TYPE_ID_ISO])

        # There are three Units, so there should be three calls to associate_unit since we didn't
        # pass which units we wanted to import. Let's make sure the three calls were made with the
        # correct Units.
        self.assertEqual(len(import_conduit.associate_unit.call_args_list), 3)
        expected_unit_names = ["test.iso", "test2.iso", "test3.iso"]
        actual_unit_names = [
            tuple(call)[0][0].unit_key["name"] for call in import_conduit.associate_unit.call_args_list
        ]
        self.assertEqual(actual_unit_names, expected_unit_names)

        # The three Units should have been returned
        self.assertEqual(imported_units, source_units)
Beispiel #2
0
    def test_import_units__units_some(self):
        """
        Make sure that when units are passed, we import only those units.
        """
        source_units = [
            Unit(ids.TYPE_ID_ISO, {"name": "test.iso"}, {}, "/path/test.iso"),
            Unit(ids.TYPE_ID_ISO, {"name": "test2.iso"}, {}, "/path/test2.iso"),
            Unit(ids.TYPE_ID_ISO, {"name": "test3.iso"}, {}, "/path/test3.iso"),
        ]
        import_conduit = importer_mocks.get_import_conduit(source_units=source_units)
        # source_repo, dest_repo, and config aren't used by import_units, so we'll just set them to
        # None for simplicity. Let's use test.iso and test3.iso, leaving out test2.iso.
        units_to_import = [source_units[i] for i in range(0, 3, 2)]
        imported_units = self.iso_importer.import_units(None, None, import_conduit, None, units=units_to_import)

        # There should have been two calls to the import_conduit. None to get_source_units(), and
        # two to associate units.
        self.assertEqual(len(import_conduit.get_source_units.call_args_list), 0)

        # There are two Units, so there should be two calls to associate_unit since we passed which
        # units we wanted to import. Let's make sure the two calls were made with the
        # correct Units.
        self.assertEqual(len(import_conduit.associate_unit.call_args_list), 2)
        expected_unit_names = ["test.iso", "test3.iso"]
        actual_unit_names = [
            tuple(call)[0][0].unit_key["name"] for call in import_conduit.associate_unit.call_args_list
        ]
        self.assertEqual(actual_unit_names, expected_unit_names)

        # Make sure that the returned units are correct
        self.assertEqual(imported_units, units_to_import)
Beispiel #3
0
    def test_import_units__units_empty_list(self):
        """
        Make sure that when an empty list is passed, we import zero units.
        """
        source_units = [
            Unit(ids.TYPE_ID_ISO, {'name': 'test.iso'}, {}, '/path/test.iso'),
            Unit(ids.TYPE_ID_ISO, {'name': 'test2.iso'}, {},
                 '/path/test2.iso'),
            Unit(ids.TYPE_ID_ISO, {'name': 'test3.iso'}, {}, '/path/test3.iso')
        ]
        import_conduit = importer_mocks.get_import_conduit(
            source_units=source_units)
        # source_repo, dest_repo, and config aren't used by import_units, so we'll just set them to
        # None for simplicity. Let's pass an empty list as the units we want to import
        units_to_import = []
        imported_units = self.iso_importer.import_units(None,
                                                        None,
                                                        import_conduit,
                                                        None,
                                                        units=units_to_import)

        # There should have been zero calls to the import_conduit. None to get_source_units(), and
        # none to associate units.
        self.assertEqual(len(import_conduit.get_source_units.call_args_list),
                         0)
        self.assertEqual(len(import_conduit.associate_unit.call_args_list), 0)

        # Make sure that the returned units are correct
        self.assertEqual(imported_units, units_to_import)
Beispiel #4
0
    def test_import_units__units_none(self):
        """
        Make sure that when units=None, we import all units from the import_conduit.
        """
        source_units = [Unit(ids.TYPE_ID_ISO, {'name': 'test.iso'}, {}, '/path/test.iso'),
                        Unit(ids.TYPE_ID_ISO, {'name': 'test2.iso'}, {}, '/path/test2.iso'),
                        Unit(ids.TYPE_ID_ISO, {'name': 'test3.iso'}, {}, '/path/test3.iso')]
        import_conduit = importer_mocks.get_import_conduit(source_units=source_units)
        # source_repo, dest_repo, and config aren't used by import_units, so we'll just set them to
        # None for simplicity.
        imported_units = self.iso_importer.import_units(None, None, import_conduit, None,
                                                        units=None)

        # There should have been four calls to the import_conduit. One to get_source_units(), and
        # three to associate units.
        # get_source_units should have a UnitAssociationCriteria that specified ISOs, so we'll
        # assert that behavior.
        self.assertEqual(len(import_conduit.get_source_units.call_args_list), 1)
        get_source_units_args = tuple(import_conduit.get_source_units.call_args_list[0])[1]
        self.assertEqual(get_source_units_args['criteria']['type_ids'], [ids.TYPE_ID_ISO])

        # There are three Units, so there should be three calls to associate_unit since we didn't
        # pass which units we wanted to import. Let's make sure the three calls were made with the
        # correct Units.
        self.assertEqual(len(import_conduit.associate_unit.call_args_list), 3)
        expected_unit_names = ['test.iso', 'test2.iso', 'test3.iso']
        actual_unit_names = [tuple(call)[0][0].unit_key['name']
                             for call in import_conduit.associate_unit.call_args_list]
        self.assertEqual(actual_unit_names, expected_unit_names)

        # The three Units should have been returned
        self.assertEqual(imported_units, source_units)
Beispiel #5
0
    def test_import_units__units_some(self):
        """
        Make sure that when units are passed, we import only those units.
        """
        source_units = [Unit(ids.TYPE_ID_ISO, {'name': 'test.iso'}, {}, '/path/test.iso'),
                        Unit(ids.TYPE_ID_ISO, {'name': 'test2.iso'}, {}, '/path/test2.iso'),
                        Unit(ids.TYPE_ID_ISO, {'name': 'test3.iso'}, {}, '/path/test3.iso')]
        import_conduit = importer_mocks.get_import_conduit(source_units=source_units)
        # source_repo, dest_repo, and config aren't used by import_units, so we'll just set them to
        # None for simplicity. Let's use test.iso and test3.iso, leaving out test2.iso.
        units_to_import = [source_units[i] for i in range(0, 3, 2)]
        imported_units = self.iso_importer.import_units(None, None, import_conduit, None,
                                                        units=units_to_import)

        # There should have been two calls to the import_conduit. None to get_source_units(), and
        # two to associate units.
        self.assertEqual(len(import_conduit.get_source_units.call_args_list), 0)

        # There are two Units, so there should be two calls to associate_unit since we passed which
        # units we wanted to import. Let's make sure the two calls were made with the
        # correct Units.
        self.assertEqual(len(import_conduit.associate_unit.call_args_list), 2)
        expected_unit_names = ['test.iso', 'test3.iso']
        actual_unit_names = [tuple(call)[0][0].unit_key['name']
                             for call in import_conduit.associate_unit.call_args_list]
        self.assertEqual(actual_unit_names, expected_unit_names)

        # Make sure that the returned units are correct
        self.assertEqual(imported_units, units_to_import)
Beispiel #6
0
    def test_import_units__units_empty_list(self):
        """
        Make sure that when an empty list is passed, we import zero units.
        """
        source_units = [Unit(ids.TYPE_ID_ISO, {'name': 'test.iso'}, {}, '/path/test.iso'),
                        Unit(ids.TYPE_ID_ISO, {'name': 'test2.iso'}, {}, '/path/test2.iso'),
                        Unit(ids.TYPE_ID_ISO, {'name': 'test3.iso'}, {}, '/path/test3.iso')]
        import_conduit = importer_mocks.get_import_conduit(source_units=source_units)
        # source_repo, dest_repo, and config aren't used by import_units, so we'll just set them to
        # None for simplicity. Let's pass an empty list as the units we want to import
        units_to_import = []
        imported_units = self.iso_importer.import_units(None, None, import_conduit, None,
                                                        units=units_to_import)

        # There should have been zero calls to the import_conduit. None to get_source_units(), and
        # none to associate units.
        self.assertEqual(len(import_conduit.get_source_units.call_args_list), 0)
        self.assertEqual(len(import_conduit.associate_unit.call_args_list), 0)

        # Make sure that the returned units are correct
        self.assertEqual(imported_units, units_to_import)