Skip to content

Commit

Permalink
Refactoring uploader into a fixture (#3679)
Browse files Browse the repository at this point in the history
* Relates-to: #3155 converting duplicted code to fixture
  • Loading branch information
sanders41 authored Feb 13, 2021
1 parent 74ec169 commit 6eaa298
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/console/commands/debug/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def tester(command_tester_factory):


@pytest.fixture(autouse=True)
def _add_packages(repo):
def __add_packages(repo):
cachy020 = get_package("cachy", "0.2.0")
cachy020.add_dependency(Factory.create_dependency("msgpack-python", ">=0.5 <0.6"))

Expand Down
17 changes: 9 additions & 8 deletions tests/publishing/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ def project(name):
return fixtures_dir / name


def test_uploader_properly_handles_400_errors(http):
@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")
uploader = Uploader(Factory().create_poetry(project("simple_project")), NullIO())

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):
def test_uploader_properly_handles_403_errors(http, uploader):
http.register_uri(http.POST, "https://foo.com", status=403, body="Unauthorized")
uploader = Uploader(Factory().create_poetry(project("simple_project")), NullIO())

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):
def test_uploader_properly_handles_301_redirects(http, uploader):
http.register_uri(http.POST, "https://foo.com", status=301, body="Redirect")
uploader = Uploader(Factory().create_poetry(project("simple_project")), NullIO())

with pytest.raises(UploadError) as e:
uploader.upload("https://foo.com")
Expand All @@ -48,12 +50,11 @@ def test_uploader_properly_handles_301_redirects(http):
)


def test_uploader_registers_for_appropriate_400_errors(mocker, http):
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"
)
uploader = Uploader(Factory().create_poetry(project("simple_project")), NullIO())

with pytest.raises(UploadError):
uploader.upload("https://foo.com")
Expand Down

0 comments on commit 6eaa298

Please sign in to comment.