コード例 #1
0
def test_upload(pytestconfig, pypi_chishop):
    """Test we can upload packages to an instance of chishop PyPI.
        This also covers the setuptools extensions register and upload.
    """
    with PkgTemplate(name='acme.tpi.test.upload-1.0.0.dev1') as pkg:
        pkg.create_pypirc(pypi_chishop.get_rc())
        pkg.install_package('pytest-cov')
        new_env = copy.copy(pkg.env)
        new_env['HOME'] = pkg.workspace
        setup_cmd = ['%s/setup.py' % pkg.trunk_dir]
        setup_cmd += ['sdist', 'register', 'upload', '--show-response']

        pkg.run_with_coverage(setup_cmd, pytestconfig, env=new_env, cd=HERE, capture_stdout=False)
    dist_location = ('chishop/media/dists/a/acme.tpi.test.upload'
                     '/acme.tpi.test.upload-1.0.0.dev1.tar.gz')
    assert os.path.isfile(os.path.join(pypi_chishop.workspace, dist_location))

    dist_url = ('http://%s:%s/media/dists/a/acme.tpi.test.upload'
                '/acme.tpi.test.upload-1.0.0.dev1.tar.gz'
                % (pypi_chishop.hostname, pypi_chishop.port))
    response = urlopen(dist_url)
    buf = response.read()
    fh = BytesIO(buf)
    with closing(tarfile.open(fileobj=fh)) as tf:
        assert 'acme.tpi.test.upload-1.0.0.dev1/PKG-INFO' in tf.getnames()
コード例 #2
0
def test_pyuninstall(pytestconfig, pypi_chishop):
    """ Creates template, runs pyinstall
    Find and install latest non-dev version of a given package, and then
    try and import it. Finally uninstall it and show it has gone.
    """
    pypi_url = "http://%s:%s/simple" % (pypi_chishop.hostname,
                                        pypi_chishop.port)

    with PkgTemplate(name="acme.bar", dev=False,
                     metadata=dict(name="acme.bar", version="1.2.3")) as pkg:
        pkg.install_package('pytest-cov')
        pkg.create_pypirc(pypi_chishop.get_rc())
        new_env = copy.copy(pkg.env)
        new_env['HOME'] = pkg.workspace
        setup_cmd = [os.path.join(pkg.trunk_dir, "setup.py"),
                     'bdist_egg', 'register', 'upload', '--show-response']

        pkg.run_with_coverage(setup_cmd, pytestconfig, env=new_env, cd=HERE, capture_stdout=False)

    with PkgTemplate(name="acme.foo", dev=False,
                     metadata=dict(name="acme.foo", version="1.2.3")) as pkg:
        pkg.install_package('pytest-cov')

        pyinstall_cmd = [os.path.join(os.path.dirname(pkg.python), 'pyinstall'),
                         '-i', pypi_url, 'acme.bar']
        pkg.run_with_coverage(pyinstall_cmd, pytestconfig, cd=HERE, capture_stdout=False)
        assert 'acme.bar' in pkg.installed_packages()

        pyuninstall_cmd = [os.path.join(os.path.dirname(pkg.python), 'pyuninstall'),
                           '--yes', 'acme.bar']
        pkg.run_with_coverage(pyuninstall_cmd, pytestconfig, cd=HERE, capture_stdout=False)
        assert 'acme.bar' not in pkg.installed_packages()
コード例 #3
0
def test_easyinstall_command_fetches_package_from_pypi(pytestconfig, pypi_chishop):
    """ Creates template, runs easy_install from the setuptools command
    Find and install latest non-dev version of a given package, and then
    try and import it
    """
    pypi_url = "http://%s:%s/simple" % (pypi_chishop.hostname,
                                        pypi_chishop.port)

    with PkgTemplate(name="acme.pypipkg", dev=False,
                     metadata=dict(name="acme.pypipkg", version="1.2.3")) as pkg:
        pkg.install_package('pytest-cov')
        pkg.create_pypirc(pypi_chishop.get_rc())
        new_env = copy.copy(pkg.env)
        new_env['HOME'] = pkg.workspace
        setup_cmd = [os.path.join(pkg.trunk_dir, "setup.py")]
        setup_cmd += ['bdist_egg', 'register', 'upload', '--show-response']

        pkg.run_with_coverage(setup_cmd, pytestconfig, env=new_env, cd=HERE, capture_stdout=False)

    with PkgTemplate(name="acme.pypipkg", dev=False,
                     metadata=dict(name="acme.pypipkg", version="1.2.3")) as pkg:
        pkg.install_package('pytest-cov')

        easyinstall_cmd = [os.path.join(pkg.trunk_dir, "setup.py"),
                           "easy_install", '-i', pypi_url, "acme.pypipkg"]

        pkg.run_with_coverage(easyinstall_cmd, pytestconfig, cd=HERE, capture_stdout=False)

        [pkg.run(cmd, capture=False, cd=HERE) for cmd in [
            '%s -c "import acme.pypipkg"' % (pkg.python),
        ]]
        installed = pkg.installed_packages()
        assert installed['acme.pypipkg'].version == '1.2.3'
        assert installed['acme.pypipkg'].isrel
コード例 #4
0
def test_prevent_upload_after_removing_platform(pytestconfig, pypi_chishop):
    """If the maintainer makes the package non-platform-aware (e.g. by de-Cythonising), we should
    refuse upload without a version bump."""
    expected_msg = ('Upload failed (400): BAD REQUEST: cannot upload a platform-independent '
                    'distribution when a platform-specific distribution already exists '
                    '(delete the existing distribution, or bump the version)')

    with PkgTemplate(name='acme.tpi.test.decythonise') as pkg:
        pkg.create_pypirc(pypi_chishop.get_rc())
        pkg.install_package('pytest-cov')
        setup_py = '%s/setup.py' % pkg.trunk_dir

        _add_ext_module(pkg)
        setup_cmd = [setup_py, 'bdist_egg', '-p', 'platform1', 'register', 'upload']
        pkg.run_with_coverage(setup_cmd, pytestconfig, env=dict(pkg.env, HOME=pkg.workspace),
                              cd=HERE, capture_stdout=False)

        with open(setup_py, 'w') as f:
            f.write("from pkglib.setuptools import setup\nsetup()")
        setup_cmd = [setup_py, 'bdist_egg', 'register', 'upload']
        with pytest.raises(CalledProcessError) as exc:
            print(pkg.run_with_coverage(setup_cmd, pytestconfig,
                                        env=dict(pkg.env, HOME=pkg.workspace),
                                        cd=HERE, capture_stderr=True))
    assert expected_msg in exc.value.output
コード例 #5
0
def test_validate_credentials_raises_user_error_on_unauthorized(pypi_chishop,
                                                                workspace):
    config = pypi_chishop.get_rc()
    config.set('server-login', 'password', 'hunter2')
    workspace.create_pypirc(config)
    pypirc = PyPiRc(os.path.join(workspace.workspace, '.pypirc'))
    with pytest.raises(UserError) as exc:
        pypirc.validate_credentials(pypi_chishop.uri)
    assert exc.value.msg.startswith(UserError('Invalid PyPi credentials',
                                              pypi_chishop.uri, '').msg)
コード例 #6
0
def test_delete_other_dev_eggs(pytestconfig, pypi_chishop):
    with PkgTemplate(name='acme.tpi.test.dev-1.0.0.dev1') as pkg:
        dist_dir = os.path.join(pypi_chishop.workspace, 'chishop/media/dists/a/acme.tpi.test.dev')
        pkg.create_pypirc(pypi_chishop.get_rc())
        pkg.install_package('pytest-cov')
        new_env = copy.copy(pkg.env)
        new_env['HOME'] = pkg.workspace
        setup_cmd = ['%s/setup.py' % pkg.trunk_dir]
        setup_cmd += ['sdist', 'register', 'upload', '--show-response']

        pkg.run_with_coverage(setup_cmd, pytestconfig, env=new_env, cd=HERE, capture_stdout=False)
        assert os.path.isfile(os.path.join(dist_dir, 'acme.tpi.test.dev-1.0.0.dev1.tar.gz'))

        update_setup_cfg('%s/setup.cfg' % pkg.trunk_dir, vcs_uri=pkg.vcs_uri,
                         metadata={'version': '1.1.0'}, dev=True)
        pkg.run_with_coverage(setup_cmd, pytestconfig, env=new_env, cd=HERE, capture_stdout=False)
        assert os.path.isfile(os.path.join(dist_dir, 'acme.tpi.test.dev-1.1.0.dev1.tar.gz'))
        assert not os.path.isfile(os.path.join(dist_dir, 'acme.tpi.test.dev-1.0.0.dev1.tar.gz'))
コード例 #7
0
def test_upload_different_platforms(pytestconfig, pypi_chishop):
    with PkgTemplate(name='acme.tpi.test.platforms') as pkg:
        pkg.create_pypirc(pypi_chishop.get_rc())
        pkg.install_package('pytest-cov')
        setup_py = '%s/setup.py' % pkg.trunk_dir
        _add_ext_module(pkg)
        setup_cmd = [setup_py, 'bdist_egg', '-p', 'platform1', 'register', 'upload']
        pkg.run_with_coverage(setup_cmd, pytestconfig, env=dict(pkg.env, HOME=pkg.workspace),
                              cd=HERE, capture_stdout=False)

        setup_cmd = [setup_py, 'bdist_egg', '-p', 'platform2', 'register', 'upload']
        pkg.run_with_coverage(setup_cmd, pytestconfig, env=dict(pkg.env, HOME=pkg.workspace),
                              cd=HERE, capture_stdout=False)

    response = urlopen('http://%s:%s/simple/acme.tpi.test.platforms' %
                       (pypi_chishop.hostname, pypi_chishop.port))
    buf = response.read()
    pyversion = sys.version[:3]  # sysconfig.get_python_version()
    assert ('acme.tpi.test.platforms-1.0.0.dev1-py%s-platform1.egg' % pyversion) in buf
    assert ('acme.tpi.test.platforms-1.0.0.dev1-py%s-platform2.egg' % pyversion) in buf
コード例 #8
0
def test_validate_credentials(pypi_chishop, workspace):
    workspace.create_pypirc(pypi_chishop.get_rc())
    pypirc = PyPiRc(os.path.join(workspace.workspace, '.pypirc'))
    pypirc.validate_credentials(pypi_chishop.uri)