From 7dfacbc387af55bd92ccbb93ae2b8d047dc3edc9 Mon Sep 17 00:00:00 2001 From: Olivier Giorgis <ogiorgis@logilab.fr> Date: Thu, 25 Jul 2024 12:18:00 +0200 Subject: [PATCH] add rabbitMQ in docker-compose --- docker-compose.yaml | 23 +++++++++++++++++++++++ tests/pulse_utils.py | 6 +++--- tests/test_integration.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 tests/test_integration.py diff --git a/docker-compose.yaml b/docker-compose.yaml index 0d12bd5..b392d3c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,3 +2,26 @@ services: sync: build: . command: ['pytest', 'tests', '-p', 'no:cacheprovider'] + environment: + - RABBITMQ=true + depends_on: + pulse: + condition: service_healthy + networks: + - pulse_network + + pulse: + image: rabbitmq:3-management-alpine + healthcheck: + test: rabbitmq-diagnostics -q ping + interval: 5s + timeout: 2s + retries: 1 + ports: + - 15672:15672 + networks: + - pulse_network + +networks: + pulse_network: + driver: bridge diff --git a/tests/pulse_utils.py b/tests/pulse_utils.py index a4b8aae..5c7c20c 100644 --- a/tests/pulse_utils.py +++ b/tests/pulse_utils.py @@ -8,7 +8,7 @@ HERE = Path(__file__).parent -def send_pulse_message(pulse_config, payload): +def send_pulse_message(pulse_config, payload, ssl=True): """Send a pulse message The routing key will be constructed from the repository URL. The Pulse message will be constructed from the specified payload @@ -29,7 +29,7 @@ def send_pulse_message(pulse_config, payload): userid=userid, password=password, connect_timeout=100, - ssl=True, + ssl=ssl, ) connection.connect() @@ -55,7 +55,7 @@ def send_pulse_message(pulse_config, payload): "exchange": exchange, "routing_key": routing_key, "serializer": "json", - "sent": datetime.utcnow().isoformat(), + "sent": datetime.now(), }, } diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..016ddb7 --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,34 @@ +import os +import pytest + +import pulse_utils + +NO_RABBITMQ = not (os.getenv("RABBITMQ") == "true") + + +@pytest.fixture +def pulse_config(): + return { + "userid": "guest", + "host": "pulse", + "port": 5672, + "exchange": "exchange/guest/test", + "routing_key": "#", + "queue": "queue/guest/test", + "password": "guest", + } + + +@pytest.mark.skipif(NO_RABBITMQ, reason="Test doesn't work without rabbitMq") +def test_send(pulse_config): + payload = { + "type": "tag", + "repo_url": "repo.git", + "tag": "Tag", + "commit": "sha", + "time": 0, + "pushid": 0, + "user": "user", + "push_json_url": "push_json_url", + } + pulse_utils.send_pulse_message(pulse_config, payload, ssl=False)