Skip to content

Commit 2af8dcf

Browse files
committed
add negative test
1 parent d411d67 commit 2af8dcf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/publishing/test_uploader.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,31 @@ def test_uploader_retries_upload_after_register(
248248
assert b'name=":action"\r\n\r\nfile_upload\r\n' in bodies[3]
249249

250250

251+
def test_uploader_retries_upload_after_register_but_does_not_loop_infinitely(
252+
http: responses.RequestsMock, uploader: Uploader
253+
) -> None:
254+
"""After registering a package, the upload must be retried but only once.
255+
256+
The server returns 400 "was ever registered" on the first upload,
257+
then 200 on the registration,
258+
but then again 400 "was ever registered" on the second upload.
259+
"""
260+
http.post("https://foo.com", status=400, body="No package was ever registered")
261+
http.post("https://foo.com", status=200) # register
262+
http.post( # retry upload
263+
"https://foo.com", status=400, body="No package was ever registered"
264+
)
265+
266+
with pytest.raises(UploadError):
267+
uploader.upload("https://foo.com")
268+
269+
assert len(http.calls) == 3
270+
bodies = [c.request.body or b"" for c in http.calls]
271+
assert b'name=":action"\r\n\r\nfile_upload\r\n' in bodies[0]
272+
assert b'name=":action"\r\n\r\nsubmit\r\n' in bodies[1]
273+
assert b'name=":action"\r\n\r\nfile_upload\r\n' in bodies[2]
274+
275+
251276
def test_uploader_register_uses_wheel_if_no_sdist(
252277
http: responses.RequestsMock, poetry: Poetry, tmp_path: Path
253278
) -> None:

0 commit comments

Comments
 (0)