mirror of https://github.com/zulip/zulip.git
tests: Clean up subscribing from webhook tests.
This commit is contained in:
parent
5fa7c3e0b2
commit
69059dcac8
|
@ -421,7 +421,7 @@ def test_unknown_action_no_data(self):
|
|||
# return if no params are sent. The fixture for this test is an empty file.
|
||||
|
||||
# subscribe to the target stream
|
||||
self.subscribe_to_stream(self.TEST_USER_EMAIL, self.STREAM_NAME)
|
||||
self.subscribe(self.test_user, self.STREAM_NAME)
|
||||
|
||||
# post to the webhook url
|
||||
post_params = {'stream_name': self.STREAM_NAME,
|
||||
|
|
|
@ -520,17 +520,17 @@ class ZulipTestCase(TestCase):
|
|||
result = self.client_post("/api/v1/users/me/subscriptions", post_data, **self.api_auth(email))
|
||||
return result
|
||||
|
||||
def send_json_payload(self, email, url, payload, stream_name=None, **post_params):
|
||||
# type: (Text, Text, Union[Text, Dict[str, Any]], Optional[Text], **Any) -> Message
|
||||
def send_json_payload(self, user_profile, url, payload, stream_name=None, **post_params):
|
||||
# type: (UserProfile, Text, Union[Text, Dict[str, Any]], Optional[Text], **Any) -> Message
|
||||
if stream_name is not None:
|
||||
self.subscribe_to_stream(email, stream_name)
|
||||
self.subscribe(user_profile, stream_name)
|
||||
|
||||
result = self.client_post(url, payload, **post_params)
|
||||
self.assert_json_success(result)
|
||||
|
||||
# Check the correct message was sent
|
||||
msg = self.get_last_message()
|
||||
self.assertEqual(msg.sender.email, email)
|
||||
self.assertEqual(msg.sender.email, user_profile.email)
|
||||
if stream_name is not None:
|
||||
self.assertEqual(get_display_recipient(msg.recipient), stream_name)
|
||||
# TODO: should also validate recipient for private messages
|
||||
|
@ -571,6 +571,11 @@ class WebhookTestCase(ZulipTestCase):
|
|||
URL_TEMPLATE = None # type: Optional[Text]
|
||||
FIXTURE_DIR_NAME = None # type: Optional[Text]
|
||||
|
||||
@property
|
||||
def test_user(self):
|
||||
# type: () -> UserProfile
|
||||
return get_user_profile_by_email(self.TEST_USER_EMAIL)
|
||||
|
||||
def setUp(self):
|
||||
# type: () -> None
|
||||
self.url = self.build_webhook_url()
|
||||
|
@ -581,7 +586,7 @@ class WebhookTestCase(ZulipTestCase):
|
|||
payload = self.get_body(fixture_name)
|
||||
if content_type is not None:
|
||||
kwargs['content_type'] = content_type
|
||||
msg = self.send_json_payload(self.TEST_USER_EMAIL, self.url, payload,
|
||||
msg = self.send_json_payload(self.test_user, self.url, payload,
|
||||
self.STREAM_NAME, **kwargs)
|
||||
self.do_test_subject(msg, expected_subject)
|
||||
self.do_test_message(msg, expected_message)
|
||||
|
@ -595,7 +600,7 @@ class WebhookTestCase(ZulipTestCase):
|
|||
if content_type is not None:
|
||||
kwargs['content_type'] = content_type
|
||||
|
||||
msg = self.send_json_payload(self.TEST_USER_EMAIL, self.url, payload,
|
||||
msg = self.send_json_payload(self.test_user, self.url, payload,
|
||||
stream_name=None, **kwargs)
|
||||
self.do_test_message(msg, expected_message)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class GithubV1HookTests(WebhookTestCase):
|
|||
# We subscribe to the stream in this test, even though
|
||||
# it won't get written, to avoid failing for the wrong
|
||||
# reason.
|
||||
self.subscribe_to_stream(self.TEST_USER_EMAIL, self.STREAM_NAME)
|
||||
self.subscribe(self.test_user, self.STREAM_NAME)
|
||||
|
||||
prior_count = Message.objects.count()
|
||||
|
||||
|
@ -168,7 +168,7 @@ class GithubV2HookTests(WebhookTestCase):
|
|||
# We subscribe to the stream in this test, even though
|
||||
# it won't get written, to avoid failing for the wrong
|
||||
# reason.
|
||||
self.subscribe_to_stream(self.TEST_USER_EMAIL, self.STREAM_NAME)
|
||||
self.subscribe(self.test_user, self.STREAM_NAME)
|
||||
|
||||
prior_count = Message.objects.count()
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class JiraHookTests(WebhookTestCase):
|
|||
# type: () -> None
|
||||
api_key = self.get_api_key(self.TEST_USER_EMAIL)
|
||||
url = "/api/v1/external/jira?api_key=%s&stream=jira_custom" % (api_key,)
|
||||
msg = self.send_json_payload(self.TEST_USER_EMAIL,
|
||||
msg = self.send_json_payload(self.test_user,
|
||||
url,
|
||||
self.get_body('created_v2'),
|
||||
stream_name="jira_custom",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from typing import Text
|
||||
from six.moves import urllib
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
from zerver.models import get_realm, get_user
|
||||
|
||||
class TravisHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'travis'
|
||||
|
@ -31,7 +32,7 @@ class TravisHookTests(WebhookTestCase):
|
|||
|
||||
def test_ignore_travis_pull_request_by_default(self):
|
||||
# type: () -> None
|
||||
self.subscribe_to_stream(self.TEST_USER_EMAIL, self.STREAM_NAME)
|
||||
self.subscribe(self.test_user, self.STREAM_NAME)
|
||||
result = self.client_post(
|
||||
self.url,
|
||||
self.get_body('pull_request'),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from six import text_type
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
from zerver.models import get_realm, get_user
|
||||
|
||||
class WordPressHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'wordpress'
|
||||
|
@ -73,7 +74,7 @@ class WordPressHookTests(WebhookTestCase):
|
|||
# return if no params are sent. The fixture for this test is an empty file.
|
||||
|
||||
# subscribe to the target stream
|
||||
self.subscribe_to_stream(self.TEST_USER_EMAIL, self.STREAM_NAME)
|
||||
self.subscribe(self.test_user, self.STREAM_NAME)
|
||||
|
||||
# post to the webhook url
|
||||
post_params = {'stream_name': self.STREAM_NAME,
|
||||
|
@ -89,7 +90,7 @@ class WordPressHookTests(WebhookTestCase):
|
|||
# Similar to unknown_action_no_data, except the fixture contains valid blog post
|
||||
# params but without the hook parameter. This should also return an error.
|
||||
|
||||
self.subscribe_to_stream(self.TEST_USER_EMAIL, self.STREAM_NAME)
|
||||
self.subscribe(self.test_user, self.STREAM_NAME)
|
||||
post_params = {'stream_name': self.STREAM_NAME,
|
||||
'content_type': 'application/x-www-form-urlencoded'}
|
||||
result = self.client_post(self.url, 'unknown_action', **post_params)
|
||||
|
|
Loading…
Reference in New Issue