diff --git a/podman/domain/networks.py b/podman/domain/networks.py index ac25dad6..7fa599bc 100644 --- a/podman/domain/networks.py +++ b/podman/domain/networks.py @@ -30,9 +30,12 @@ class Network(PodmanResource): @property def id(self): # pylint: disable=invalid-name """str: Returns the identifier of the network.""" - with suppress(KeyError): + if "Id" in self.attrs: return self.attrs["Id"] + if "id" in self.attrs: + return self.attrs["id"] + with suppress(KeyError): sha256 = hashlib.sha256(self.attrs["name"].encode("ascii")) return sha256.hexdigest() diff --git a/podman/tests/integration/test_networks.py b/podman/tests/integration/test_networks.py index 76e9b854..182eaea6 100644 --- a/podman/tests/integration/test_networks.py +++ b/podman/tests/integration/test_networks.py @@ -64,6 +64,13 @@ def test_network_crud(self): names = [i.name for i in nets] self.assertIn("integration_test", names) + with self.subTest("Get by ID"): + network = self.client.networks.get("integration_test") + net_id = network.id + assert isinstance(net_id, str) + network_by_id = self.client.networks.get(net_id) + self.assertEqual(network.name, network_by_id.name) + with self.subTest("Delete network"): network = self.client.networks.get("integration_test") network.remove(force=True)