mypy: Convert zerver/tests/ to use typing.Text.

This commit is contained in:
bulat22101 2016-12-04 17:38:56 +00:00 committed by Tim Abbott
parent 88e2ff3e1c
commit 9f68efa47b
32 changed files with 108 additions and 125 deletions

View File

@ -24,7 +24,7 @@ from zerver.models import (
UserProfile,
)
from six import text_type
from typing import Text
import ujson
@ -167,7 +167,7 @@ class AlertWordTests(ZulipTestCase):
self.assertEqual(data['alert_words'], ['a', 'b', 'c'])
def message_does_alert(self, user_profile, message):
# type: (UserProfile, text_type) -> bool
# type: (UserProfile, Text) -> bool
"""Send a bunch of messages as othello, so Hamlet is notified"""
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, message)
user_message = most_recent_usermessage(user_profile)
@ -241,4 +241,3 @@ class AlertWordTests(ZulipTestCase):
user_message = most_recent_usermessage(user_profile)
self.assertEqual(user_message.message.content, 'sorry false alarm')
self.assertNotIn('has_alert_word', user_message.flags_list())

View File

@ -4,7 +4,7 @@ from django.http import HttpResponse
from django.test import TestCase, override_settings
from django_auth_ldap.backend import _LDAPUser
from django.test.client import RequestFactory
from typing import Any, Callable, Dict, Optional
from typing import Any, Callable, Dict, Optional, Text
from builtins import object
from oauth2client.crypt import AppIdentityError
from django.core import signing
@ -40,7 +40,6 @@ from social.storage.django_orm import BaseDjangoStorage
from social.backends.github import GithubOrganizationOAuth2, GithubTeamOAuth2, \
GithubOAuth2
from six import text_type
from six.moves import urllib
from six.moves.http_cookies import SimpleCookie
import ujson
@ -50,7 +49,7 @@ class AuthBackendTest(TestCase):
def verify_backend(self, backend, good_args=None,
good_kwargs=None, bad_kwargs=None,
email_to_username=None):
# type: (Any, List[Any], Dict[str, Any], Dict[str, Any], Callable[[text_type], text_type]) -> None
# type: (Any, List[Any], Dict[str, Any], Dict[str, Any], Callable[[Text], Text]) -> None
if good_args is None:
good_args = []
if good_kwargs is None:

View File

@ -42,10 +42,9 @@ import os
import ujson
import six
from six import text_type
from six.moves import urllib
from zerver.lib.str_utils import NonBinaryStr
from typing import Any, AnyStr, Dict, List, Optional, Tuple
from typing import Any, AnyStr, Dict, List, Optional, Tuple, Text
class FencedBlockPreprocessorTest(TestCase):
def test_simple_quoting(self):
@ -159,17 +158,17 @@ class FencedBlockPreprocessorTest(TestCase):
self.assertEqual(lines, expected)
def bugdown_convert(text):
# type: (text_type) -> text_type
# type: (Text) -> Text
return bugdown.convert(text, "zulip.com")
class BugdownTest(TestCase):
def common_bugdown_test(self, text, expected):
# type: (text_type, text_type) -> None
# type: (Text, Text) -> None
converted = bugdown_convert(text)
self.assertEqual(converted, expected)
def load_bugdown_tests(self):
# type: () -> Tuple[Dict[text_type, Any], List[List[text_type]]]
# type: () -> Tuple[Dict[Text, Any], List[List[Text]]]
test_fixtures = {}
data_file = open(os.path.join(os.path.dirname(__file__), '../fixtures/bugdown-data.json'), 'r')
data = ujson.loads('\n'.join(data_file.readlines()))
@ -190,7 +189,7 @@ class BugdownTest(TestCase):
self.assertEqual(converted, test['expected_output'])
def replaced(payload, url, phrase=''):
# type: (text_type, text_type, text_type) -> text_type
# type: (Text, Text, Text) -> Text
target = " target=\"_blank\""
if url[:4] == 'http':
href = url
@ -290,7 +289,7 @@ class BugdownTest(TestCase):
def test_inline_interesting_links(self):
# type: () -> None
def make_link(url):
# type: (text_type) -> text_type
# type: (Text) -> Text
return '<a href="%s" target="_blank" title="%s">%s</a>' % (url, url, url)
normal_tweet_html = ('<a href="https://twitter.com/twitter" target="_blank"'
@ -309,7 +308,7 @@ class BugdownTest(TestCase):
'http://twitter.com/NEVNBoston/status/421654515616849920/photo/1</a>')
def make_inline_twitter_preview(url, tweet_html, image_html=''):
# type: (text_type, text_type, text_type) -> text_type
# type: (Text, Text, Text) -> Text
## As of right now, all previews are mocked to be the exact same tweet
return ('<div class="inline-preview-twitter">'
'<div class="twitter-tweet">'
@ -408,7 +407,7 @@ class BugdownTest(TestCase):
def test_realm_emoji(self):
# type: () -> None
def emoji_img(name, url):
# type: (text_type, text_type) -> text_type
# type: (Text, Text) -> Text
return '<img alt="%s" class="emoji" src="%s" title="%s">' % (name, get_camo_url(url), name)
zulip_realm = get_realm_by_string_id('zulip')
@ -564,7 +563,7 @@ class BugdownTest(TestCase):
realm_alert_words = alert_words_in_realm(user_profile.realm)
def render(msg, content):
# type: (Message, text_type) -> text_type
# type: (Message, Text) -> Text
return render_markdown(msg,
content,
realm_alert_words=realm_alert_words,

View File

@ -42,19 +42,18 @@ import mock
import os
import sys
from os.path import dirname, abspath
from six import text_type
from six.moves import cStringIO as StringIO
from django.conf import settings
from zerver.lib.str_utils import force_str
from typing import Any, Callable, Mapping, Union
from typing import Any, Callable, Mapping, Union, Text
class TestEmailMirrorLibrary(ZulipTestCase):
def test_get_missed_message_token(self):
# type: () -> None
def get_token(address):
# type: (text_type) -> text_type
# type: (Text) -> Text
with self.settings(EMAIL_GATEWAY_PATTERN="%s@example.com"):
return get_missed_message_token_from_address(address)

View File

@ -27,7 +27,7 @@ import ujson
from six.moves import urllib
from six.moves import range
from six import text_type
from typing import Text
class MITNameTest(TestCase):
def test_valid_hesiod(self):
@ -69,7 +69,7 @@ class RateLimitTests(ZulipTestCase):
remove_ratelimit_rule(1, 5)
def send_api_message(self, email, content):
# type: (text_type, text_type) -> HttpResponse
# type: (Text, Text) -> HttpResponse
return self.client_post("/api/v1/messages", {"type": "stream",
"to": "Verona",
"client": "test suite",

View File

@ -50,9 +50,8 @@ import DNS
import mock
import time
import ujson
from six import text_type
from six.moves import range
from typing import Any, Optional
from typing import Any, Optional, Text
class TopicHistoryTest(ZulipTestCase):
def test_topics_history(self):
@ -145,7 +144,7 @@ class TopicHistoryTest(ZulipTestCase):
class TestCrossRealmPMs(ZulipTestCase):
def make_realm(self, domain):
# type: (text_type) -> Realm
# type: (Text) -> Realm
realm = Realm.objects.create(string_id=domain, domain=domain, invite_required=False)
RealmAlias.objects.create(realm=realm, domain=domain)
return realm
@ -162,7 +161,7 @@ class TestCrossRealmPMs(ZulipTestCase):
dep.save()
def create_user(self, email):
# type: (text_type) -> UserProfile
# type: (Text) -> UserProfile
username, domain = email.split('@')
self.register(username, 'test', domain=domain)
return get_user_profile_by_email(email)
@ -321,7 +320,7 @@ class PersonalMessagesTest(ZulipTestCase):
self.assertEqual(most_recent_message(user_profile).recipient, recipient)
def assert_personal(self, sender_email, receiver_email, content="test content"):
# type: (text_type, text_type, text_type) -> None
# type: (Text, Text, Text) -> None
"""
Send a private message from `sender_email` to `receiver_email` and check
that only those two parties actually received the message.
@ -379,7 +378,7 @@ class StreamMessagesTest(ZulipTestCase):
def assert_stream_message(self, stream_name, subject="test subject",
content="test content"):
# type: (text_type, text_type, text_type) -> None
# type: (Text, Text, Text) -> None
"""
Check that messages sent to a stream reach all subscribers to that stream.
"""
@ -873,7 +872,7 @@ class MessagePOSTTest(ZulipTestCase):
class EditMessageTest(ZulipTestCase):
def check_message(self, msg_id, subject=None, content=None):
# type: (int, Optional[text_type], Optional[text_type]) -> Message
# type: (int, Optional[Text], Optional[Text]) -> Message
msg = Message.objects.get(id=msg_id)
cached = message_to_dict(msg, False)
uncached = MessageDict.to_dict_uncached_helper(msg, False)
@ -1002,7 +1001,7 @@ class EditMessageTest(ZulipTestCase):
self.assert_json_success(result)
def do_edit_message_assert_success(id_, unique_str, topic_only = False):
# type: (int, text_type, bool) -> None
# type: (int, Text, bool) -> None
new_subject = 'subject' + unique_str
new_content = 'content' + unique_str
params_dict = {'message_id': id_, 'subject': new_subject}
@ -1016,7 +1015,7 @@ class EditMessageTest(ZulipTestCase):
self.check_message(id_, subject=new_subject, content=new_content)
def do_edit_message_assert_error(id_, unique_str, error, topic_only = False):
# type: (int, text_type, text_type, bool) -> None
# type: (int, Text, Text, bool) -> None
message = Message.objects.get(id=id_)
old_subject = message.topic_name()
old_content = message.content
@ -1124,7 +1123,7 @@ class MirroredMessageUsersTest(TestCase):
def test_invalid_sender(self):
# type: () -> None
user = get_user_profile_by_email('hamlet@zulip.com')
recipients = [] # type: List[text_type]
recipients = [] # type: List[Text]
request = self.Request()
request.POST = dict() # no sender
@ -1141,7 +1140,7 @@ class MirroredMessageUsersTest(TestCase):
user = get_user_profile_by_email('hamlet@zulip.com')
sender = user
recipients = [] # type: List[text_type]
recipients = [] # type: List[Text]
request = self.Request()
request.POST = dict(
sender=sender.email,

View File

@ -33,7 +33,7 @@ from zerver.views.messages import (
NarrowBuilder, BadNarrowOperator
)
from six import text_type
from typing import Text
from six.moves import range
import os
import re
@ -519,7 +519,7 @@ class GetOldMessagesTest(ZulipTestCase):
self.login(email)
def send(content):
# type: (text_type) -> None
# type: (Text) -> None
msg_id = self.send_message(
sender_name=email,
raw_recipients="Verona",

View File

@ -1,8 +1,7 @@
import mock
from mock import call
import time
from typing import Any, Union, SupportsInt
from six import text_type
from typing import Any, Union, SupportsInt, Text
import gcmclient
@ -302,7 +301,7 @@ class GCMCanonicalTest(GCMTest):
mock_send.return_value = res
def get_count(hex_token):
# type: (text_type) -> int
# type: (Text) -> int
token = apn.hex_to_b64(hex_token)
return PushDeviceToken.objects.filter(
token=token, kind=PushDeviceToken.GCM).count()
@ -332,7 +331,7 @@ class GCMCanonicalTest(GCMTest):
mock_send.return_value = res
def get_count(hex_token):
# type: (text_type) -> int
# type: (Text) -> int
token = apn.hex_to_b64(hex_token)
return PushDeviceToken.objects.filter(
token=token, kind=PushDeviceToken.GCM).count()
@ -360,7 +359,7 @@ class GCMNotRegisteredTest(GCMTest):
mock_send.return_value = res
def get_count(hex_token):
# type: (text_type) -> int
# type: (Text) -> int
token = apn.hex_to_b64(hex_token)
return PushDeviceToken.objects.filter(
token=token, kind=PushDeviceToken.GCM).count()

View File

@ -42,8 +42,7 @@ import ujson
from six.moves import urllib
from six.moves import range
import six
from six import text_type
from typing import Any
from typing import Any, Text
class PublicURLTest(ZulipTestCase):
"""
@ -299,7 +298,7 @@ class LoginTest(ZulipTestCase):
class InviteUserTest(ZulipTestCase):
def invite(self, users, streams):
# type: (str, List[text_type]) -> HttpResponse
# type: (str, List[Text]) -> HttpResponse
"""
Invites the specified users to Zulip with the specified streams.

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from typing import Any, Dict, List, Mapping, Optional, Sequence
from typing import Any, Dict, List, Mapping, Optional, Sequence, Text
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
@ -52,7 +52,6 @@ import mock
import random
import ujson
import six
from six import text_type
from six.moves import range, urllib, zip
class TestCreateStreams(ZulipTestCase):
@ -612,7 +611,7 @@ class StreamAdminTest(ZulipTestCase):
class DefaultStreamTest(ZulipTestCase):
def get_default_stream_names(self, realm):
# type: (Realm) -> Set[text_type]
# type: (Realm) -> Set[Text]
streams = get_default_streams_for_realm(realm)
stream_names = [s.name for s in streams]
return set(stream_names)
@ -1062,7 +1061,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.streams = self.get_streams(self.test_email)
def make_random_stream_names(self, existing_stream_names):
# type: (List[text_type]) -> List[text_type]
# type: (List[Text]) -> List[Text]
"""
Helper function to make up random stream names. It takes
existing_stream_names and randomly appends a digit to the end of each,
@ -1102,7 +1101,7 @@ class SubscriptionAPITest(ZulipTestCase):
def helper_check_subs_before_and_after_add(self, subscriptions, other_params,
subscribed, already_subscribed,
email, new_subs, invite_only=False):
# type: (List[text_type], Dict[str, Any], List[text_type], List[text_type], text_type, List[text_type], bool) -> None
# type: (List[Text], Dict[str, Any], List[Text], List[Text], Text, List[Text], bool) -> None
"""
Check result of adding subscriptions.
@ -1323,7 +1322,7 @@ class SubscriptionAPITest(ZulipTestCase):
"Invalid stream name (%s)." % (invalid_stream_name,))
def assert_adding_subscriptions_for_principal(self, invitee, streams, invite_only=False):
# type: (text_type, List[text_type], bool) -> None
# type: (Text, List[Text], bool) -> None
"""
Calling POST /json/users/me/subscriptions on behalf of another principal (for
whom you have permission to add subscriptions) should successfully add
@ -1663,7 +1662,7 @@ class SubscriptionAPITest(ZulipTestCase):
def helper_check_subs_before_and_after_remove(self, subscriptions, json_dict,
email, new_subs):
# type: (List[text_type], Dict[str, Any], text_type, List[text_type]) -> None
# type: (List[Text], Dict[str, Any], Text, List[Text]) -> None
"""
Check result of removing subscriptions.
@ -1720,7 +1719,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.assert_json_error(result, "Stream(s) (%s) do not exist" % (random_streams[0],))
def helper_subscriptions_exists(self, stream, exists, subscribed):
# type: (text_type, bool, bool) -> None
# type: (Text, bool, bool) -> None
"""
A helper function that calls /json/subscriptions/exists on a stream and
verifies that the returned JSON dictionary has the exists and
@ -1797,7 +1796,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.assertTrue(json["exists"])
def get_subscription(self, user_profile, stream_name):
# type: (UserProfile, text_type) -> Subscription
# type: (UserProfile, Text) -> Subscription
stream = Stream.objects.get(realm=self.realm, name=stream_name)
return Subscription.objects.get(
user_profile=user_profile,
@ -1994,7 +1993,7 @@ class GetSubscribersTest(ZulipTestCase):
self.login(self.email)
def check_well_formed_result(self, result, stream_name, domain):
# type: (Dict[str, Any], text_type, text_type) -> None
# type: (Dict[str, Any], Text, Text) -> None
"""
A successful call to get_subscribers returns the list of subscribers in
the form:
@ -2010,14 +2009,14 @@ class GetSubscribersTest(ZulipTestCase):
self.assertEqual(sorted(result["subscribers"]), sorted(true_subscribers))
def make_subscriber_request(self, stream_name, email=None):
# type: (text_type, Optional[str]) -> HttpResponse
# type: (Text, Optional[str]) -> HttpResponse
if email is None:
email = self.email
return self.client_get("/api/v1/streams/%s/members" % (stream_name,),
**self.api_auth(email))
def make_successful_subscriber_request(self, stream_name):
# type: (text_type) -> None
# type: (Text) -> None
result = self.make_subscriber_request(stream_name)
self.assert_json_success(result)
self.check_well_formed_result(ujson.loads(result.content),
@ -2174,7 +2173,7 @@ class GetSubscribersTest(ZulipTestCase):
result_dict = ujson.loads(result.content)
self.assertIn('subscribers', result_dict)
self.assertIsInstance(result_dict['subscribers'], list)
subscribers = [] # type: List[text_type]
subscribers = [] # type: List[Text]
for subscriber in result_dict['subscribers']:
self.assertIsInstance(subscriber, six.string_types)
subscribers.append(subscriber)

View File

@ -17,7 +17,6 @@ from zerver.lib.actions import do_delete_old_unclaimed_attachments
import ujson
from six.moves import urllib
from six import text_type
from PIL import Image
from boto.s3.connection import S3Connection
@ -38,7 +37,7 @@ from moto import mock_s3
TEST_AVATAR_DIR = os.path.join(os.path.dirname(__file__), 'images')
from typing import Any, Callable, TypeVar
from typing import Any, Callable, TypeVar, Text
def destroy_uploads():
# type: () -> None

View File

@ -2,7 +2,7 @@
from __future__ import absolute_import
from __future__ import print_function
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple, TypeVar
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Tuple, TypeVar, Text
from mock import patch, MagicMock
from django.http import HttpResponse
@ -41,7 +41,6 @@ from zerver.worker import queue_processors
from django.conf import settings
from django.core import mail
from six import text_type
from six.moves import range, urllib
import os
import re
@ -105,7 +104,7 @@ class ModelTest(TestCase):
class RealmTest(ZulipTestCase):
def assert_user_profile_cache_gets_new_name(self, email, new_realm_name):
# type: (text_type, text_type) -> None
# type: (Text, Text) -> None
user_profile = get_user_profile_by_email(email)
self.assertEqual(user_profile.realm.name, new_realm_name)
@ -1665,13 +1664,13 @@ class ChangeSettingsTest(ZulipTestCase):
class GetProfileTest(ZulipTestCase):
def common_update_pointer(self, email, pointer):
# type: (text_type, int) -> None
# type: (Text, int) -> None
self.login(email)
result = self.client_put("/json/users/me/pointer", {"pointer": pointer})
self.assert_json_success(result)
def common_get_profile(self, email):
# type: (str) -> Dict[text_type, Any]
# type: (str) -> Dict[Text, Any]
user_profile = get_user_profile_by_email(email)
self.send_message(email, "Verona", Recipient.STREAM, "hello")
@ -2113,7 +2112,7 @@ class ExtractedRecipientsTest(TestCase):
class TestMissedMessages(ZulipTestCase):
def normalize_string(self, s):
# type: (text_type) -> text_type
# type: (Text) -> Text
s = s.strip()
return re.sub(r'\s+', ' ', s)

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.webhooks.git import COMMITS_LIMIT
from zerver.lib.test_classes import WebhookTestCase
@ -61,5 +61,5 @@ class BeanstalkHookTests(WebhookTestCase):
**self.api_auth(self.TEST_USER_EMAIL))
def get_body(self, fixture_name):
# type: (text_type) -> Dict[str, text_type]
# type: (Text) -> Dict[str, Text]
return {'payload': self.fixture_data('beanstalk', fixture_name)}

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Union
from typing import Union, Text
from zerver.lib.webhooks.git import COMMITS_LIMIT
from zerver.lib.test_classes import WebhookTestCase
@ -213,17 +212,17 @@ class BitbucketHookTests(WebhookTestCase):
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
def get_body(self, fixture_name):
# type: (text_type) -> Union[text_type, Dict[str, text_type]]
# type: (Text) -> Union[Text, Dict[str, Text]]
return {}
def get_payload(self, fixture_name):
# type: (text_type) -> Union[text_type, Dict[str, text_type]]
# type: (Text) -> Union[Text, Dict[str, Text]]
return self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name)
def build_webhook_url(self):
# type: () -> text_type
# type: () -> Text
return ''
def build_url(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.URL_TEMPLATE.format(payload=self.get_payload(fixture_name), stream=self.STREAM_NAME)

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
# Tests for the Desk.com webhook integration.
@ -63,5 +63,5 @@ class DeskDotComHookTests(WebhookTestCase):
**self.api_auth(self.TEST_USER_EMAIL))
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data("deskdotcom", fixture_name, file_type="txt")

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class FreshdeskHookTests(WebhookTestCase):
@ -53,7 +53,7 @@ Priority: **High** => **Low**"""
**self.api_auth(self.TEST_USER_EMAIL))
def note_change(self, fixture, note_type):
# type: (text_type, text_type) -> None
# type: (Text, Text) -> None
"""
Messages are generated when a note gets added to a ticket through
Freshdesk's "Observer" service.
@ -86,9 +86,9 @@ Priority: **High** => **Low**"""
**self.api_auth(self.TEST_USER_EMAIL))
def build_webhook_url(self):
# type: () -> text_type
# type: () -> Text
return self.URL_TEMPLATE.format(stream=self.STREAM_NAME)
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data("freshdesk", fixture_name, file_type="json")

View File

@ -1,17 +1,16 @@
import ujson
from six import text_type
from typing import Dict, Optional
from typing import Dict, Optional, Text
from zerver.models import Message
from zerver.lib.webhooks.git import COMMITS_LIMIT
from zerver.lib.test_classes import WebhookTestCase
class GithubV1HookTests(WebhookTestCase):
STREAM_NAME = None # type: Optional[text_type]
STREAM_NAME = None # type: Optional[Text]
URL_TEMPLATE = u"/api/v1/external/github"
FIXTURE_DIR_NAME = 'github'
SEND_STREAM = False
BRANCHES = None # type: Optional[text_type]
BRANCHES = None # type: Optional[Text]
push_content = u"""zbenjamin [pushed](https://github.com/zbenjamin/zulip-test/compare/4f9adc4777d5...b95449196980) to branch master
@ -40,7 +39,7 @@ class GithubV1HookTests(WebhookTestCase):
self.assertEqual(prior_count, after_count)
def get_body(self, fixture_name):
# type: (text_type) -> Dict[str, text_type]
# type: (Text) -> Dict[str, Text]
api_key = self.get_api_key(self.TEST_USER_EMAIL)
data = ujson.loads(self.fixture_data(self.FIXTURE_DIR_NAME, 'v1_' + fixture_name))
data.update({'email': self.TEST_USER_EMAIL,
@ -54,7 +53,7 @@ class GithubV1HookTests(WebhookTestCase):
return data
def basic_test(self, fixture_name, stream_name, expected_subject, expected_content, send_stream=False, branches=None):
# type: (text_type, text_type, text_type, text_type, bool, Optional[text_type]) -> None
# type: (Text, Text, Text, Text, bool, Optional[Text]) -> None
self.STREAM_NAME = stream_name
self.SEND_STREAM = send_stream
self.BRANCHES = branches
@ -147,11 +146,11 @@ class GithubV1HookTests(WebhookTestCase):
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on [7c99467](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~")
class GithubV2HookTests(WebhookTestCase):
STREAM_NAME = None # type: Optional[text_type]
STREAM_NAME = None # type: Optional[Text]
URL_TEMPLATE = u"/api/v1/external/github"
FIXTURE_DIR_NAME = 'github'
SEND_STREAM = False
BRANCHES = None # type: Optional[text_type]
BRANCHES = None # type: Optional[Text]
push_content = """zbenjamin [pushed](https://github.com/zbenjamin/zulip-test/compare/4f9adc4777d5...b95449196980) to branch master
@ -180,7 +179,7 @@ class GithubV2HookTests(WebhookTestCase):
self.assertEqual(prior_count, after_count)
def get_body(self, fixture_name):
# type: (text_type) -> Dict[str, text_type]
# type: (Text) -> Dict[str, Text]
api_key = self.get_api_key(self.TEST_USER_EMAIL)
data = ujson.loads(self.fixture_data(self.FIXTURE_DIR_NAME, 'v2_' + fixture_name))
data.update({'email': self.TEST_USER_EMAIL,
@ -194,7 +193,7 @@ class GithubV2HookTests(WebhookTestCase):
return data
def basic_test(self, fixture_name, stream_name, expected_subject, expected_content, send_stream=False, branches=None):
# type: (text_type, text_type, text_type, text_type, bool, Optional[text_type]) -> None
# type: (Text, Text, Text, Text, bool, Optional[Text]) -> None
self.STREAM_NAME = stream_name
self.SEND_STREAM = send_stream
self.BRANCHES = branches

View File

@ -1,6 +1,5 @@
import ujson
from six import text_type
from typing import Dict, Optional
from typing import Dict, Optional, Text
from zerver.models import Message
from zerver.lib.webhooks.git import COMMITS_LIMIT

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class HelloWorldHookTests(WebhookTestCase):
@ -27,5 +27,5 @@ class HelloWorldHookTests(WebhookTestCase):
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data("helloworld", fixture_name, file_type="json")

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class JiraHookTests(WebhookTestCase):
@ -147,5 +147,5 @@ Making a comment, **Othello, the Moor of Venice** is watching this issue
self.send_and_test_stream_message('updated_priority', expected_subject, expected_message)
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data('jira', fixture_name)

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from six import text_type
from six.moves import urllib
from typing import Optional
from typing import Optional, Text
from zerver.lib.test_classes import WebhookTestCase
class LibratoHookTests(WebhookTestCase):
@ -11,13 +10,13 @@ class LibratoHookTests(WebhookTestCase):
IS_ATTACHMENT = False
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
if self.IS_ATTACHMENT:
return self.fixture_data("librato", fixture_name, file_type='json')
return urllib.parse.urlencode({'payload': self.fixture_data("librato", fixture_name, file_type='json')})
def build_webhook_url(self, topic=None):
# type: (Optional[text_type]) -> text_type
# type: (Optional[Text]) -> Text
api_key = self.get_api_key(self.TEST_USER_EMAIL)
url = self.URL_TEMPLATE.format(stream=self.STREAM_NAME, api_key=api_key)
if topic:

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class NewRelicHookTests(WebhookTestCase):
@ -24,5 +24,5 @@ Description sent via curl\n\nChangelog string'
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data("newrelic", fixture_name, file_type="txt")

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class PagerDutyHookTests(WebhookTestCase):

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class PivotalV3HookTests(WebhookTestCase):
@ -79,7 +79,7 @@ class PivotalV3HookTests(WebhookTestCase):
self.send_and_test_stream_message('type_changed', expected_subject, expected_message, content_type="application/xml")
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data('pivotal', fixture_name, file_type='xml')
class PivotalV5HookTests(WebhookTestCase):
@ -173,5 +173,5 @@ Try again next time
self.send_and_test_stream_message('type_changed', expected_subject, expected_message, content_type="application/xml")
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data('pivotal', "v5_{}".format(fixture_name), file_type='json')

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class SemaphoreHookTests(WebhookTestCase):
@ -27,5 +27,5 @@ class SemaphoreHookTests(WebhookTestCase):
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data("semaphore", fixture_name, file_type="json")

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class StashHookTests(WebhookTestCase):
@ -23,5 +23,5 @@ class StashHookTests(WebhookTestCase):
**self.api_auth(self.TEST_USER_EMAIL))
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data("stash", fixture_name, file_type="json")

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class StripeHookTests(WebhookTestCase):
@ -152,5 +152,5 @@ class StripeHookTests(WebhookTestCase):
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return self.fixture_data("stripe", fixture_name, file_type="json")

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class TaigaHookTests(WebhookTestCase):
@ -9,7 +9,7 @@ class TaigaHookTests(WebhookTestCase):
FIXTURE_DIR_NAME = 'taiga'
def build_webhook_url(self):
# type: () -> text_type
# type: () -> Text
api_key = self.get_api_key(self.TEST_USER_EMAIL)
return self.URL_TEMPLATE.format(stream=self.STREAM_NAME, api_key=api_key, topic=self.TOPIC)

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Any, Dict
from typing import Any, Dict, Text
from zerver.lib.test_classes import WebhookTestCase
class TransifexHookTests(WebhookTestCase):
@ -34,7 +33,7 @@ class TransifexHookTests(WebhookTestCase):
self.REVIEWED = True
def build_webhook_url(self):
# type: () -> text_type
# type: () -> Text
url_data = self.URL_DATA_TEMPLATE.format(
project=self.PROJECT,
language=self.LANGUAGE,
@ -45,5 +44,5 @@ class TransifexHookTests(WebhookTestCase):
return self.URL_TEMPLATE.format(api_key=api_key, stream=self.STREAM_NAME, data_template=url_data)
def get_body(self, fixture_name):
# type: (text_type) -> Dict[str, Any]
# type: (Text) -> Dict[str, Any]
return {}

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Text
from six.moves import urllib
from zerver.lib.test_classes import WebhookTestCase
@ -29,5 +29,5 @@ class TravisHookTests(WebhookTestCase):
)
def get_body(self, fixture_name):
# type: (text_type) -> text_type
# type: (Text) -> Text
return urllib.parse.urlencode({'payload': self.fixture_data("travis", fixture_name, file_type="json")})

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Any, Dict
from typing import Any, Dict, Text
from zerver.lib.test_classes import WebhookTestCase
class YoHookTests(WebhookTestCase):
@ -18,11 +17,11 @@ class YoHookTests(WebhookTestCase):
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name):
# type: (text_type) -> Dict[str, Any]
# type: (Text) -> Dict[str, Any]
return {}
def build_webhook_url(self):
# type: () -> text_type
# type: () -> Text
api_key = self.get_api_key(self.TEST_USER_EMAIL)
email = "cordelia@zulip.com"
username = "IAGO"

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from six import text_type
from typing import Any, Optional
from typing import Any, Optional, Text
from zerver.lib.test_classes import WebhookTestCase
@ -18,7 +17,7 @@ class ZenDeskHookTests(WebhookTestCase):
MESSAGE = DEFAULT_MESSAGE
def get_body(self, fixture_name):
# type: (text_type) -> Dict[str, Any]
# type: (Text) -> Dict[str, Any]
return {
'ticket_title': self.TICKET_TITLE,
'ticket_id': self.TICKET_ID,
@ -27,7 +26,7 @@ class ZenDeskHookTests(WebhookTestCase):
}
def do_test(self, expected_subject=None, expected_message=None):
# type: (Optional[text_type], Optional[text_type]) -> None
# type: (Optional[Text], Optional[Text]) -> None
self.send_and_test_stream_message(None, expected_subject, expected_message,
content_type=None, **self.api_auth(self.TEST_USER_EMAIL))
self.TICKET_TITLE = self.DEFAULT_TICKET_TITLE