webhook tests: Remove needless get_body functions.

These all did essentially what the parent implementation
does, except for checking that it's valid json.
This commit is contained in:
Steve Howell
2020-08-20 18:29:32 +00:00
committed by Tim Abbott
parent 7fbe08f515
commit 6d65af1790
31 changed files with 10 additions and 96 deletions

View File

@@ -154,6 +154,3 @@ Job: [#2722 System - Updates - Ubuntu](http://awx.example.co.uk/#/jobs/playbook/
"(http://awx.example.co.uk/#/jobs/system/2721) failed.")
self.check_webhook("system_job_failed", expected_topic, expected_message)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("ansibletower", fixture_name, file_type="json")

View File

@@ -5,6 +5,7 @@ from zerver.webhooks.appfollow.view import convert_markdown
class AppFollowHookTests(WebhookTestCase):
STREAM_NAME = 'appfollow'
URL_TEMPLATE = "/api/v1/external/appfollow?stream={stream}&api_key={api_key}"
FIXTURE_DIR_NAME = 'appfollow'
def test_sample(self) -> None:
expected_topic = "Webhook integration was successful."
@@ -55,9 +56,6 @@ Acme enables me to manage the flow of information quite well. I only wish I coul
)
self.URL_TEMPLATE = original_url_template
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("appfollow", fixture_name, file_type="json")
class ConvertMarkdownTest(ZulipTestCase):
def test_convert_bold(self) -> None:
self.assertEqual(convert_markdown("*test message*"), "**test message**")

View File

@@ -33,6 +33,3 @@ class AppveyorHookTests(WebhookTestCase):
""".strip()
self.check_webhook("appveyor_build_failure", expected_topic, expected_message)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("appveyor", fixture_name, file_type="json")

View File

@@ -7,6 +7,7 @@ from zerver.lib.test_classes import WebhookTestCase
class BeeminderHookTests(WebhookTestCase):
STREAM_NAME = 'beeminder'
URL_TEMPLATE = "/api/v1/external/beeminder?api_key={api_key}&stream={stream}"
FIXTURE_DIR_NAME = "beeminder"
@patch('zerver.webhooks.beeminder.view.time.time')
def test_beeminder_derail(self, time: Any) -> None:
@@ -36,6 +37,3 @@ You are going to derail from goal **gainweight** in **5.6 hours**. You need **+2
self.check_webhook(
"derail_worried", expected_topic, expected_message, content_type="application/json"
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("beeminder", fixture_name, file_type="json")

View File

@@ -86,6 +86,3 @@ class BitbucketHookTests(WebhookTestCase):
result = self.api_post(self.test_user, self.url, payload, content_type="application/json,")
self.assertFalse(check_send_webhook_message_mock.called)
self.assert_json_success(result)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data(self.FIXTURE_DIR_NAME, fixture_name)

View File

@@ -43,6 +43,3 @@ Your service is slow, but nearly flawless! Keep up the good work!
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("delighted", fixture_name, file_type="json")

View File

@@ -3,6 +3,7 @@ from zerver.lib.test_classes import WebhookTestCase
class DialogflowHookTests(WebhookTestCase):
URL_TEMPLATE = "/api/v1/external/dialogflow?api_key={api_key}&email=AARON@zulip.com"
FIXTURE_DIR_NAME = "dialogflow"
def test_dialogflow_default(self) -> None:
self.url = self.build_webhook_url(
@@ -39,8 +40,3 @@ class DialogflowHookTests(WebhookTestCase):
)
expected_message = "DialogFlow couldn't process your query."
self.send_and_test_private_message("exception", expected_message)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("dialogflow",
fixture_name,
file_type="json")

View File

@@ -18,9 +18,6 @@ class DropboxHookTests(WebhookTestCase):
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("dropbox", fixture_name, file_type="json")
def test_verification_request(self) -> None:
self.subscribe(self.test_user, self.STREAM_NAME)
get_params = {'stream_name': self.STREAM_NAME,

View File

@@ -4,6 +4,7 @@ from zerver.lib.test_classes import WebhookTestCase
class FlockHookTests(WebhookTestCase):
STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/flock?api_key={api_key}&stream={stream}"
FIXTURE_DIR_NAME = "flock"
def test_flock_message(self) -> None:
expected_topic = "Flock notifications"
@@ -74,6 +75,3 @@ class FlockHookTests(WebhookTestCase):
self.check_webhook(
"todo", expected_topic, expected_message, content_type="application/json"
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("flock", fixture_name, file_type="json")

View File

@@ -6,6 +6,7 @@ from zerver.lib.test_classes import WebhookTestCase
class FreshdeskHookTests(WebhookTestCase):
STREAM_NAME = 'freshdesk'
URL_TEMPLATE = "/api/v1/external/freshdesk?stream={stream}"
FIXTURE_DIR_NAME = "freshdesk"
def test_ticket_creation(self) -> None:
"""
@@ -104,6 +105,3 @@ Requester \u2603 Bob <requester-bob@example.com> created [ticket #12](http://tes
""".strip()
self.api_stream_message(self.test_user, "inline_images", expected_topic, expected_message,
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("freshdesk", fixture_name, file_type="json")

View File

@@ -210,6 +210,3 @@ class FrontHookTests(WebhookTestCase):
content_type="application/x-www-form-urlencoded")
self.assert_json_error(result, "Unknown webhook request")
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data('front', fixture_name, file_type="json")

View File

@@ -34,6 +34,3 @@ class GocdHookTests(WebhookTestCase):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("gocd", fixture_name, file_type="json")

View File

@@ -33,6 +33,3 @@ class GoSquaredHookTests(WebhookTestCase):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("gosquared", fixture_name, file_type="json")

View File

@@ -60,6 +60,3 @@ The panel has no data.
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("grafana", fixture_name, file_type="json")

View File

@@ -72,6 +72,3 @@ New Prospect Application Trisha Troy (ID: 968190), applying for:
result = self.client_post(self.url, payload, content_type=self.CONTENT_TYPE)
self.assertFalse(check_send_webhook_message_mock.called)
self.assert_json_success(result)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("greenhouse", fixture_name, file_type="json")

View File

@@ -123,6 +123,3 @@ This is a note added to a ticket
expected_message,
content_type="application/x-ww-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("groove", fixture_name, file_type="json")

View File

@@ -6,6 +6,7 @@ from zerver.lib.test_classes import WebhookTestCase
class HarborHookTests(WebhookTestCase):
STREAM_NAME = "harbor"
URL_TEMPLATE = "/api/v1/external/harbor?api_key={api_key}&stream={stream}"
FIXTURE_DIR_NAME = "harbor"
def test_push_image(self) -> None:
expected_topic = "example/test"
@@ -35,6 +36,3 @@ Image scan completed for `example/test:latest`. Vulnerabilities by severity:
""".strip()
self.check_webhook("scanning_completed", expected_topic, expected_message)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("harbor", fixture_name, file_type="json")

View File

@@ -8,7 +8,7 @@ class HelloWorldHookTests(WebhookTestCase):
STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/helloworld?&api_key={api_key}&stream={stream}"
PM_URL_TEMPLATE = "/api/v1/external/helloworld?&api_key={api_key}"
FIXTURE_DIR_NAME = 'hello'
FIXTURE_DIR_NAME = "helloworld"
# Note: Include a test function per each distinct message condition your integration supports
def test_hello_message(self) -> None:
@@ -66,6 +66,3 @@ class HelloWorldHookTests(WebhookTestCase):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("helloworld", fixture_name, file_type="json")

View File

@@ -27,6 +27,3 @@ class HomeAssistantHookTests(WebhookTestCase):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("homeassistant", fixture_name, file_type="json")

View File

@@ -37,6 +37,3 @@ State changed to **Not Responding**:
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("insping", fixture_name, file_type="json")

View File

@@ -219,6 +219,3 @@ New user created:
self.check_webhook(
"user_unsubscribed", "Contact: Eeshan Garg", "User unsubscribed from emails.",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data('intercom', fixture_name, file_type="json")

View File

@@ -7,6 +7,7 @@ from zerver.lib.users import get_api_key
class JiraHookTests(WebhookTestCase):
STREAM_NAME = 'jira'
URL_TEMPLATE = "/api/v1/external/jira?api_key={api_key}&stream={stream}"
FIXTURE_DIR_NAME = "jira"
def test_custom_stream(self) -> None:
api_key = get_api_key(self.test_user)
@@ -193,9 +194,6 @@ Adding a comment. Oh, what a comment it is!
self.check_webhook("change_status_v1", expected_topic, expected_message)
self.check_webhook("change_status_v2", expected_topic, expected_message)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data('jira', fixture_name)
def test_comment_event_comment_created(self) -> None:
expected_topic = "SP-1: Add support for newer format Jira issue comment events"
expected_message = """Hemanth V. Alluri commented on issue: *"Add support for newer format Jira issue comment events"*\n``` quote\nSounds like its pretty important. Ill get this fixed ASAP!\n```"""

View File

@@ -24,6 +24,3 @@ Children up and down the country are \u2026
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("mention", fixture_name, file_type="json")

View File

@@ -51,6 +51,3 @@ class NetlifyHookTests(WebhookTestCase):
self.check_webhook(
"deploy_unlocked", expected_topic, expected_message, content_type="application/json"
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("netlify", fixture_name, file_type="json")

View File

@@ -232,6 +232,3 @@ class OpsGenieHookTests(WebhookTestCase):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("opsgenie", fixture_name, file_type="json")

View File

@@ -130,6 +130,3 @@ New [Error](http://app.raygun.io/error-url) occurred:
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("raygun", fixture_name, file_type="json")

View File

@@ -8,6 +8,7 @@ from zerver.lib.test_classes import WebhookTestCase
class SemaphoreHookTests(WebhookTestCase):
STREAM_NAME = 'semaphore'
URL_TEMPLATE = "/api/v1/external/semaphore?stream={stream}&api_key={api_key}"
FIXTURE_DIR_NAME = "semaphore"
# Messages are generated by Semaphore on git push. The subject lines below
# contain information on the repo and branch, and the message has links and
@@ -126,9 +127,6 @@ class SemaphoreHookTests(WebhookTestCase):
"tag", expected_topic, expected_message, content_type="application/json"
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("semaphore", fixture_name, file_type="json")
def get_unknown_event(self, fixture_name: str) -> str:
"""Return modified payload with revision.reference_type changed"""
fixture_data = orjson.loads(self.webhook_fixture_data("semaphore", fixture_name, file_type="json"))

View File

@@ -73,6 +73,3 @@ Build update (see [build log](https://ci.solanolabs.com:443/reports/3317799)):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data(self.FIXTURE_DIR_NAME, fixture_name, file_type="json")

View File

@@ -165,6 +165,3 @@ Splunk alert from saved search:
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("splunk", fixture_name, file_type="json")

View File

@@ -4,6 +4,7 @@ from zerver.lib.test_classes import WebhookTestCase
class StatuspageHookTests(WebhookTestCase):
STREAM_NAME = 'statuspage-test'
URL_TEMPLATE = "/api/v1/external/statuspage?api_key={api_key}&stream={stream}"
FIXTURE_DIR_NAME = "statuspage"
def test_statuspage_incident(self) -> None:
expected_topic = "Database query delays: All Systems Operational"
@@ -42,6 +43,3 @@ class StatuspageHookTests(WebhookTestCase):
expected_message,
content_type="application/x-www-form-urlencoded",
)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("statuspage", fixture_name, file_type="json")

View File

@@ -34,6 +34,3 @@ class ZabbixHookTests(WebhookTestCase):
msg = self.get_last_message()
self.assertEqual(msg.content, expected_message)
self.assertEqual(msg.recipient.type, Recipient.PERSONAL)
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("zabbix", fixture_name, file_type="json")