test_callmebot_url_encoding.py 1011 B

1234567891011121314151617181920212223242526272829
  1. """CallMeBot gets the phone number and API key URL-encoded.
  2. They went into the query string as typed, so a phone number written as
  3. "+49 151 2345678" reached CallMeBot without its "+", which a query string reads
  4. as a space.
  5. """
  6. from unittest.mock import AsyncMock, MagicMock
  7. from urllib.parse import parse_qs, urlparse
  8. import pytest
  9. from backend.app.services.notification_service import NotificationService
  10. @pytest.mark.asyncio
  11. async def test_the_phone_and_key_arrive_as_typed():
  12. service = NotificationService()
  13. client = MagicMock()
  14. client.get = AsyncMock(return_value=MagicMock(status_code=200, text="ok"))
  15. service._get_client = AsyncMock(return_value=client)
  16. ok, _ = await service._send_callmebot({"phone": "+49 151 2345678", "apikey": "12&34"}, "Done: 100%")
  17. assert ok is True
  18. query = parse_qs(urlparse(client.get.await_args.args[0]).query)
  19. assert query["phone"] == ["+49 151 2345678"]
  20. assert query["apikey"] == ["12&34"]
  21. assert query["text"] == ["Done: 100%"]