2018-08-18 18:46:01 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2018-08-18 18:46:01 +02:00
|
|
|
class NetlifyHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'netlify'
|
|
|
|
URL_TEMPLATE = u"/api/v1/external/netlify?stream={stream}&api_key={api_key}"
|
2019-07-04 21:00:56 +02:00
|
|
|
FIXTURE_DIR_NAME = "netlify"
|
2018-08-18 18:46:01 +02:00
|
|
|
|
|
|
|
def test_building_message(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"master"
|
2018-08-18 18:46:01 +02:00
|
|
|
expected_message = u'The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) on branch master is now building.'
|
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('deploy_building', expected_topic, expected_message,
|
2019-07-04 21:00:56 +02:00
|
|
|
content_type="application/json")
|
2018-08-18 18:46:01 +02:00
|
|
|
|
|
|
|
def test_created_message(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"master"
|
2018-08-18 18:46:01 +02:00
|
|
|
expected_message = u'The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) on branch master is now ready.'
|
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('deploy_created', expected_topic, expected_message,
|
2019-07-04 21:00:56 +02:00
|
|
|
content_type="application/json")
|
2018-08-18 18:46:01 +02:00
|
|
|
|
|
|
|
def test_failed_message(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"master"
|
2018-08-18 18:46:01 +02:00
|
|
|
expected_message = (u"The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) "
|
|
|
|
u"on branch master failed during stage 'building site': Build script returned non-zero exit code: 127"
|
|
|
|
)
|
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('deploy_failed', expected_topic, expected_message,
|
2019-07-04 21:00:56 +02:00
|
|
|
content_type="application/json")
|
2018-08-18 18:46:01 +02:00
|
|
|
|
|
|
|
def test_locked_message(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"master"
|
2018-08-18 18:46:01 +02:00
|
|
|
expected_message = (u"The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) "
|
|
|
|
u"on branch master is now locked."
|
|
|
|
)
|
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('deploy_locked', expected_topic, expected_message,
|
2019-07-04 21:00:56 +02:00
|
|
|
content_type="application/json")
|
2018-08-18 18:46:01 +02:00
|
|
|
|
|
|
|
def test_unlocked_message(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"master"
|
2018-08-18 18:46:01 +02:00
|
|
|
expected_message = (u"The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) "
|
|
|
|
u"on branch master is now unlocked."
|
|
|
|
)
|
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('deploy_unlocked', expected_topic, expected_message,
|
2019-07-04 21:00:56 +02:00
|
|
|
content_type="application/json")
|
2018-08-18 18:46:01 +02:00
|
|
|
|
|
|
|
def get_body(self, fixture_name: str) -> str:
|
|
|
|
return self.webhook_fixture_data("netlify", fixture_name, file_type="json")
|