2016-09-20 22:51:11 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-11-05 05:30:31 +01:00
|
|
|
import urllib
|
2017-11-16 00:43:10 +01:00
|
|
|
from typing import Text
|
|
|
|
|
2016-11-10 19:30:09 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2017-08-25 06:37:47 +02:00
|
|
|
from zerver.models import get_realm, get_user
|
2016-09-20 22:51:11 +02:00
|
|
|
|
|
|
|
class TravisHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'travis'
|
|
|
|
URL_TEMPLATE = u"/api/v1/external/travis?stream={stream}&api_key={api_key}&topic=builds"
|
|
|
|
FIXTURE_DIR_NAME = 'travis'
|
2017-03-06 07:12:40 +01:00
|
|
|
TOPIC = 'builds'
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_travis_message(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
"""
|
|
|
|
Build notifications are generated by Travis after build completes.
|
|
|
|
|
|
|
|
The subject describes the repo and Stash "project". The
|
|
|
|
content describes the commits pushed.
|
|
|
|
"""
|
2018-02-07 03:26:08 +01:00
|
|
|
expected_message = (u"Author: josh_mandel\nBuild status: Passed :thumbs_up:\n"
|
2016-09-20 22:51:11 +02:00
|
|
|
u"Details: [changes](https://github.com/hl7-fhir/fhir-sv"
|
|
|
|
u"n/compare/6dccb98bcfd9...6c457d366a31), [build log](ht"
|
|
|
|
u"tps://travis-ci.org/hl7-fhir/fhir-svn/builds/92495257)")
|
|
|
|
|
|
|
|
self.send_and_test_stream_message(
|
|
|
|
'build',
|
2017-03-06 07:12:40 +01:00
|
|
|
self.TOPIC,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded"
|
|
|
|
)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_ignore_travis_pull_request_by_default(self) -> None:
|
2017-08-25 06:37:47 +02:00
|
|
|
self.subscribe(self.test_user, self.STREAM_NAME)
|
2017-03-06 07:12:40 +01:00
|
|
|
result = self.client_post(
|
|
|
|
self.url,
|
|
|
|
self.get_body('pull_request'),
|
|
|
|
content_type="application/x-www-form-urlencoded"
|
|
|
|
)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
msg = self.get_last_message()
|
|
|
|
self.assertNotEquals(msg.subject, self.TOPIC)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_travis_pull_requests_are_not_ignored_when_applicable(self) -> None:
|
2017-03-06 07:12:40 +01:00
|
|
|
self.url = "{}&ignore_pull_requests=false".format(self.build_webhook_url())
|
2018-02-07 03:26:08 +01:00
|
|
|
expected_message = (u"Author: josh_mandel\nBuild status: Passed :thumbs_up:\n"
|
2017-03-06 07:12:40 +01:00
|
|
|
u"Details: [changes](https://github.com/hl7-fhir/fhir-sv"
|
|
|
|
u"n/compare/6dccb98bcfd9...6c457d366a31), [build log](ht"
|
|
|
|
u"tps://travis-ci.org/hl7-fhir/fhir-svn/builds/92495257)")
|
|
|
|
|
|
|
|
self.send_and_test_stream_message(
|
|
|
|
'pull_request',
|
|
|
|
self.TOPIC,
|
2016-09-20 22:51:11 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded"
|
|
|
|
)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def get_body(self, fixture_name: Text) -> Text:
|
2016-09-20 22:51:11 +02:00
|
|
|
return urllib.parse.urlencode({'payload': self.fixture_data("travis", fixture_name, file_type="json")})
|