Skip to content

Commit 5f5536a

Browse files
committed
Remove class-level variables from azurite.
1 parent 2bcb931 commit 5f5536a

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

azurite/testcontainers/azurite/__init__.py

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,11 @@ class AzuriteContainer(DockerContainer):
3939
... api_version="2019-12-12"
4040
... )
4141
"""
42-
43-
_AZURITE_ACCOUNT_NAME = os.environ.get("AZURITE_ACCOUNT_NAME", "devstoreaccount1")
44-
_AZURITE_ACCOUNT_KEY = os.environ.get("AZURITE_ACCOUNT_KEY", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDX"
45-
"J1OUzFT50uSRZ6IFsuFq2UVErCz4I6"
46-
"tq/K1SZFPTOtr/KBHBeksoGMGw==")
47-
48-
_BLOB_SERVICE_PORT = 10_000
49-
_QUEUE_SERVICE_PORT = 10_001
50-
_TABLE_SERVICE_PORT = 10_002
51-
52-
def __init__(self, image: str = "mcr.microsoft.com/azure-storage/azurite:latest",
53-
ports_to_expose: Optional[Iterable[int]] = None, **kwargs) -> None:
42+
def __init__(self, image: str = "mcr.microsoft.com/azure-storage/azurite:latest", *,
43+
ports_to_expose: Optional[Iterable[int]] = None, blob_service_port: int = 10_000,
44+
queue_service_port: int = 10_001, table_service_port: int = 10_002,
45+
account_name: Optional[str] = None, account_key: Optional[str] = None, **kwargs) \
46+
-> None:
5447
""" Constructs an AzuriteContainer.
5548
5649
Args:
@@ -59,41 +52,41 @@ def __init__(self, image: str = "mcr.microsoft.com/azure-storage/azurite:latest"
5952
**kwargs: Keyword arguments passed to super class.
6053
"""
6154
super().__init__(image=image, **kwargs)
62-
63-
if ports_to_expose is None:
64-
ports_to_expose = [
65-
self._BLOB_SERVICE_PORT,
66-
self._QUEUE_SERVICE_PORT,
67-
self._TABLE_SERVICE_PORT
68-
]
69-
70-
if len(ports_to_expose) == 0:
71-
raise ValueError("Expected a list with port numbers to expose")
55+
self.account_name = account_name or os.environ.get(
56+
"AZURITE_ACCOUNT_NAME", "devstoreaccount1")
57+
self.account_key = account_key or os.environ.get(
58+
"AZURITE_ACCOUNT_KEY", "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/"
59+
"K1SZFPTOtr/KBHBeksoGMGw==")
60+
61+
self.blob_service_port = blob_service_port
62+
self.queue_service_port = queue_service_port
63+
self.table_service_port = table_service_port
64+
if not ports_to_expose:
65+
ports_to_expose = [blob_service_port, queue_service_port, table_service_port]
7266

7367
self.with_exposed_ports(*ports_to_expose)
74-
self.with_env("AZURITE_ACCOUNTS",
75-
f"{self._AZURITE_ACCOUNT_NAME}:{self._AZURITE_ACCOUNT_KEY}")
68+
self.with_env("AZURITE_ACCOUNTS", f"{self.account_name}:{self.account_key}")
7669

7770
def get_connection_string(self) -> str:
7871
host_ip = self.get_container_host_ip()
7972
connection_string = f"DefaultEndpointsProtocol=http;" \
80-
f"AccountName={self._AZURITE_ACCOUNT_NAME};" \
81-
f"AccountKey={self._AZURITE_ACCOUNT_KEY};"
73+
f"AccountName={self.account_name};" \
74+
f"AccountKey={self.account_key};"
8275

83-
if self._BLOB_SERVICE_PORT in self.ports:
76+
if self.blob_service_port in self.ports:
8477
connection_string += f"BlobEndpoint=http://{host_ip}:" \
85-
f"{self.get_exposed_port(self._BLOB_SERVICE_PORT)}" \
86-
f"/{self._AZURITE_ACCOUNT_NAME};"
78+
f"{self.get_exposed_port(self.blob_service_port)}" \
79+
f"/{self.account_name};"
8780

88-
if self._QUEUE_SERVICE_PORT in self.ports:
81+
if self.queue_service_port in self.ports:
8982
connection_string += f"QueueEndpoint=http://{host_ip}:" \
90-
f"{self.get_exposed_port(self._QUEUE_SERVICE_PORT)}" \
91-
f"/{self._AZURITE_ACCOUNT_NAME};"
83+
f"{self.get_exposed_port(self.queue_service_port)}" \
84+
f"/{self.account_name};"
9285

93-
if self._TABLE_SERVICE_PORT in self.ports:
86+
if self.table_service_port in self.ports:
9487
connection_string += f"TableEndpoint=http://{host_ip}:" \
95-
f"{self.get_exposed_port(self._TABLE_SERVICE_PORT)}" \
96-
f"/{self._AZURITE_ACCOUNT_NAME};"
88+
f"{self.get_exposed_port(self.table_service_port)}" \
89+
f"/{self.account_name};"
9790

9891
return connection_string
9992

0 commit comments

Comments
 (0)