Пример #1
0
    def test_matches_version_with_require_current_system_no_match(self):
        """Testing PackageRules.matches_version with
        require_current_system=True and no match
        """
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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))
        channel._loaded = True

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

        self.spy_on(platform.system, call_fake=lambda: 'Linux')
        self.spy_on(platform.dist, call_fake=lambda: ('MyDistro', '1.3', ''))

        self.assertFalse(rules.matches_version('1.0',
                                               require_current_system=True))
Пример #2
0
    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, {})
Пример #3
0
    def test_serialize_package_entry(self):
        """Testing PackageChannel.serialize_package_entry"""
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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',
            channel_type=PackageChannel.CHANNEL_TYPE_PRERELEASE,
            current=True,
            visible=True,
            manifest_url='1.0.x.json')

        self.assertEqual(
            channel.serialize_package_entry(),
            {
                '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': 'prerelease',
                'current': True,
                'visible': True,
                'manifest_file': '1.0.x.json',
            })
Пример #4
0
    def test_latest_release_with_no_releases(self):
        """Testing PackageChannel.latest_release with no releases"""
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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))
        channel._loaded = True

        self.assertEqual(channel.latest_release, None)
Пример #5
0
    def test_get_all_rules_for_version(self):
        """Testing PackageChannel.get_all_rules_for_version"""
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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))
        channel._loaded = True

        rules1 = PackageRules(channel=channel,
                              version_range='*',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        rules2 = PackageRules(channel=channel,
                              version_range='>=1.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        rules3 = PackageRules(channel=channel,
                              version_range='>=1.0,<=2.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        rules4 = PackageRules(channel=channel,
                              version_range='<=2.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        rules5 = PackageRules(channel=channel,
                              version_range='>=4.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        rules6 = PackageRules(channel=channel,
                              version_range='<1.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        channel._package_rules = [
            rules1, rules2, rules3, rules4, rules5, rules6
        ]

        self.assertEqual(
            channel.get_all_rules_for_version('1.0',
                                              require_current_system=False),
            [rules1, rules2, rules3, rules4])
Пример #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)
Пример #7
0
    def test_deserialize_with_all_info(self):
        """Testing PackageChannel.deserialize with all available info"""
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        channel = PackageChannel.deserialize(
            bundle,
            {
                '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',
                'current': True,
                'visible': False,
                'manifest_file': '1.0.x.json',
            })

        self.assertEqual(channel.name, '1.0.x')
        self.assertEqual(channel.manifest_url, '1.0.x.json')
        self.assertEqual(channel.absolute_manifest_url,
                         'packages/TestPackage/1.0.x.json')
        self.assertEqual(channel.created_timestamp,
                         datetime(2015, 10, 11, 8, 17, 29, 958569))
        self.assertEqual(channel.last_updated_timestamp,
                         datetime(2015, 10, 12, 8, 17, 29, 958569))
        self.assertEqual(channel.latest_version, '1.0.0')
        self.assertTrue(channel.current)
        self.assertFalse(channel.visible)
Пример #8
0
    def test_get_all_rules_for_version_and_current_system(self):
        """Testing PackageChannel.get_all_rules_for_version with
        require_current_system=True
        """
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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))
        channel._loaded = True

        rules1 = PackageRules(channel=channel,
                              version_range='*',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['macosx'])
        rules2 = PackageRules(channel=channel,
                              version_range='>=1.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['windows'])
        rules3 = PackageRules(channel=channel,
                              version_range='>=1.0,<=2.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['MyDistro>1.2'])
        rules4 = PackageRules(channel=channel,
                              version_range='<=2.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['MyDistro'])
        rules5 = PackageRules(channel=channel,
                              version_range='<=2.0',
                              package_type='python',
                              package_name='TestPackage',
                              systems=['*'])
        channel._package_rules = [rules1, rules2, rules3, rules4, rules5]

        self.spy_on(platform.system, call_fake=lambda: 'Linux')
        self.spy_on(platform.dist, call_fake=lambda: ('MyDistro', '1.3', ''))

        self.assertEqual(
            channel.get_all_rules_for_version('1.0',
                                              require_current_system=True),
            [rules3, rules4, rules5])
Пример #9
0
    def test_serialize(self):
        """Testing PackageChannel.serialize"""
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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))
        channel._loaded = True

        release = PackageRelease(
            channel=channel,
            version='1.0',
            release_type=PackageRelease.TYPE_STABLE)
        channel._releases.append(release)

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

        self.assertEqual(
            channel.serialize(),
            {
                'format_version': '1.0',
                'created_timestamp': '2015-10-11T08:17:29.958569',
                'last_updated_timestamp': '2015-10-12T08:17:29.958569',
                'releases': [
                    {
                        'version': '1.0',
                        'type': 'stable',
                        'visible': True,
                    }
                ],
                'package_rules': [
                    {
                        'version_range': '*',
                        'package_type': 'python',
                        'package_name': 'TestPackage',
                        'systems': ['*'],
                    },
                ],
            })
Пример #10
0
    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,
                }
            })
Пример #11
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, {})
Пример #12
0
    def test_matches_version_without_match(self):
        """Testing PackageRules.matches_version without match"""
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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))
        channel._loaded = True

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

        self.assertFalse(rules.matches_version('1.0',
                                               require_current_system=False))
Пример #13
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,
        )
Пример #14
0
    def test_load(self):
        """Testing PackageChannel.load"""
        self.data_loader.path_to_content['packages/TestPackage/1.0.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.0',
                    'type': 'stable',
                    'visible': True,
                }
            ],
            'package_rules': [
                {
                    'version_range': '*',
                    'package_type': 'python',
                    'package_name': 'TestPackage',
                    'systems': ['*'],
                },
            ],
        }

        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        channel = PackageChannel(
            bundle,
            manifest_url='1.0.x.json')
        channel.load()

        self.assertEqual(channel.created_timestamp,
                         datetime(2015, 10, 11, 8, 17, 29, 958569))
        self.assertEqual(channel.last_updated_timestamp,
                         datetime(2015, 10, 12, 8, 17, 29, 958569))
        self.assertEqual(len(channel.releases), 1)
        self.assertEqual(len(channel.package_rules), 1)
        self.assertEqual(channel.releases[0].version, '1.0')
        self.assertEqual(channel.package_rules[0].package_type,
                         'python')
Пример #15
0
    def test_latest_release(self):
        """Testing PackageChannel.latest_release"""
        bundle = PackageBundle(manifest_url='packages/TestPackage/index.json')

        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))
        channel._loaded = True

        release1 = PackageRelease(
            channel=channel,
            version='1.0.1',
            release_type=PackageRelease.TYPE_STABLE)
        release2 = PackageRelease(
            channel=channel,
            version='1.0',
            release_type=PackageRelease.TYPE_STABLE)
        channel._releases = [release1, release2]

        self.assertEqual(channel.latest_release, release1)
Пример #16
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
        )
Пример #17
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')
Пример #18
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)