2020-09-15 00:24:01 +02:00
|
|
|
# Zulip's OpenAPI-based API documentation system is documented at
|
|
|
|
# https://zulip.readthedocs.io/en/latest/documentation/api.html
|
|
|
|
#
|
|
|
|
# This file defines the Python code examples that appears in Zulip's
|
|
|
|
# REST API documentation, and also contains a system for running the
|
|
|
|
# example code as part of the `tools/test-api` test suite.
|
|
|
|
#
|
|
|
|
# The actual documentation appears within these blocks:
|
|
|
|
# # {code_example|start}
|
|
|
|
# Code here
|
|
|
|
# # {code_example|end}
|
|
|
|
#
|
|
|
|
# Whereas the surrounding code is test setup logic.
|
|
|
|
|
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
|
2022-07-27 23:33:49 +02:00
|
|
|
from email.headerregistry import Address
|
2019-08-08 20:40:30 +02:00
|
|
|
from functools import wraps
|
2022-08-21 04:26:00 +02:00
|
|
|
from typing import Any, Callable, Dict, List, Set, TypeVar
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2022-08-21 04:26:00 +02:00
|
|
|
from typing_extensions import ParamSpec
|
2020-06-11 00:54:34 +02:00
|
|
|
from zulip import Client
|
2018-04-27 22:09:57 +02:00
|
|
|
|
2019-08-20 01:44:44 +02:00
|
|
|
from zerver.models import get_realm, get_user
|
2020-06-11 00:54:34 +02:00
|
|
|
from zerver.openapi.openapi import validate_against_openapi_schema
|
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__))))
|
|
|
|
|
2020-09-02 08:14:51 +02:00
|
|
|
TEST_FUNCTIONS: Dict[str, Callable[..., object]] = {}
|
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
|
|
|
REGISTERED_TEST_FUNCTIONS: Set[str] = set()
|
|
|
|
CALLED_TEST_FUNCTIONS: Set[str] = set()
|
2019-08-07 20:03:43 +02:00
|
|
|
|
2022-08-21 04:26:00 +02:00
|
|
|
ParamT = ParamSpec("ParamT")
|
|
|
|
ReturnT = TypeVar("ReturnT")
|
2020-06-24 01:52:37 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2022-08-21 04:26:00 +02:00
|
|
|
def openapi_test_function(
|
|
|
|
endpoint: str,
|
|
|
|
) -> Callable[[Callable[ParamT, ReturnT]], Callable[ParamT, ReturnT]]:
|
2020-10-23 02:43:28 +02:00
|
|
|
"""This decorator is used to register an OpenAPI test function with
|
2019-08-08 20:40:30 +02:00
|
|
|
its endpoint. Example usage:
|
|
|
|
|
|
|
|
@openapi_test_function("/messages/render:post")
|
|
|
|
def ...
|
|
|
|
"""
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2022-08-21 04:26:00 +02:00
|
|
|
def wrapper(test_func: Callable[ParamT, ReturnT]) -> Callable[ParamT, ReturnT]:
|
2019-08-08 20:40:30 +02:00
|
|
|
@wraps(test_func)
|
2022-08-21 04:26:00 +02:00
|
|
|
def _record_calls_wrapper(*args: ParamT.args, **kwargs: ParamT.kwargs) -> ReturnT:
|
2019-08-08 20:40:30 +02:00
|
|
|
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
|
|
|
|
|
2022-08-21 04:26:00 +02:00
|
|
|
return _record_calls_wrapper
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
return wrapper
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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")
|
2022-07-27 23:33:49 +02:00
|
|
|
user_ids = [
|
|
|
|
get_user(Address(username=name, domain="zulip.com").addr_spec, realm).id
|
|
|
|
for name in user_names
|
|
|
|
]
|
2019-08-20 01:44:44 +02:00
|
|
|
|
|
|
|
assert ids_list == user_ids
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2018-02-06 04:17:10 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Subscribe to the stream "new stream"
|
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
"name": "new stream",
|
|
|
|
"description": "New stream for testing",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
},
|
|
|
|
],
|
2018-02-06 04:17:10 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2022-01-13 04:57:39 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "post", "200")
|
2018-02-06 04:17:10 +01:00
|
|
|
|
2023-04-11 19:51:14 +02:00
|
|
|
ensure_users([25], ["newbie"])
|
2018-02-06 04:17:10 +01:00
|
|
|
# {code_example|start}
|
2020-06-25 23:34:10 +02:00
|
|
|
# To subscribe other users to a stream, you may pass
|
2018-02-06 04:17:10 +01:00
|
|
|
# the `principals` argument, like so:
|
2023-04-11 19:51:14 +02:00
|
|
|
user_id = 25
|
2018-02-06 04:17:10 +01:00
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
2021-02-12 08:20:45 +01:00
|
|
|
{"name": "new stream", "description": "New stream for testing"},
|
2018-02-06 04:17:10 +01:00
|
|
|
],
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
principals=[user_id],
|
2018-02-06 04:17:10 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
|
|
|
assert "newbie@zulip.com" in result["subscribed"]
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +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=[
|
2021-02-12 08:20:45 +01:00
|
|
|
{"name": "new stream", "description": "New stream for testing"},
|
2018-02-16 22:41:29 +01:00
|
|
|
],
|
2021-02-12 08:20:45 +01:00
|
|
|
principals=["newbie@zulip.com"],
|
2018-02-16 22:41:29 +01:00
|
|
|
)
|
|
|
|
|
2022-01-13 04:57:39 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "post", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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=[
|
2021-02-12 08:20:45 +01:00
|
|
|
{"name": "private_stream"},
|
2018-02-16 23:22:45 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
stream_id = client.get_stream_id("private_stream")["stream_id"]
|
2018-02-16 23:22:45 +01:00
|
|
|
client.call_endpoint(
|
2021-02-12 08:20:45 +01:00
|
|
|
f"streams/{stream_id}",
|
|
|
|
method="PATCH",
|
|
|
|
request={"is_private": True},
|
2018-02-16 23:22:45 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
result = nonadmin_client.add_subscriptions(
|
|
|
|
streams=[
|
2021-02-12 08:20:45 +01:00
|
|
|
{"name": "private_stream"},
|
2018-02-16 23:22:45 +01:00
|
|
|
],
|
|
|
|
authorization_errors_fatal=False,
|
|
|
|
)
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "post", "400")
|
2018-02-16 23:22:45 +01:00
|
|
|
|
|
|
|
result = nonadmin_client.add_subscriptions(
|
|
|
|
streams=[
|
2021-02-12 08:20:45 +01:00
|
|
|
{"name": "private_stream"},
|
2018-02-16 23:22:45 +01:00
|
|
|
],
|
|
|
|
authorization_errors_fatal=True,
|
|
|
|
)
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "post", "400")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-02-16 23:22:45 +01:00
|
|
|
|
2022-07-12 12:41:18 +02:00
|
|
|
@openapi_test_function("/realm/presence:get")
|
|
|
|
def get_presence(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Get presence information of all the users in an organization.
|
|
|
|
result = client.get_realm_presence()
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/realm/presence", "get", "200")
|
|
|
|
|
|
|
|
|
2022-08-01 15:33:11 +02:00
|
|
|
@openapi_test_function("/default_streams:post")
|
|
|
|
def add_default_stream(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Add a stream to the set of default streams for new users.
|
|
|
|
stream_id = 7
|
|
|
|
|
|
|
|
result = client.add_default_stream(stream_id)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/default_streams", "post", "200")
|
|
|
|
|
|
|
|
|
|
|
|
@openapi_test_function("/default_streams:delete")
|
|
|
|
def remove_default_stream(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Remove a stream from the set of default streams for new users.
|
|
|
|
request = {"stream_id": 7}
|
|
|
|
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/default_streams",
|
|
|
|
method="DELETE",
|
|
|
|
request=request,
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/default_streams", "delete", "200")
|
|
|
|
|
|
|
|
|
2021-01-04 19:36:00 +01:00
|
|
|
@openapi_test_function("/users/{user_id_or_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"
|
2021-02-12 08:20:45 +01:00
|
|
|
result = client.get_user_presence("iago@zulip.com")
|
2018-08-07 17:52:03 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-01-04 19:36:00 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id_or_email}/presence", "get", "200")
|
2018-08-07 17:52:03 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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 = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"status": "active",
|
|
|
|
"ping_only": False,
|
|
|
|
"new_user_input": False,
|
2019-04-22 23:58:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.update_presence(request)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
2019-04-22 23:58:53 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2018-01-31 05:36:57 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Create a user
|
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"email": "newbie@zulip.com",
|
|
|
|
"password": "temp",
|
|
|
|
"full_name": "New User",
|
2018-01-31 05:36:57 +01:00
|
|
|
}
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.create_user(request)
|
2018-01-31 05:36:57 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01: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)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users", "post", "400")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-07-26 17:34:02 +02:00
|
|
|
@openapi_test_function("/users/me/status:post")
|
|
|
|
def update_status(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# The request contains the new status and away boolean
|
|
|
|
request = {
|
|
|
|
"status_text": "on vacation",
|
|
|
|
"away": False,
|
|
|
|
"emoji_name": "car",
|
|
|
|
"emoji_code": "1f697",
|
|
|
|
"reaction_type": "unicode_emoji",
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(url="/users/me/status", method="POST", request=request)
|
|
|
|
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/users/me/status", "post", "200")
|
|
|
|
|
|
|
|
# Test "status_text is too long error"
|
|
|
|
request = {
|
|
|
|
"status_text": "This is a message that exceeds 60 characters, and so should throw an error.",
|
|
|
|
"away": "false",
|
|
|
|
}
|
|
|
|
validate_against_openapi_schema(result, "/users/me/status", "post", "400")
|
|
|
|
|
|
|
|
|
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:
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users", "get", "200")
|
2018-06-18 19:43:40 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
members = [m for m in result["members"] if m["email"] == "newbie@zulip.com"]
|
2017-01-13 13:50:39 +01:00
|
|
|
assert len(members) == 1
|
2018-02-07 04:25:23 +01:00
|
|
|
newbie = members[0]
|
2021-02-12 08:20:45 +01:00
|
|
|
assert not newbie["is_admin"]
|
|
|
|
assert newbie["full_name"] == "New User"
|
2018-02-07 04:25:23 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# You may pass the `client_gravatar` query parameter as follows:
|
2021-08-05 19:48:43 +02:00
|
|
|
result = client.get_members({"client_gravatar": False})
|
2018-02-07 04:25:23 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users", "get", "200")
|
2021-08-09 11:15:55 +02:00
|
|
|
assert result["members"][0]["avatar_url"] is not 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:
|
2021-02-12 08:20:45 +01:00
|
|
|
result = client.get_members({"include_custom_profile_fields": True})
|
2019-10-26 19:38:27 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users", "get", "200")
|
|
|
|
for member in result["members"]:
|
2019-10-26 19:38:27 +02:00
|
|
|
if member["is_bot"]:
|
2021-02-12 08:20:45 +01:00
|
|
|
assert member.get("profile_data", None) is None
|
2019-10-26 19:38:27 +02:00
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
assert member.get("profile_data", None) is not None
|
2021-08-09 11:15:55 +02:00
|
|
|
assert member["avatar_url"] is None
|
2019-10-26 19:38:27 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-01-02 15:05:29 +01:00
|
|
|
@openapi_test_function("/users/{email}:get")
|
|
|
|
def get_user_by_email(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Fetch details on a user given a user ID
|
|
|
|
email = "iago@zulip.com"
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=f"/users/{email}",
|
|
|
|
method="GET",
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/users/{email}", "get", "200")
|
|
|
|
|
|
|
|
|
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:
|
2021-07-12 19:45:03 +02:00
|
|
|
ensure_users([8], ["cordelia"])
|
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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}", "get", "200")
|
2020-02-14 21:39:12 +01:00
|
|
|
|
|
|
|
# {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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}", "get", "200")
|
2020-02-14 21:39:12 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2021-07-12 19:45:03 +02:00
|
|
|
ensure_users([8], ["cordelia"])
|
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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}", "delete", "200")
|
2020-02-14 22:02:24 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-05-19 19:30:47 +02:00
|
|
|
@openapi_test_function("/users/{user_id}/reactivate:post")
|
|
|
|
def reactivate_user(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Reactivate a user
|
|
|
|
user_id = 8
|
|
|
|
result = client.reactivate_user_by_id(user_id)
|
|
|
|
# {code_example|end}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}/reactivate", "post", "200")
|
2020-05-19 19:30:47 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2021-07-12 19:45:03 +02:00
|
|
|
ensure_users([8, 10], ["cordelia", "hamlet"])
|
2020-02-14 22:13:01 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Change a user's full name.
|
|
|
|
user_id = 10
|
2021-02-12 08:19:30 +01:00
|
|
|
result = client.update_user_by_id(user_id, full_name="New Name")
|
2020-02-14 22:13:01 +01:00
|
|
|
# {code_example|end}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}", "patch", "200")
|
2020-02-14 22:13:01 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Change value of the custom profile field with ID 9.
|
|
|
|
user_id = 8
|
2021-02-12 08:20:45 +01: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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}", "patch", "400")
|
2020-02-14 22:13:01 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-05-31 19:10:41 +02:00
|
|
|
@openapi_test_function("/users/{user_id}/subscriptions/{stream_id}:get")
|
|
|
|
def get_subscription_status(client: Client) -> None:
|
2021-07-12 19:45:03 +02:00
|
|
|
ensure_users([7], ["zoe"])
|
|
|
|
|
2020-05-31 19:10:41 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Check whether a user is a subscriber to a given stream.
|
|
|
|
user_id = 7
|
|
|
|
stream_id = 1
|
|
|
|
result = client.call_endpoint(
|
2021-02-12 08:20:45 +01:00
|
|
|
url=f"/users/{user_id}/subscriptions/{stream_id}",
|
|
|
|
method="GET",
|
2020-05-31 19:10:41 +02:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
2021-02-12 08:19:30 +01:00
|
|
|
validate_against_openapi_schema(
|
2021-02-12 08:20:45 +01:00
|
|
|
result, "/users/{user_id}/subscriptions/{stream_id}", "get", "200"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
|
|
|
|
2020-05-31 19:10:41 +02:00
|
|
|
|
2021-03-30 12:51:54 +02:00
|
|
|
@openapi_test_function("/realm/linkifiers:get")
|
|
|
|
def get_realm_linkifiers(client: Client) -> None:
|
2018-08-14 03:10:37 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Fetch all the filters in this organization
|
2021-03-30 12:51:54 +02:00
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/realm/linkifiers",
|
|
|
|
method="GET",
|
|
|
|
)
|
2018-08-14 03:10:37 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-03-30 12:51:54 +02:00
|
|
|
validate_against_openapi_schema(result, "/realm/linkifiers", "get", "200")
|
2018-08-14 03:10:37 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2023-08-10 04:09:25 +02:00
|
|
|
@openapi_test_function("/realm/linkifiers:patch")
|
|
|
|
def reorder_realm_linkifiers(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Reorder the linkifiers in the user's organization.
|
|
|
|
order = [4, 3, 2, 1]
|
|
|
|
request = {"ordered_linkifier_ids": json.dumps(order)}
|
|
|
|
|
|
|
|
result = client.call_endpoint(url="/realm/linkifiers", method="PATCH", request=request)
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/realm/linkifiers", "patch", "200")
|
|
|
|
|
|
|
|
|
2020-07-03 17:57:22 +02:00
|
|
|
@openapi_test_function("/realm/profile_fields:get")
|
|
|
|
def get_realm_profile_fields(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Fetch all the custom profile fields in the user's organization.
|
|
|
|
result = client.call_endpoint(
|
2021-02-12 08:20:45 +01:00
|
|
|
url="/realm/profile_fields",
|
|
|
|
method="GET",
|
2020-07-03 17:57:22 +02:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/profile_fields", "get", "200")
|
2020-07-03 17:57:22 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-04 13:09:52 +02:00
|
|
|
@openapi_test_function("/realm/profile_fields:patch")
|
|
|
|
def reorder_realm_profile_fields(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Reorder the custom profile fields in the user's organization.
|
2022-10-01 12:16:11 +02:00
|
|
|
order = [9, 8, 7, 6, 5, 4, 3, 2, 1]
|
2021-02-12 08:20:45 +01:00
|
|
|
request = {"order": json.dumps(order)}
|
2020-07-04 13:09:52 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = client.call_endpoint(url="/realm/profile_fields", method="PATCH", request=request)
|
2020-07-04 13:09:52 +02:00
|
|
|
# {code_example|end}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/profile_fields", "patch", "200")
|
2020-07-04 13:09:52 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-04 18:43:57 +02:00
|
|
|
@openapi_test_function("/realm/profile_fields:post")
|
|
|
|
def create_realm_profile_field(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Create a custom profile field in the user's organization.
|
2021-05-10 07:02:14 +02:00
|
|
|
request = {"name": "Phone", "hint": "Contact no.", "field_type": 1}
|
2020-07-04 18:43:57 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = client.call_endpoint(url="/realm/profile_fields", method="POST", request=request)
|
2020-07-04 18:43:57 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/profile_fields", "post", "200")
|
2020-07-04 18:43:57 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
linkifier: Support URL templates for linkifiers.
This swaps out url_format_string from all of our APIs and replaces it
with url_template. Note that the documentation changes in the following
commits will be squashed with this commit.
We change the "url_format" key to "url_template" for the
realm_linkifiers events in event_schema, along with updating
LinkifierDict. "url_template" is the name chosen to normalize
mixed usages of "url_format_string" and "url_format" throughout
the backend.
The markdown processor is updated to stop handling the format string
interpolation and delegate the task template expansion to the uri_template
library instead.
This change affects many test cases. We mostly just replace "%(name)s"
with "{name}", "url_format_string" with "url_template" to make sure that
they still pass. There are some test cases dedicated for testing "%"
escaping, which aren't relevant anymore and are subject to removal.
But for now we keep most of them as-is, and make sure that "%" is always
escaped since we do not use it for variable substitution any more.
Since url_format_string is not populated anymore, a migration is created
to remove this field entirely, and make url_template non-nullable since
we will always populate it. Note that it is possible to have
url_template being null after migration 0422 and before 0424, but
in practice, url_template will not be None after backfilling and the
backend now is always setting url_template.
With the removal of url_format_string, RealmFilter model will now be cleaned
with URL template checks, and the old checks for escapes are removed.
We also modified RealmFilter.clean to skip the validation when the
url_template is invalid. This avoids raising mulitple ValidationError's
when calling full_clean on a linkifier. But we might eventually want to
have a more centric approach to data validation instead of having
the same validation in both the clean method and the validator.
Fixes #23124.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-10-05 20:55:31 +02:00
|
|
|
# TODO: Switch back to using client.add_realm_filter when python-zulip-api
|
|
|
|
# begins to support url_template.
|
|
|
|
|
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
|
linkifier: Support URL templates for linkifiers.
This swaps out url_format_string from all of our APIs and replaces it
with url_template. Note that the documentation changes in the following
commits will be squashed with this commit.
We change the "url_format" key to "url_template" for the
realm_linkifiers events in event_schema, along with updating
LinkifierDict. "url_template" is the name chosen to normalize
mixed usages of "url_format_string" and "url_format" throughout
the backend.
The markdown processor is updated to stop handling the format string
interpolation and delegate the task template expansion to the uri_template
library instead.
This change affects many test cases. We mostly just replace "%(name)s"
with "{name}", "url_format_string" with "url_template" to make sure that
they still pass. There are some test cases dedicated for testing "%"
escaping, which aren't relevant anymore and are subject to removal.
But for now we keep most of them as-is, and make sure that "%" is always
escaped since we do not use it for variable substitution any more.
Since url_format_string is not populated anymore, a migration is created
to remove this field entirely, and make url_template non-nullable since
we will always populate it. Note that it is possible to have
url_template being null after migration 0422 and before 0424, but
in practice, url_template will not be None after backfilling and the
backend now is always setting url_template.
With the removal of url_format_string, RealmFilter model will now be cleaned
with URL template checks, and the old checks for escapes are removed.
We also modified RealmFilter.clean to skip the validation when the
url_template is invalid. This avoids raising mulitple ValidationError's
when calling full_clean on a linkifier. But we might eventually want to
have a more centric approach to data validation instead of having
the same validation in both the clean method and the validator.
Fixes #23124.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-10-05 20:55:31 +02:00
|
|
|
request = {
|
|
|
|
"pattern": "#(?P<id>[0-9]+)",
|
|
|
|
"url_template": "https://github.com/zulip/zulip/issues/{id}",
|
|
|
|
}
|
|
|
|
result = client.call_endpoint("/realm/filters", method="POST", request=request)
|
2018-08-14 02:54:36 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/filters", "post", "200")
|
2018-08-14 02:54:36 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-04-15 19:51:36 +02:00
|
|
|
@openapi_test_function("/realm/filters/{filter_id}:patch")
|
|
|
|
def update_realm_filter(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
2023-08-11 01:10:21 +02:00
|
|
|
# Update the linkifier (realm_filter) with ID 4
|
|
|
|
filter_id = 4
|
2021-04-15 19:51:36 +02:00
|
|
|
request = {
|
|
|
|
"pattern": "#(?P<id>[0-9]+)",
|
linkifier: Support URL templates for linkifiers.
This swaps out url_format_string from all of our APIs and replaces it
with url_template. Note that the documentation changes in the following
commits will be squashed with this commit.
We change the "url_format" key to "url_template" for the
realm_linkifiers events in event_schema, along with updating
LinkifierDict. "url_template" is the name chosen to normalize
mixed usages of "url_format_string" and "url_format" throughout
the backend.
The markdown processor is updated to stop handling the format string
interpolation and delegate the task template expansion to the uri_template
library instead.
This change affects many test cases. We mostly just replace "%(name)s"
with "{name}", "url_format_string" with "url_template" to make sure that
they still pass. There are some test cases dedicated for testing "%"
escaping, which aren't relevant anymore and are subject to removal.
But for now we keep most of them as-is, and make sure that "%" is always
escaped since we do not use it for variable substitution any more.
Since url_format_string is not populated anymore, a migration is created
to remove this field entirely, and make url_template non-nullable since
we will always populate it. Note that it is possible to have
url_template being null after migration 0422 and before 0424, but
in practice, url_template will not be None after backfilling and the
backend now is always setting url_template.
With the removal of url_format_string, RealmFilter model will now be cleaned
with URL template checks, and the old checks for escapes are removed.
We also modified RealmFilter.clean to skip the validation when the
url_template is invalid. This avoids raising mulitple ValidationError's
when calling full_clean on a linkifier. But we might eventually want to
have a more centric approach to data validation instead of having
the same validation in both the clean method and the validator.
Fixes #23124.
Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-10-05 20:55:31 +02:00
|
|
|
"url_template": "https://github.com/zulip/zulip/issues/{id}",
|
2021-04-15 19:51:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=f"/realm/filters/{filter_id}", method="PATCH", request=request
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/realm/filters/{filter_id}", "patch", "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}
|
2023-08-11 01:10:21 +02:00
|
|
|
# Remove the linkifier (realm_filter) with ID 4
|
|
|
|
result = client.remove_realm_filter(4)
|
2018-08-14 03:20:39 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/filters/{filter_id}", "delete", "200")
|
2018-08-14 03:20:39 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-10-27 02:14:56 +01:00
|
|
|
@openapi_test_function("/realm/playgrounds:post")
|
|
|
|
def add_realm_playground(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Add a realm playground for Python
|
|
|
|
request = {
|
|
|
|
"name": "Python playground",
|
2021-04-17 08:26:57 +02:00
|
|
|
"pygments_language": "Python",
|
2023-05-27 05:04:50 +02:00
|
|
|
"url_template": "https://python.example.com?code={code}",
|
2020-10-27 02:14:56 +01:00
|
|
|
}
|
|
|
|
result = client.call_endpoint(url="/realm/playgrounds", method="POST", request=request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/realm/playgrounds", "post", "200")
|
|
|
|
|
|
|
|
|
2020-10-27 02:21:22 +01:00
|
|
|
@openapi_test_function("/realm/playgrounds/{playground_id}:delete")
|
|
|
|
def remove_realm_playground(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Remove the playground with ID 1
|
|
|
|
result = client.call_endpoint(url="/realm/playgrounds/1", method="DELETE")
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/realm/playgrounds/{playground_id}", "delete", "200")
|
|
|
|
|
|
|
|
|
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:
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me", "get", "200")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-01-05 18:09:03 +01:00
|
|
|
@openapi_test_function("/users/me:delete")
|
|
|
|
def deactivate_own_user(client: Client, owner_client: Client) -> None:
|
|
|
|
user_id = client.get_profile()["user_id"]
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Deactivate the account of the current user/bot that requests.
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/users/me",
|
|
|
|
method="DELETE",
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
# Reactivate the account to avoid polluting other tests.
|
|
|
|
owner_client.reactivate_user_by_id(user_id)
|
|
|
|
validate_against_openapi_schema(result, "/users/me", "delete", "200")
|
|
|
|
|
|
|
|
|
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:
|
2018-01-28 00:06:45 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get the ID of a given stream
|
2021-02-12 08:20:45 +01:00
|
|
|
stream_name = "new stream"
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.get_stream_id(stream_name)
|
2018-01-28 00:06:45 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/get_stream_id", "get", "200")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
return result["stream_id"]
|
2019-04-08 10:11:18 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/streams/{stream_id}:delete")
|
2021-03-31 16:15:24 +02:00
|
|
|
def archive_stream(client: Client, stream_id: int) -> None:
|
2019-06-29 03:16:34 +02:00
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{
|
2021-03-31 16:15:24 +02:00
|
|
|
"name": "stream to be archived",
|
2021-02-12 08:20:45 +01:00
|
|
|
"description": "New stream for testing",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
},
|
|
|
|
],
|
2019-06-29 03:16:34 +02:00
|
|
|
)
|
2019-04-08 10:11:18 +02:00
|
|
|
|
2019-06-22 08:22:32 +02:00
|
|
|
# {code_example|start}
|
2021-03-31 16:15:24 +02:00
|
|
|
# Archive the stream named 'stream to be archived'
|
|
|
|
stream_id = client.get_stream_id("stream to be archived")["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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/streams/{stream_id}", "delete", "200")
|
2019-04-08 10:11:18 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
2019-04-08 10:11:18 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-07-25 22:20:15 +02:00
|
|
|
@openapi_test_function("/streams/{stream_id}/delete_topic:post")
|
|
|
|
def delete_topic(client: Client, stream_id: int, topic: str) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Delete a topic given its stream_id
|
|
|
|
request = {
|
|
|
|
"topic_name": topic,
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=f"/streams/{stream_id}/delete_topic", method="POST", request=request
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/streams/{stream_id}/delete_topic", "post", "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:
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/streams", "get", "200")
|
|
|
|
streams = [s for s in result["streams"] if s["name"] == "new stream"]
|
|
|
|
assert streams[0]["description"] == "New stream for testing"
|
2017-01-13 13:50:39 +01:00
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/streams", "get", "200")
|
2021-04-29 17:22:48 +02:00
|
|
|
assert len(result["streams"]) == 5
|
2018-02-03 00:04:48 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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 = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"stream_id": stream_id,
|
|
|
|
"stream_post_policy": 2,
|
|
|
|
"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
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/streams/{stream_id}", "patch", "200")
|
|
|
|
assert result["result"] == "success"
|
2019-04-23 00:11:49 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/user_groups", "get", "200")
|
2023-07-22 00:34:11 +02:00
|
|
|
[hamlet_user_group] = (u for u in result["user_groups"] if u["name"] == "hamletcharacters")
|
2021-02-12 08:20:45 +01:00
|
|
|
assert hamlet_user_group["description"] == "Characters of Hamlet"
|
2018-08-18 23:06:53 +02:00
|
|
|
|
2023-07-22 00:34:11 +02:00
|
|
|
[marketing_user_group] = (u for u in result["user_groups"] if u["name"] == "marketing")
|
2021-02-12 08:20:45 +01:00
|
|
|
return marketing_user_group["id"]
|
2019-04-22 21:21:52 +02:00
|
|
|
|
2021-02-12 08:19:30 +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_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)
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/rest-error-handling", "post", "400")
|
2018-02-16 21:58:03 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-07-17 00:29:45 +02:00
|
|
|
@openapi_test_function("/streams/{stream_id}/members: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_subscribers(client: Client) -> None:
|
2023-04-11 19:51:14 +02:00
|
|
|
ensure_users([11, 25], ["iago", "newbie"])
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-07-17 00:29:45 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Get the subscribers to a stream
|
2021-02-12 08:20:45 +01:00
|
|
|
result = client.get_subscribers(stream="new stream")
|
2021-07-17 00:29:45 +02:00
|
|
|
# {code_example|end}
|
2023-04-11 19:51:14 +02:00
|
|
|
assert result["subscribers"] == [11, 25]
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +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()
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result.startswith("ZulipPython/")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/subscriptions:get")
|
2021-07-16 23:58:15 +02:00
|
|
|
def get_subscriptions(client: Client) -> None:
|
2018-01-28 00:39:16 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get all streams that the user is subscribed to
|
2021-07-16 23:58:15 +02:00
|
|
|
result = client.get_subscriptions()
|
2018-01-28 00:39:16 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "get", "200")
|
2018-01-28 00:39:16 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
streams = [s for s in result["subscriptions"] if s["name"] == "new stream"]
|
|
|
|
assert streams[0]["description"] == "New stream for testing"
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2018-02-06 04:47:40 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Unsubscribe from the stream "new stream"
|
|
|
|
result = client.remove_subscriptions(
|
2021-02-12 08:20:45 +01:00
|
|
|
["new stream"],
|
2018-02-06 04:47:40 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "delete", "200")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
# test it was actually removed
|
2021-07-16 23:58:15 +02:00
|
|
|
result = client.get_subscriptions()
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
|
|
|
streams = [s for s in result["subscriptions"] if s["name"] == "new stream"]
|
2017-01-13 13:50:39 +01:00
|
|
|
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(
|
2021-02-12 08:20:45 +01:00
|
|
|
["new stream"],
|
|
|
|
principals=["newbie@zulip.com"],
|
2018-02-08 04:25:11 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "delete", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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 = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
|
|
|
"topic": "boat party",
|
2018-07-10 08:17:35 +02:00
|
|
|
}
|
|
|
|
client.call_endpoint(
|
2021-02-12 08:20:45 +01:00
|
|
|
url="messages",
|
|
|
|
method="POST",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
request=message,
|
2018-07-10 08:17:35 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Mute the topic "boat party" in the stream "Denmark"
|
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"stream": "Denmark",
|
|
|
|
"topic": "boat party",
|
|
|
|
"op": "add",
|
2018-07-10 08:17:35 +02:00
|
|
|
}
|
|
|
|
result = client.mute_topic(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions/muted_topics", "patch", "200")
|
2018-07-10 08:17:35 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Unmute the topic "boat party" in the stream "Denmark"
|
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"stream": "Denmark",
|
|
|
|
"topic": "boat party",
|
|
|
|
"op": "remove",
|
2018-07-10 08:17:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
result = client.mute_topic(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions/muted_topics", "patch", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-07-10 08:17:35 +02:00
|
|
|
|
2023-03-31 21:18:12 +02:00
|
|
|
@openapi_test_function("/user_topics:post")
|
|
|
|
def update_user_topic(client: Client) -> None:
|
|
|
|
stream_id = client.get_stream_id("Denmark")["stream_id"]
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Mute the topic "dinner" in the stream having id 'stream_id'.
|
|
|
|
request = {
|
|
|
|
"stream_id": stream_id,
|
|
|
|
"topic": "dinner",
|
|
|
|
"visibility_policy": 1,
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="user_topics",
|
|
|
|
method="POST",
|
|
|
|
request=request,
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/user_topics", "post", "200")
|
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Remove mute from the topic "dinner" in the stream having id 'stream_id'.
|
|
|
|
request = {
|
|
|
|
"stream_id": stream_id,
|
|
|
|
"topic": "dinner",
|
|
|
|
"visibility_policy": 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="user_topics",
|
|
|
|
method="POST",
|
|
|
|
request=request,
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/user_topics", "post", "200")
|
|
|
|
|
|
|
|
|
2021-03-27 12:23:32 +01:00
|
|
|
@openapi_test_function("/users/me/muted_users/{muted_user_id}:post")
|
|
|
|
def add_user_mute(client: Client) -> None:
|
|
|
|
ensure_users([10], ["hamlet"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Mute user with ID 10
|
|
|
|
muted_user_id = 10
|
|
|
|
result = client.call_endpoint(url=f"/users/me/muted_users/{muted_user_id}", method="POST")
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/users/me/muted_users/{muted_user_id}", "post", "200")
|
|
|
|
|
|
|
|
|
|
|
|
@openapi_test_function("/users/me/muted_users/{muted_user_id}:delete")
|
|
|
|
def remove_user_mute(client: Client) -> None:
|
|
|
|
ensure_users([10], ["hamlet"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Unmute user with ID 10
|
|
|
|
muted_user_id = 10
|
|
|
|
result = client.call_endpoint(url=f"/users/me/muted_users/{muted_user_id}", method="DELETE")
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(
|
|
|
|
result, "/users/me/muted_users/{muted_user_id}", "delete", "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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/mark_all_as_read", "post", "200")
|
2018-08-11 13:38:55 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/mark_stream_as_read", "post", "200")
|
2018-08-11 13:38:55 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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
|
2021-02-12 08:20:45 +01: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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/mark_stream_as_read", "post", "200")
|
2018-08-11 13:38:55 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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"
|
2021-02-12 08:19:30 +01:00
|
|
|
request = [
|
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
"stream_id": 1,
|
|
|
|
"property": "pin_to_top",
|
|
|
|
"value": True,
|
2021-02-12 08:19:30 +01:00
|
|
|
},
|
|
|
|
{
|
2021-04-27 16:56:45 +02:00
|
|
|
"stream_id": 7,
|
2021-02-12 08:20:45 +01:00
|
|
|
"property": "color",
|
|
|
|
"value": "#f00f00",
|
2021-02-12 08:19:30 +01:00
|
|
|
},
|
|
|
|
]
|
2018-07-12 10:09:50 +02:00
|
|
|
result = client.update_subscription_settings(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions/properties", "POST", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-07-12 10:09:50 +02:00
|
|
|
|
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:
|
2018-01-26 22:11:42 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Render a message
|
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"content": "**foo**",
|
2018-01-26 22:11:42 +01:00
|
|
|
}
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.render_message(request)
|
2018-01-26 22:11:42 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/render", "post", "200")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +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] = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"anchor": "newest",
|
|
|
|
"num_before": 100,
|
|
|
|
"num_after": 0,
|
|
|
|
"narrow": [
|
|
|
|
{"operator": "sender", "operand": "iago@zulip.com"},
|
|
|
|
{"operator": "stream", "operand": "Verona"},
|
2021-02-12 08:19:30 +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
|
|
|
}
|
2018-06-23 17:31:12 +02:00
|
|
|
result = client.get_messages(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages", "get", "200")
|
|
|
|
assert len(result["messages"]) <= request["num_before"]
|
2018-06-23 17:31:12 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-03-15 14:16:02 +01:00
|
|
|
@openapi_test_function("/messages/matches_narrow:get")
|
|
|
|
def check_messages_match_narrow(client: Client) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
message = {"type": "stream", "to": "Verona", "topic": "test_topic", "content": "http://foo.com"}
|
2020-03-15 14:16:02 +01:00
|
|
|
msg_ids = []
|
|
|
|
response = client.send_message(message)
|
2021-02-12 08:20:45 +01:00
|
|
|
msg_ids.append(response["id"])
|
|
|
|
message["content"] = "no link here"
|
2020-03-15 14:16:02 +01:00
|
|
|
response = client.send_message(message)
|
2021-02-12 08:20:45 +01:00
|
|
|
msg_ids.append(response["id"])
|
2020-03-15 14:16:02 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Check which messages within an array match a narrow.
|
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"msg_ids": msg_ids,
|
|
|
|
"narrow": [{"operator": "has", "operand": "link"}],
|
2020-03-15 14:16:02 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = client.call_endpoint(url="messages/matches_narrow", method="GET", request=request)
|
2020-03-15 14:16:02 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/matches_narrow", "get", "200")
|
2020-03-15 14:16:02 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}", "get", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-06-23 18:17:05 +02:00
|
|
|
|
2020-03-20 23:23:25 +01:00
|
|
|
@openapi_test_function("/attachments:get")
|
2021-07-30 11:58:11 +02:00
|
|
|
def get_attachments(client: Client) -> int:
|
2020-03-20 23:23:25 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Get your attachments.
|
|
|
|
|
|
|
|
result = client.get_attachments()
|
|
|
|
# {code_example|end}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/attachments", "get", "200")
|
2021-07-30 11:58:11 +02:00
|
|
|
return result["attachments"][0]["id"]
|
|
|
|
|
|
|
|
|
|
|
|
@openapi_test_function("/attachments/{attachment_id}:delete")
|
|
|
|
def remove_attachment(client: Client, attachment_id: int) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Delete the attachment with given attachment_id.
|
|
|
|
|
|
|
|
url = "attachments/" + str(attachment_id)
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
|
|
|
method="DELETE",
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/attachments/{attachment_id}", "delete", "200")
|
2020-03-20 23:23:25 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
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",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +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)
|
2023-04-17 17:02:07 +02:00
|
|
|
|
2018-01-27 22:26:16 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01: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
|
2021-02-12 08:20:45 +01:00
|
|
|
message_id = result["id"]
|
|
|
|
url = "messages/" + str(message_id)
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
2021-02-12 08:20:45 +01:00
|
|
|
method="GET",
|
2017-01-13 13:50:39 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
|
|
|
assert result["raw_content"] == request["content"]
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
ensure_users([10], ["hamlet"])
|
2020-03-06 08:44:00 +01:00
|
|
|
|
2018-01-27 22:56:36 +01:00
|
|
|
# {code_example|start}
|
2023-04-17 17:02:07 +02:00
|
|
|
# Send a direct 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],
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"content": "With mirth and laughter let old wrinkles come.",
|
2018-01-27 22:56:36 +01:00
|
|
|
}
|
|
|
|
result = client.send_message(request)
|
2023-04-17 17:02:07 +02:00
|
|
|
|
2018-01-27 22:56:36 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01: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
|
2021-02-12 08:20:45 +01:00
|
|
|
message_id = result["id"]
|
|
|
|
url = "messages/" + str(message_id)
|
2018-01-27 22:56:36 +01:00
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
2021-02-12 08:20:45 +01:00
|
|
|
method="GET",
|
2018-01-27 22:56:36 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
|
|
|
assert result["raw_content"] == request["content"]
|
2018-01-27 22:56:36 +01:00
|
|
|
|
2018-06-18 17:44:48 +02:00
|
|
|
return message_id
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2021-02-23 15:32:15 +01:00
|
|
|
request: Dict[str, Any] = {}
|
2020-02-29 15:02:34 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Add an emoji reaction
|
2019-02-17 07:58:55 +01:00
|
|
|
request = {
|
2021-02-23 15:32:15 +01:00
|
|
|
"message_id": message_id,
|
2021-02-12 08:20:45 +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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}/reactions", "post", "200")
|
2019-02-17 07:58:55 +01:00
|
|
|
|
2021-02-12 08:19:30 +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:
|
2021-02-23 15:32:15 +01:00
|
|
|
request: Dict[str, Any] = {}
|
2020-03-07 11:20:57 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Remove an emoji reaction
|
2019-04-03 15:10:37 +02:00
|
|
|
request = {
|
2021-02-23 15:32:15 +01:00
|
|
|
"message_id": message_id,
|
2021-02-12 08:20:45 +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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}/reactions", "delete", "200")
|
2019-04-03 15:10:37 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-06-16 21:15:47 +02:00
|
|
|
@openapi_test_function("/messages/{message_id}/read_receipts:get")
|
|
|
|
def get_read_receipts(client: Client, message_id: int) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Get read receipts for a message
|
|
|
|
result = client.call_endpoint(f"/messages/{message_id}/read_receipts", method="GET")
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}/read_receipts", "get", "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_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",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +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)
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages", "post", "400")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"content": "With mirth and laughter let old wrinkles come.",
|
2018-02-16 20:35:05 +01:00
|
|
|
}
|
|
|
|
result = client.send_message(request)
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages", "post", "400")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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,
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"content": "New content",
|
2018-01-27 23:18:19 +01:00
|
|
|
}
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.update_message(request)
|
2018-01-27 23:18:19 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}", "patch", "200")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
|
|
|
# test it was actually updated
|
2021-02-12 08:20:45 +01:00
|
|
|
url = "messages/" + str(message_id)
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
2021-02-12 08:20:45 +01:00
|
|
|
method="GET",
|
2017-01-13 13:50:39 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
|
|
|
assert result["raw_content"] == request["content"]
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +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",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +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"],
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
"content": "New content",
|
2018-02-16 21:26:43 +01:00
|
|
|
}
|
|
|
|
result = nonadmin_client.update_message(request)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}", "patch", "400")
|
2018-02-16 21:26:43 +01:00
|
|
|
|
2021-02-12 08:19:30 +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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}", "delete", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-06-26 16:30:46 +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_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",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +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)
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
result = nonadmin_client.delete_message(result["id"])
|
2018-06-26 16:30:46 +02:00
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}", "delete", "400")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/{message_id}/history", "get", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-06-27 22:54:08 +02:00
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/emoji", "GET", "200")
|
2018-07-03 20:22:53 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +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
|
|
|
}
|
2023-07-31 22:52:35 +02:00
|
|
|
message_ids = [client.send_message(request)["id"] for i in range(3)]
|
2018-07-03 18:17:23 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Add the "read" flag to the messages with IDs in "message_ids"
|
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"messages": message_ids,
|
|
|
|
"op": "add",
|
|
|
|
"flag": "read",
|
2018-07-03 18:17:23 +02:00
|
|
|
}
|
|
|
|
result = client.update_message_flags(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/flags", "post", "200")
|
2018-07-03 18:17:23 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Remove the "starred" flag from the messages with IDs in "message_ids"
|
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"messages": message_ids,
|
|
|
|
"op": "remove",
|
|
|
|
"flag": "starred",
|
2018-07-03 18:17:23 +02:00
|
|
|
}
|
|
|
|
result = client.update_message_flags(request)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages/flags", "post", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-07-03 18:17:23 +02:00
|
|
|
|
2020-08-04 15:12:00 +02:00
|
|
|
def register_queue_all_events(client: Client) -> str:
|
|
|
|
# Register the queue and get all events
|
|
|
|
# Mainly for verifying schema of /register.
|
|
|
|
result = client.register()
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/register", "post", "200")
|
|
|
|
return result["queue_id"]
|
2020-08-04 15:12:00 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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(
|
2021-02-12 08:20:45 +01:00
|
|
|
event_types=["message", "realm_emoji"],
|
2018-02-07 05:00:10 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/register", "post", "200")
|
|
|
|
return result["queue_id"]
|
2018-02-07 05:00:10 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01: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)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/events", "delete", "400")
|
2018-02-16 23:49:35 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-06-24 16:16:13 +02:00
|
|
|
@openapi_test_function("/events:get")
|
|
|
|
def get_queue(client: Client, queue_id: str) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# If you already have a queue registered and thus, have a queue_id
|
|
|
|
# on hand, you may use client.get_events() and pass in the above
|
|
|
|
# parameters, like so:
|
|
|
|
result = client.get_events(queue_id=queue_id, last_event_id=-1)
|
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/events", "get", "200")
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/server_settings", "get", "200")
|
2018-08-11 15:50:56 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-07-07 22:08:11 +02:00
|
|
|
@openapi_test_function("/settings:patch")
|
|
|
|
def update_settings(client: Client) -> None:
|
2018-08-10 02:15:45 +02:00
|
|
|
# {code_example|start}
|
2021-09-08 21:21:51 +02:00
|
|
|
# Enable push notifications even when online and change emoji set
|
2018-08-10 02:15:45 +02:00
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"enable_offline_push_notifications": True,
|
|
|
|
"enable_online_push_notifications": True,
|
2021-05-08 17:36:47 +02:00
|
|
|
"emojiset": "google",
|
2021-03-25 07:19:05 +01:00
|
|
|
}
|
2021-07-07 22:08:11 +02:00
|
|
|
result = client.call_endpoint("/settings", method="PATCH", request=request)
|
2021-03-25 07:19:05 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-07-07 22:08:11 +02:00
|
|
|
validate_against_openapi_schema(result, "/settings", "patch", "200")
|
2021-03-25 07:19:05 +01:00
|
|
|
|
|
|
|
|
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:
|
2021-02-12 08:20:45 +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
|
2021-02-12 08:20:45 +01:00
|
|
|
with open(path_to_file, "rb") as fp:
|
2021-03-29 17:53:10 +02:00
|
|
|
result = client.upload_file(fp)
|
2019-11-30 01:10:18 +01:00
|
|
|
|
2021-03-29 17:53:10 +02:00
|
|
|
# Share the file by including it in a message.
|
2021-02-12 08:19:30 +01:00
|
|
|
client.send_message(
|
|
|
|
{
|
|
|
|
"type": "stream",
|
|
|
|
"to": "Denmark",
|
|
|
|
"topic": "Castle",
|
2021-02-12 08:20:45 +01:00
|
|
|
"content": "Check out [this picture]({}) of my castle!".format(result["uri"]),
|
2021-02-12 08:19:30 +01:00
|
|
|
}
|
|
|
|
)
|
2018-02-25 01:01:45 +01:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/user_uploads", "post", "200")
|
2018-02-25 01:01:45 +01:00
|
|
|
|
2021-02-12 08:19:30 +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}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/{stream_id}/topics", "get", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2021-02-12 08:20:45 +01:00
|
|
|
ensure_users([10, 11], ["hamlet", "iago"])
|
2018-08-09 20:27:12 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
2023-04-17 17:02:07 +02:00
|
|
|
# The user has started typing in the group direct message
|
|
|
|
# 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 = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"op": "start",
|
|
|
|
"to": [user_id1, user_id2],
|
2018-08-09 20:27:12 +02:00
|
|
|
}
|
|
|
|
result = client.set_typing_status(request)
|
2020-12-24 21:00:20 +01:00
|
|
|
|
2018-08-09 20:27:12 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/typing", "post", "200")
|
2018-08-09 20:27:12 +02:00
|
|
|
|
|
|
|
# {code_example|start}
|
2023-04-17 17:02:07 +02:00
|
|
|
# The user has finished typing in the group direct message
|
|
|
|
# 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 = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"op": "stop",
|
|
|
|
"to": [user_id1, user_id2],
|
2018-08-09 20:27:12 +02:00
|
|
|
}
|
|
|
|
result = client.set_typing_status(request)
|
2020-12-24 21:00:20 +01:00
|
|
|
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/typing", "post", "200")
|
|
|
|
|
|
|
|
# {code_example|start}
|
2023-04-17 17:02:07 +02:00
|
|
|
# The user has started to type in topic "typing status"
|
|
|
|
# of stream "Denmark"
|
2020-12-24 21:00:20 +01:00
|
|
|
stream_id = client.get_stream_id("Denmark")["stream_id"]
|
|
|
|
topic = "typing status"
|
|
|
|
|
|
|
|
request = {
|
|
|
|
"type": "stream",
|
|
|
|
"op": "start",
|
2023-10-12 09:13:34 +02:00
|
|
|
"stream_id": stream_id,
|
2020-12-24 21:00:20 +01:00
|
|
|
"topic": topic,
|
|
|
|
}
|
|
|
|
result = client.set_typing_status(request)
|
|
|
|
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/typing", "post", "200")
|
|
|
|
|
|
|
|
# {code_example|start}
|
2023-04-17 17:02:07 +02:00
|
|
|
# The user has finished typing in topic "typing status"
|
|
|
|
# of stream "Denmark"
|
2020-12-24 21:00:20 +01:00
|
|
|
stream_id = client.get_stream_id("Denmark")["stream_id"]
|
|
|
|
topic = "typing status"
|
|
|
|
|
|
|
|
request = {
|
|
|
|
"type": "stream",
|
|
|
|
"op": "stop",
|
2023-10-12 09:13:34 +02:00
|
|
|
"stream_id": stream_id,
|
2020-12-24 21:00:20 +01:00
|
|
|
"topic": topic,
|
|
|
|
}
|
|
|
|
result = client.set_typing_status(request)
|
|
|
|
|
2018-08-09 20:27:12 +02:00
|
|
|
# {code_example|end}
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/typing", "post", "200")
|
2018-08-09 20:27:12 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2021-02-12 08:20:45 +01:00
|
|
|
emoji_path = os.path.join(ZULIP_DIR, "zerver", "tests", "images", "img.jpg")
|
2018-12-12 19:49:14 +01:00
|
|
|
|
|
|
|
# {code_example|start}
|
|
|
|
# Upload a custom emoji; assume `emoji_path` is the path to your image.
|
2021-02-12 08:20:45 +01:00
|
|
|
with open(emoji_path, "rb") as fp:
|
|
|
|
emoji_name = "my_custom_emoji"
|
2019-07-14 21:37:08 +02:00
|
|
|
result = client.call_endpoint(
|
2021-02-12 08:20:45 +01:00
|
|
|
f"realm/emoji/{emoji_name}",
|
|
|
|
method="POST",
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
files=[fp],
|
2019-07-14 21:37:08 +02:00
|
|
|
)
|
2018-12-12 19:49:14 +01:00
|
|
|
# {code_example|end}
|
2019-07-14 21:37:08 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/emoji/{emoji_name}", "post", "200")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-08-09 20:27:12 +02:00
|
|
|
|
2023-01-25 08:29:51 +01:00
|
|
|
@openapi_test_function("/realm/emoji/{emoji_name}:delete")
|
|
|
|
def delete_custom_emoji(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
# Delete a custom emoji.
|
|
|
|
emoji_name = "my_custom_emoji"
|
|
|
|
result = client.call_endpoint(f"realm/emoji/{emoji_name}", method="DELETE")
|
|
|
|
# {code_example|end}
|
|
|
|
|
|
|
|
validate_against_openapi_schema(result, "/realm/emoji/{emoji_name}", "delete", "200")
|
|
|
|
|
|
|
|
|
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:
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Get all of the user's configured alert words.
|
2019-04-22 19:49:33 +02:00
|
|
|
result = client.get_alert_words()
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/users/me/alert_words", "get", "200")
|
2019-04-22 19:49:33 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
2019-04-22 19:49:33 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Add words (or phrases) to the user's set of configured alert words.
|
2021-02-12 08:20:45 +01:00
|
|
|
word = ["foo", "bar"]
|
2019-04-22 19:51:05 +02:00
|
|
|
|
|
|
|
result = client.add_alert_words(word)
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/users/me/alert_words", "post", "200")
|
2019-04-22 19:51:05 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
2019-04-22 19:51:05 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Remove words (or phrases) from the user's set of configured alert words.
|
2021-02-12 08:20:45 +01:00
|
|
|
word = ["foo"]
|
2019-04-22 19:52:15 +02:00
|
|
|
|
|
|
|
result = client.remove_alert_words(word)
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|end}
|
|
|
|
validate_against_openapi_schema(result, "/users/me/alert_words", "delete", "200")
|
2019-04-22 19:52:15 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
2019-04-22 19:52:15 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
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:
|
2021-02-12 08:20:45 +01: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 = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"name": "marketing",
|
|
|
|
"description": "The marketing team.",
|
|
|
|
"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}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/user_groups/create", "post", "200")
|
2019-04-22 20:16:30 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
2019-04-22 20:16:30 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-16 20:39:53 +02:00
|
|
|
@openapi_test_function("/user_groups/{user_group_id}:patch")
|
|
|
|
def update_user_group(client: Client, user_group_id: int) -> None:
|
2019-06-25 21:43:53 +02:00
|
|
|
# {code_example|start}
|
2019-04-22 21:21:52 +02:00
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"group_id": user_group_id,
|
|
|
|
"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}
|
2021-02-12 08:20:45 +01:00
|
|
|
assert result["result"] == "success"
|
2019-04-22 21:21:52 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-16 20:39:53 +02:00
|
|
|
@openapi_test_function("/user_groups/{user_group_id}:delete")
|
|
|
|
def remove_user_group(client: Client, user_group_id: int) -> None:
|
2019-06-25 22:00:34 +02:00
|
|
|
# {code_example|start}
|
2020-07-16 20:39:53 +02:00
|
|
|
result = client.remove_user_group(user_group_id)
|
2019-06-25 22:00:34 +02:00
|
|
|
# {code_example|end}
|
2019-04-22 21:32:35 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/user_groups/{user_group_id}", "delete", "200")
|
|
|
|
assert result["result"] == "success"
|
2019-04-22 21:32:35 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-16 20:39:53 +02:00
|
|
|
@openapi_test_function("/user_groups/{user_group_id}/members:post")
|
|
|
|
def update_user_group_members(client: Client, user_group_id: int) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
ensure_users([8, 10, 11], ["cordelia", "hamlet", "iago"])
|
2020-07-15 14:50:48 +02:00
|
|
|
# {code_example|start}
|
2019-04-22 22:18:15 +02:00
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"delete": [8, 10],
|
|
|
|
"add": [11],
|
2019-04-22 22:18:15 +02:00
|
|
|
}
|
|
|
|
|
2021-03-26 02:27:19 +01:00
|
|
|
result = client.update_user_group_members(user_group_id, request)
|
2020-07-15 14:50:48 +02:00
|
|
|
# {code_example|end}
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/user_groups/{group_id}/members", "post", "200")
|
2019-04-22 22:18:15 +02:00
|
|
|
|
2021-02-12 08:19:30 +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_api_key(client_with_invalid_key: Client) -> None:
|
2021-07-16 23:58:15 +02:00
|
|
|
result = client_with_invalid_key.get_subscriptions()
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/rest-error-handling", "post", "400")
|
2018-02-06 21:04:07 +01:00
|
|
|
|
2021-02-12 08:19:30 +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({})
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/rest-error-handling", "post", "400")
|
2020-04-02 02:15:28 +02:00
|
|
|
|
2018-02-06 21:04:07 +01:00
|
|
|
|
2021-03-31 12:00:56 +02:00
|
|
|
def test_user_account_deactivated(client: Client) -> None:
|
|
|
|
request = {
|
|
|
|
"content": "**foo**",
|
|
|
|
}
|
|
|
|
result = client.render_message(request)
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/rest-error-handling", "post", "403")
|
2021-03-31 12:00:56 +02:00
|
|
|
|
|
|
|
|
2021-03-31 13:14:08 +02:00
|
|
|
def test_realm_deactivated(client: Client) -> None:
|
|
|
|
request = {
|
|
|
|
"content": "**foo**",
|
|
|
|
}
|
|
|
|
result = client.render_message(request)
|
|
|
|
|
2022-01-13 05:00:50 +01:00
|
|
|
validate_against_openapi_schema(result, "/rest-error-handling", "post", "403")
|
2021-03-31 13:14:08 +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_invalid_stream_error(client: Client) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
result = client.get_stream_id("nonexistent")
|
2018-02-16 22:23:51 +01:00
|
|
|
|
2021-02-12 08:20:45 +01: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
|
2018-01-26 22:11:42 +01:00
|
|
|
|
2021-02-12 08:19:30 +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)
|
2020-03-15 14:16:02 +01:00
|
|
|
check_messages_match_narrow(client)
|
2018-06-27 22:54:08 +02:00
|
|
|
get_message_history(client, message_id)
|
2021-06-16 21:15:47 +02:00
|
|
|
get_read_receipts(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
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-01-05 18:09:03 +01:00
|
|
|
def test_users(client: Client, owner_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-05-19 19:30:47 +02:00
|
|
|
reactivate_user(client)
|
2020-02-14 22:13:01 +01:00
|
|
|
update_user(client)
|
2021-07-26 17:34:02 +02:00
|
|
|
update_status(client)
|
2021-01-02 15:05:29 +01:00
|
|
|
get_user_by_email(client)
|
2020-05-31 19:10:41 +02:00
|
|
|
get_subscription_status(client)
|
2017-01-13 13:50:39 +01:00
|
|
|
get_profile(client)
|
2021-07-07 22:08:11 +02:00
|
|
|
update_settings(client)
|
2018-02-25 01:01:45 +01:00
|
|
|
upload_file(client)
|
2021-07-30 11:58:11 +02:00
|
|
|
attachment_id = get_attachments(client)
|
|
|
|
remove_attachment(client, attachment_id)
|
2018-08-09 20:27:12 +02:00
|
|
|
set_typing_status(client)
|
2019-04-22 23:58:53 +02:00
|
|
|
update_presence(client)
|
2020-06-10 21:18:27 +02:00
|
|
|
get_user_presence(client)
|
2022-07-12 12:41:18 +02:00
|
|
|
get_presence(client)
|
2019-04-22 20:16:30 +02:00
|
|
|
create_user_group(client)
|
2020-07-16 20:39:53 +02:00
|
|
|
user_group_id = get_user_groups(client)
|
|
|
|
update_user_group(client, user_group_id)
|
|
|
|
update_user_group_members(client, user_group_id)
|
|
|
|
remove_user_group(client, user_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)
|
2021-01-05 18:09:03 +01:00
|
|
|
deactivate_own_user(client, owner_client)
|
2021-03-27 12:23:32 +01:00
|
|
|
add_user_mute(client)
|
|
|
|
remove_user_mute(client)
|
2022-07-27 19:30:03 +02:00
|
|
|
get_alert_words(client)
|
|
|
|
add_alert_words(client)
|
|
|
|
remove_alert_words(client)
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2021-02-12 08:19:30 +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)
|
2021-07-16 23:58:15 +02:00
|
|
|
get_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)
|
2023-03-31 21:18:12 +02:00
|
|
|
update_user_topic(client)
|
2018-07-12 10:09:50 +02:00
|
|
|
update_subscription_settings(client)
|
2018-06-01 18:58:07 +02:00
|
|
|
get_stream_topics(client, 1)
|
2021-07-25 22:20:15 +02:00
|
|
|
delete_topic(client, 1, "test")
|
2021-03-31 16:15:24 +02:00
|
|
|
archive_stream(client, stream_id)
|
2022-08-01 15:33:11 +02:00
|
|
|
add_default_stream(client)
|
|
|
|
remove_default_stream(client)
|
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:
|
2023-06-21 19:59:26 +02:00
|
|
|
# Note that the example for api/get-events is not tested here.
|
|
|
|
#
|
2018-02-16 02:53:45 +01:00
|
|
|
# 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.
|
2023-06-21 19:59:26 +02:00
|
|
|
#
|
|
|
|
# We do validate endpoint example responses in zerver/tests/test_openapi.py,
|
|
|
|
# as well as the example events returned by api/get-events.
|
2018-02-08 03:54:20 +01:00
|
|
|
queue_id = register_queue(client)
|
2021-06-24 16:16:13 +02:00
|
|
|
get_queue(client, queue_id)
|
2018-02-08 03:54:20 +01:00
|
|
|
deregister_queue(client, queue_id)
|
2020-08-04 15:12:00 +02:00
|
|
|
register_queue_all_events(client)
|
2018-02-07 05:00:10 +01:00
|
|
|
|
2021-02-12 08:19:30 +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:
|
2021-03-30 12:51:54 +02:00
|
|
|
get_realm_linkifiers(client)
|
2018-08-14 02:54:36 +02:00
|
|
|
add_realm_filter(client)
|
2021-04-15 19:51:36 +02:00
|
|
|
update_realm_filter(client)
|
2020-10-27 02:14:56 +01:00
|
|
|
add_realm_playground(client)
|
2018-08-11 15:50:56 +02:00
|
|
|
get_server_settings(client)
|
2023-08-10 04:09:25 +02:00
|
|
|
reorder_realm_linkifiers(client)
|
2018-08-14 03:20:39 +02:00
|
|
|
remove_realm_filter(client)
|
2020-10-27 02:21:22 +01:00
|
|
|
remove_realm_playground(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)
|
2023-01-25 08:29:51 +01:00
|
|
|
delete_custom_emoji(client)
|
2020-07-03 17:57:22 +02:00
|
|
|
get_realm_profile_fields(client)
|
2020-07-04 13:09:52 +02:00
|
|
|
reorder_realm_profile_fields(client)
|
2020-07-04 18:43:57 +02:00
|
|
|
create_realm_profile_field(client)
|
2018-08-11 15:10:38 +02:00
|
|
|
|
2021-02-12 08:19:30 +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_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
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-01-05 18:09:03 +01:00
|
|
|
def test_the_api(client: Client, nonadmin_client: Client, owner_client: Client) -> None:
|
2017-01-13 13:50:39 +01:00
|
|
|
get_user_agent(client)
|
2021-01-05 18:09:03 +01:00
|
|
|
test_users(client, owner_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)
|