From 167301ff66047e2c58bf4086c54e879548a8f1ad Mon Sep 17 00:00:00 2001 From: Heather White Date: Sat, 1 Jun 2024 07:18:43 -0500 Subject: [PATCH] Fix local tests (#855) --- CHANGES/849.bugfix | 1 + CONTRIBUTORS.txt | 1 + tests/conftest.py | 2 +- tests/test_containers.py | 12 ++++++++---- tests/test_networks.py | 11 ++++++++--- 5 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 CHANGES/849.bugfix diff --git a/CHANGES/849.bugfix b/CHANGES/849.bugfix new file mode 100644 index 00000000..535cc040 --- /dev/null +++ b/CHANGES/849.bugfix @@ -0,0 +1 @@ +Fixes unittests that don't run locally due to deprecations in later versions of Docker. Tested with 26.00, v1.45. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 4bec19ec..ad752477 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -7,6 +7,7 @@ Byeongjun Park Cecil Tonglet Christian Barra Danny Song +eevelweezel Gaopeiliang Greg Guthe Hiroki Kiyohara diff --git a/tests/conftest.py b/tests/conftest.py index 3d11acbd..909a1415 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,7 +52,7 @@ async def random_name(): docker = Docker() images = await docker.images.list() for img in images: - if img["RepoTags"] is None: + if not img["RepoTags"]: continue try: if img["RepoTags"][0].startswith("aiodocker-"): diff --git a/tests/test_containers.py b/tests/test_containers.py index d06c9b10..65a0fb25 100644 --- a/tests/test_containers.py +++ b/tests/test_containers.py @@ -170,12 +170,17 @@ async def test_resize(shell_container): ) @pytest.mark.asyncio async def test_commit(docker, image_name, shell_container): + """ + "Container" key was removed in v1.45. + "ContainerConfig" is not present, although this information is now present in "Config" + These changes have been verified against v1.45. + """ ret = await shell_container.commit() img_id = ret["Id"] img = await docker.images.inspect(img_id) - assert img["Container"].startswith(shell_container.id) - assert "Image" in img["ContainerConfig"] - assert image_name == img["ContainerConfig"]["Image"] + + assert "Image" in img["Config"] + assert image_name == img["Config"]["Image"] python_img = await docker.images.inspect(image_name) python_id = python_img["Id"] assert "Parent" in img @@ -191,7 +196,6 @@ async def test_commit_with_changes(docker, image_name, shell_container): ret = await shell_container.commit(changes=["EXPOSE 8000", 'CMD ["py"]']) img_id = ret["Id"] img = await docker.images.inspect(img_id) - assert img["Container"].startswith(shell_container.id) assert "8000/tcp" in img["Config"]["ExposedPorts"] assert img["Config"]["Cmd"] == ["py"] await docker.images.delete(img_id) diff --git a/tests/test_networks.py b/tests/test_networks.py index a96f5556..8a9c6905 100644 --- a/tests/test_networks.py +++ b/tests/test_networks.py @@ -13,12 +13,17 @@ async def test_list_networks(docker): @pytest.mark.asyncio async def test_list_networks_with_filter(docker): - await docker.networks.create({ + network = await docker.networks.create({ "Name": "test-net-filter", "Labels": {"some": "label"}, }) - networks = await docker.networks.list(filters={"label": "some=label"}) - assert len(networks) == 1 + try: + networks = await docker.networks.list(filters={"label": "some=label"}) + assert len(networks) == 1 + finally: + if network: + deleted = await network.delete() + assert deleted is True @pytest.mark.asyncio