Skip to content

Commit

Permalink
Change: Make the upload release artifacts test reliable
Browse files Browse the repository at this point in the history
The tests for the upload heavily depend on the internal ordering in
asyncio of the as_completed function. Therefore check the order of the
iterated files before asserting.
  • Loading branch information
bjoernricks committed Oct 25, 2022
1 parent 48a2666 commit 5172e57
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions tests/github/api/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,26 +375,37 @@ async def test_upload_release_assets(self):
]
upload_files = [file1, (file2, "application/pdf")]

def assert_file1(index: int):
args = self.client.post.await_args_list[index].args
self.assertEqual(args, ("https://uploads/assets",))
kwargs = self.client.post.await_args_list[index].kwargs
self.assertEqual(kwargs["params"], {"name": "foo.txt"})
self.assertEqual(kwargs["content_type"], "application/octet-stream")

def assert_file2(index: int):
args = self.client.post.await_args_list[index].args
self.assertEqual(args, ("https://uploads/assets",))
kwargs = self.client.post.await_args_list[index].kwargs
self.assertEqual(kwargs["params"], {"name": "bar.pdf"})
self.assertEqual(kwargs["content_type"], "application/pdf")

it = aiter(
self.api.upload_release_assets("foo/bar", "v1.2.3", upload_files)
)

# the order of the files is non-deterministic

f = await anext(it)
self.assertEqual(f, file1)
if f == file1:
assert_file1(0)
else:
assert_file2(0)

f = await anext(it)
self.assertEqual(f, file2)

args = self.client.post.await_args_list[0].args
self.assertEqual(args, ("https://uploads/assets",))
kwargs = self.client.post.await_args_list[0].kwargs
self.assertEqual(kwargs["params"], {"name": "foo.txt"})
self.assertEqual(kwargs["content_type"], "application/octet-stream")

args = self.client.post.await_args_list[1].args
self.assertEqual(args, ("https://uploads/assets",))
kwargs = self.client.post.await_args_list[1].kwargs
self.assertEqual(kwargs["params"], {"name": "bar.pdf"})
self.assertEqual(kwargs["content_type"], "application/pdf")
if f == file1:
assert_file1(1)
else:
assert_file2(1)

self.client.get.assert_awaited_once_with(
"/repos/foo/bar/releases/tags/v1.2.3"
Expand Down

0 comments on commit 5172e57

Please sign in to comment.