integrations: Add test event handler to Solano.

This commit is contained in:
Tomasz Kolek 2017-04-11 08:58:23 +02:00 committed by Tim Abbott
parent d74f72f08f
commit 2a55eff44b
3 changed files with 55 additions and 3 deletions

View File

@ -0,0 +1,37 @@
{
"event": "test",
"timestamp": "2015-08-25T00:58:27Z",
"session": 351279,
"guid": "c946783126c9e74291d24465f0a60",
"url": "https://ci.solanolabs.com/1/reports/351279",
"parent_session": 351278,
"profile_name": "default",
"commit_id": "38d4d2548e85729e138fdba32e08421bb899ba37",
"committers": [],
"status": "passed",
"counts": {
"notstarted": 0,
"started": 0,
"passed": 234.0,
"failed": 0.0,
"pending": 3.0,
"skipped": 0.0,
"error": 0.0
},
"workers": 24,
"stopped_by": "user@mycompany.com",
"timing": {
"ci_received_at": 1475250402.480408,
"queue_first_seen_at": 1475250412.841408,
"queue_first_allowed_at": 1475250492.863428,
"workers_assigned_at": 1475250493.136248
},
"branch": "production",
"ref": "refs/head/production",
"repository": {
"name": "repo_name",
"url": "ssh://git@github.com/organization_name/repo_name",
"org_name": "organization_name"
},
"xid": "372da4f69"
}

View File

@ -52,6 +52,14 @@ class SolanoHookTests(WebhookTestCase):
self.send_and_test_stream_message('received', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def test_solano_test_message(self):
# type: () -> None
expected_topic = u'build update'
expected_message = "Solano webhook set up correctly"
self.send_and_test_stream_message('test', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name):
# type: (Text) -> Text
return self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name, file_type="json")

View File

@ -7,11 +7,9 @@ from django.utils.translation import ugettext as _
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.actions import check_send_message
from zerver.lib.response import json_success, json_error
from zerver.lib.validator import check_dict, check_list, check_string
from zerver.models import UserProfile, Client
from typing import Any, Callable, Dict, Optional
import ujson
from typing import Any, Dict
@api_key_only_webhook_view('SolanoLabs')
@ -21,6 +19,9 @@ def api_solano_webhook(request, user_profile, client,
topic=REQ(default='build update'),
payload=REQ(argument_type='body')):
# type: (HttpRequest, UserProfile, Client, str, str, Dict[str, Any]) -> HttpResponse
event = payload.get('event')
if event == 'test':
return handle_test_event(user_profile, client, stream, topic)
try:
try:
author = payload['committers'][0]
@ -66,3 +67,9 @@ def api_solano_webhook(request, user_profile, client,
check_send_message(user_profile, client, 'stream', [stream], topic, body)
return json_success()
def handle_test_event(user_profile, client, stream, topic):
# type: (UserProfile, Client, str, str) -> HttpResponse
body = 'Solano webhook set up correctly'
check_send_message(user_profile, client, 'stream', [stream], topic, body)
return json_success()