/
test_publish.py
111 lines (71 loc) · 2.95 KB
/
test_publish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from typing import NoReturn
import pytest
import requests
from poetry.publishing.uploader import UploadError
from poetry.utils._compat import PY36
from poetry.utils._compat import Path
@pytest.mark.skipif(
not PY36, reason="Improved error rendering is only available on Python >=3.6"
)
def test_publish_returns_non_zero_code_for_upload_errors(app, app_tester, http):
http.register_uri(
http.POST, "https://upload.pypi.org/legacy/", status=400, body="Bad Request"
)
exit_code = app_tester.execute("publish --username foo --password bar")
assert 1 == exit_code
expected = """
Publishing simple-project (1.2.3) to PyPI
UploadError
HTTP Error 400: Bad Request
"""
assert expected in app_tester.io.fetch_output()
def test_publish_returns_non_zero_code_for_connection_errors(app, app_tester, http):
def request_callback(*_, **__) -> NoReturn:
raise requests.ConnectionError()
http.register_uri(
http.POST, "https://upload.pypi.org/legacy/", body=request_callback
)
exit_code = app_tester.execute("publish --username foo --password bar")
assert 1 == exit_code
expected = str(UploadError(error=requests.ConnectionError()))
assert expected in app_tester.io.fetch_output()
@pytest.mark.skipif(
PY36, reason="Improved error rendering is not available on Python <3.6"
)
def test_publish_returns_non_zero_code_for_upload_errors_older_python(
app, app_tester, http
):
http.register_uri(
http.POST, "https://upload.pypi.org/legacy/", status=400, body="Bad Request"
)
exit_code = app_tester.execute("publish --username foo --password bar")
assert 1 == exit_code
expected = """
Publishing simple-project (1.2.3) to PyPI
UploadError
HTTP Error 400: Bad Request
"""
assert app_tester.io.fetch_output() == expected
def test_publish_with_cert(app_tester, mocker):
publisher_publish = mocker.patch("poetry.publishing.Publisher.publish")
app_tester.execute("publish --cert path/to/ca.pem")
assert [
(None, None, None, Path("path/to/ca.pem"), None, False)
] == publisher_publish.call_args
def test_publish_with_client_cert(app_tester, mocker):
publisher_publish = mocker.patch("poetry.publishing.Publisher.publish")
app_tester.execute("publish --client-cert path/to/client.pem")
assert [
(None, None, None, None, Path("path/to/client.pem"), False)
] == publisher_publish.call_args
def test_publish_dry_run(app_tester, http):
http.register_uri(
http.POST, "https://upload.pypi.org/legacy/", status=403, body="Forbidden"
)
exit_code = app_tester.execute("publish --dry-run --username foo --password bar")
assert 0 == exit_code
output = app_tester.io.fetch_output()
error = app_tester.io.fetch_error()
assert "Publishing simple-project (1.2.3) to PyPI" in output
assert "- Uploading simple-project-1.2.3.tar.gz" in error
assert "- Uploading simple_project-1.2.3-py2.py3-none-any.whl" in error