def _test_get_mirror_targets( dirs, expected_pkg_dirs, expected_target_dirs, namespace_packages=None, ): pypi = CluePyPIAPI('http://example.com') src_root = "/src" target_root = '/path/to/dest' def walk_mock(_): data = [(src_root, dirs.keys(), [])] for d in dirs: data.append((os.path.join(src_root, d), dirs[d], [])) return data # Test full list with ExitStack() as stack: stack.enter_context(patch("os.walk", side_effect=walk_mock)) stack.enter_context(patch("os.path.isdir", return_value=True)) pkg_dirs, target_dirs = pypi.get_mirror_targets( src_root, target_root, namespace_packages) assert set(pkg_dirs) == set( os.path.join(src_root, p) for p in expected_pkg_dirs) assert set(target_dirs) == set( os.path.join(target_root, d) for d in expected_target_dirs)
def test_scrape_uri_from_clue(): """ Tests the clue url scraper """ pypi = CluePyPIAPI('http://example.com') with patch('pkglib.pypi.clue.urllib2.urlopen', mock_clue()): assert pypi.scrape_pkg_uri('http://dummy', 'acme.foo') == \ 'http://mysvn/acme.foo'
def test_get_mirror_config(): pypi = CluePyPIAPI('http://example.com') mirror_cfg = cStringIO(MIRROR_CONFIG) file_dict = {'mirror.cfg': mirror_cfg} with ExitStack() as stack: stack.enter_context(_patch_open(file_dict=file_dict)) stack.enter_context(patch("os.path.isfile", return_value=True)) cfg = pypi.get_mirror_config('mirror.cfg') assert len(cfg) == 2 for c in cfg: assert c['target_host'] in ('foohost', 'barhost') if c['target_host'] == 'foohost': assert c['target_dir'] == '/path/to/foodir' else: assert c['target_dir'] == '/path/to/bardir'
def _test_mirror_eggs(dirs, target_pkgs=None): pypi = CluePyPIAPI('http://example.com') src_root = "/src" target_root = '/path/to/dest' target_host = "dlonfoobar" eggs_by_pkg = dict((p, ['%s-%0.1f.egg' % (p, v) for v in [1.0, 2.0, 3.0]]) for d in dirs for p in dirs[d]) eggs_by_path = dict( (os.path.join(src_root, [d for d in dirs if p in dirs[d]][0], p), egg) for p, egg in eggs_by_pkg.items()) # Disable the egg unpack stage for this test pypi.unpack_eggs = lambda _i, _j, _k: None def walk_mock(_): data = [(src_root, dirs.keys(), [])] for d in dirs: data.append((os.path.join(src_root, d), dirs[d], [])) return data def is_file_mock(f): return os.path.basename(f) in eggs_by_path.get(os.path.dirname(f), {}) @patch_subprocess(get_subprocess_mock('', '', 0)) def run(): pypi.mirror_eggs(src_root, target_host, target_root, target_pkgs, 1) return subprocess.Popen with ExitStack() as stack: ec = stack.enter_context ec(patch("os.walk", side_effect=walk_mock)) ec(patch("os.path.isdir", return_value=True)) ec(patch("os.listdir", side_effect=lambda d: eggs_by_path[d])) ec(patch("os.path.isfile", side_effect=is_file_mock)) return run(), src_root, target_root, target_host, eggs_by_pkg
def test_get_mirror_dirname(): pypi = CluePyPIAPI('http://example.com') assert pypi.get_mirror_dirname('foo') == 'f' assert pypi.get_mirror_dirname('acme.foo') == 'af' assert pypi.get_mirror_dirname('acme.foo.bar') == 'af'
def test_homepage(): """ Api package homepage method test """ pypi = CluePyPIAPI('http://example.com') assert pypi._pkg_home('acme.foo') == "http://example.com/d/acme.foo"