Skip to content

Commit 23e93b2

Browse files
committed
Remove static variables from rabbitmq.
1 parent d407859 commit 23e93b2

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

rabbitmq/testcontainers/rabbitmq/__init__.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ class RabbitMqContainer(DockerContainer):
2323
... connection = pika.BlockingConnection(rabbitmq.get_connection_params())
2424
... channel = connection.channel()
2525
"""
26-
27-
RABBITMQ_NODE_PORT = os.environ.get("RABBITMQ_NODE_PORT", 5672)
28-
RABBITMQ_DEFAULT_USER = os.environ.get("RABBITMQ_DEFAULT_USER", "guest")
29-
RABBITMQ_DEFAULT_PASS = os.environ.get("RABBITMQ_DEFAULT_PASS", "guest")
30-
3126
def __init__(self, image: str = "rabbitmq:latest", port: Optional[int] = None,
3227
username: Optional[str] = None, password: Optional[str] = None, **kwargs) -> None:
3328
"""Initialize the RabbitMQ test container.
@@ -39,14 +34,14 @@ def __init__(self, image: str = "rabbitmq:latest", port: Optional[int] = None,
3934
password: RabbitMQ password.
4035
"""
4136
super(RabbitMqContainer, self).__init__(image=image, **kwargs)
42-
self.RABBITMQ_NODE_PORT = port or int(self.RABBITMQ_NODE_PORT)
43-
self.RABBITMQ_DEFAULT_USER = username or self.RABBITMQ_DEFAULT_USER
44-
self.RABBITMQ_DEFAULT_PASS = password or self.RABBITMQ_DEFAULT_PASS
37+
self.port = port or int(os.environ.get("RABBITMQ_NODE_PORT", 5672))
38+
self.username = username or os.environ.get("RABBITMQ_DEFAULT_USER", "guest")
39+
self.password = password or os.environ.get("RABBITMQ_DEFAULT_PASS", "guest")
4540

46-
self.with_exposed_ports(self.RABBITMQ_NODE_PORT)
47-
self.with_env("RABBITMQ_NODE_PORT", self.RABBITMQ_NODE_PORT)
48-
self.with_env("RABBITMQ_DEFAULT_USER", self.RABBITMQ_DEFAULT_USER)
49-
self.with_env("RABBITMQ_DEFAULT_PASS", self.RABBITMQ_DEFAULT_PASS)
41+
self.with_exposed_ports(self.port)
42+
self.with_env("RABBITMQ_NODE_PORT", self.port)
43+
self.with_env("RABBITMQ_DEFAULT_USER", self.username)
44+
self.with_env("RABBITMQ_DEFAULT_PASS", self.password)
5045

5146
@wait_container_is_ready(pika.exceptions.IncompatibleProtocolError)
5247
def readiness_probe(self) -> bool:
@@ -63,12 +58,11 @@ def get_connection_params(self) -> pika.ConnectionParameters:
6358
For more details see:
6459
https://pika.readthedocs.io/en/latest/modules/parameters.html
6560
"""
66-
credentials = pika.PlainCredentials(username=self.RABBITMQ_DEFAULT_USER,
67-
password=self.RABBITMQ_DEFAULT_PASS)
61+
credentials = pika.PlainCredentials(username=self.username, password=self.password)
6862

6963
return pika.ConnectionParameters(
7064
host=self.get_container_host_ip(),
71-
port=self.get_exposed_port(self.RABBITMQ_NODE_PORT),
65+
port=self.get_exposed_port(self.port),
7266
credentials=credentials,
7367
)
7468

0 commit comments

Comments
 (0)