-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
test_uploader.py
71 lines (42 loc) · 2.02 KB
/
test_uploader.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
from pathlib import Path
import pytest
from cleo.io.null_io import NullIO
from poetry.factory import Factory
from poetry.publishing.uploader import Uploader
from poetry.publishing.uploader import UploadError
fixtures_dir = Path(__file__).parent.parent / "fixtures"
def project(name):
return fixtures_dir / name
@pytest.fixture
def uploader():
return Uploader(Factory().create_poetry(project("simple_project")), NullIO())
def test_uploader_properly_handles_400_errors(http, uploader):
http.register_uri(http.POST, "https://foo.com", status=400, body="Bad request")
with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")
assert "HTTP Error 400: Bad Request" == str(e.value)
def test_uploader_properly_handles_403_errors(http, uploader):
http.register_uri(http.POST, "https://foo.com", status=403, body="Unauthorized")
with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")
assert "HTTP Error 403: Forbidden" == str(e.value)
def test_uploader_properly_handles_301_redirects(http, uploader):
http.register_uri(http.POST, "https://foo.com", status=301, body="Redirect")
with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")
assert "Redirects are not supported. Is the URL missing a trailing slash?" == str(
e.value
)
def test_uploader_registers_for_appropriate_400_errors(mocker, http, uploader):
register = mocker.patch("poetry.publishing.uploader.Uploader._register")
http.register_uri(
http.POST, "https://foo.com", status=400, body="No package was ever registered"
)
with pytest.raises(UploadError):
uploader.upload("https://foo.com")
assert 1 == register.call_count
def test_uploader_properly_handles_file_not_existing(mocker, http, uploader):
mocker.patch("pathlib.Path.is_file", return_value=False)
with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")
assert f"Archive ({uploader.files[0]}) does not exist" == str(e.value)