def test_add_package_without_matching_package_type(self):
        """Testing PendingInstall.add_package without matching package type"""
        pending_install = PendingInstall()

        bundle = PackageBundle(name='MyPackage')
        channel = PackageChannel(bundle, name='1.0.x')
        channel._loaded = True
        bundle._channels = [channel]

        release = PackageRelease(channel=channel, version='1.0')
        channel._releases = [release]

        rules = PackageRules(channel=channel,
                             version_range='*',
                             package_type='rpm',
                             package_name='TestPackage',
                             systems=['*'])
        channel._package_rules = [rules]

        self.assertRaises(
            PackageInstallError,
            lambda: pending_install.add_package(release, 'python'))

        self.assertEqual(pending_install._bundle_infos, [])
        self.assertEqual(pending_install._bundle_infos_map, {})
Example #2
0
    def test_get_latest_release_for_version_range_with_channel_types(self):
        """Testing PackageBundle.get_latest_release_for_version_range with
        channel_types
        """
        bundle = PackageBundle(manifest_url="packages/TestPackage/index.json", name="MyPackage")
        bundle._loaded = True

        channel1 = PackageChannel(
            bundle=bundle, name="2.0.x", current=False, channel_type=PackageChannel.CHANNEL_TYPE_PRERELEASE
        )
        channel1._loaded = True
        channel2 = PackageChannel(
            bundle=bundle, name="1.0.x", current=True, channel_type=PackageChannel.CHANNEL_TYPE_RELEASE
        )
        channel2._loaded = True
        bundle._channels = [channel1, channel2]

        release1 = PackageRelease(channel=channel1, version="2.0")
        channel1._releases = [release1]

        release2 = PackageRelease(channel=channel2, version="1.0")
        channel2._releases = [release2]

        self.assertEqual(
            bundle.get_latest_release_for_version_range(
                version_range=">=1.0", channel_types=[PackageChannel.CHANNEL_TYPE_RELEASE]
            ),
            release2,
        )
        self.assertEqual(
            bundle.get_latest_release_for_version_range(">=2.0", channel_types=[PackageChannel.CHANNEL_TYPE_RELEASE]),
            None,
        )
Example #3
0
    def test_current_channel_with_no_current(self):
        """Testing PackageBundle.current_channel with no current channel"""
        bundle = PackageBundle(manifest_url="packages/TestPackage/index.json")
        bundle._loaded = True

        channel = PackageChannel(
            bundle=bundle, name="staging", current=False, visible=False, manifest_url="staging.json"
        )
        bundle._channels = [channel]

        self.assertEqual(bundle.current_channel, None)
Example #4
0
    def test_current_channel(self):
        """Testing PackageBundle.current_channel"""
        bundle = PackageBundle(manifest_url="packages/TestPackage/index.json")
        bundle._loaded = True

        channel1 = PackageChannel(bundle=bundle, name="beta", current=False, visible=True, manifest_url="beta.json")
        channel2 = PackageChannel(bundle=bundle, name="1.0.x", current=True, visible=True, manifest_url="1.0.x.json")
        channel3 = PackageChannel(bundle=bundle, name="0.5.x", current=False, visible=True, manifest_url="0.5.x.json")
        bundle._channels = [channel1, channel2, channel3]

        self.assertEqual(bundle.current_channel, channel2)
Example #5
0
    def test_serialize(self):
        """Testing PackageBundle.serialize"""
        bundle = PackageBundle(
            manifest_url="packages/TestPackage/index.json",
            name="TestPackage",
            description="This is a summary.\n\nThis is a description.",
            created_timestamp=datetime(2015, 10, 10, 8, 17, 29, 958569),
            last_updated_timestamp=datetime(2015, 10, 15, 8, 17, 29, 958569),
            current_version="1.0.0",
            channel_aliases={"stable": "1.0.x", "beta": "2.0.x"},
            package_names=[{"system": ["centos", "rhel"], "name": "reviewboard", "type": "rpm"}],
        )
        bundle._loaded = True

        channel = PackageChannel(
            bundle=bundle,
            name="1.0.x",
            created_timestamp=datetime(2015, 10, 11, 8, 17, 29, 958569),
            last_updated_timestamp=datetime(2015, 10, 12, 8, 17, 29, 958569),
            latest_version="1.0.0",
            current=True,
            visible=True,
            manifest_url="1.0.x.json",
        )
        bundle._channels = [channel]

        self.assertEqual(
            bundle.serialize(),
            {
                "format_version": "1.0",
                "name": "TestPackage",
                "description": ["This is a summary.", "", "This is a description."],
                "created_timestamp": "2015-10-10T08:17:29.958569",
                "last_updated_timestamp": "2015-10-15T08:17:29.958569",
                "current_version": "1.0.0",
                "package_names": [{"system": ["centos", "rhel"], "name": "reviewboard", "type": "rpm"}],
                "channel_aliases": {"stable": "1.0.x", "beta": "2.0.x"},
                "channels": [
                    {
                        "name": "1.0.x",
                        "created_timestamp": "2015-10-11T08:17:29.958569",
                        "last_updated_timestamp": "2015-10-12T08:17:29.958569",
                        "latest_version": "1.0.0",
                        "channel_type": "release",
                        "current": True,
                        "visible": True,
                        "manifest_file": "1.0.x.json",
                    }
                ],
            },
        )
Example #6
0
    def test_get_latest_release_for_version_range(self):
        """Testing PackageBundle.get_latest_release_for_version_range"""
        bundle = PackageBundle(manifest_url="packages/TestPackage/index.json", name="MyPackage")
        bundle._loaded = True

        channel = PackageChannel(bundle=bundle, name="staging", current=True)
        channel._loaded = True
        bundle._channels = [channel]

        release1 = PackageRelease(channel=channel, version="1.5")
        release2 = PackageRelease(channel=channel, version="1.0")
        channel._releases = [release1, release2]

        self.assertEqual(bundle.get_latest_release_for_version_range(">=1.0"), release1)
        self.assertEqual(bundle.get_latest_release_for_version_range("<1.0"), None)
Example #7
0
    def deserialize(cls, manifest_url, data):
        """Deserialize a payload into a PackageIndex.

        Args:
            manifest_url (unicode):
                The URL to the manifest file being deserialized.

            data (dict):
                The JSON dictionary data for the package bundle definition.

        Returns:
            PackageIndex:
            The resulting package index.
        """
        index = PackageIndex(
            manifest_url=manifest_url,
            last_updated_timestamp=dateutil.parser.parse(
                data['last_updated_timestamp']))

        base_url = urljoin(manifest_url, '.')

        index.bundles = [
            PackageBundle.deserialize(
                base_url=base_url,
                manifest_url=bundle_data['manifest_file'],
                data=bundle_data)
            for bundle_data in data['bundles']
        ]

        return index
Example #8
0
    def lookup_package_bundle(self, name):
        """Look up a package bundle by name.

        Args:
            name (unicode):
                The name of the package bundle.

        Returns:
            PackageBundle:
            The package bundle, if found, or ``None`` if a bundle with
            that name doesn't exist.
        """
        package_bundle = self._package_bundle_cache.get(name)

        if package_bundle is None:
            path = self._build_package_bundle_path(name)

            try:
                package_bundle_data = get_data_loader().load_by_path(path)
            except LoadDataError as e:
                raise PackageLookupError(six.text_type(e))

            package_bundle = PackageBundle.deserialize(
                base_url=self.BASE_PATH, manifest_url=path, data=package_bundle_data
            )

            self._package_bundle_cache[name] = package_bundle

        return package_bundle
    def test_add_package(self):
        """Testing PendingInstall.add_package"""
        pending_install = PendingInstall()

        bundle = PackageBundle(name='MyPackage')
        channel = PackageChannel(bundle, name='1.0.x')
        channel._loaded = True
        bundle._channels = [channel]

        release = PackageRelease(channel=channel, version='1.0')
        channel._releases = [release]

        rules1 = PackageRules(channel=channel,
                              version_range='*',
                              package_type='rpm',
                              package_name='TestPackage',
                              systems=['*'])
        rules2 = PackageRules(channel=channel,
                              version_range='*',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        channel._package_rules = [rules1, rules2]

        pending_install.add_package(release, 'python')

        self.assertEqual(
            pending_install._bundle_infos,
            [
                {
                    'bundle': bundle,
                    'release': release,
                    'package_type': 'python',
                    'rules': rules2,
                }
            ])

        self.assertEqual(
            pending_install._bundle_infos_map,
            {
                'MyPackage': {
                    'bundle': bundle,
                    'release': release,
                    'package_type': 'python',
                    'rules': rules2,
                }
            })
Example #10
0
    def test_add_package_without_available_rules(self):
        """Testing PendingInstall.add_package without available rules"""
        pending_install = PendingInstall()

        bundle = PackageBundle(name='MyPackage')
        channel = PackageChannel(bundle, name='1.0.x')
        channel._loaded = True
        bundle._channels = [channel]

        release = PackageRelease(channel=channel, version='1.0')
        channel._releases = [release]

        self.assertRaises(
            PackageInstallError,
            lambda: pending_install.add_package(release, 'python'))

        self.assertEqual(pending_install._bundle_infos, [])
        self.assertEqual(pending_install._bundle_infos_map, {})
Example #11
0
    def test_deserialize_with_all_info(self):
        """Testing PackageBundle.deserialize with all available info"""
        bundle = PackageBundle.deserialize(
            "/packages/",
            "TestPackage/index.json",
            {
                "format_version": "1.0",
                "name": "TestPackage",
                "description": ["This is the summary.", "", "This is the multi-line", "description."],
                "created_timestamp": "2015-10-10T08:17:29.958569",
                "last_updated_timestamp": "2015-10-15T08:17:29.958569",
                "current_version": "1.0.5",
                "package_names": [{"system": ["centos", "rhel"], "name": "reviewboard", "type": "rpm"}],
                "channel_aliases": {"stable": "1.0.x", "beta": "2.0.x"},
                "channels": [
                    {
                        "name": "2.0.x",
                        "created_timestamp": "2015-10-13T08:17:29.958569",
                        "last_updated_timestamp": "2015-10-14T08:17:29.958569",
                        "latest_version": "2.0beta1",
                        "current": False,
                        "visible": True,
                        "manifest_file": "2.0.x.json",
                    },
                    {
                        "name": "1.0.x",
                        "created_timestamp": "2015-10-11T08:17:29.958569",
                        "last_updated_timestamp": "2015-10-12T08:17:29.958569",
                        "latest_version": "1.0.5",
                        "current": True,
                        "visible": True,
                        "manifest_file": "1.0.x.json",
                    },
                ],
            },
        )

        self.assertEqual(bundle.manifest_url, "TestPackage/index.json")
        self.assertEqual(bundle.absolute_manifest_url, "/packages/TestPackage/index.json")
        self.assertEqual(bundle.name, "TestPackage")
        self.assertEqual(bundle.description, "This is the summary.\n" "\n" "This is the multi-line\n" "description.")
        self.assertEqual(bundle.current_version, "1.0.5")
        self.assertEqual(bundle.created_timestamp, datetime(2015, 10, 10, 8, 17, 29, 958569))
        self.assertEqual(bundle.last_updated_timestamp, datetime(2015, 10, 15, 8, 17, 29, 958569))
        self.assertEqual(bundle.package_names, [{"system": ["centos", "rhel"], "name": "reviewboard", "type": "rpm"}])
        self.assertEqual(bundle.channel_aliases, {"stable": "1.0.x", "beta": "2.0.x"})

        # The exact details will be compared in a later unit test. Just
        # sanity-check that we have what we expect.
        self.assertEqual(len(bundle.channels), 2)
        self.assertEqual(bundle.channels[0].name, "2.0.x")
        self.assertEqual(bundle.channels[1].name, "1.0.x")
Example #12
0
    def test_get_latest_release_for_version_range_with_release_types(self):
        """Testing PackageBundle.get_latest_release_for_version_range with
        release_types
        """
        bundle = PackageBundle(manifest_url="packages/TestPackage/index.json", name="MyPackage")
        bundle._loaded = True

        channel = PackageChannel(bundle=bundle, name="2.0.x", current=False)
        channel._loaded = True
        bundle._channels = [channel]

        release1 = PackageRelease(channel=channel, version="2.0", release_type=PackageRelease.TYPE_BETA)
        release2 = PackageRelease(channel=channel, version="1.0", release_type=PackageRelease.TYPE_STABLE)
        channel._releases = [release1, release2]

        self.assertEqual(
            bundle.get_latest_release_for_version_range(
                version_range=">=1.0", release_types=[PackageRelease.TYPE_STABLE]
            ),
            release2,
        )
        self.assertEqual(
            bundle.get_latest_release_for_version_range(">=1.0", release_types=[PackageRelease.TYPE_ALPHA]), None
        )
Example #13
0
    def test_deserialize_with_minimal_info(self):
        """Testing PackageBundle.deserialize with minimum info"""
        bundle = PackageBundle.deserialize(
            "/packages/",
            "TestPackage/index.json",
            {
                "format_version": "1.0",
                "name": "TestPackage",
                "created_timestamp": "2015-10-10T08:17:29.958569",
                "last_updated_timestamp": "2015-10-15T08:17:29.958569",
                "channels": [
                    {
                        "name": "2.0.x",
                        "created_timestamp": "2015-10-13T08:17:29.958569",
                        "last_updated_timestamp": "2015-10-14T08:17:29.958569",
                        "latest_version": "2.0beta1",
                        "current": False,
                        "visible": True,
                        "manifest_file": "2.0.x.json",
                    },
                    {
                        "name": "1.0.x",
                        "created_timestamp": "2015-10-11T08:17:29.958569",
                        "last_updated_timestamp": "2015-10-12T08:17:29.958569",
                        "latest_version": "1.0.5",
                        "current": True,
                        "visible": True,
                        "manifest_file": "1.0.x.json",
                    },
                ],
            },
        )

        self.assertEqual(bundle.manifest_url, "TestPackage/index.json")
        self.assertEqual(bundle.absolute_manifest_url, "/packages/TestPackage/index.json")
        self.assertEqual(bundle.name, "TestPackage")
        self.assertEqual(bundle.description, None)
        self.assertEqual(bundle.created_timestamp, datetime(2015, 10, 10, 8, 17, 29, 958569))
        self.assertEqual(bundle.last_updated_timestamp, datetime(2015, 10, 15, 8, 17, 29, 958569))
        self.assertEqual(bundle.current_version, None)
        self.assertEqual(bundle.package_names, [])
        self.assertEqual(bundle.channel_aliases, {})

        # The exact details will be compared in a later unit test. Just
        # sanity-check that we have what we expect.
        self.assertEqual(len(bundle.channels), 2)
        self.assertEqual(bundle.channels[0].name, "2.0.x")
        self.assertEqual(bundle.channels[1].name, "1.0.x")
Example #14
0
    def test_get_install_order(self):
        """Testing PendingInstall.get_install_order"""
        self.data_loader.path_to_content.update({
            '/packages/DepPackage1/index.json': {
                'format_version': '1.0',
                'name': 'DepPackage1',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'current_version': '1.5',
                'channels': [
                    {
                        'name': '1.x',
                        'created_timestamp': '2015-10-13T08:17:29.958569',
                        'last_updated_timestamp': '2015-10-14T08:17:29.958569',
                        'latest_version': '1.5',
                        'current': True,
                        'visible': True,
                        'manifest_file': '1.x.json',
                    },
                ],
            },
            '/packages/DepPackage1/1.x.json': {
                'format_version': '1.0',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'releases': [
                    {
                        'version': '1.5',
                        'type': 'stable',
                        'visible': True,
                    }
                ],
                'package_rules': [
                    {
                        'version_range': '*',
                        'package_type': 'python',
                        'package_name': 'DepPackage1',
                        'systems': ['*'],
                        'dependencies': {
                            'required': [
                                'DepPackage2>=1.5',
                            ],
                        },
                    },
                ],
            },
            '/packages/DepPackage2/index.json': {
                'format_version': '1.0',
                'name': 'DepPackage2',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'current_version': '1.5',
                'channels': [
                    {
                        'name': '1.x',
                        'created_timestamp': '2015-10-13T08:17:29.958569',
                        'last_updated_timestamp': '2015-10-14T08:17:29.958569',
                        'latest_version': '1.5',
                        'current': True,
                        'visible': True,
                        'manifest_file': '1.x.json',
                    },
                ],
            },
            '/packages/DepPackage2/1.x.json': {
                'format_version': '1.0',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'releases': [
                    {
                        'version': '1.5',
                        'type': 'stable',
                        'visible': True,
                    },
                ],
                'package_rules': [
                    {
                        'version_range': '*',
                        'package_type': 'python',
                        'package_name': 'DepPackage2',
                        'systems': ['*'],
                    },
                ],
            },
        })

        pending_install = PendingInstall()

        bundle = PackageBundle(name='MyPackage')
        channel = PackageChannel(bundle, name='1.0.x')
        channel._loaded = True
        bundle._channels = [channel]

        release = PackageRelease(channel=channel, version='1.0')
        channel._releases = [release]

        rules = PackageRules(
            channel=channel,
            version_range='*',
            required_dependencies=[
                'DepPackage1>=1.0',
            ],
            package_type='python',
            package_name='TestPackage',
            systems=['*'])
        channel._package_rules = [rules]

        pending_install.add_package(release, 'python')
        pending_install.resolve_dependencies()

        install_order = pending_install.get_install_order()
        self.assertEqual(len(install_order), 3)
        self.assertEqual(install_order[0]['bundle'].name, 'DepPackage2')
        self.assertEqual(install_order[1]['bundle'].name, 'DepPackage1')
        self.assertEqual(install_order[2]['bundle'].name, 'MyPackage')
Example #15
0
    def test_resolve_dependencies_with_prerelease(self):
        """Testing PendingInstall.resolve_dependencies with considering
        pre-release packages
        """
        self.data_loader.path_to_content.update({
            '/packages/DepPackage1/index.json': {
                'format_version': '1.0',
                'name': 'DepPackage1',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'current_version': '1.5',
                'channels': [
                    {
                        'name': '2.x',
                        'created_timestamp': '2015-10-13T08:17:29.958569',
                        'last_updated_timestamp': '2015-10-14T08:17:29.958569',
                        'latest_version': '2.0',
                        'current': False,
                        'visible': True,
                        'type': 'prerelease',
                        'manifest_file': '2.x.json',
                    },
                    {
                        'name': '1.x',
                        'created_timestamp': '2015-10-13T08:17:29.958569',
                        'last_updated_timestamp': '2015-10-14T08:17:29.958569',
                        'latest_version': '1.5',
                        'current': True,
                        'visible': True,
                        'type': 'release',
                        'manifest_file': '1.x.json',
                    },
                ],
            },
            '/packages/DepPackage1/2.x.json': {
                'format_version': '1.0',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'releases': [
                    {
                        'version': '2.0',
                        'type': 'stable',
                        'visible': True,
                    }
                ],
                'package_rules': [
                    {
                        'version_range': '*',
                        'package_type': 'python',
                        'package_name': 'DepPackage1',
                        'systems': ['*'],
                    },
                ],
            },
            '/packages/DepPackage1/1.x.json': {
                'format_version': '1.0',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'releases': [
                    {
                        'version': '1.5',
                        'type': 'stable',
                        'visible': True,
                    }
                ],
                'package_rules': [
                    {
                        'version_range': '*',
                        'package_type': 'python',
                        'package_name': 'DepPackage1',
                        'systems': ['*'],
                    },
                ],
            },
        })

        pending_install = PendingInstall(PendingInstall.INSTALL_DEPS_ALL)

        bundle = PackageBundle(name='MyPackage')
        channel = PackageChannel(
            bundle,
            name='1.0.x',
            channel_type=PackageChannel.CHANNEL_TYPE_PRERELEASE)
        channel._loaded = True
        bundle._channels = [channel]

        release = PackageRelease(channel=channel, version='1.0')
        channel._releases = [release]

        rules = PackageRules(
            channel=channel,
            version_range='*',
            required_dependencies=[
                'DepPackage1>=1.0',
            ],
            package_type='python',
            package_name='TestPackage',
            systems=['*'])
        channel._package_rules = [rules]

        pending_install.add_package(release, 'python')

        pending_install.resolve_dependencies()

        self.assertEqual(len(pending_install._bundle_infos), 2)
        self.assertEqual(pending_install._bundle_infos[0]['bundle'].name,
                         'MyPackage')
        self.assertEqual(pending_install._bundle_infos[1]['bundle'].name,
                         'DepPackage1')
        self.assertEqual(pending_install._bundle_infos[1]['release'].version,
                         '2.0')
        self.assertEqual(len(pending_install._bundle_infos_map), 2)
        self.assertTrue('MyPackage' in pending_install._bundle_infos_map)
        self.assertTrue('DepPackage1' in pending_install._bundle_infos_map)