2017-11-16 00:43:10 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2017-02-08 18:43:16 +01:00
|
|
|
class HomeAssistantHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'homeassistant'
|
2018-03-16 22:53:50 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/homeassistant?&api_key={api_key}&stream={stream}"
|
2017-02-08 18:43:16 +01:00
|
|
|
FIXTURE_DIR_NAME = 'homeassistant'
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_simplereq(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "homeassistant"
|
2017-02-19 06:51:08 +01:00
|
|
|
expected_message = "The sun will be shining today!"
|
2017-02-08 18:43:16 +01:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('simplereq', expected_topic, expected_message,
|
2017-02-08 18:43:16 +01:00
|
|
|
content_type="application/x-www-form-urlencoded")
|
2017-02-19 06:51:08 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_req_with_title(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Weather forecast"
|
2017-02-19 06:51:08 +01:00
|
|
|
expected_message = "It will be 30 degrees Celsius out there today!"
|
2017-02-08 18:43:16 +01:00
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('reqwithtitle', expected_topic, expected_message,
|
2017-02-08 18:43:16 +01:00
|
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> str:
|
2018-04-20 03:57:21 +02:00
|
|
|
return self.webhook_fixture_data("homeassistant", fixture_name, file_type="json")
|