22import os
33import unittest
44import urllib .request
5- import uuid
65from typing import Optional
76
8- import docker
97from testcontainers .core .container import DockerContainer
8+ from testcontainers .core .network import Network
109from testcontainers .core .waiting_utils import wait_container_is_ready
1110
1211from zitadel_client .transport_options import TransportOptions
@@ -30,21 +29,21 @@ class TransportOptionsTest(unittest.TestCase):
3029 proxy_port : Optional [str ] = None
3130 ca_cert_path : Optional [str ] = None
3231 wiremock : DockerContainer = None
33- proxy_docker = None
34- docker_network = None
32+ proxy : DockerContainer = None
33+ network : Network = None
3534
3635 @classmethod
3736 def setup_class (cls ) -> None :
3837 cls .ca_cert_path = os .path .join (FIXTURES_DIR , "ca.pem" )
3938 keystore_path = os .path .join (FIXTURES_DIR , "keystore.p12" )
4039 squid_conf = os .path .join (FIXTURES_DIR , "squid.conf" )
4140
42- docker_client = docker .from_env ()
43- cls .network_name = f"zitadel-test-{ uuid .uuid4 ().hex [:8 ]} "
44- cls .docker_network = docker_client .networks .create (cls .network_name )
41+ cls .network = Network ().create ()
4542
4643 cls .wiremock = (
4744 DockerContainer ("wiremock/wiremock:3.3.1" )
45+ .with_network (cls .network )
46+ .with_network_aliases ("wiremock" )
4847 .with_exposed_ports (8080 , 8443 )
4948 .with_volume_mapping (keystore_path , "/home/wiremock/keystore.p12" , mode = "ro" )
5049 .with_command (
@@ -57,22 +56,18 @@ def setup_class(cls) -> None:
5756 )
5857 cls .wiremock .start ()
5958
60- wiremock_id = cls .wiremock ._container .id
61- cls .docker_network .connect (wiremock_id , aliases = ["wiremock" ])
62-
63- cls .proxy_docker = docker_client .containers .run (
64- "ubuntu/squid:6.10-24.10_beta" ,
65- detach = True ,
66- network = cls .network_name ,
67- ports = {"3128/tcp" : None },
68- volumes = {squid_conf : {"bind" : "/etc/squid/squid.conf" , "mode" : "ro" }},
59+ cls .proxy = (
60+ DockerContainer ("ubuntu/squid:6.10-24.10_beta" )
61+ .with_network (cls .network )
62+ .with_exposed_ports (3128 )
63+ .with_volume_mapping (squid_conf , "/etc/squid/squid.conf" , mode = "ro" )
6964 )
70- cls .proxy_docker . reload ()
65+ cls .proxy . start ()
7166
7267 cls .host = cls .wiremock .get_container_host_ip ()
7368 cls .http_port = cls .wiremock .get_exposed_port (8080 )
7469 cls .https_port = cls .wiremock .get_exposed_port (8443 )
75- cls .proxy_port = cls .proxy_docker . ports [ " 3128/tcp" ][ 0 ][ "HostPort" ]
70+ cls .proxy_port = cls .proxy . get_exposed_port ( 3128 )
7671
7772 _wait_for_wiremock (cls .host , cls .http_port )
7873
@@ -151,13 +146,12 @@ def setup_class(cls) -> None:
151146
152147 @classmethod
153148 def teardown_class (cls ) -> None :
154- if cls .proxy_docker is not None :
155- cls .proxy_docker .stop ()
156- cls .proxy_docker .remove ()
149+ if cls .proxy is not None :
150+ cls .proxy .stop ()
157151 if cls .wiremock is not None :
158152 cls .wiremock .stop ()
159- if cls .docker_network is not None :
160- cls .docker_network .remove ()
153+ if cls .network is not None :
154+ cls .network .remove ()
161155
162156 def test_custom_ca_cert (self ) -> None :
163157 zitadel = Zitadel .with_client_credentials (
0 commit comments