Exemple #1
0
 def create_repository(self) -> repository.Repository:
     """Create a new repository for uploading."""
     repo = repository.Repository(
         cast(str, self.repository_config["repository"]),
         self.username,
         self.password,
         self.disable_progress_bar,
     )
     repo.set_certificate_authority(self.cacert)
     repo.set_client_certificate(self.client_cert)
     return repo
Exemple #2
0
def test_set_client_certificate():
    repo = repository.Repository(
        repository_url=DEFAULT_REPOSITORY,
        username='******',
        password='******',
    )

    assert repo.session.cert is None

    repo.set_client_certificate(('/path/to/cert', '/path/to/key'))
    assert repo.session.cert == ('/path/to/cert', '/path/to/key')
Exemple #3
0
def test_set_certificate_authority():
    repo = repository.Repository(
        repository_url=DEFAULT_REPOSITORY,
        username='******',
        password='******',
    )

    assert repo.session.verify is True

    repo.set_certificate_authority('/path/to/cert')
    assert repo.session.verify == '/path/to/cert'
Exemple #4
0
def test_package_is_uploaded_incorrect_repo_url():
    """Test that a package upload fails on providing wrong repo url"""
    repo = repository.Repository(
        repository_url="https://bad.repo.com/legacy",
        username="******",
        password="******",
    )

    repo.url = "https://bad.repo.com/legacy"

    assert repo.package_is_uploaded(None) is False
Exemple #5
0
def test_package_is_uploaded_incorrect_repo_url():
    """Return False when using an incorrect repository URL."""
    repo = repository.Repository(
        repository_url="https://bad.repo.com/legacy",
        username="******",
        password="******",
    )

    repo.url = "https://bad.repo.com/legacy"

    assert repo.package_is_uploaded(None) is False
Exemple #6
0
def test_set_certificate_authority():
    repo = repository.Repository(
        repository_url='https://pypi.python.org/pypi',
        username='******',
        password='******',
    )

    assert repo.session.verify is True

    repo.set_certificate_authority('/path/to/cert')
    assert repo.session.verify == '/path/to/cert'
Exemple #7
0
def test_set_client_certificate():
    repo = repository.Repository(
        repository_url='https://pypi.python.org/pypi',
        username='******',
        password='******',
    )

    assert repo.session.cert is None

    repo.set_client_certificate(('/path/to/cert', '/path/to/key'))
    assert repo.session.cert == ('/path/to/cert', '/path/to/key')
Exemple #8
0
def test_release_urls(package_meta, repository_url, release_urls):
    """Test that the correct release urls are read"""
    packages = [
        pretend.stub(safe_name=name, metadata=pretend.stub(version=version),)
        for name, version in package_meta
    ]

    repo = repository.Repository(
        repository_url=repository_url, username="******", password="******",
    )

    assert repo.release_urls(packages) == release_urls
Exemple #9
0
def test_release_urls(package_meta, repository_url, release_urls):
    """Generate a set of PyPI release URLs for a list of packages."""
    packages = [
        pretend.stub(safe_name=name, metadata=pretend.stub(version=version))
        for name, version in package_meta
    ]

    repo = repository.Repository(
        repository_url=repository_url,
        username="******",
        password="******",
    )

    assert repo.release_urls(packages) == release_urls
Exemple #10
0
def test_package_is_uploaded_404s():
    repo = repository.Repository(
        repository_url=DEFAULT_REPOSITORY,
        username='******',
        password='******',
    )
    repo.session = pretend.stub(
        get=lambda url, headers: response_with(status_code=404))
    package = pretend.stub(
        safe_name='fake',
        metadata=pretend.stub(version='2.12.0'),
    )

    assert repo.package_is_uploaded(package) is False
Exemple #11
0
def test_make_user_agent_string():
    repo = repository.Repository(
        repository_url=DEFAULT_REPOSITORY,
        username='******',
        password='******',
    )

    assert 'User-Agent' in repo.session.headers

    user_agent = repo.session.headers['User-Agent']
    assert 'twine/' in user_agent
    assert 'requests/' in user_agent
    assert 'requests-toolbelt/' in user_agent
    assert 'pkginfo/' in user_agent
    assert 'setuptools/' in user_agent
Exemple #12
0
def test_package_is_uploaded_200s_with_no_releases():
    repo = repository.Repository(
        repository_url=DEFAULT_REPOSITORY,
        username='******',
        password='******',
    )
    repo.session = pretend.stub(get=lambda url, headers: response_with(
        status_code=200, _content=b'{"releases": {}}', _content_consumed=True),
                                )
    package = pretend.stub(
        safe_name='fake',
        metadata=pretend.stub(version='2.12.0'),
    )

    assert repo.package_is_uploaded(package) is False
Exemple #13
0
def test_release_urls(package_meta, repository_url, release_urls):
    packages = [
        pretend.stub(
            safe_name=name,
            metadata=pretend.stub(version=version),
        ) for name, version in package_meta
    ]

    repo = repository.Repository(
        repository_url=repository_url,
        username='******',
        password='******',
    )

    assert repo.release_urls(packages) == release_urls
Exemple #14
0
def test_make_user_agent_string():
    repo = repository.Repository(
        repository_url='https://pypi.python.org/pypi',
        username='******',
        password='******',
    )

    assert 'User-Agent' in repo.session.headers

    user_agent = repo.session.headers['User-Agent']
    assert 'twine/' in user_agent
    assert 'requests/' in user_agent
    assert 'requests-toolbelt/' in user_agent
    assert 'pkginfo/' in user_agent
    assert 'setuptools/' in user_agent
Exemple #15
0
def test_disable_progress_bar_is_forwarded_to_tqdm(monkeypatch, tmpdir,
                                                   disable_progress_bar):
    """Test whether the disable flag is passed to tqdm
        when the disable_progress_bar option is passed to the
        repository
    """
    @contextmanager
    def progressbarstub(*args, **kwargs):
        assert "disable" in kwargs
        assert kwargs["disable"] == disable_progress_bar
        yield

    monkeypatch.setattr(repository, "ProgressBar", progressbarstub)
    repo = repository.Repository(
        repository_url=DEFAULT_REPOSITORY,
        username='******',
        password='******',
        disable_progress_bar=disable_progress_bar
    )

    repo.session = pretend.stub(
        post=lambda url, data, allow_redirects, headers: response_with(
            status_code=200)
    )

    fakefile = tmpdir.join('fake.whl')
    fakefile.write('.')

    def dictfunc():
        return {"name": "fake"}

    package = pretend.stub(
        safe_name='fake',
        metadata=pretend.stub(version='2.12.0'),
        basefilename="fake.whl",
        filename=str(fakefile),
        metadata_dictionary=dictfunc
    )

    repo.upload(package)
Exemple #16
0
def default_repo():
    return repository.Repository(
        repository_url=utils.DEFAULT_REPOSITORY,
        username="******",
        password="******",
    )