2019-08-20 01:44:44 +02:00
|
|
|
from typing import Dict, Any, Optional, Iterable, Callable, Set, List
|
2018-02-25 01:01:45 +01:00
|
|
|
|
2018-04-27 22:09:57 +02:00
|
|
|
import json
|
2018-04-27 23:48:47 +02:00
|
|
|
import os
|
2019-08-08 20:40:30 +02:00
|
|
|
import sys
|
|
|
|
from functools import wraps
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-04-27 22:09:57 +02:00
|
|
|
from zerver.lib import mdiff
|
2020-02-23 18:10:42 +01:00
|
|
|
from zerver.openapi.openapi import validate_against_openapi_schema
|
2018-04-27 22:09:57 +02:00
|
|
|
|
2019-08-20 01:44:44 +02:00
|
|
|
from zerver.models import get_realm, get_user
|
|
|
|
|
2019-07-23 23:58:11 +02:00
|
|
|
from zulip import Client
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-01-26 22:11:42 +01:00
|
|
|
ZULIP_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
TEST_FUNCTIONS: Dict[str, Callable[..., None]] = dict()
|
|
|
|
REGISTERED_TEST_FUNCTIONS: Set[str] = set()
|
|
|
|
CALLED_TEST_FUNCTIONS: Set[str] = set()
|
2019-08-07 20:03:43 +02:00
|
|
|
|
|
|
|
def openapi_test_function(endpoint: str) -> Callable[[Callable[..., Any]], Callable[..., Any]]:
|
2019-08-08 20:40:30 +02:00
|
|
|
"""This decorator is used to register an openapi test function with
|
|
|
|
its endpoint. Example usage:
|
|
|
|
|
|
|
|
@openapi_test_function("/messages/render:post")
|
|
|
|
def ...
|
|
|
|
"""
|
2019-08-07 20:03:43 +02:00
|
|
|
def wrapper(test_func: Callable[..., Any]) -> Callable[..., Any]:
|
2019-08-08 20:40:30 +02:00
|
|
|
@wraps(test_func)
|
|
|
|
def _record_calls_wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
|
|
CALLED_TEST_FUNCTIONS.add(test_func.__name__)
|
|
|
|
return test_func(*args, **kwargs)
|
|
|
|
|
|
|
|
REGISTERED_TEST_FUNCTIONS.add(test_func.__name__)
|
|
|
|
TEST_FUNCTIONS[endpoint] = _record_calls_wrapper
|
|
|
|
|
|
|
|
return _record_calls_wrapper
|
2019-08-07 20:03:43 +02:00
|
|
|
return wrapper
|
|
|
|
|
2019-08-20 01:44:44 +02:00
|
|
|
def ensure_users(ids_list: List[int], user_names: List[str]) -> None:
|
|
|
|
# Ensure that the list of user ids (ids_list)
|
|
|
|
# matches the users we want to refer to (user_names).
|
|
|
|
realm = get_realm("zulip")
|
|
|
|
user_ids = [get_user(name + '@zulip.com', realm).id for name in user_names]
|
|
|
|
|
|
|
|
assert ids_list == user_ids
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/subscriptions:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def add_subscriptions(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-02-06 04:17:10 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Subscribe to the stream "new stream"
|
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{
|
|
|
|
'name': 'new stream',
|
|
|
|
'description': 'New stream for testing'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-07 19:47:49 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/subscriptions', 'post',
|
2020-04-17 19:16:43 +02:00
|
|
|
'200_0')
|
2018-02-06 04:17:10 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# To subscribe another user to a stream, you may pass in
|
|
|
|
# the `principals` argument, like so:
|
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{'name': 'new stream', 'description': 'New stream for testing'}
|
|
|
|
],
|
|
|
|
principals=['newbie@zulip.com']
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2017-01-13 13:50:39 +01:00
|
|
|
assert result['result'] == 'success'
|
2018-02-06 04:17:10 +01:00
|
|
|
assert 'newbie@zulip.com' in result['subscribed']
|
2017-01-13 13:50:39 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_add_subscriptions_already_subscribed(client: Client) -> None:
|
2018-02-16 22:41:29 +01:00
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{'name': 'new stream', 'description': 'New stream for testing'}
|
|
|
|
],
|
|
|
|
principals=['newbie@zulip.com']
|
|
|
|
)
|
|
|
|
|
2018-06-07 19:47:49 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/subscriptions', 'post',
|
2020-04-17 19:16:43 +02:00
|
|
|
'200_1')
|
2018-02-16 22:41:29 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_authorization_errors_fatal(client: Client, nonadmin_client: Client) -> None:
|
2018-02-16 23:22:45 +01:00
|
|
|
client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{'name': 'private_stream'}
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
stream_id = client.get_stream_id('private_stream')['stream_id']
|
|
|
|
client.call_endpoint(
|
|
|
|
'streams/{}'.format(stream_id),
|
|
|
|
method='PATCH',
|
|
|
|
request={'is_private': True}
|
|
|
|
)
|
|
|
|
|
|
|
|
result = nonadmin_client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{'name': 'private_stream'}
|
|
|
|
],
|
|
|
|
authorization_errors_fatal=False,
|
|
|
|
)
|
|
|
|
|
2018-06-07 19:47:49 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/subscriptions', 'post',
|
2020-04-17 19:16:43 +02:00
|
|
|
'400_0')
|
2018-02-16 23:22:45 +01:00
|
|
|
|
|
|
|
result = nonadmin_client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{'name': 'private_stream'}
|
|
|
|
],
|
|
|
|
authorization_errors_fatal=True,
|
|
|
|
)
|
|
|
|
|
2018-06-07 19:47:49 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/subscriptions', 'post',
|
2020-04-17 19:16:43 +02:00
|
|
|
'400_1')
|
2018-02-16 23:22:45 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/{email}/presence:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_user_presence(client: Client) -> None:
|
2018-08-07 17:52:03 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Get presence information for "iago@zulip.com"
|
|
|
|
result = client.get_user_presence('iago@zulip.com')
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/users/{email}/presence', 'get', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/presence:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_presence(client: Client) -> None:
|
2019-04-22 23:58:53 +02:00
|
|
|
request = {
|
|
|
|
'status': 'active',
|
|
|
|
'ping_only': False,
|
|
|
|
'new_user_input': False
|
|
|
|
}
|
|
|
|
|
|
|
|
result = client.update_presence(request)
|
|
|
|
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def create_user(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-01-31 05:36:57 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Create a user
|
|
|
|
request = {
|
|
|
|
'email': 'newbie@zulip.com',
|
|
|
|
'password': 'temp',
|
|
|
|
'full_name': 'New User',
|
|
|
|
'short_name': 'newbie'
|
|
|
|
}
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.create_user(request)
|
2018-01-31 05:36:57 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-21 01:47:22 +02:00
|
|
|
validate_against_openapi_schema(result, '/users', 'post', '200')
|
2018-02-16 23:38:10 +01:00
|
|
|
|
|
|
|
# Test "Email already used error"
|
|
|
|
result = client.create_user(request)
|
|
|
|
|
2018-06-21 01:47:22 +02:00
|
|
|
validate_against_openapi_schema(result, '/users', 'post', '400')
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_members(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-02-07 04:25:23 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get all users in the realm
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.get_members()
|
2018-02-07 04:25:23 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 19:43:40 +02:00
|
|
|
validate_against_openapi_schema(result, '/users', 'get', '200')
|
|
|
|
|
2017-01-13 13:50:39 +01:00
|
|
|
members = [m for m in result['members'] if m['email'] == 'newbie@zulip.com']
|
|
|
|
assert len(members) == 1
|
2018-02-07 04:25:23 +01:00
|
|
|
newbie = members[0]
|
|
|
|
assert not newbie['is_admin']
|
|
|
|
assert newbie['full_name'] == 'New User'
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# You may pass the `client_gravatar` query parameter as follows:
|
2018-07-26 21:04:19 +02:00
|
|
|
result = client.get_members({'client_gravatar': True})
|
2018-02-07 04:25:23 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 19:43:40 +02:00
|
|
|
validate_against_openapi_schema(result, '/users', 'get', '200')
|
2018-02-07 04:25:23 +01:00
|
|
|
assert result['members'][0]['avatar_url'] is None
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2019-10-26 19:38:27 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# You may pass the `include_custom_profile_fields` query parameter as follows:
|
|
|
|
result = client.get_members({'include_custom_profile_fields': True})
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/users', 'get', '200')
|
|
|
|
for member in result['members']:
|
|
|
|
if member["is_bot"]:
|
|
|
|
assert member.get('profile_data', None) is None
|
|
|
|
else:
|
|
|
|
assert member.get('profile_data', None) is not None
|
|
|
|
|
2020-02-14 21:39:12 +01:00
|
|
|
@openapi_test_function("/users/{user_id}:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_single_user(client: Client) -> None:
|
2020-02-14 21:39:12 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Fetch details on a user given a user ID
|
|
|
|
user_id = 8
|
2020-03-27 23:49:20 +01:00
|
|
|
result = client.get_user_by_id(user_id)
|
2020-02-14 21:39:12 +01:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/users/{user_id}', 'get', '200')
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# If you'd like data on custom profile fields, you can request them as follows:
|
2020-04-22 02:09:20 +02:00
|
|
|
result = client.get_user_by_id(user_id, include_custom_profile_fields=True)
|
2020-02-14 21:39:12 +01:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/users/{user_id}', 'get', '200')
|
|
|
|
|
2020-02-14 22:02:24 +01:00
|
|
|
@openapi_test_function("/users/{user_id}:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def deactivate_user(client: Client) -> None:
|
2020-02-14 22:02:24 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Deactivate a user
|
|
|
|
user_id = 8
|
2020-05-16 20:51:21 +02:00
|
|
|
result = client.deactivate_user_by_id(user_id)
|
2020-02-14 22:02:24 +01:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/users/{user_id}', 'delete', '200')
|
|
|
|
|
2020-02-14 22:13:01 +01:00
|
|
|
@openapi_test_function("/users/{user_id}:patch")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_user(client: Client) -> None:
|
2020-02-14 22:13:01 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Change a user's full name.
|
|
|
|
user_id = 10
|
2020-05-16 20:57:15 +02:00
|
|
|
result = client.update_user_by_id(user_id, full_name = "New Name")
|
2020-02-14 22:13:01 +01:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/users/{user_id}', 'patch', '200')
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Change value of the custom profile field with ID 9.
|
|
|
|
user_id = 8
|
2020-05-16 20:57:15 +02:00
|
|
|
result = client.update_user_by_id(user_id, profile_data = [{'id': 9, 'value': 'some data'}])
|
2020-02-14 22:13:01 +01:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/users/{user_id}', 'patch', '400')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/realm/filters:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_realm_filters(client: Client) -> None:
|
2018-08-14 03:10:37 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Fetch all the filters in this organization
|
|
|
|
result = client.get_realm_filters()
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/realm/filters', 'get', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/realm/filters:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def add_realm_filter(client: Client) -> None:
|
2018-08-14 02:54:36 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Add a filter to automatically linkify #<number> to the corresponding
|
|
|
|
# issue in Zulip's server repo
|
|
|
|
result = client.add_realm_filter('#(?P<id>[0-9]+)',
|
|
|
|
'https://github.com/zulip/zulip/issues/%(id)s')
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/realm/filters', 'post', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/realm/filters/{filter_id}:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def remove_realm_filter(client: Client) -> None:
|
2018-08-14 03:20:39 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Remove the organization filter with ID 42
|
|
|
|
result = client.remove_realm_filter(42)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2019-07-11 12:45:26 +02:00
|
|
|
validate_against_openapi_schema(result, '/realm/filters/{filter_id}', 'delete', '200')
|
2018-08-14 03:20:39 +02:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_profile(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-01-31 06:06:56 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get the profile of the user/bot that requests this endpoint,
|
|
|
|
# which is `client` in this case:
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.get_profile()
|
2018-01-31 06:06:56 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2019-08-04 13:08:36 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me', 'get', '200')
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/get_stream_id:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_stream_id(client: Client) -> int:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-01-28 00:06:45 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get the ID of a given stream
|
2017-01-13 13:50:39 +01:00
|
|
|
stream_name = 'new stream'
|
|
|
|
result = client.get_stream_id(stream_name)
|
2018-01-28 00:06:45 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 19:20:55 +02:00
|
|
|
validate_against_openapi_schema(result, '/get_stream_id', 'get', '200')
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2019-04-08 10:11:18 +02:00
|
|
|
return result['stream_id']
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/streams/{stream_id}:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def delete_stream(client: Client, stream_id: int) -> None:
|
2019-06-29 03:16:34 +02:00
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{
|
|
|
|
'name': 'stream to be deleted',
|
|
|
|
'description': 'New stream for testing'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2019-04-08 10:11:18 +02:00
|
|
|
|
2019-06-22 08:22:32 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Delete the stream named 'new stream'
|
2019-06-29 03:16:34 +02:00
|
|
|
stream_id = client.get_stream_id('stream to be deleted')['stream_id']
|
2019-04-08 10:11:18 +02:00
|
|
|
result = client.delete_stream(stream_id)
|
2019-06-22 08:22:32 +02:00
|
|
|
# {code_example|end}
|
2019-04-08 10:11:18 +02:00
|
|
|
validate_against_openapi_schema(result, '/streams/{stream_id}', 'delete', '200')
|
|
|
|
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/streams:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_streams(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-01-31 05:04:43 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get all streams that the user has access to
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.get_streams()
|
2018-01-31 05:04:43 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 18:53:13 +02:00
|
|
|
validate_against_openapi_schema(result, '/streams', 'get', '200')
|
2017-01-13 13:50:39 +01:00
|
|
|
streams = [s for s in result['streams'] if s['name'] == 'new stream']
|
|
|
|
assert streams[0]['description'] == 'New stream for testing'
|
|
|
|
|
2018-02-03 00:04:48 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# You may pass in one or more of the query parameters mentioned above
|
|
|
|
# as keyword arguments, like so:
|
|
|
|
result = client.get_streams(include_public=False)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 18:53:13 +02:00
|
|
|
validate_against_openapi_schema(result, '/streams', 'get', '200')
|
2018-02-03 00:04:48 +01:00
|
|
|
assert len(result['streams']) == 4
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/streams/{stream_id}:patch")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_stream(client: Client, stream_id: int) -> None:
|
2019-06-23 14:38:28 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Update the stream by a given ID
|
2019-04-23 00:11:49 +02:00
|
|
|
request = {
|
|
|
|
'stream_id': stream_id,
|
2020-02-04 21:50:55 +01:00
|
|
|
'stream_post_policy': 2,
|
2019-06-23 14:38:28 +02:00
|
|
|
'is_private': True,
|
2019-04-23 00:11:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.update_stream(request)
|
2019-06-23 14:38:28 +02:00
|
|
|
# {code_example|end}
|
2019-04-23 00:11:49 +02:00
|
|
|
|
2019-06-23 14:38:28 +02:00
|
|
|
validate_against_openapi_schema(result, '/streams/{stream_id}', 'patch', '200')
|
2019-04-23 00:11:49 +02:00
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/user_groups:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_user_groups(client: Client) -> int:
|
2018-08-18 23:06:53 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Get all user groups of the realm
|
|
|
|
result = client.get_user_groups()
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/user_groups', 'get', '200')
|
2019-06-29 03:16:34 +02:00
|
|
|
hamlet_user_group = [u for u in result['user_groups']
|
|
|
|
if u['name'] == "hamletcharacters"][0]
|
|
|
|
assert hamlet_user_group['description'] == 'Characters of Hamlet'
|
2018-08-18 23:06:53 +02:00
|
|
|
|
2019-06-29 03:16:34 +02:00
|
|
|
marketing_user_group = [u for u in result['user_groups']
|
|
|
|
if u['name'] == "marketing"][0]
|
|
|
|
return marketing_user_group['id']
|
2019-04-22 21:21:52 +02:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_user_not_authorized_error(nonadmin_client: Client) -> None:
|
2018-02-16 21:58:03 +01:00
|
|
|
result = nonadmin_client.get_streams(include_all_active=True)
|
|
|
|
|
2020-04-17 19:16:43 +02:00
|
|
|
validate_against_openapi_schema(result, '/rest-error-handling', 'post', '400_2')
|
2018-02-16 21:58:03 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_subscribers(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
result = client.get_subscribers(stream='new stream')
|
2018-02-06 04:17:10 +01:00
|
|
|
assert result['subscribers'] == ['iago@zulip.com', 'newbie@zulip.com']
|
2017-01-13 13:50:39 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_user_agent(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
result = client.get_user_agent()
|
|
|
|
assert result.startswith('ZulipPython/')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/subscriptions:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def list_subscriptions(client: Client) -> None:
|
2018-01-28 00:39:16 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get all streams that the user is subscribed to
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.list_subscriptions()
|
2018-01-28 00:39:16 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2019-07-19 07:02:10 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/subscriptions',
|
|
|
|
'get', '200')
|
2018-01-28 00:39:16 +01:00
|
|
|
|
2017-01-13 13:50:39 +01:00
|
|
|
streams = [s for s in result['subscriptions'] if s['name'] == 'new stream']
|
|
|
|
assert streams[0]['description'] == 'New stream for testing'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/subscriptions:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def remove_subscriptions(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-02-06 04:47:40 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Unsubscribe from the stream "new stream"
|
|
|
|
result = client.remove_subscriptions(
|
|
|
|
['new stream']
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-21 02:23:47 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/subscriptions',
|
|
|
|
'delete', '200')
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
# test it was actually removed
|
|
|
|
result = client.list_subscriptions()
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
streams = [s for s in result['subscriptions'] if s['name'] == 'new stream']
|
|
|
|
assert len(streams) == 0
|
|
|
|
|
2018-02-08 04:25:11 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Unsubscribe another user from the stream "new stream"
|
|
|
|
result = client.remove_subscriptions(
|
|
|
|
['new stream'],
|
|
|
|
principals=['newbie@zulip.com']
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-21 02:23:47 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/subscriptions',
|
|
|
|
'delete', '200')
|
2018-02-06 04:47:40 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/subscriptions/muted_topics:patch")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def toggle_mute_topic(client: Client) -> None:
|
2018-07-10 08:17:35 +02:00
|
|
|
|
|
|
|
# Send a test message
|
|
|
|
message = {
|
|
|
|
'type': 'stream',
|
|
|
|
'to': 'Denmark',
|
2018-11-10 22:49:43 +01:00
|
|
|
'topic': 'boat party'
|
2018-07-10 08:17:35 +02:00
|
|
|
}
|
|
|
|
client.call_endpoint(
|
|
|
|
url='messages',
|
|
|
|
method='POST',
|
|
|
|
request=message
|
|
|
|
)
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Mute the topic "boat party" in the stream "Denmark"
|
|
|
|
request = {
|
|
|
|
'stream': 'Denmark',
|
|
|
|
'topic': 'boat party',
|
|
|
|
'op': 'add'
|
|
|
|
}
|
|
|
|
result = client.mute_topic(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result,
|
|
|
|
'/users/me/subscriptions/muted_topics',
|
|
|
|
'patch', '200')
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Unmute the topic "boat party" in the stream "Denmark"
|
|
|
|
request = {
|
|
|
|
'stream': 'Denmark',
|
|
|
|
'topic': 'boat party',
|
|
|
|
'op': 'remove'
|
|
|
|
}
|
|
|
|
|
|
|
|
result = client.mute_topic(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result,
|
|
|
|
'/users/me/subscriptions/muted_topics',
|
|
|
|
'patch', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/mark_all_as_read:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def mark_all_as_read(client: Client) -> None:
|
2018-08-11 13:38:55 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Mark all of the user's unread messages as read
|
|
|
|
result = client.mark_all_as_read()
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/mark_all_as_read', 'post', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/mark_stream_as_read:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def mark_stream_as_read(client: Client) -> None:
|
2018-08-11 13:38:55 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Mark the unread messages in stream with ID "1" as read
|
|
|
|
result = client.mark_stream_as_read(1)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/mark_stream_as_read', 'post', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/mark_topic_as_read:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def mark_topic_as_read(client: Client) -> None:
|
2018-08-11 13:38:55 +02:00
|
|
|
|
|
|
|
# Grab an existing topic name
|
2019-04-06 08:03:54 +02:00
|
|
|
topic_name = client.get_stream_topics(1)['topics'][0]['name']
|
2018-08-11 13:38:55 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Mark the unread messages in stream 1's topic "topic_name" as read
|
2019-04-06 08:03:54 +02:00
|
|
|
result = client.mark_topic_as_read(1, topic_name)
|
2018-08-11 13:38:55 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/mark_stream_as_read', 'post', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/subscriptions/properties:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_subscription_settings(client: Client) -> None:
|
2018-07-12 10:09:50 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Update the user's subscription in stream #1 to pin it to the top of the
|
|
|
|
# stream list; and in stream #3 to have the hex color "f00"
|
|
|
|
request = [{
|
|
|
|
'stream_id': 1,
|
|
|
|
'property': 'pin_to_top',
|
|
|
|
'value': True
|
|
|
|
}, {
|
|
|
|
'stream_id': 3,
|
|
|
|
'property': 'color',
|
|
|
|
'value': 'f00'
|
|
|
|
}]
|
|
|
|
result = client.update_subscription_settings(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result,
|
|
|
|
'/users/me/subscriptions/properties',
|
|
|
|
'POST', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages/render:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def render_message(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-01-26 22:11:42 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Render a message
|
|
|
|
request = {
|
|
|
|
'content': '**foo**'
|
|
|
|
}
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.render_message(request)
|
2018-01-26 22:11:42 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 19:29:12 +02:00
|
|
|
validate_against_openapi_schema(result, '/messages/render', 'post', '200')
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_messages(client: Client) -> None:
|
2018-06-23 17:31:12 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
2020-01-29 02:58:17 +01:00
|
|
|
# Get the 100 last messages sent by "iago@zulip.com" to the stream "Verona"
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
request: Dict[str, Any] = {
|
2020-01-29 02:58:17 +01:00
|
|
|
'anchor': 'newest',
|
|
|
|
'num_before': 100,
|
2018-06-23 17:31:12 +02:00
|
|
|
'num_after': 0,
|
|
|
|
'narrow': [{'operator': 'sender', 'operand': 'iago@zulip.com'},
|
|
|
|
{'operator': 'stream', 'operand': 'Verona'}],
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
}
|
2018-06-23 17:31:12 +02:00
|
|
|
result = client.get_messages(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/messages', 'get', '200')
|
|
|
|
assert len(result['messages']) <= request['num_before']
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages/{message_id}:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_raw_message(client: Client, message_id: int) -> None:
|
2018-06-23 18:17:05 +02:00
|
|
|
|
|
|
|
assert int(message_id)
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Get the raw content of the message with ID "message_id"
|
|
|
|
result = client.get_raw_message(message_id)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}', 'get',
|
|
|
|
'200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def send_message(client: Client) -> int:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
request: Dict[str, Any] = {}
|
2020-03-06 08:44:00 +01:00
|
|
|
|
2018-01-27 22:26:16 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Send a stream message
|
|
|
|
request = {
|
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
2019-12-30 23:06:50 +01:00
|
|
|
"topic": "Castle",
|
2018-10-23 00:42:54 +02:00
|
|
|
"content": "I come not, friends, to steal away your hearts."
|
2018-01-27 22:26:16 +01:00
|
|
|
}
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.send_message(request)
|
2018-01-27 22:26:16 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
validate_against_openapi_schema(result, '/messages', 'post', '200')
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
# test that the message was actually sent
|
2018-01-27 22:26:16 +01:00
|
|
|
message_id = result['id']
|
2017-01-13 13:50:39 +01:00
|
|
|
url = 'messages/' + str(message_id)
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
|
|
|
method='GET'
|
|
|
|
)
|
|
|
|
assert result['result'] == 'success'
|
2018-01-27 22:26:16 +01:00
|
|
|
assert result['raw_content'] == request['content']
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2020-05-17 18:46:14 +02:00
|
|
|
ensure_users([10], ['hamlet'])
|
2020-03-06 08:44:00 +01:00
|
|
|
|
2018-01-27 22:56:36 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Send a private message
|
2020-05-17 18:46:14 +02:00
|
|
|
user_id = 10
|
2018-01-27 22:56:36 +01:00
|
|
|
request = {
|
|
|
|
"type": "private",
|
2020-03-06 08:44:00 +01:00
|
|
|
"to": [user_id],
|
2018-10-23 00:42:54 +02:00
|
|
|
"content": "With mirth and laughter let old wrinkles come."
|
2018-01-27 22:56:36 +01:00
|
|
|
}
|
|
|
|
result = client.send_message(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
validate_against_openapi_schema(result, '/messages', 'post', '200')
|
2018-01-27 22:56:36 +01:00
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
# test that the message was actually sent
|
2018-01-27 22:56:36 +01:00
|
|
|
message_id = result['id']
|
|
|
|
url = 'messages/' + str(message_id)
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
|
|
|
method='GET'
|
|
|
|
)
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
assert result['raw_content'] == request['content']
|
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
return message_id
|
|
|
|
|
2020-02-29 15:02:34 +01:00
|
|
|
@openapi_test_function("/messages/{message_id}/reactions:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def add_reaction(client: Client, message_id: int) -> None:
|
2020-02-29 15:02:34 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Add an emoji reaction
|
2019-02-17 07:58:55 +01:00
|
|
|
request = {
|
2019-08-07 03:44:04 +02:00
|
|
|
'message_id': str(message_id),
|
2020-02-29 15:02:34 +01:00
|
|
|
'emoji_name': 'octopus',
|
2019-02-17 07:58:55 +01:00
|
|
|
}
|
|
|
|
|
2020-02-29 15:02:34 +01:00
|
|
|
result = client.add_reaction(request)
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}/reactions', 'post', '200')
|
2019-02-17 07:58:55 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages/{message_id}/reactions:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def remove_reaction(client: Client, message_id: int) -> None:
|
2020-03-07 11:20:57 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Remove an emoji reaction
|
2019-04-03 15:10:37 +02:00
|
|
|
request = {
|
2019-08-07 03:44:04 +02:00
|
|
|
'message_id': str(message_id),
|
2020-02-29 15:02:34 +01:00
|
|
|
'emoji_name': 'octopus',
|
2019-04-03 15:10:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.remove_reaction(request)
|
2020-03-07 11:20:57 +01:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}/reactions', 'delete', '200')
|
2019-04-03 15:10:37 +02:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_nonexistent_stream_error(client: Client) -> None:
|
2018-06-18 17:44:48 +02:00
|
|
|
request = {
|
|
|
|
"type": "stream",
|
|
|
|
"to": "nonexistent_stream",
|
2018-11-10 22:49:43 +01:00
|
|
|
"topic": "Castle",
|
2018-10-23 00:42:54 +02:00
|
|
|
"content": "I come not, friends, to steal away your hearts."
|
2018-06-18 17:44:48 +02:00
|
|
|
}
|
|
|
|
result = client.send_message(request)
|
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
validate_against_openapi_schema(result, '/messages', 'post',
|
2020-04-17 19:16:43 +02:00
|
|
|
'400_0')
|
2018-06-18 17:44:48 +02:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_private_message_invalid_recipient(client: Client) -> None:
|
2018-02-16 20:35:05 +01:00
|
|
|
request = {
|
|
|
|
"type": "private",
|
|
|
|
"to": "eeshan@zulip.com",
|
2018-10-23 00:42:54 +02:00
|
|
|
"content": "With mirth and laughter let old wrinkles come."
|
2018-02-16 20:35:05 +01:00
|
|
|
}
|
|
|
|
result = client.send_message(request)
|
|
|
|
|
2018-06-18 18:15:08 +02:00
|
|
|
validate_against_openapi_schema(result, '/messages', 'post',
|
2020-04-17 19:16:43 +02:00
|
|
|
'400_1')
|
2018-02-16 20:35:05 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages/{message_id}:patch")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_message(client: Client, message_id: int) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
assert int(message_id)
|
2018-01-27 23:18:19 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Edit a message
|
|
|
|
# (make sure that message_id below is set to the ID of the
|
|
|
|
# message you wish to update)
|
|
|
|
request = {
|
|
|
|
"message_id": message_id,
|
|
|
|
"content": "New content"
|
|
|
|
}
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.update_message(request)
|
2018-01-27 23:18:19 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 16:32:30 +02:00
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}', 'patch',
|
|
|
|
'200')
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
# test it was actually updated
|
|
|
|
url = 'messages/' + str(message_id)
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
|
|
|
method='GET'
|
|
|
|
)
|
|
|
|
assert result['result'] == 'success'
|
2018-01-27 23:18:19 +01:00
|
|
|
assert result['raw_content'] == request['content']
|
2017-01-13 13:50:39 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_update_message_edit_permission_error(client: Client, nonadmin_client: Client) -> None:
|
2018-02-16 21:26:43 +01:00
|
|
|
request = {
|
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
2018-11-10 22:49:43 +01:00
|
|
|
"topic": "Castle",
|
2018-10-23 00:42:54 +02:00
|
|
|
"content": "I come not, friends, to steal away your hearts."
|
2018-02-16 21:26:43 +01:00
|
|
|
}
|
|
|
|
result = client.send_message(request)
|
|
|
|
|
|
|
|
request = {
|
|
|
|
"message_id": result["id"],
|
|
|
|
"content": "New content"
|
|
|
|
}
|
|
|
|
result = nonadmin_client.update_message(request)
|
|
|
|
|
2020-03-15 17:28:23 +01:00
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}', 'patch', '400')
|
2018-02-16 21:26:43 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages/{message_id}:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def delete_message(client: Client, message_id: int) -> None:
|
2018-06-26 16:30:46 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Delete the message with ID "message_id"
|
|
|
|
result = client.delete_message(message_id)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}', 'delete',
|
|
|
|
'200')
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_delete_message_edit_permission_error(client: Client, nonadmin_client: Client) -> None:
|
2018-06-26 16:30:46 +02:00
|
|
|
request = {
|
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
2018-11-10 22:49:43 +01:00
|
|
|
"topic": "Castle",
|
2018-10-23 00:42:54 +02:00
|
|
|
"content": "I come not, friends, to steal away your hearts."
|
2018-06-26 16:30:46 +02:00
|
|
|
}
|
|
|
|
result = client.send_message(request)
|
|
|
|
|
|
|
|
result = nonadmin_client.delete_message(result['id'])
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}', 'delete',
|
2020-04-17 19:16:43 +02:00
|
|
|
'400_1')
|
2018-06-26 16:30:46 +02:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages/{message_id}/history:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_message_history(client: Client, message_id: int) -> None:
|
2018-06-27 22:54:08 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Get the edit history for message with ID "message_id"
|
|
|
|
result = client.get_message_history(message_id)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/messages/{message_id}/history',
|
|
|
|
'get', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/realm/emoji:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_realm_emoji(client: Client) -> None:
|
2018-07-03 20:22:53 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
result = client.get_realm_emoji()
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/realm/emoji', 'GET', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/messages/flags:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_message_flags(client: Client) -> None:
|
2018-07-03 18:17:23 +02:00
|
|
|
|
|
|
|
# Send a few test messages
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
request: Dict[str, Any] = {
|
2018-07-03 18:17:23 +02:00
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
2018-11-10 22:49:43 +01:00
|
|
|
"topic": "Castle",
|
2018-10-23 00:42:54 +02:00
|
|
|
"content": "I come not, friends, to steal away your hearts."
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
}
|
2018-07-03 18:17:23 +02:00
|
|
|
message_ids = []
|
|
|
|
for i in range(0, 3):
|
|
|
|
message_ids.append(client.send_message(request)['id'])
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Add the "read" flag to the messages with IDs in "message_ids"
|
|
|
|
request = {
|
|
|
|
'messages': message_ids,
|
|
|
|
'op': 'add',
|
|
|
|
'flag': 'read'
|
|
|
|
}
|
|
|
|
result = client.update_message_flags(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/messages/flags', 'post',
|
|
|
|
'200')
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Remove the "starred" flag from the messages with IDs in "message_ids"
|
|
|
|
request = {
|
|
|
|
'messages': message_ids,
|
|
|
|
'op': 'remove',
|
|
|
|
'flag': 'starred'
|
|
|
|
}
|
|
|
|
result = client.update_message_flags(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/messages/flags', 'post',
|
|
|
|
'200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/register:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def register_queue(client: Client) -> str:
|
2018-02-07 05:00:10 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Register the queue
|
|
|
|
result = client.register(
|
2018-08-01 12:39:52 +02:00
|
|
|
event_types=['message', 'realm_emoji']
|
2018-02-07 05:00:10 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-20 23:03:01 +02:00
|
|
|
validate_against_openapi_schema(result, '/register', 'post', '200')
|
2018-02-07 05:00:10 +01:00
|
|
|
return result['queue_id']
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/events:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def deregister_queue(client: Client, queue_id: str) -> None:
|
2018-02-08 03:54:20 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Delete a queue (queue_id is the ID of the queue
|
|
|
|
# to be removed)
|
|
|
|
result = client.deregister(queue_id)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-21 01:28:33 +02:00
|
|
|
validate_against_openapi_schema(result, '/events', 'delete', '200')
|
2018-02-08 03:54:20 +01:00
|
|
|
|
2018-02-16 23:49:35 +01:00
|
|
|
# Test "BAD_EVENT_QUEUE_ID" error
|
|
|
|
result = client.deregister(queue_id)
|
2018-06-21 01:28:33 +02:00
|
|
|
validate_against_openapi_schema(result, '/events', 'delete', '400')
|
2018-02-16 23:49:35 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/server_settings:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_server_settings(client: Client) -> None:
|
2018-08-11 15:50:56 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Fetch the settings for this server
|
|
|
|
result = client.get_server_settings()
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/server_settings', 'get', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/settings/notifications:patch")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_notification_settings(client: Client) -> None:
|
2018-08-10 02:15:45 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Enable push notifications even when online
|
|
|
|
request = {
|
|
|
|
'enable_offline_push_notifications': True,
|
|
|
|
'enable_online_push_notifications': True,
|
|
|
|
}
|
|
|
|
result = client.update_notification_settings(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/settings/notifications', 'patch', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/user_uploads:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def upload_file(client: Client) -> None:
|
2018-12-12 19:49:14 +01:00
|
|
|
path_to_file = os.path.join(ZULIP_DIR, 'zerver', 'tests', 'images', 'img.jpg')
|
2018-02-25 01:01:45 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Upload a file
|
2019-07-14 21:37:08 +02:00
|
|
|
with open(path_to_file, 'rb') as fp:
|
|
|
|
result = client.call_endpoint(
|
|
|
|
'user_uploads',
|
|
|
|
method='POST',
|
|
|
|
files=[fp]
|
|
|
|
)
|
2019-11-30 01:10:18 +01:00
|
|
|
|
|
|
|
client.send_message({
|
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
|
|
|
"topic": "Castle",
|
|
|
|
"content": "Check out [this picture](%s) of my castle!" % (result['uri'],)
|
|
|
|
})
|
2018-02-25 01:01:45 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-21 03:04:05 +02:00
|
|
|
validate_against_openapi_schema(result, '/user_uploads', 'post', '200')
|
2018-02-25 01:01:45 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/{stream_id}/topics:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_stream_topics(client: Client, stream_id: int) -> None:
|
2018-06-01 18:58:07 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
result = client.get_stream_topics(stream_id)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2018-06-18 16:32:30 +02:00
|
|
|
validate_against_openapi_schema(result, '/users/me/{stream_id}/topics',
|
|
|
|
'get', '200')
|
2018-06-01 18:58:07 +02:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/typing:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def set_typing_status(client: Client) -> None:
|
2020-05-17 18:46:14 +02:00
|
|
|
ensure_users([10, 11], ['hamlet', 'iago'])
|
2018-08-09 20:27:12 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# The user has started to type in the group PM with Iago and Polonius
|
2020-05-17 18:46:14 +02:00
|
|
|
user_id1 = 10
|
|
|
|
user_id2 = 11
|
2020-02-22 13:38:09 +01:00
|
|
|
|
2018-08-09 20:27:12 +02:00
|
|
|
request = {
|
|
|
|
'op': 'start',
|
2020-02-22 13:38:09 +01:00
|
|
|
'to': [user_id1, user_id2],
|
2018-08-09 20:27:12 +02:00
|
|
|
}
|
|
|
|
result = client.set_typing_status(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/typing', 'post', '200')
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# The user has finished typing in the group PM with Iago and Polonius
|
2020-05-17 18:46:14 +02:00
|
|
|
user_id1 = 10
|
|
|
|
user_id2 = 11
|
2020-02-22 13:38:09 +01:00
|
|
|
|
2018-08-09 20:27:12 +02:00
|
|
|
request = {
|
|
|
|
'op': 'stop',
|
2020-02-22 13:38:09 +01:00
|
|
|
'to': [user_id1, user_id2],
|
2018-08-09 20:27:12 +02:00
|
|
|
}
|
|
|
|
result = client.set_typing_status(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, '/typing', 'post', '200')
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/realm/emoji/{emoji_name}:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def upload_custom_emoji(client: Client) -> None:
|
2018-12-12 19:49:14 +01:00
|
|
|
emoji_path = os.path.join(ZULIP_DIR, 'zerver', 'tests', 'images', 'img.jpg')
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Upload a custom emoji; assume `emoji_path` is the path to your image.
|
2019-07-14 21:37:08 +02:00
|
|
|
with open(emoji_path, 'rb') as fp:
|
|
|
|
emoji_name = 'my_custom_emoji'
|
|
|
|
result = client.call_endpoint(
|
|
|
|
'realm/emoji/{}'.format(emoji_name),
|
|
|
|
method='POST',
|
|
|
|
files=[fp]
|
|
|
|
)
|
2018-12-12 19:49:14 +01:00
|
|
|
# {code_example|end}
|
2019-07-14 21:37:08 +02:00
|
|
|
|
2018-12-12 19:49:14 +01:00
|
|
|
validate_against_openapi_schema(result,
|
2019-07-11 12:45:26 +02:00
|
|
|
'/realm/emoji/{emoji_name}',
|
2018-12-12 19:49:14 +01:00
|
|
|
'post', '200')
|
2018-08-09 20:27:12 +02:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/alert_words:get")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def get_alert_words(client: Client) -> None:
|
2019-04-22 19:49:33 +02:00
|
|
|
result = client.get_alert_words()
|
|
|
|
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/alert_words:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def add_alert_words(client: Client) -> None:
|
2019-04-22 19:51:05 +02:00
|
|
|
word = ['foo', 'bar']
|
|
|
|
|
|
|
|
result = client.add_alert_words(word)
|
|
|
|
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/alert_words:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def remove_alert_words(client: Client) -> None:
|
2019-04-22 19:52:15 +02:00
|
|
|
word = ['foo']
|
|
|
|
|
|
|
|
result = client.remove_alert_words(word)
|
|
|
|
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/user_groups/create:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def create_user_group(client: Client) -> None:
|
2020-05-17 18:46:14 +02:00
|
|
|
ensure_users([6, 7, 8, 10], ['aaron', 'zoe', 'cordelia', 'hamlet'])
|
2019-08-20 01:44:44 +02:00
|
|
|
|
2019-06-24 22:27:06 +02:00
|
|
|
# {code_example|start}
|
2019-04-22 20:16:30 +02:00
|
|
|
request = {
|
2019-06-24 22:27:06 +02:00
|
|
|
'name': 'marketing',
|
|
|
|
'description': 'The marketing team.',
|
2020-05-17 18:46:14 +02:00
|
|
|
'members': [6, 7, 8, 10],
|
2019-04-22 20:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.create_user_group(request)
|
2019-06-24 22:27:06 +02:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, '/user_groups/create', 'post', '200')
|
2019-04-22 20:16:30 +02:00
|
|
|
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/user_groups/{group_id}:patch")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_user_group(client: Client, group_id: int) -> None:
|
2019-06-25 21:43:53 +02:00
|
|
|
# {code_example|start}
|
2019-04-22 21:21:52 +02:00
|
|
|
request = {
|
|
|
|
'group_id': group_id,
|
2019-06-25 21:43:53 +02:00
|
|
|
'name': 'marketing',
|
|
|
|
'description': 'The marketing team.',
|
2019-04-22 21:21:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.update_user_group(request)
|
2019-06-25 21:43:53 +02:00
|
|
|
# {code_example|end}
|
2019-04-22 21:21:52 +02:00
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/user_groups/{group_id}:delete")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def remove_user_group(client: Client, group_id: int) -> None:
|
2019-06-25 22:00:34 +02:00
|
|
|
# {code_example|start}
|
2019-04-22 21:32:35 +02:00
|
|
|
result = client.remove_user_group(group_id)
|
2019-06-25 22:00:34 +02:00
|
|
|
# {code_example|end}
|
2019-04-22 21:32:35 +02:00
|
|
|
|
2019-06-25 22:00:34 +02:00
|
|
|
validate_against_openapi_schema(result, '/user_groups/{group_id}', 'delete', '200')
|
2019-04-22 21:32:35 +02:00
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/user_groups/{group_id}/members:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_user_group_members(client: Client, group_id: int) -> None:
|
2020-05-17 18:46:14 +02:00
|
|
|
ensure_users([8, 10, 11], ['cordelia', 'hamlet', 'iago'])
|
2019-08-20 01:44:44 +02:00
|
|
|
|
2019-04-22 22:18:15 +02:00
|
|
|
request = {
|
|
|
|
'group_id': group_id,
|
2020-05-17 18:46:14 +02:00
|
|
|
'delete': [8, 10],
|
|
|
|
'add': [11]
|
2019-04-22 22:18:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.update_user_group_members(request)
|
|
|
|
|
|
|
|
assert result['result'] == 'success'
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_invalid_api_key(client_with_invalid_key: Client) -> None:
|
2018-02-06 21:04:07 +01:00
|
|
|
result = client_with_invalid_key.list_subscriptions()
|
2020-04-17 19:16:43 +02:00
|
|
|
validate_against_openapi_schema(result, '/rest-error-handling', 'post', '400_0')
|
2018-02-06 21:04:07 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_missing_request_argument(client: Client) -> None:
|
2018-02-16 21:03:50 +01:00
|
|
|
result = client.render_message({})
|
|
|
|
|
2020-04-17 19:16:43 +02:00
|
|
|
validate_against_openapi_schema(result, '/rest-error-handling', 'post', '400_1')
|
2020-04-02 02:15:28 +02:00
|
|
|
|
2018-02-06 21:04:07 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_invalid_stream_error(client: Client) -> None:
|
2018-02-16 22:23:51 +01:00
|
|
|
result = client.get_stream_id('nonexistent')
|
|
|
|
|
2018-06-18 19:20:55 +02:00
|
|
|
validate_against_openapi_schema(result, '/get_stream_id', 'get', '400')
|
2018-02-16 22:23:51 +01:00
|
|
|
|
2018-01-26 22:11:42 +01:00
|
|
|
|
2017-01-13 13:50:39 +01:00
|
|
|
# SETUP METHODS FOLLOW
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_against_fixture(result: Dict[str, Any], fixture: Dict[str, Any], check_if_equal: Optional[Iterable[str]] = [], check_if_exists: Optional[Iterable[str]] = []) -> None:
|
2018-04-27 22:09:57 +02:00
|
|
|
assertLength(result, fixture)
|
2018-01-27 22:26:16 +01:00
|
|
|
|
2018-01-26 22:11:42 +01:00
|
|
|
if not check_if_equal and not check_if_exists:
|
|
|
|
for key, value in fixture.items():
|
2018-04-27 22:09:57 +02:00
|
|
|
assertEqual(key, result, fixture)
|
2018-01-26 22:11:42 +01:00
|
|
|
|
|
|
|
if check_if_equal:
|
|
|
|
for key in check_if_equal:
|
2018-04-27 22:09:57 +02:00
|
|
|
assertEqual(key, result, fixture)
|
2018-01-26 22:11:42 +01:00
|
|
|
|
|
|
|
if check_if_exists:
|
|
|
|
for key in check_if_exists:
|
2018-04-27 22:09:57 +02:00
|
|
|
assertIn(key, result)
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def assertEqual(key: str, result: Dict[str, Any], fixture: Dict[str, Any]) -> None:
|
2018-04-27 22:09:57 +02:00
|
|
|
if result[key] != fixture[key]:
|
|
|
|
first = "{key} = {value}".format(key=key, value=result[key])
|
|
|
|
second = "{key} = {value}".format(key=key, value=fixture[key])
|
|
|
|
raise AssertionError("Actual and expected outputs do not match; showing diff:\n" +
|
|
|
|
mdiff.diff_strings(first, second))
|
|
|
|
else:
|
|
|
|
assert result[key] == fixture[key]
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def assertLength(result: Dict[str, Any], fixture: Dict[str, Any]) -> None:
|
2018-04-27 22:09:57 +02:00
|
|
|
if len(result) != len(fixture):
|
|
|
|
result_string = json.dumps(result, indent=4, sort_keys=True)
|
|
|
|
fixture_string = json.dumps(fixture, indent=4, sort_keys=True)
|
|
|
|
raise AssertionError("The lengths of the actual and expected outputs do not match; showing diff:\n" +
|
|
|
|
mdiff.diff_strings(result_string, fixture_string))
|
|
|
|
else:
|
|
|
|
assert len(result) == len(fixture)
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def assertIn(key: str, result: Dict[str, Any]) -> None:
|
2018-04-27 22:09:57 +02:00
|
|
|
if key not in result.keys():
|
|
|
|
raise AssertionError(
|
|
|
|
"The actual output does not contain the the key `{key}`.".format(key=key)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
assert key in result
|
2018-01-26 22:11:42 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_messages(client: Client, nonadmin_client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
render_message(client)
|
2018-06-18 17:44:48 +02:00
|
|
|
message_id = send_message(client)
|
2019-02-17 07:58:55 +01:00
|
|
|
add_reaction(client, message_id)
|
2019-04-03 15:10:37 +02:00
|
|
|
remove_reaction(client, message_id)
|
2017-01-13 13:50:39 +01:00
|
|
|
update_message(client, message_id)
|
2018-06-23 18:17:05 +02:00
|
|
|
get_raw_message(client, message_id)
|
2018-06-23 17:31:12 +02:00
|
|
|
get_messages(client)
|
2018-06-27 22:54:08 +02:00
|
|
|
get_message_history(client, message_id)
|
2018-06-26 16:30:46 +02:00
|
|
|
delete_message(client, message_id)
|
2018-08-11 13:38:55 +02:00
|
|
|
mark_all_as_read(client)
|
|
|
|
mark_stream_as_read(client)
|
|
|
|
mark_topic_as_read(client)
|
2018-07-03 18:17:23 +02:00
|
|
|
update_message_flags(client)
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-02-16 20:25:59 +01:00
|
|
|
test_nonexistent_stream_error(client)
|
2018-02-16 20:35:05 +01:00
|
|
|
test_private_message_invalid_recipient(client)
|
2018-06-23 22:46:44 +02:00
|
|
|
test_update_message_edit_permission_error(client, nonadmin_client)
|
2018-06-26 16:30:46 +02:00
|
|
|
test_delete_message_edit_permission_error(client, nonadmin_client)
|
2018-02-16 20:25:59 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_users(client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
create_user(client)
|
|
|
|
get_members(client)
|
2020-02-14 21:39:12 +01:00
|
|
|
get_single_user(client)
|
2020-02-14 22:02:24 +01:00
|
|
|
deactivate_user(client)
|
2020-02-14 22:13:01 +01:00
|
|
|
update_user(client)
|
2017-01-13 13:50:39 +01:00
|
|
|
get_profile(client)
|
2018-08-10 02:15:45 +02:00
|
|
|
update_notification_settings(client)
|
2018-02-25 01:01:45 +01:00
|
|
|
upload_file(client)
|
2018-08-09 20:27:12 +02:00
|
|
|
set_typing_status(client)
|
2018-08-07 17:52:03 +02:00
|
|
|
get_user_presence(client)
|
2019-04-22 23:58:53 +02:00
|
|
|
update_presence(client)
|
2019-04-22 20:16:30 +02:00
|
|
|
create_user_group(client)
|
2019-06-29 03:16:34 +02:00
|
|
|
group_id = get_user_groups(client)
|
2019-04-22 21:21:52 +02:00
|
|
|
update_user_group(client, group_id)
|
2019-04-22 22:18:15 +02:00
|
|
|
update_user_group_members(client, group_id)
|
2019-04-22 21:32:35 +02:00
|
|
|
remove_user_group(client, group_id)
|
2019-04-22 19:49:33 +02:00
|
|
|
get_alert_words(client)
|
2019-04-22 19:51:05 +02:00
|
|
|
add_alert_words(client)
|
2019-04-22 19:52:15 +02:00
|
|
|
remove_alert_words(client)
|
2017-01-13 13:50:39 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_streams(client: Client, nonadmin_client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
add_subscriptions(client)
|
2018-02-16 22:41:29 +01:00
|
|
|
test_add_subscriptions_already_subscribed(client)
|
2017-01-13 13:50:39 +01:00
|
|
|
list_subscriptions(client)
|
2019-04-08 10:11:18 +02:00
|
|
|
stream_id = get_stream_id(client)
|
2019-04-23 00:11:49 +02:00
|
|
|
update_stream(client, stream_id)
|
2017-01-13 13:50:39 +01:00
|
|
|
get_streams(client)
|
|
|
|
get_subscribers(client)
|
2018-02-06 04:47:40 +01:00
|
|
|
remove_subscriptions(client)
|
2018-07-10 08:17:35 +02:00
|
|
|
toggle_mute_topic(client)
|
2018-07-12 10:09:50 +02:00
|
|
|
update_subscription_settings(client)
|
2019-04-22 23:37:57 +02:00
|
|
|
update_notification_settings(client)
|
2018-06-01 18:58:07 +02:00
|
|
|
get_stream_topics(client, 1)
|
2019-04-08 10:11:18 +02:00
|
|
|
delete_stream(client, stream_id)
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2018-06-23 22:46:44 +02:00
|
|
|
test_user_not_authorized_error(nonadmin_client)
|
|
|
|
test_authorization_errors_fatal(client, nonadmin_client)
|
|
|
|
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_queues(client: Client) -> None:
|
2018-02-16 02:53:45 +01:00
|
|
|
# Note that the example for api/get-events-from-queue is not tested.
|
|
|
|
# Since, methods such as client.get_events() or client.call_on_each_message
|
|
|
|
# are blocking calls and since the event queue backend is already
|
|
|
|
# thoroughly tested in zerver/tests/test_event_queue.py, it is not worth
|
|
|
|
# the effort to come up with asynchronous logic for testing those here.
|
2018-02-08 03:54:20 +01:00
|
|
|
queue_id = register_queue(client)
|
|
|
|
deregister_queue(client, queue_id)
|
2018-02-07 05:00:10 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_server_organizations(client: Client) -> None:
|
2018-08-14 02:54:36 +02:00
|
|
|
|
2018-08-14 03:10:37 +02:00
|
|
|
get_realm_filters(client)
|
2018-08-14 02:54:36 +02:00
|
|
|
add_realm_filter(client)
|
2018-08-11 15:50:56 +02:00
|
|
|
get_server_settings(client)
|
2018-08-14 03:20:39 +02:00
|
|
|
remove_realm_filter(client)
|
2018-07-03 20:22:53 +02:00
|
|
|
get_realm_emoji(client)
|
2018-12-12 19:49:14 +01:00
|
|
|
upload_custom_emoji(client)
|
2018-08-11 15:10:38 +02:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_errors(client: Client) -> None:
|
2018-02-16 21:03:50 +01:00
|
|
|
test_missing_request_argument(client)
|
2018-02-16 22:23:51 +01:00
|
|
|
test_invalid_stream_error(client)
|
2018-02-16 21:03:50 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def test_the_api(client: Client, nonadmin_client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
get_user_agent(client)
|
|
|
|
test_users(client)
|
2018-06-23 22:46:44 +02:00
|
|
|
test_streams(client, nonadmin_client)
|
|
|
|
test_messages(client, nonadmin_client)
|
2018-02-07 05:00:10 +01:00
|
|
|
test_queues(client)
|
2018-08-11 15:10:38 +02:00
|
|
|
test_server_organizations(client)
|
2018-02-16 21:03:50 +01:00
|
|
|
test_errors(client)
|
2019-08-08 20:40:30 +02:00
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
if REGISTERED_TEST_FUNCTIONS != CALLED_TEST_FUNCTIONS:
|
|
|
|
print("Error! Some @openapi_test_function tests were never called:")
|
|
|
|
print(" ", REGISTERED_TEST_FUNCTIONS - CALLED_TEST_FUNCTIONS)
|
|
|
|
sys.exit(1)
|