def test_latest_releases_uninitialized(self): _mock_config(self.config_contents) bandersnatch.filter.filter_release_plugins() mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foo", 1, mirror) pkg.info = {"name": "foo", "version": "2.0.0"} pkg.releases = { "1.0.0": {}, "1.1.0": {}, "1.1.1": {}, "1.1.2": {}, "1.1.3": {}, "2.0.0": {}, } pkg._filter_releases() assert pkg.releases == { "1.0.0": {}, "1.1.0": {}, "1.1.1": {}, "1.1.2": {}, "1.1.3": {}, "2.0.0": {}, }
def test__filter__matches__package(self): with open(TEST_CONF, "w") as testconfig_handle: testconfig_handle.write( """\ [plugins] enabled = whitelist_release_pyversion [whitelist] python_versions = foo """ ) instance = BandersnatchConfig() instance.config_file = TEST_CONF instance.load_configuration() mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foo", 1, mirror) pkg.info = {"name": "foo"} pkg.releases = {"1.2.0": [{'python_version': 'foo'}, {'python_version': 'foo2'}], "1.2.1": [{'python_version': 'foo2'}]} pkg._filter_releases() self.assertListEqual(list(pkg.releases.keys()), ["1.2.0"]) self.assertEqual(len(pkg.releases["1.2.0"]), 1) self.assertEqual(pkg.releases["1.2.0"][0], {'python_version': 'foo'})
def test_plugin_check_match(self): _mock_config(self.config_contents) bandersnatch.filter.filter_release_plugins() mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foo", 1, mirror) pkg.releases = {"foo-1.2.0rc2": {}, "foo-1.2.0": {}, "foo-1.2.0alpha2": {}} pkg._filter_releases() assert pkg.releases == {"foo-1.2.0": {}}
def test__filter__pyversions(self): instance = BandersnatchConfig() instance.config_file = TEST_CONF instance.load_configuration() with open(TEST_JSON) as json_file: package_json = json.load(json_file) mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foo", 1, mirror) pkg.info = package_json["info"] pkg.releases = package_json["releases"] pkg._filter_releases() self.assertEqual(set([v['python_version'] for v in pkg.releases["0.4.3"]]), set(['cp35', 'cp36']))
def test_plugin_check_match(self): _mock_config(self.config_contents) bandersnatch.filter.filter_release_plugins() mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foo", 1, mirror) pkg.info = {"name": "foo", "version": "1.2.0"} pkg.releases = { "1.2.0alpha1": {}, "1.2.0a2": {}, "1.2.0beta1": {}, "1.2.0b2": {}, "1.2.0rc1": {}, "1.2.0": {}, } pkg._filter_releases() assert pkg.releases == {"1.2.0": {}}
def test__filter__matches__release(self): with open("test.conf", "w") as testconfig_handle: testconfig_handle.write("""\ [blacklist] plugins = blacklist_release packages = foo==1.2.0 """) instance = BandersnatchConfig() instance.config_file = "test.conf" instance.load_configuration() mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foo", 1, mirror) pkg.releases = {"1.2.0": {}, "1.2.1": {}} pkg._filter_releases() self.assertEqual(pkg.releases, {"1.2.1": {}})
def test_latest_releases_keep_stable(self): _mock_config(self.config_contents) bandersnatch.filter.filter_release_plugins() mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foo", 1, mirror) pkg.info = {"name": "foo", "version": "2.0.0"} # stable version pkg.releases = { "1.0.0": {}, "1.1.0": {}, "1.1.1": {}, "1.1.2": {}, "1.1.3": {}, "2.0.0": {}, # <= stable version, keep it "2.0.1b1": {}, "2.0.1b2": {}, # <= most recent, keep it } pkg._filter_releases() assert pkg.releases == {"2.0.1b2": {}, "2.0.0": {}}
def test__filter__matches__release(self): with open(TEST_CONF, "w") as testconfig_handle: testconfig_handle.write( """\ [blacklist] plugins = safety_db_release """ ) instance = BandersnatchConfig() instance.config_file = TEST_CONF instance.load_configuration() self._dump_config(instance) mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("aiohttp", 1, mirror) pkg.info = {"name": "aiohttp"} pkg.releases = {"0.16.3": {}, "0.16.0": {}, "0.15.1": {}} pkg._filter_releases() self.assertEqual(pkg.releases, {"0.16.3": {}})
def test_exclude_platform(self): """ Tests the platform filter for what it will keep and excluded based on the config provided. It is expected to drop all windows, freebsd and macos packages while only dropping linux-armv7l from linux packages """ _mock_config(self.config_contents) bandersnatch.filter.filter_release_plugins() mirror = Mirror(".", Master(url="https://foo.bar.com")) pkg = Package("foobar", 1, mirror) pkg.info = {"name": "foobar", "version": "1.0"} pkg.releases = { "1.0": [ { "packagetype": "sdist", "filename": "foobar-1.0-win32.tar.gz", "flag": "KEEP", }, { "packagetype": "bdist_msi", "filename": "foobar-1.0.msi", "flag": "DROP", }, { "packagetype": "bdist_wininst", "filename": "foobar-1.0.exe", "flag": "DROP", }, { "packagetype": "bdist_dmg", "filename": "foobar-1.0.dmg", "flag": "DROP", }, { "packagetype": "bdist_wheel", "filename": "foobar-1.0-win32.zip", "flag": "DROP", }, { "packagetype": "bdist_wheel", "filename": "foobar-1.0-linux.tar.gz", "flag": "KEEP", }, { "packagetype": "bdist_wheel", "filename": "foobar-1.0-manylinux1_i686.whl", "flag": "KEEP", }, { "packagetype": "bdist_wheel", "filename": "foobar-1.0-linux_armv7l.whl", "flag": "DROP", }, { "packagetype": "bdist_wheel", "filename": "foobar-1.0-macosx_10_14_x86_64.whl", "flag": "DROP", }, { "packagetype": "bdist_egg", "filename": "foobar-1.0-win_amd64.zip", "flag": "DROP", }, { "packagetype": "unknown", "filename": "foobar-1.0-unknown", "flag": "KEEP", }, ], "0.1": [ { "packagetype": "sdist", "filename": "foobar-0.1-win32.msi", "flag": "KEEP", }, { "packagetype": "bdist_wheel", "filename": "foobar-0.1-win32.whl", "flag": "DROP", }, ], "0.2": [{ "packagetype": "bdist_egg", "filename": "foobar-0.1-freebsd-6.0-RELEASE-i386.egg", "flag": "DROP", }], } # count the files we should keep rv = pkg.releases.values() keep_count = sum(f["flag"] == "KEEP" for r in rv for f in r) pkg._filter_releases() # we should have the same keep count and no drop rv = pkg.releases.values() assert sum(f["flag"] == "KEEP" for r in rv for f in r) == keep_count assert all(f["flag"] == "DROP" for r in rv for f in r) is False # the release "0.2" should have been deleted since there is no more file in it assert len(pkg.releases.keys()) == 2
def setUp_mirror(self): self.mirror = Mirror(self.mirror_path, Master(url="https://foo.bar.com")) pkg = Package("foobar", 1, self.mirror) pkg.info = {"name": "foobar", "version": "1.0"} pkg.releases = mock.Mock() self.pkgs.append(pkg)