Repository navigation
adding rabbitmq container #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
646c46a
46acd11
7886b4f
79d9a65
9c6d74e
48e3f14
4d8069f
ad629c7
e42bd2a
f655277
4cd3354
7608f42
c4aed46
772069a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. You may obtain | ||
| # a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
| from .core.container import DockerContainer | ||
| from .core.waiting_utils import wait_container_is_ready | ||
| import os | ||
| import pika | ||
|
|
||
|
|
||
| class RabbitmqContainer(DockerContainer): | ||
| RABBITMQ_DEFAULT_USER = os.environ.get("RABBITMQ_DEFAULT_USER", "guest") | ||
| RABBITMQ_DEFAULT_PASS = os.environ.get("RABBITMQ_DEFAULT_PASS", "guest") | ||
| SERVICE_STARTED = r"Server startup complete;" | ||
|
|
||
| def __init__(self, image="rabbitmq:latest"): | ||
| super(RabbitmqContainer, self).__init__(image=image) | ||
| self.port_to_expose = 5672 | ||
| self.with_exposed_ports(self.port_to_expose) | ||
| self.queues = list() | ||
|
|
||
| def _configure(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method is not called at all, nowhere |
||
| self.with_env('RABBITMQ_DEFAULT_USER', 'guest') | ||
| self.with_env('RABBITMQ_DEFAULT_PASS', 'guest') | ||
|
|
||
| @wait_container_is_ready() | ||
| def get_connection_parameters(self): | ||
| credentials = pika.PlainCredentials(self.RABBITMQ_DEFAULT_USER, self.RABBITMQ_DEFAULT_PASS) | ||
| parameters = pika.ConnectionParameters(self.get_container_host_ip(), self.port_to_expose, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| '/', credentials) | ||
| return parameters | ||
|
|
||
| @wait_container_is_ready() | ||
| def get_connection(self): | ||
| return self.get_container_host_ip(), self.port_to_expose | ||
|
|
||
| @wait_container_is_ready() | ||
| def declare_queue(self, queue): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be a duplicate (in terms of signature) of the function in line 48. Should this be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to the logic - this method is supposed to declare multiple queues |
||
| a = list() | ||
| for q in queue: | ||
| a.append(self.declare_queue(q)) | ||
| return a | ||
|
|
||
| @wait_container_is_ready() | ||
| def declare_queue(self, queue): | ||
| cmd = "rabbitmqadmin declare queue name={}".format(queue) | ||
| return self.exec(cmd) | ||
|
|
||
| @wait_container_is_ready() | ||
| def declare_binding(self, src, dest): | ||
| cmd = "rabbitmqadmin declare binding source={} destination= {}".format(src, dest) | ||
| return self.exec(cmd) | ||
|
|
||
| @wait_container_is_ready() | ||
| def declare_exchange(self, name, type): | ||
| cmd = "rabbitmqadmin declare exchange name={} type={}".format(name, type) | ||
| return self.exec(cmd) | ||
|
|
||
| @wait_container_is_ready() | ||
| def declare_vhost(self, vhost): | ||
| cmd = "rabbitmqadmin declare exchange vhost={} type={}".format(vhost) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type is missing |
||
| return self.exec(cmd) | ||
|
|
||
| @wait_container_is_ready() | ||
| def declare_parameter(self, component, name, value): | ||
| cmd = "rabbitmqadmin declare parameter component={} name={} value={}".format(component, name, value) | ||
| return self.exec(cmd) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import time | ||
|
|
||
| from testcontainers.core.waiting_utils import wait_for_logs | ||
| from testcontainers.rabbitmq import RabbitmqContainer | ||
|
|
||
|
|
||
| def test_declare_queue(): | ||
| rabbitmq_container = RabbitmqContainer("rabbitmq:lastest") | ||
| queue_name = "test" | ||
| with rabbitmq_container as rabbit: | ||
| wait_for_logs(rabbit, RabbitmqContainer.SERVICE_STARTED, timeout=30, interval=1) | ||
| time.sleep(30) | ||
| assert rabbit.declare_queue(queue_name)[1] == b'queue declared\n' | ||
|
|
||
|
|
||
| def test_connection(): | ||
| rabbitmq_container = RabbitmqContainer("rabbitmq:lastest") | ||
| with rabbitmq_container as rabbit: | ||
| wait_for_logs(rabbit, RabbitmqContainer.SERVICE_STARTED, timeout=30, interval=1) | ||
| _, exposed_port = rabbit.get_connection() | ||
| assert exposed_port == 5672 | ||
|
|
||
|
|
||
| def test_declare_vhost(): | ||
| rabbitmq_container = RabbitmqContainer("rabbitmq:lastest") | ||
| vhost_name = "test" | ||
| with rabbitmq_container as rabbit: | ||
| wait_for_logs(rabbit, RabbitmqContainer.SERVICE_STARTED, timeout=30, interval=1) | ||
| time.sleep(30) | ||
|
dabrign marked this conversation as resolved.
Resolved
|
||
| assert rabbit.declare_vhost(vhost_name)[1] == b'queue declared\n' | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rabbitmq:latestdoes not haverabbitmqadmin, so all methods below which are using it do not work