Skip to content

Commit

Permalink
Fix test_attachments test
Browse files Browse the repository at this point in the history
  • Loading branch information
Era-Dorta committed Oct 6, 2024
1 parent 24c402c commit acc08af
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tests/test_message.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import base64
import unittest
from unittest.mock import AsyncMock, patch

from unittest.mock import AsyncMock, patch, Mock
import aiohttp
from signalbot import Message, MessageType
from signalbot.api import SignalAPI
from signalbot.utils import ChatTestCase, SendMessagesMock, ReceiveMessagesMock


class TestMessage(unittest.IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -77,9 +78,16 @@ async def test_read_reaction(self):
self.assertEqual(message.reaction, "👍")

@patch("aiohttp.ClientSession.get", new_callable=AsyncMock)
async def test_attachments(self, mock):
mock.return_value = b"test"
expected_base64_bytes = base64.b64encode(mock.return_value)
async def test_attachments(self, mock_get):
attachment_bytes_str = b"test"

mock_response = AsyncMock(spec=aiohttp.ClientResponse)
mock_response.raise_for_status = Mock()
mock_response.content.read = AsyncMock(return_value=attachment_bytes_str)

mock_get.return_value = mock_response

expected_base64_bytes = base64.b64encode(attachment_bytes_str)
expected_base64_str = str(expected_base64_bytes, encoding="utf-8")

message = await Message.parse(
Expand Down

0 comments on commit acc08af

Please sign in to comment.