mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Unhide facebook tests (#118867)
This commit is contained in:
parent
279483ddb0
commit
6de26ca811
@ -10,13 +10,15 @@ from homeassistant.core import HomeAssistant
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def facebook():
|
def facebook() -> fb.FacebookNotificationService:
|
||||||
"""Fixture for facebook."""
|
"""Fixture for facebook."""
|
||||||
access_token = "page-access-token"
|
access_token = "page-access-token"
|
||||||
return fb.FacebookNotificationService(access_token)
|
return fb.FacebookNotificationService(access_token)
|
||||||
|
|
||||||
|
|
||||||
async def test_send_simple_message(hass: HomeAssistant, facebook) -> None:
|
async def test_send_simple_message(
|
||||||
|
hass: HomeAssistant, facebook: fb.FacebookNotificationService
|
||||||
|
) -> None:
|
||||||
"""Test sending a simple message with success."""
|
"""Test sending a simple message with success."""
|
||||||
with requests_mock.Mocker() as mock:
|
with requests_mock.Mocker() as mock:
|
||||||
mock.register_uri(requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK)
|
mock.register_uri(requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK)
|
||||||
@ -40,7 +42,9 @@ async def test_send_simple_message(hass: HomeAssistant, facebook) -> None:
|
|||||||
assert mock.last_request.qs == expected_params
|
assert mock.last_request.qs == expected_params
|
||||||
|
|
||||||
|
|
||||||
async def test_send_multiple_message(hass: HomeAssistant, facebook) -> None:
|
async def test_send_multiple_message(
|
||||||
|
hass: HomeAssistant, facebook: fb.FacebookNotificationService
|
||||||
|
) -> None:
|
||||||
"""Test sending a message to multiple targets."""
|
"""Test sending a message to multiple targets."""
|
||||||
with requests_mock.Mocker() as mock:
|
with requests_mock.Mocker() as mock:
|
||||||
mock.register_uri(requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK)
|
mock.register_uri(requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK)
|
||||||
@ -66,7 +70,9 @@ async def test_send_multiple_message(hass: HomeAssistant, facebook) -> None:
|
|||||||
assert request.qs == expected_params
|
assert request.qs == expected_params
|
||||||
|
|
||||||
|
|
||||||
async def test_send_message_attachment(hass: HomeAssistant, facebook) -> None:
|
async def test_send_message_attachment(
|
||||||
|
hass: HomeAssistant, facebook: fb.FacebookNotificationService
|
||||||
|
) -> None:
|
||||||
"""Test sending a message with a remote attachment."""
|
"""Test sending a message with a remote attachment."""
|
||||||
with requests_mock.Mocker() as mock:
|
with requests_mock.Mocker() as mock:
|
||||||
mock.register_uri(requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK)
|
mock.register_uri(requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK)
|
||||||
@ -95,32 +101,36 @@ async def test_send_message_attachment(hass: HomeAssistant, facebook) -> None:
|
|||||||
expected_params = {"access_token": ["page-access-token"]}
|
expected_params = {"access_token": ["page-access-token"]}
|
||||||
assert mock.last_request.qs == expected_params
|
assert mock.last_request.qs == expected_params
|
||||||
|
|
||||||
async def test_send_targetless_message(hass, facebook):
|
|
||||||
"""Test sending a message without a target."""
|
|
||||||
with requests_mock.Mocker() as mock:
|
|
||||||
mock.register_uri(
|
|
||||||
requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK
|
|
||||||
)
|
|
||||||
|
|
||||||
facebook.send_message(message="going nowhere")
|
async def test_send_targetless_message(
|
||||||
assert not mock.called
|
hass: HomeAssistant, facebook: fb.FacebookNotificationService
|
||||||
|
) -> None:
|
||||||
|
"""Test sending a message without a target."""
|
||||||
|
with requests_mock.Mocker() as mock:
|
||||||
|
mock.register_uri(requests_mock.POST, fb.BASE_URL, status_code=HTTPStatus.OK)
|
||||||
|
|
||||||
async def test_send_message_with_400(hass, facebook):
|
facebook.send_message(message="going nowhere")
|
||||||
"""Test sending a message with a 400 from Facebook."""
|
assert not mock.called
|
||||||
with requests_mock.Mocker() as mock:
|
|
||||||
mock.register_uri(
|
|
||||||
requests_mock.POST,
|
async def test_send_message_with_400(
|
||||||
fb.BASE_URL,
|
hass: HomeAssistant, facebook: fb.FacebookNotificationService
|
||||||
status_code=HTTPStatus.BAD_REQUEST,
|
) -> None:
|
||||||
json={
|
"""Test sending a message with a 400 from Facebook."""
|
||||||
"error": {
|
with requests_mock.Mocker() as mock:
|
||||||
"message": "Invalid OAuth access token.",
|
mock.register_uri(
|
||||||
"type": "OAuthException",
|
requests_mock.POST,
|
||||||
"code": 190,
|
fb.BASE_URL,
|
||||||
"fbtrace_id": "G4Da2pFp2Dp",
|
status_code=HTTPStatus.BAD_REQUEST,
|
||||||
}
|
json={
|
||||||
},
|
"error": {
|
||||||
)
|
"message": "Invalid OAuth access token.",
|
||||||
facebook.send_message(message="nope!", target=["+15555551234"])
|
"type": "OAuthException",
|
||||||
assert mock.called
|
"code": 190,
|
||||||
assert mock.call_count == 1
|
"fbtrace_id": "G4Da2pFp2Dp",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
facebook.send_message(message="nope!", target=["+15555551234"])
|
||||||
|
assert mock.called
|
||||||
|
assert mock.call_count == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user