"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/publishing/test_publisher.py" between
poetry-1.1.15.tar.gz and poetry-1.2.0.tar.gz

About: Poetry is a tool for dependency management and packaging in Python.

test_publisher.py  (poetry-1.1.15):test_publisher.py  (poetry-1.2.0)
from __future__ import annotations
import os import os
from pathlib import Path
from typing import TYPE_CHECKING
import pytest import pytest
from cleo.io import BufferedIO from cleo.io.buffered_io import BufferedIO
from cleo.io.null_io import NullIO
from poetry.factory import Factory from poetry.factory import Factory
from poetry.io.null_io import NullIO
from poetry.publishing.publisher import Publisher from poetry.publishing.publisher import Publisher
from poetry.utils._compat import Path
def test_publish_publishes_to_pypi_by_default(fixture_dir, mocker, config): if TYPE_CHECKING:
from pytest_mock import MockerFixture
from tests.conftest import Config
from tests.types import FixtureDirGetter
def test_publish_publishes_to_pypi_by_default(
fixture_dir: FixtureDirGetter, mocker: MockerFixture, config: Config
):
uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth") uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth")
uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload")
poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry = Factory().create_poetry(fixture_dir("sample_project"))
poetry._config = config poetry._config = config
poetry.config.merge( poetry.config.merge(
{"http-basic": {"pypi": {"username": "foo", "password": "bar"}}} {"http-basic": {"pypi": {"username": "foo", "password": "bar"}}}
) )
publisher = Publisher(poetry, NullIO()) publisher = Publisher(poetry, NullIO())
publisher.publish(None, None, None) publisher.publish(None, None, None)
assert [("foo", "bar")] == uploader_auth.call_args assert [("foo", "bar")] == uploader_auth.call_args
assert [ assert [
("https://upload.pypi.org/legacy/",), ("https://upload.pypi.org/legacy/",),
{"cert": None, "client_cert": None, "dry_run": False}, {"cert": True, "client_cert": None, "dry_run": False, "skip_existing": F alse},
] == uploader_upload.call_args ] == uploader_upload.call_args
@pytest.mark.parametrize( @pytest.mark.parametrize("fixture_name", ["sample_project", "with_default_source
("fixture_name",), [("sample_project",), ("with_default_source",)] "])
)
def test_publish_can_publish_to_given_repository( def test_publish_can_publish_to_given_repository(
fixture_dir, mocker, config, fixture_name fixture_dir: FixtureDirGetter,
mocker: MockerFixture,
config: Config,
fixture_name: str,
): ):
uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth") uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth")
uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload")
config.merge( config.merge(
{ {
"repositories": {"foo": {"url": "http://foo.bar"}}, "repositories": {"foo": {"url": "http://foo.bar"}},
"http-basic": {"foo": {"username": "foo", "password": "bar"}}, "http-basic": {"foo": {"username": "foo", "password": "bar"}},
} }
) )
mocker.patch("poetry.factory.Factory.create_config", return_value=config) mocker.patch("poetry.config.config.Config.create", return_value=config)
poetry = Factory().create_poetry(fixture_dir(fixture_name)) poetry = Factory().create_poetry(fixture_dir(fixture_name))
io = BufferedIO() io = BufferedIO()
publisher = Publisher(poetry, io) publisher = Publisher(poetry, io)
publisher.publish("foo", None, None) publisher.publish("foo", None, None)
assert [("foo", "bar")] == uploader_auth.call_args assert [("foo", "bar")] == uploader_auth.call_args
assert [ assert [
("http://foo.bar",), ("http://foo.bar",),
{"cert": None, "client_cert": None, "dry_run": False}, {"cert": True, "client_cert": None, "dry_run": False, "skip_existing": F alse},
] == uploader_upload.call_args ] == uploader_upload.call_args
assert "Publishing my-package (1.2.3) to foo" in io.fetch_output() assert "Publishing my-package (1.2.3) to foo" in io.fetch_output()
def test_publish_raises_error_for_undefined_repository(fixture_dir, mocker, conf def test_publish_raises_error_for_undefined_repository(
ig): fixture_dir: FixtureDirGetter, config: Config
):
poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry = Factory().create_poetry(fixture_dir("sample_project"))
poetry._config = config poetry._config = config
poetry.config.merge( poetry.config.merge(
{"http-basic": {"my-repo": {"username": "foo", "password": "bar"}}} {"http-basic": {"my-repo": {"username": "foo", "password": "bar"}}}
) )
publisher = Publisher(poetry, NullIO()) publisher = Publisher(poetry, NullIO())
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
publisher.publish("my-repo", None, None) publisher.publish("my-repo", None, None)
def test_publish_uses_token_if_it_exists(fixture_dir, mocker, config): def test_publish_uses_token_if_it_exists(
fixture_dir: FixtureDirGetter, mocker: MockerFixture, config: Config
):
uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth") uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth")
uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload")
poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry = Factory().create_poetry(fixture_dir("sample_project"))
poetry._config = config poetry._config = config
poetry.config.merge({"pypi-token": {"pypi": "my-token"}}) poetry.config.merge({"pypi-token": {"pypi": "my-token"}})
publisher = Publisher(poetry, NullIO()) publisher = Publisher(poetry, NullIO())
publisher.publish(None, None, None) publisher.publish(None, None, None)
assert [("__token__", "my-token")] == uploader_auth.call_args assert [("__token__", "my-token")] == uploader_auth.call_args
assert [ assert [
("https://upload.pypi.org/legacy/",), ("https://upload.pypi.org/legacy/",),
{"cert": None, "client_cert": None, "dry_run": False}, {"cert": True, "client_cert": None, "dry_run": False, "skip_existing": F alse},
] == uploader_upload.call_args ] == uploader_upload.call_args
def test_publish_uses_cert(fixture_dir, mocker, config): def test_publish_uses_cert(
fixture_dir: FixtureDirGetter, mocker: MockerFixture, config: Config
):
cert = "path/to/ca.pem" cert = "path/to/ca.pem"
uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth") uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth")
uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload")
poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry = Factory().create_poetry(fixture_dir("sample_project"))
poetry._config = config poetry._config = config
poetry.config.merge( poetry.config.merge(
{ {
"repositories": {"foo": {"url": "https://foo.bar"}}, "repositories": {"foo": {"url": "https://foo.bar"}},
"http-basic": {"foo": {"username": "foo", "password": "bar"}}, "http-basic": {"foo": {"username": "foo", "password": "bar"}},
"certificates": {"foo": {"cert": cert}}, "certificates": {"foo": {"cert": cert}},
} }
) )
publisher = Publisher(poetry, NullIO()) publisher = Publisher(poetry, NullIO())
publisher.publish("foo", None, None) publisher.publish("foo", None, None)
assert [("foo", "bar")] == uploader_auth.call_args assert [("foo", "bar")] == uploader_auth.call_args
assert [ assert [
("https://foo.bar",), ("https://foo.bar",),
{"cert": Path(cert), "client_cert": None, "dry_run": False}, {
"cert": Path(cert),
"client_cert": None,
"dry_run": False,
"skip_existing": False,
},
] == uploader_upload.call_args ] == uploader_upload.call_args
def test_publish_uses_client_cert(fixture_dir, mocker, config): def test_publish_uses_client_cert(
fixture_dir: FixtureDirGetter, mocker: MockerFixture, config: Config
):
client_cert = "path/to/client.pem" client_cert = "path/to/client.pem"
uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload")
poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry = Factory().create_poetry(fixture_dir("sample_project"))
poetry._config = config poetry._config = config
poetry.config.merge( poetry.config.merge(
{ {
"repositories": {"foo": {"url": "https://foo.bar"}}, "repositories": {"foo": {"url": "https://foo.bar"}},
"certificates": {"foo": {"client-cert": client_cert}}, "certificates": {"foo": {"client-cert": client_cert}},
} }
) )
publisher = Publisher(poetry, NullIO()) publisher = Publisher(poetry, NullIO())
publisher.publish("foo", None, None) publisher.publish("foo", None, None)
assert [ assert [
("https://foo.bar",), ("https://foo.bar",),
{"cert": None, "client_cert": Path(client_cert), "dry_run": False}, {
"cert": True,
"client_cert": Path(client_cert),
"dry_run": False,
"skip_existing": False,
},
] == uploader_upload.call_args ] == uploader_upload.call_args
def test_publish_read_from_environment_variable(fixture_dir, environ, mocker, co def test_publish_read_from_environment_variable(
nfig): fixture_dir: FixtureDirGetter,
environ: None,
mocker: MockerFixture,
config: Config,
):
os.environ["POETRY_REPOSITORIES_FOO_URL"] = "https://foo.bar" os.environ["POETRY_REPOSITORIES_FOO_URL"] = "https://foo.bar"
os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar" os.environ["POETRY_HTTP_BASIC_FOO_USERNAME"] = "bar"
os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz" os.environ["POETRY_HTTP_BASIC_FOO_PASSWORD"] = "baz"
uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth") uploader_auth = mocker.patch("poetry.publishing.uploader.Uploader.auth")
uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload") uploader_upload = mocker.patch("poetry.publishing.uploader.Uploader.upload")
poetry = Factory().create_poetry(fixture_dir("sample_project")) poetry = Factory().create_poetry(fixture_dir("sample_project"))
publisher = Publisher(poetry, NullIO()) publisher = Publisher(poetry, NullIO())
publisher.publish("foo", None, None) publisher.publish("foo", None, None)
assert [("bar", "baz")] == uploader_auth.call_args assert [("bar", "baz")] == uploader_auth.call_args
assert [ assert [
("https://foo.bar",), ("https://foo.bar",),
{"cert": None, "client_cert": None, "dry_run": False}, {"cert": True, "client_cert": None, "dry_run": False, "skip_existing": F alse},
] == uploader_upload.call_args ] == uploader_upload.call_args
 End of changes. 20 change blocks. 
22 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)