devtools: Add custom HTTP headers support to the integrations dev panel.

This commit introduces a simple field where the user can now specify custom
HTTP headers. This commit does not introduce an improved system for storing
HTTP headers as fixtures - such a change would modify both the existing unit
tests as well as this devtool.
This commit is contained in:
Hemanth V. Alluri
2019-05-16 12:53:15 +05:30
committed by Tim Abbott
parent 64b4fd5923
commit 2bd9c8cb42
7 changed files with 76 additions and 13 deletions

View File

@@ -15,7 +15,8 @@ class TestIntegrationsDevPanel(ZulipTestCase):
data = {
"url": url,
"body": body
"body": body,
"custom_headers": "",
}
response = self.client_post(target_url, data)
@@ -24,7 +25,7 @@ class TestIntegrationsDevPanel(ZulipTestCase):
expected_response = {"result": "error", "msg": "Internal server error"}
self.assertEqual(ujson.loads(response.content), expected_response)
def test_check_send_webhook_fixture_message_for_success(self) -> None:
def test_check_send_webhook_fixture_message_for_success_without_headers(self) -> None:
bot = get_user('webhook-bot@zulip.com', self.zulip_realm)
url = "/api/v1/external/airbrake?api_key={key}&stream=Denmark&topic=Airbrake Notifications".format(key=bot.api_key)
target_url = "/devtools/integrations/check_send_webhook_fixture_message"
@@ -34,6 +35,7 @@ class TestIntegrationsDevPanel(ZulipTestCase):
data = {
"url": url,
"body": body,
"custom_headers": "",
}
response = self.client_post(target_url, data)
@@ -45,6 +47,28 @@ class TestIntegrationsDevPanel(ZulipTestCase):
self.assertEqual(Stream.objects.get(id=latest_msg.recipient.type_id).name, "Denmark")
self.assertEqual(latest_msg.topic_name(), "Airbrake Notifications")
def test_check_send_webhook_fixture_message_for_success_with_headers(self) -> None:
bot = get_user('webhook-bot@zulip.com', self.zulip_realm)
url = "/api/v1/external/github?api_key={key}&stream=Denmark&topic=GitHub Notifications".format(key=bot.api_key)
target_url = "/devtools/integrations/check_send_webhook_fixture_message"
with open("zerver/webhooks/github/fixtures/ping_organization.json", "r") as f:
body = f.read()
data = {
"url": url,
"body": body,
"custom_headers": ujson.dumps({"X_GITHUB_EVENT": "ping"}),
}
response = self.client_post(target_url, data)
self.assertEqual(response.status_code, 200)
latest_msg = Message.objects.latest('id')
expected_message = "GitHub webhook has been successfully configured by eeshangarg."
self.assertEqual(latest_msg.content, expected_message)
self.assertEqual(Stream.objects.get(id=latest_msg.recipient.type_id).name, "Denmark")
self.assertEqual(latest_msg.topic_name(), "GitHub Notifications")
def test_get_fixtures_for_nonexistant_integration(self) -> None:
target_url = "/devtools/integrations/somerandomnonexistantintegration/fixtures"
response = self.client_get(target_url)