Skip to content
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

Cv2 5589 singular queues downstream #123

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/queue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def send_message(self, queue_name: str, message: schemas.Message):
"""
Send a message to a specific queue.
"""
queue = self.get_or_create_queue(queue_name)
queue = self.get_or_create_queue(queue_name)[0]
message_data = {"MessageBody": json.dumps(message.dict())}
if queue_name.endswith('.fifo'):
message_data["MessageGroupId"] = message.body.id
Expand Down Expand Up @@ -169,7 +169,7 @@ def receive_messages(self, batch_size: int = 1):
"""
Receive messages from a queue.
"""
queue = self.get_or_create_queue(self.input_queue_name)
queue = self.get_or_create_queue(self.input_queue_name)[0]
return queue.receive_messages(MaxNumberOfMessages=min(batch_size, SQS_MAX_BATCH_SIZE))

def find_queue_by_name(self, queue_name: str) -> boto3.resources.base.ServiceResource:
Expand Down
22 changes: 16 additions & 6 deletions test/lib/queue/test_queue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pdb
import json
import os
import unittest
Expand Down Expand Up @@ -109,14 +108,25 @@ def test_process(self):

def test_receive_messages(self):
self.queue.input_queue = self.queue_name_input
# Mocking the queue and messages
mock_queue1 = MagicMock()
mock_queue1.receive_messages.return_value = [FakeSQSMessage(receipt_handle="blah", body=json.dumps({"body": {"id": 1, "callback_url": "http://example.com", "text": "This is a test"}})), FakeSQSMessage(receipt_handle="blah", body=json.dumps({"body": {"id": 2, "callback_url": "http://example.com", "text": "This is another test"}}))]
self.queue.get_or_create_queue = MagicMock(return_value=mock_queue1)
mock_queue1.receive_messages.return_value = [
FakeSQSMessage(
receipt_handle="blah",
body=json.dumps({"body": {"id": 1, "callback_url": "http://example.com", "text": "This is a test"}})
),
FakeSQSMessage(
receipt_handle="blah",
body=json.dumps({"body": {"id": 2, "callback_url": "http://example.com", "text": "This is another test"}})
)
]
# Set up get_or_create_queue to return mock_queue1
self.queue.get_or_create_queue = MagicMock(return_value=[mock_queue1])
received_messages = self.queue.receive_messages(5)
# Check if the right number of messages were received and the content is correct
# Assertions
self.assertEqual(len(received_messages), 2)
self.assertIn("a test", received_messages[0].body)
self.assertIn("another test", received_messages[1].body)
self.assertIn("a test", json.loads(received_messages[0].body)["body"]["text"])
self.assertIn("another test", json.loads(received_messages[1].body)["body"]["text"])

def test_restrict_queues_by_suffix(self):
queues = [
Expand Down
Loading