Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed Jun 18, 2024
1 parent eb67d13 commit 5dd53ef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from lib.helpers import get_class
from lib import schemas
from lib.cache import Cache
class Model(ABC):
BATCH_SIZE = 1
def __init__(self):
Expand Down
5 changes: 4 additions & 1 deletion test/lib/model/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def test_respond_with_single_video(self):
mock_process.assert_called_once_with(video)
self.assertEqual(result, [video])

def test_respond_with_multiple_videos(self):
@patch('lib.cache.Cache')
def test_respond_with_multiple_videos(self, mock_cache):
mock_cache.get_cached_result.return_value = None
mock_cache.set_cached_result.return_value = True
videos = [schemas.parse_message({"body": {"id": "123", "callback_url": "http://blah.com?callback_id=123", "url": "http://example.com/video.mp4"}, "model_name": "video__Model"}), schemas.parse_message({"body": {"id": "123", "callback_url": "http://blah.com?callback_id=123", "url": "http://example.com/video2.mp4"}, "model_name": "video__Model"})]
mock_process = MagicMock()
self.video_model.process = mock_process
Expand Down
8 changes: 4 additions & 4 deletions test/lib/queue/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ def test_delete_messages_from_queue(self, mock_logger):
mock_logger.assert_called_with(f"Deleting message: {mock_messages[-1]}")

def test_push_message(self):
message_to_push = schemas.parse_message({"body": {"id": 1, "callback_url": "http://example.com", "text": "This is a test"}, "model_name": "mean_tokens__Model"})
message_to_push = schemas.parse_message({"body": {"id": 1, "content_hash": None, "callback_url": "http://example.com", "text": "This is a test"}, "model_name": "mean_tokens__Model"})
# Call push_message
returned_message = self.queue.push_message(self.queue_name_output, message_to_push)
# Check if the message was correctly serialized and sent
self.mock_output_queue.send_message.assert_called_once_with(MessageBody='{"body": {"id": 1, "callback_url": "http://example.com", "url": null, "text": "This is a test", "raw": {}, "parameters": {}, "result": {"hash_value": null}}, "model_name": "mean_tokens__Model", "retry_count": 0}')
self.mock_output_queue.send_message.assert_called_once_with(MessageBody='{"body": {"id": 1, "content_hash": null, "callback_url": "http://example.com", "url": null, "text": "This is a test", "raw": {}, "parameters": {}, "result": {"hash_value": null}}, "model_name": "mean_tokens__Model", "retry_count": 0}')
self.assertEqual(returned_message, message_to_push)

def test_push_to_dead_letter_queue(self):
message_to_push = schemas.parse_message({"body": {"id": 1, "callback_url": "http://example.com", "text": "This is a test"}, "model_name": "mean_tokens__Model"})
message_to_push = schemas.parse_message({"body": {"id": 1, "content_hash": None, "callback_url": "http://example.com", "text": "This is a test"}, "model_name": "mean_tokens__Model"})
# Call push_to_dead_letter_queue
self.queue.push_to_dead_letter_queue(message_to_push)
# Check if the message was correctly serialized and sent to the DLQ
self.mock_dlq_queue.send_message.assert_called_once_with(MessageBody='{"body": {"id": 1, "callback_url": "http://example.com", "url": null, "text": "This is a test", "raw": {}, "parameters": {}, "result": {"hash_value": null}}, "model_name": "mean_tokens__Model", "retry_count": 0}')
self.mock_dlq_queue.send_message.assert_called_once_with(MessageBody='{"body": {"id": 1,"content_hash": null, "callback_url": "http://example.com", "url": null, "text": "This is a test", "raw": {}, "parameters": {}, "result": {"hash_value": null}}, "model_name": "mean_tokens__Model", "retry_count": 0}')

def test_increment_message_error_counts_exceed_max_retries(self):
message_body = {
Expand Down

0 comments on commit 5dd53ef

Please sign in to comment.