hass-core/tests/components/google_mail/test_notify.py
Robert Hillis ad65fc27bc
Add Google Mail integration (#82637)
* Add Google Mail integration

* oops

* prettier

* Add email service

* adjustments

* update

* move email to notify

* break out services

* tweaks

* Add CC and BCC support

* drop scope check, breakout tests

* use abstract auth

* tweak

* bump dependency

* dependency bump

* remove oauth2client
2023-01-07 11:59:14 -08:00

76 lines
2 KiB
Python

"""Notify tests for the Google Mail integration."""
from unittest.mock import patch
import pytest
from voluptuous.error import Invalid
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
from homeassistant.core import HomeAssistant
from .conftest import BUILD, ComponentSetup
async def test_notify(
hass: HomeAssistant,
setup_integration: ComponentSetup,
) -> None:
"""Test service call draft email."""
await setup_integration()
with patch(BUILD) as mock_client:
await hass.services.async_call(
NOTIFY_DOMAIN,
"example_gmail_com",
{
"title": "Test",
"message": "test email",
"target": "text@example.com",
},
blocking=True,
)
assert len(mock_client.mock_calls) == 5
with patch(BUILD) as mock_client:
await hass.services.async_call(
NOTIFY_DOMAIN,
"example_gmail_com",
{
"title": "Test",
"message": "test email",
"target": "text@example.com",
"data": {"send": False},
},
blocking=True,
)
assert len(mock_client.mock_calls) == 5
async def test_notify_voluptuous_error(
hass: HomeAssistant,
setup_integration: ComponentSetup,
) -> None:
"""Test voluptuous error thrown when drafting email."""
await setup_integration()
with pytest.raises(Invalid) as ex:
await hass.services.async_call(
NOTIFY_DOMAIN,
"example_gmail_com",
{
"title": "Test",
"message": "test email",
},
blocking=True,
)
assert ex.match("recipient address required")
with pytest.raises(Invalid) as ex:
await hass.services.async_call(
NOTIFY_DOMAIN,
"example_gmail_com",
{
"title": "Test",
},
blocking=True,
)
assert ex.getrepr("required key not provided")