Пример #1
0
    def test_validate_config(self):
        """
        There is no config, so we'll just assert that validation passes.
        """
        pulpimp = importer.WinImporter()
        return_value = pulpimp.validate_config(mock.MagicMock(), {})

        self.assertEqual(return_value, (True, None))
Пример #2
0
    def test_upload_unit_msi(self, _plugin_api, from_file,
                             _get_db, _repo_controller):
        """
        Assert correct operation of upload_unit().
        """
        _plugin_api.get_unit_model_by_id.return_value = models.MSI
        file_path, checksum = self.new_file("foo.msi")
        msi_file, checksum = self.new_file('foo.msi')

        unit_key = dict()
        metadata = dict(
            name="foo", version="1.1",
            ProductName="foo",
            Manufacturer="ACME Inc.",
            ProductCode="aaa",
            UpgradeCode="bbb",
            filename=os.path.basename(file_path),
            checksumtype="sha256",
            checksum=checksum)
        package = models.MSI(**metadata)
        from_file.return_value = package

        pulpimp = importer.WinImporter()
        repo = mock.MagicMock()
        type_id = ids.TYPE_ID_MSI
        conduit = mock.MagicMock()
        config = {}
        models.MSI.attach_signals()

        report = pulpimp.upload_unit(repo, type_id, unit_key, metadata,
                                     msi_file, conduit, config)

        from_file.assert_called_once_with(file_path, metadata)

        obj_id = _get_db.return_value.__getitem__.return_value.save.return_value.decode.return_value  # noqa

        metadata.update(
            id=obj_id,
            ModuleSignature=[],
            downloaded=True,
            pulp_user_metadata=dict(),
            relativepath=None,
            size=None,
        )
        unit_key = dict((x, metadata[x])
                        for x in models.MSI.unit_key_fields)

        self.assertEqual(report,
                         {'success_flag': True,
                          'details': dict(
                              unit=dict(unit_key=unit_key, metadata=metadata)
                          ),
                          'summary': ''})
Пример #3
0
    def test_sync(self, _RepoSync):
        # Basic test to make sure we're passing information correctly into
        # RepoSync, which itself is tested in test_sync
        repo = mock.MagicMock()
        conduit = mock.MagicMock()
        cfg = mock.MagicMock()

        pulpimp = importer.WinImporter()
        pulpimp.sync_repo(repo, conduit, cfg)

        self.assertEquals(pulpimp._current_sync,
                          _RepoSync.return_value)
        _RepoSync.assert_called_once_with(
            repo.repo_obj, conduit, cfg)
        self.assertEquals(repo.repo_obj, conduit.repo)
Пример #4
0
    def test_import_units_units_none(self, _repo_controller, _platform_models):
        """
        Assert correct behavior when units == None.
        """
        src_repo = mock.MagicMock()
        dst_repo = mock.MagicMock()
        _platform_models.Repository.objects.get.side_effect = [src_repo,
                                                               dst_repo]
        units = [
            models.MSI(name="unit_a", version="1"),
            models.MSI(name="unit_b", version="1"),
            models.MSI(name="unit_3", version="1"),
        ]

        _repo_controller.find_repo_content_units.return_value = units

        pulpimp = importer.WinImporter()
        import_conduit = mock.MagicMock()

        imported_units = pulpimp.import_units(mock.MagicMock(),
                                              mock.MagicMock(),
                                              import_conduit,
                                              mock.MagicMock(),
                                              units=None)

        # Assert that the correct criteria was used
        _repo_controller.find_repo_content_units.assert_called_once_with(
            src_repo, yield_content_unit=True)
        # Assert that the units were associated correctly
        _u = sorted(units)
        self.assertEquals(
            [
                mock.call(repository=dst_repo, unit=_u[0]),
                mock.call(repository=dst_repo, unit=_u[1]),
                mock.call(repository=dst_repo, unit=_u[2]),
            ],
            _repo_controller.associate_single_unit.call_args_list)
        self.assertEqual(imported_units, sorted(units))