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
|
2024-07-12 02:30:25 +02:00
|
|
|
from collections.abc import Callable
|
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
|
2024-07-12 02:30:25 +02:00
|
|
|
from typing import Any, 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
|
|
|
|
2023-12-15 02:14:24 +01:00
|
|
|
from zerver.models.realms import get_realm
|
2023-12-15 01:16:00 +01:00
|
|
|
from zerver.models.users import 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__))))
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
TEST_FUNCTIONS: dict[str, Callable[..., object]] = {}
|
|
|
|
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
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def ensure_users(ids_list: list[int], user_names: list[str]) -> None:
|
2019-08-20 01:44:44 +02:00
|
|
|
# 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
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def assert_success_response(response: dict[str, Any]) -> None:
|
2024-05-24 11:23:44 +02:00
|
|
|
assert "result" in response
|
2024-06-21 08:08:25 +02:00
|
|
|
assert response["result"] == "success"
|
|
|
|
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def assert_error_response(response: dict[str, Any], code: str = "BAD_REQUEST") -> None:
|
2024-06-21 08:08:25 +02:00
|
|
|
assert "result" in response
|
|
|
|
assert response["result"] == "error"
|
|
|
|
assert "code" in response
|
|
|
|
assert response["code"] == code
|
2024-05-24 11:23:44 +02:00
|
|
|
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def get_subscribed_stream_ids(client: Client) -> list[int]:
|
2024-05-24 10:34:26 +02:00
|
|
|
streams = client.get_subscriptions()
|
|
|
|
stream_ids = [stream["stream_id"] for stream in streams["subscriptions"]]
|
|
|
|
return stream_ids
|
|
|
|
|
|
|
|
|
2024-05-24 09:44:44 +02:00
|
|
|
def validate_message(client: Client, message_id: int, content: Any) -> None:
|
|
|
|
url = "messages/" + str(message_id)
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
|
|
|
method="GET",
|
|
|
|
)
|
|
|
|
assert result["raw_content"] == content
|
|
|
|
|
|
|
|
|
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}
|
2024-05-19 13:52:11 +02:00
|
|
|
# Create and subscribe to channel "python-test".
|
2018-02-06 04:17:10 +01:00
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
|
|
|
{
|
2024-05-19 13:52:11 +02:00
|
|
|
"name": "python-test",
|
|
|
|
"description": "Channel for testing Python",
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
|
2024-05-24 13:44:23 +02:00
|
|
|
user_id = 25
|
|
|
|
ensure_users([user_id], ["newbie"])
|
2018-02-06 04:17:10 +01:00
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# To subscribe other users to a channel, you may pass
|
2018-02-06 04:17:10 +01:00
|
|
|
# the `principals` argument, like so:
|
|
|
|
result = client.add_subscriptions(
|
|
|
|
streams=[
|
2024-05-19 13:52:11 +02:00
|
|
|
{"name": "python-test"},
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-24 11:02:23 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "post", "200")
|
2021-02-12 08:20:45 +01:00
|
|
|
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=[
|
2024-05-19 13:52:11 +02:00
|
|
|
{"name": "python-test"},
|
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
|
|
|
)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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=[
|
2024-05-19 14:03:47 +02:00
|
|
|
{"name": "private-channel"},
|
2018-02-16 23:22:45 +01:00
|
|
|
],
|
|
|
|
)
|
2024-05-19 14:03:47 +02:00
|
|
|
stream_id = client.get_stream_id("private-channel")["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=[
|
2024-05-19 14:03:47 +02:00
|
|
|
{"name": "private-channel"},
|
2018-02-16 23:22:45 +01:00
|
|
|
],
|
|
|
|
authorization_errors_fatal=False,
|
|
|
|
)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-24 11:02:23 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "post", "200")
|
2018-02-16 23:22:45 +01:00
|
|
|
|
|
|
|
result = nonadmin_client.add_subscriptions(
|
|
|
|
streams=[
|
2024-05-19 14:03:47 +02:00
|
|
|
{"name": "private-channel"},
|
2018-02-16 23:22:45 +01:00
|
|
|
],
|
|
|
|
authorization_errors_fatal=True,
|
|
|
|
)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2022-07-12 12:41:18 +02:00
|
|
|
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:
|
2024-05-24 13:57:00 +02:00
|
|
|
client.add_subscriptions(
|
2024-05-24 10:34:26 +02:00
|
|
|
streams=[
|
|
|
|
{
|
|
|
|
"name": "test channel",
|
|
|
|
"description": "New channel for testing",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
)
|
|
|
|
stream_id = client.get_stream_id("test channel")["stream_id"]
|
2022-08-01 15:33:11 +02:00
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Add a channel to the set of default channels for new users.
|
2022-08-01 15:33:11 +02:00
|
|
|
result = client.add_default_stream(stream_id)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2022-08-01 15:33:11 +02:00
|
|
|
validate_against_openapi_schema(result, "/default_streams", "post", "200")
|
|
|
|
|
|
|
|
|
|
|
|
@openapi_test_function("/default_streams:delete")
|
|
|
|
def remove_default_stream(client: Client) -> None:
|
2024-05-24 10:34:26 +02:00
|
|
|
stream_id = client.get_stream_id("test channel")["stream_id"]
|
2022-08-01 15:33:11 +02:00
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Remove a channel from the set of default channels for new users.
|
2024-05-24 10:34:26 +02:00
|
|
|
request = {"stream_id": stream_id}
|
2022-08-01 15:33:11 +02:00
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/default_streams",
|
|
|
|
method="DELETE",
|
|
|
|
request=request,
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2022-08-01 15:33:11 +02:00
|
|
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
|
2024-05-16 15:59:27 +02:00
|
|
|
@openapi_test_function("/users/{user_id}/status:get")
|
|
|
|
def get_user_status(client: Client) -> None:
|
2024-05-24 13:44:23 +02:00
|
|
|
user_id = 11
|
|
|
|
ensure_users([user_id], ["iago"])
|
2024-05-16 15:59:27 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Get the status currently set by a user.
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=f"/users/{user_id}/status",
|
|
|
|
method="GET",
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-16 15:59:27 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}/status", "get", "200")
|
|
|
|
|
|
|
|
|
2019-08-07 20:03:43 +02:00
|
|
|
@openapi_test_function("/users/me/presence:post")
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def update_presence(client: Client) -> None:
|
2024-06-07 10:49:36 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Update your presence.
|
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,
|
2024-06-07 10:49:36 +02:00
|
|
|
"last_update_id": -1,
|
2019-04-22 23:58:53 +02:00
|
|
|
}
|
|
|
|
result = client.update_presence(request)
|
2024-06-07 10:49:36 +02:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-06-07 10:49:36 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/presence", "post", "200")
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Create a user.
|
2018-01-31 05:36:57 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users", "post", "200")
|
2018-02-16 23:38:10 +01:00
|
|
|
|
2024-06-02 20:19:28 +02:00
|
|
|
# Test "Email already used error".
|
2018-02-16 23:38:10 +01:00
|
|
|
result = client.create_user(request)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# The request contains the new status and "away" boolean.
|
2021-07-26 17:34:02 +02:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-07-26 17:34:02 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/status", "post", "200")
|
|
|
|
|
2024-06-02 20:19:28 +02:00
|
|
|
# Test "status_text is too long error".
|
2021-07-26 17:34:02 +02:00
|
|
|
request = {
|
|
|
|
"status_text": "This is a message that exceeds 60 characters, and so should throw an error.",
|
|
|
|
"away": "false",
|
|
|
|
}
|
2024-05-24 11:02:23 +02:00
|
|
|
result = client.call_endpoint(url="/users/me/status", method="POST", request=request)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
2021-07-26 17:34:02 +02:00
|
|
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Get all users in the organization.
|
2017-01-13 13:50:39 +01:00
|
|
|
result = client.get_members()
|
2018-02-07 04:25:23 +01:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users", "get", "200")
|
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
|
|
|
email = "iago@zulip.com"
|
2024-05-24 14:10:40 +02:00
|
|
|
# {code_example|start}
|
2021-01-02 15:05:29 +01:00
|
|
|
result = client.call_endpoint(
|
|
|
|
url=f"/users/{email}",
|
|
|
|
method="GET",
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-01-02 15:05:29 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/{email}", "get", "200")
|
|
|
|
|
|
|
|
|
2024-04-01 16:38:09 +02:00
|
|
|
@openapi_test_function("/invites:get")
|
|
|
|
def get_invitations(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Get all invitations.
|
2024-04-01 16:38:09 +02:00
|
|
|
result = client.call_endpoint(url="/invites", method="GET")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-04-01 16:38:09 +02:00
|
|
|
validate_against_openapi_schema(result, "/invites", "get", "200")
|
|
|
|
|
|
|
|
|
|
|
|
@openapi_test_function("/invites:post")
|
|
|
|
def send_invitations(client: Client) -> None:
|
2024-05-24 10:34:26 +02:00
|
|
|
stream_ids = get_subscribed_stream_ids(client)[:3]
|
2024-04-01 16:38:09 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Send invitations.
|
2024-04-01 16:38:09 +02:00
|
|
|
request = {
|
|
|
|
"invitee_emails": "example@zulip.com, logan@zulip.com",
|
2024-04-03 09:44:10 +02:00
|
|
|
"invite_expires_in_minutes": 60 * 24 * 10, # 10 days
|
2024-04-01 16:38:09 +02:00
|
|
|
"invite_as": 400,
|
2024-05-24 10:34:26 +02:00
|
|
|
"stream_ids": stream_ids,
|
2024-04-01 16:38:09 +02:00
|
|
|
}
|
|
|
|
result = client.call_endpoint(url="/invites", method="POST", request=request)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-04-01 16:38:09 +02:00
|
|
|
validate_against_openapi_schema(result, "/invites", "post", "200")
|
|
|
|
|
|
|
|
|
2024-04-09 17:36:23 +02:00
|
|
|
@openapi_test_function("/invites/multiuse:post")
|
|
|
|
def create_reusable_invitation_link(client: Client) -> None:
|
2024-05-24 10:34:26 +02:00
|
|
|
stream_ids = get_subscribed_stream_ids(client)[:3]
|
2024-04-09 17:36:23 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Create a reusable invitation link.
|
2024-04-09 17:36:23 +02:00
|
|
|
request = {
|
|
|
|
"invite_expires_in_minutes": 60 * 24 * 10, # 10 days
|
|
|
|
"invite_as": 400,
|
2024-05-24 10:34:26 +02:00
|
|
|
"stream_ids": stream_ids,
|
2024-04-09 17:36:23 +02:00
|
|
|
}
|
|
|
|
result = client.call_endpoint(url="/invites/multiuse", method="POST", request=request)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-04-09 17:36:23 +02:00
|
|
|
validate_against_openapi_schema(result, "/invites/multiuse", "post", "200")
|
|
|
|
|
|
|
|
|
2024-04-20 08:41:38 +02:00
|
|
|
@openapi_test_function("/invites/{invite_id}:delete")
|
|
|
|
def revoke_email_invitation(client: Client) -> None:
|
2024-05-24 19:17:40 +02:00
|
|
|
# Send email invitation.
|
|
|
|
email = "delete-invite@zulip.com"
|
2024-04-20 08:41:38 +02:00
|
|
|
request = {
|
2024-05-24 19:17:40 +02:00
|
|
|
"invitee_emails": email,
|
|
|
|
"stream_ids": [],
|
2024-04-20 08:41:38 +02:00
|
|
|
}
|
2024-05-24 19:17:40 +02:00
|
|
|
client.call_endpoint(url="/invites", method="POST", request=request)
|
|
|
|
# Get invitation ID.
|
|
|
|
invites = client.call_endpoint(url="/invites", method="GET")["invites"]
|
|
|
|
invite = [s for s in invites if not s["is_multiuse"] and s["email"] == email]
|
|
|
|
assert len(invite) == 1
|
|
|
|
invite_id = invite[0]["id"]
|
2024-04-20 08:41:38 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Revoke email invitation.
|
2024-04-20 08:41:38 +02:00
|
|
|
result = client.call_endpoint(url=f"/invites/{invite_id}", method="DELETE")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-04-20 08:41:38 +02:00
|
|
|
validate_against_openapi_schema(result, "/invites/{invite_id}", "delete", "200")
|
|
|
|
|
|
|
|
|
2024-05-08 09:46:20 +02:00
|
|
|
@openapi_test_function("/invites/multiuse/{invite_id}:delete")
|
|
|
|
def revoke_reusable_invitation_link(client: Client) -> None:
|
2024-05-24 19:17:40 +02:00
|
|
|
# Create multiuse invitation link.
|
|
|
|
invite_url = client.call_endpoint(url="/invites/multiuse", method="POST", request={})[
|
|
|
|
"invite_link"
|
|
|
|
]
|
|
|
|
# Get invitation ID.
|
|
|
|
invites = client.call_endpoint(url="/invites", method="GET")["invites"]
|
|
|
|
invite = [s for s in invites if s["is_multiuse"] and s["link_url"] == invite_url]
|
|
|
|
assert len(invite) == 1
|
|
|
|
invite_id = invite[0]["id"]
|
2024-05-08 09:46:20 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Revoke reusable invitation link.
|
2024-05-08 09:46:20 +02:00
|
|
|
result = client.call_endpoint(url=f"/invites/multiuse/{invite_id}", method="DELETE")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-08 09:46:20 +02:00
|
|
|
validate_against_openapi_schema(result, "/invites/multiuse/{invite_id}", "delete", "200")
|
|
|
|
|
|
|
|
|
2024-06-07 17:11:42 +02:00
|
|
|
@openapi_test_function("/invites/{invite_id}/resend:post")
|
|
|
|
def resend_email_invitation(client: Client) -> None:
|
|
|
|
invites = client.call_endpoint(url="/invites", method="GET")["invites"]
|
|
|
|
email_invites = [s for s in invites if not s["is_multiuse"]]
|
|
|
|
assert len(email_invites) > 0
|
|
|
|
invite_id = email_invites[0]["id"]
|
|
|
|
# {code_example|start}
|
|
|
|
# Resend email invitation.
|
|
|
|
result = client.call_endpoint(url=f"/invites/{invite_id}/resend", method="POST")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-06-07 17:11:42 +02:00
|
|
|
validate_against_openapi_schema(result, "/invites/{invite_id}/resend", "post", "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:
|
2020-02-14 21:39:12 +01:00
|
|
|
user_id = 8
|
2024-05-24 13:44:23 +02:00
|
|
|
ensure_users([user_id], ["cordelia"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Fetch details on a user given a user ID.
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2020-02-14 22:02:24 +01:00
|
|
|
user_id = 8
|
2024-05-24 13:44:23 +02:00
|
|
|
ensure_users([user_id], ["cordelia"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Deactivate a user given a user ID.
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
|
|
|
user_id = 8
|
2024-05-24 13:44:23 +02:00
|
|
|
ensure_users([user_id], ["cordelia"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Reactivate a user given a user ID.
|
2020-05-19 19:30:47 +02:00
|
|
|
result = client.reactivate_user_by_id(user_id)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
user_id = 10
|
2024-05-24 13:44:23 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Change a user's full name given a user ID.
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
|
2024-05-24 13:44:23 +02:00
|
|
|
user_id = 8
|
2020-02-14 22:13:01 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Change value of the custom profile field with ID 9.
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-24 11:02:23 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/{user_id}", "patch", "200")
|
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:
|
2024-05-24 13:44:23 +02:00
|
|
|
user_id = 7
|
|
|
|
ensure_users([user_id], ["zoe"])
|
2024-05-24 10:34:26 +02:00
|
|
|
stream_id = client.get_subscriptions()["subscriptions"][0]["stream_id"]
|
2020-05-31 19:10:41 +02:00
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Check whether a user is a subscriber to a given channel.
|
2020-05-31 19:10:41 +02:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Fetch all the linkifiers 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-05-24 10:34:26 +02:00
|
|
|
realm_linkifiers = client.call_endpoint(
|
|
|
|
url="/realm/linkifiers",
|
|
|
|
method="GET",
|
|
|
|
)
|
|
|
|
reordered_linkifiers = [linkifier["id"] for linkifier in realm_linkifiers["linkifiers"]][::-1]
|
2023-08-10 04:09:25 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Reorder the linkifiers in the user's organization.
|
2024-05-24 10:34:26 +02:00
|
|
|
request = {"ordered_linkifier_ids": json.dumps(reordered_linkifiers)}
|
2023-08-10 04:09:25 +02:00
|
|
|
result = client.call_endpoint(url="/realm/linkifiers", method="PATCH", request=request)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2023-08-10 04:09:25 +02:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-05-24 10:34:26 +02:00
|
|
|
realm_profile_fields = client.call_endpoint(
|
|
|
|
url="/realm/profile_fields",
|
|
|
|
method="GET",
|
|
|
|
)
|
|
|
|
realm_profile_field_ids = [field["id"] for field in realm_profile_fields["custom_fields"]]
|
|
|
|
reordered_profile_fields = realm_profile_field_ids[::-1]
|
2020-07-04 13:09:52 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Reorder the custom profile fields in the user's organization.
|
2024-05-24 10:34:26 +02:00
|
|
|
request = {"order": json.dumps(reordered_profile_fields)}
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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")
|
2024-05-24 10:34:39 +02:00
|
|
|
def add_realm_filter(client: Client) -> int:
|
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
|
2024-06-02 20:19:28 +02:00
|
|
|
# issue in Zulip's server repository.
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/realm/filters", "post", "200")
|
2024-05-24 10:34:39 +02:00
|
|
|
return result["id"]
|
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")
|
2024-05-24 10:34:39 +02:00
|
|
|
def update_realm_filter(client: Client, filter_id: int) -> None:
|
2021-04-15 19:51:36 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Update a linkifier.
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-04-15 19:51:36 +02:00
|
|
|
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")
|
2024-05-24 10:34:39 +02:00
|
|
|
def remove_realm_filter(client: Client, filter_id: int) -> None:
|
2018-08-14 03:20:39 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Remove a linkifier.
|
2024-05-24 10:34:39 +02:00
|
|
|
result = client.remove_realm_filter(filter_id)
|
2018-08-14 03:20:39 +02:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Add a code playground for Python.
|
2020-10-27 02:14:56 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2020-10-27 02:14:56 +01:00
|
|
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Remove the code playground with ID 1.
|
2020-10-27 02:21:22 +01:00
|
|
|
result = client.call_endpoint(url="/realm/playgrounds/1", method="DELETE")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2020-10-27 02:21:22 +01:00
|
|
|
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,
|
2024-06-02 20:19:28 +02:00
|
|
|
# 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Deactivate the account of the current user/bot.
|
2021-01-05 18:09:03 +01:00
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/users/me",
|
|
|
|
method="DELETE",
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-24 11:23:44 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me", "delete", "200")
|
2021-01-05 18:09:03 +01:00
|
|
|
|
|
|
|
# Reactivate the account to avoid polluting other tests.
|
|
|
|
owner_client.reactivate_user_by_id(user_id)
|
|
|
|
|
|
|
|
|
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:
|
2024-05-24 14:10:40 +02:00
|
|
|
name = "python-test"
|
2018-01-28 00:06:45 +01:00
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Get the ID of a given channel name.
|
2024-05-19 13:52:11 +02:00
|
|
|
result = client.get_stream_id(name)
|
2018-01-28 00:06:45 +01:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/get_stream_id", "get", "200")
|
|
|
|
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")
|
2024-05-19 13:26:40 +02:00
|
|
|
def archive_stream(client: Client) -> None:
|
2024-05-24 13:57:00 +02:00
|
|
|
client.add_subscriptions(
|
2019-06-29 03:16:34 +02:00
|
|
|
streams=[
|
|
|
|
{
|
2024-05-19 13:26:40 +02:00
|
|
|
"name": "example to archive",
|
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
|
|
|
)
|
2024-05-19 13:26:40 +02:00
|
|
|
stream_id = client.get_stream_id("example to archive")["stream_id"]
|
2024-05-24 14:10:40 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Archive a channel, given the channel's 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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: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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Delete a topic in a channel, given the channel's ID.
|
2021-07-25 22:20:15 +02:00
|
|
|
request = {
|
|
|
|
"topic_name": topic,
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=f"/streams/{stream_id}/delete_topic", method="POST", request=request
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-07-25 22:20:15 +02:00
|
|
|
validate_against_openapi_schema(result, "/streams/{stream_id}/delete_topic", "post", "200")
|
|
|
|
|
|
|
|
|
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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Get all channels 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/streams", "get", "200")
|
2024-05-19 13:52:11 +02:00
|
|
|
streams = [s for s in result["streams"] if s["name"] == "python-test"]
|
|
|
|
assert streams[0]["description"] == "Channel for testing Python"
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/streams", "get", "200")
|
2024-03-26 13:58:30 +01:00
|
|
|
assert len(result["streams"]) == 7
|
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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Update settings for the channel with 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/streams/{stream_id}", "patch", "200")
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Get all user groups of the organization.
|
2018-08-18 23:06:53 +02:00
|
|
|
result = client.get_user_groups()
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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"
|
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)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
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:
|
2024-05-24 13:44:23 +02:00
|
|
|
user_ids = [11, 25]
|
|
|
|
ensure_users(user_ids, ["iago", "newbie"])
|
2021-07-17 00:29:45 +02:00
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Get the subscribers to a channel. Note that `client.get_subscribers`
|
|
|
|
# takes a `stream` parameter with the channel's name and not the
|
|
|
|
# channel's ID.
|
2024-05-19 13:52:11 +02:00
|
|
|
result = client.get_subscribers(stream="python-test")
|
2021-07-17 00:29:45 +02:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-24 11:02:23 +02:00
|
|
|
validate_against_openapi_schema(result, "/streams/{stream_id}/members", "get", "200")
|
2024-05-24 13:44:23 +02:00
|
|
|
assert result["subscribers"] == user_ids
|
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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Get all channels 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/users/me/subscriptions", "get", "200")
|
2024-05-19 13:52:11 +02:00
|
|
|
streams = [s for s in result["subscriptions"] if s["name"] == "python-test"]
|
|
|
|
assert streams[0]["description"] == "Channel for testing Python"
|
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}
|
2024-05-19 13:52:11 +02:00
|
|
|
# Unsubscribe from channel "python-test".
|
2018-02-06 04:47:40 +01:00
|
|
|
result = client.remove_subscriptions(
|
2024-05-19 13:52:11 +02:00
|
|
|
["python-test"],
|
2018-02-06 04:47:40 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
|
2024-05-24 10:34:50 +02:00
|
|
|
# Confirm user is no longer subscribed to "python-test".
|
|
|
|
subscriptions = client.get_subscriptions()["subscriptions"]
|
|
|
|
streams = [s for s in subscriptions if s["name"] == "python-test"]
|
2017-01-13 13:50:39 +01:00
|
|
|
assert len(streams) == 0
|
|
|
|
|
2018-02-08 04:25:11 +01:00
|
|
|
# {code_example|start}
|
2024-05-19 13:52:11 +02:00
|
|
|
# Unsubscribe another user from channel "python-test".
|
2018-02-08 04:25:11 +01:00
|
|
|
result = client.remove_subscriptions(
|
2024-05-19 13:52:11 +02:00
|
|
|
["python-test"],
|
2021-02-12 08:20:45 +01:00
|
|
|
principals=["newbie@zulip.com"],
|
2018-02-08 04:25:11 +01:00
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-06-02 20:19:28 +02:00
|
|
|
# Send a test message.
|
2018-07-10 08:17:35 +02:00
|
|
|
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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Mute the topic "boat party" in the channel named "Denmark".
|
2018-07-10 08:17:35 +02:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Unmute the topic "boat party" in the channel named "Denmark".
|
2018-07-10 08:17:35 +02:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Mute the topic "dinner" in a channel, given the channel's ID.
|
2023-03-31 21:18:12 +02:00
|
|
|
request = {
|
|
|
|
"stream_id": stream_id,
|
|
|
|
"topic": "dinner",
|
|
|
|
"visibility_policy": 1,
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="user_topics",
|
|
|
|
method="POST",
|
|
|
|
request=request,
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2023-03-31 21:18:12 +02:00
|
|
|
validate_against_openapi_schema(result, "/user_topics", "post", "200")
|
|
|
|
|
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Remove mute from the topic "dinner" in a channel, given the channel's ID.
|
2023-03-31 21:18:12 +02:00
|
|
|
request = {
|
|
|
|
"stream_id": stream_id,
|
|
|
|
"topic": "dinner",
|
|
|
|
"visibility_policy": 0,
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="user_topics",
|
|
|
|
method="POST",
|
|
|
|
request=request,
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2023-03-31 21:18:12 +02:00
|
|
|
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:
|
|
|
|
muted_user_id = 10
|
2024-05-24 13:44:23 +02:00
|
|
|
ensure_users([muted_user_id], ["hamlet"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Mute a user, given the user's ID.
|
2021-03-27 12:23:32 +01:00
|
|
|
result = client.call_endpoint(url=f"/users/me/muted_users/{muted_user_id}", method="POST")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-03-27 12:23:32 +01:00
|
|
|
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:
|
|
|
|
muted_user_id = 10
|
2024-05-24 13:44:23 +02:00
|
|
|
ensure_users([muted_user_id], ["hamlet"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Unmute a user, given the user's ID.
|
2021-03-27 12:23:32 +01:00
|
|
|
result = client.call_endpoint(url=f"/users/me/muted_users/{muted_user_id}", method="DELETE")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-03-27 12:23:32 +01:00
|
|
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Mark all of the user's unread messages as read.
|
2018-08-11 13:38:55 +02:00
|
|
|
result = client.mark_all_as_read()
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-05-24 10:34:26 +02:00
|
|
|
stream_id = client.get_subscriptions()["subscriptions"][0]["stream_id"]
|
2018-08-11 13:38:55 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Mark the unread messages in a channel as read, given the channel's ID.
|
2024-05-24 10:34:26 +02:00
|
|
|
result = client.mark_stream_as_read(stream_id)
|
2018-08-11 13:38:55 +02:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-05-24 10:34:26 +02:00
|
|
|
stream_id = client.get_subscriptions()["subscriptions"][0]["stream_id"]
|
|
|
|
topic_name = client.get_stream_topics(stream_id)["topics"][0]["name"]
|
2018-08-11 13:38:55 +02:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Mark unread messages in a given topic/channel as read.
|
2024-05-24 10:34:26 +02:00
|
|
|
result = client.mark_topic_as_read(stream_id, topic_name)
|
2018-08-11 13:38:55 +02:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-05-24 10:34:26 +02:00
|
|
|
subscriptions = client.get_subscriptions()["subscriptions"]
|
|
|
|
assert len(subscriptions) >= 2
|
|
|
|
stream_a_id = subscriptions[0]["stream_id"]
|
|
|
|
stream_b_id = subscriptions[1]["stream_id"]
|
2018-07-12 10:09:50 +02:00
|
|
|
# {code_example|start}
|
2024-05-24 10:34:26 +02:00
|
|
|
# Update the user's subscription of the channel with ID `stream_a_id`
|
|
|
|
# so that it's pinned to the top of the user's channel list, and in
|
|
|
|
# the channel with ID `stream_b_id` so that it has the hex color "f00".
|
2021-02-12 08:19:30 +01:00
|
|
|
request = [
|
|
|
|
{
|
2024-05-24 10:34:26 +02:00
|
|
|
"stream_id": stream_a_id,
|
2021-02-12 08:20:45 +01:00
|
|
|
"property": "pin_to_top",
|
|
|
|
"value": True,
|
2021-02-12 08:19:30 +01:00
|
|
|
},
|
|
|
|
{
|
2024-05-24 10:34:26 +02:00
|
|
|
"stream_id": stream_b_id,
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Render a message.
|
2018-01-26 22:11:42 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Get the 100 last messages sent by "iago@zulip.com" to
|
|
|
|
# the channel named "Verona".
|
2024-07-12 02:30:17 +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"},
|
2024-05-19 13:19:05 +02:00
|
|
|
{"operator": "channel", "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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Check which messages, given the message IDs, match a narrow.
|
2020-03-15 14:16:02 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Get the raw content of a message given the message's ID.
|
2018-06-23 18:17:05 +02:00
|
|
|
result = client.get_raw_message(message_id)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Delete the attachment given the attachment's ID.
|
2021-07-30 11:58:11 +02:00
|
|
|
url = "attachments/" + str(attachment_id)
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url=url,
|
|
|
|
method="DELETE",
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-07-30 11:58:11 +02:00
|
|
|
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:
|
2024-07-12 02:30:17 +02:00
|
|
|
request: dict[str, Any] = {}
|
2018-01-27 22:26:16 +01:00
|
|
|
# {code_example|start}
|
2024-05-20 13:25:39 +02:00
|
|
|
# Send a channel message.
|
2018-01-27 22:26:16 +01:00
|
|
|
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)
|
2018-01-27 22:26:16 +01:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages", "post", "200")
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2024-06-02 20:19:28 +02:00
|
|
|
# Confirm the message was actually sent.
|
2021-02-12 08:20:45 +01:00
|
|
|
message_id = result["id"]
|
2024-05-24 09:44:44 +02:00
|
|
|
validate_message(client, message_id, request["content"])
|
2017-01-13 13:50:39 +01:00
|
|
|
|
2020-05-17 18:46:14 +02:00
|
|
|
user_id = 10
|
2024-05-24 13:44:23 +02:00
|
|
|
ensure_users([user_id], ["hamlet"])
|
|
|
|
# {code_example|start}
|
|
|
|
# Send a direct message.
|
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)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/messages", "post", "200")
|
2018-01-27 22:56:36 +01:00
|
|
|
|
2024-06-02 20:19:28 +02:00
|
|
|
# Confirm the message was actually sent.
|
2021-02-12 08:20:45 +01:00
|
|
|
message_id = result["id"]
|
2024-05-24 09:44:44 +02:00
|
|
|
validate_message(client, message_id, request["content"])
|
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:
|
2024-07-12 02:30:17 +02:00
|
|
|
request: dict[str, Any] = {}
|
2020-02-29 15:02:34 +01:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-07-12 02:30:17 +02:00
|
|
|
request: dict[str, Any] = {}
|
2020-03-07 11:20:57 +01:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Get read receipts for a message, given the message's ID.
|
2021-06-16 21:15:47 +02:00
|
|
|
result = client.call_endpoint(f"/messages/{message_id}/read_receipts", method="GET")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-06-16 21:15:47 +02:00
|
|
|
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",
|
2024-05-19 14:03:47 +02:00
|
|
|
"to": "nonexistent-channel",
|
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)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result, code="STREAM_DOES_NOT_EXIST")
|
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)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
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:
|
2018-01-27 23:18:19 +01:00
|
|
|
# {code_example|start}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Edit a message. Make sure that `message_id` is set to the ID of the
|
|
|
|
# message you wish to update.
|
2018-01-27 23:18:19 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
|
2024-06-02 20:19:28 +02:00
|
|
|
# Confirm the message was actually updated.
|
2024-05-24 09:44:44 +02:00
|
|
|
validate_message(client, message_id, 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)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Delete a message, given the message's ID.
|
2018-06-26 16:30:46 +02:00
|
|
|
result = client.delete_message(message_id)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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"])
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Get the edit history for a message, given the message's ID.
|
2018-06-27 22:54:08 +02:00
|
|
|
result = client.get_message_history(message_id)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-06-02 20:19:28 +02:00
|
|
|
# Send a few test messages.
|
2024-07-12 02:30:17 +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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Add the "read" flag to messages, given the messages' IDs.
|
2018-07-03 18:17:23 +02:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Remove the "starred" flag from messages, given the messages' IDs.
|
2018-07-03 18:17:23 +02:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-06-02 20:19:28 +02:00
|
|
|
# Register the queue and get all events.
|
2020-08-04 15:12:00 +02:00
|
|
|
# Mainly for verifying schema of /register.
|
|
|
|
result = client.register()
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Register the queue.
|
2018-02-07 05:00:10 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Delete a queue, where `queue_id` is the ID of the queue
|
|
|
|
# to be removed.
|
2018-02-08 03:54:20 +01:00
|
|
|
result = client.deregister(queue_id)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/events", "delete", "200")
|
2018-02-08 03:54:20 +01:00
|
|
|
|
2024-06-02 20:19:28 +02:00
|
|
|
# Test "BAD_EVENT_QUEUE_ID" error.
|
2018-02-16 23:49:35 +01:00
|
|
|
result = client.deregister(queue_id)
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result, code="BAD_EVENT_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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# 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 below
|
2021-06-24 16:16:13 +02:00
|
|
|
# parameters, like so:
|
|
|
|
result = client.get_events(queue_id=queue_id, last_event_id=-1)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-06-24 16:16:13 +02:00
|
|
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# Fetch the settings for this server.
|
2018-08-11 15:50:56 +02:00
|
|
|
result = client.get_server_settings()
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-02 20:19:28 +02:00
|
|
|
# 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)
|
|
|
|
# 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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
|
|
|
2024-05-10 06:26:36 +02:00
|
|
|
@openapi_test_function("/users/me/apns_device_token:post")
|
|
|
|
def add_apns_token(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
request = {"token": "apple-tokenbb", "appid": "org.zulip.Zulip"}
|
|
|
|
result = client.call_endpoint(url="/users/me/apns_device_token", method="POST", request=request)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-10 06:26:36 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/apns_device_token", "post", "200")
|
|
|
|
|
|
|
|
|
|
|
|
@openapi_test_function("/users/me/apns_device_token:delete")
|
|
|
|
def remove_apns_token(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
request = {
|
|
|
|
"token": "apple-tokenbb",
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/users/me/apns_device_token", method="DELETE", request=request
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-10 06:26:36 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/apns_device_token", "delete", "200")
|
|
|
|
|
|
|
|
|
2024-05-10 06:45:01 +02:00
|
|
|
@openapi_test_function("/users/me/android_gcm_reg_id:post")
|
|
|
|
def add_fcm_token(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
request = {"token": "android-token"}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/users/me/android_gcm_reg_id", method="POST", request=request
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-10 06:45:01 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/android_gcm_reg_id", "post", "200")
|
|
|
|
|
|
|
|
|
|
|
|
@openapi_test_function("/users/me/android_gcm_reg_id:delete")
|
|
|
|
def remove_fcm_token(client: Client) -> None:
|
|
|
|
# {code_example|start}
|
|
|
|
request = {
|
|
|
|
"token": "android-token",
|
|
|
|
}
|
|
|
|
result = client.call_endpoint(
|
|
|
|
url="/users/me/android_gcm_reg_id", method="DELETE", request=request
|
|
|
|
)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-10 06:45:01 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/android_gcm_reg_id", "delete", "200")
|
|
|
|
|
|
|
|
|
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"])
|
2024-05-24 13:44:23 +02:00
|
|
|
user_a_id = 10
|
|
|
|
user_b_id = 11
|
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
|
2024-05-24 13:44:23 +02:00
|
|
|
# with two users, "user_a" and "user_b".
|
2018-08-09 20:27:12 +02:00
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"op": "start",
|
2024-05-24 13:44:23 +02:00
|
|
|
"to": [user_a_id, user_b_id],
|
2018-08-09 20:27:12 +02:00
|
|
|
}
|
|
|
|
result = client.set_typing_status(request)
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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
|
2024-05-24 13:44:23 +02:00
|
|
|
# with "user_a" and "user_b".
|
2018-08-09 20:27:12 +02:00
|
|
|
request = {
|
2021-02-12 08:20:45 +01:00
|
|
|
"op": "stop",
|
2024-05-24 13:44:23 +02:00
|
|
|
"to": [user_a_id, user_b_id],
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2020-12-24 21:00:20 +01:00
|
|
|
validate_against_openapi_schema(result, "/typing", "post", "200")
|
|
|
|
|
|
|
|
stream_id = client.get_stream_id("Denmark")["stream_id"]
|
|
|
|
topic = "typing status"
|
2024-05-24 14:10:40 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# The user has started typing in a topic/channel.
|
2020-12-24 21:00:20 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2020-12-24 21:00:20 +01:00
|
|
|
validate_against_openapi_schema(result, "/typing", "post", "200")
|
|
|
|
|
|
|
|
# {code_example|start}
|
2024-05-24 14:10:40 +02:00
|
|
|
# The user has finished typing in a topic/channel.
|
2020-12-24 21:00:20 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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:
|
2024-05-24 14:10:40 +02:00
|
|
|
emoji_name = "my_custom_emoji"
|
2023-01-25 08:29:51 +01:00
|
|
|
# {code_example|start}
|
|
|
|
# Delete a custom emoji.
|
|
|
|
result = client.call_endpoint(f"realm/emoji/{emoji_name}", method="DELETE")
|
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2023-01-25 08:29:51 +01:00
|
|
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2022-07-27 19:30:03 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/alert_words", "get", "200")
|
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:
|
2024-05-24 14:10:40 +02:00
|
|
|
words = ["foo", "bar"]
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Add words (or phrases) to the user's set of configured alert words.
|
2024-05-24 14:10:40 +02:00
|
|
|
result = client.add_alert_words(words)
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2022-07-27 19:30:03 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/alert_words", "post", "200")
|
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:
|
2024-05-24 10:34:26 +02:00
|
|
|
words = client.get_alert_words()["alert_words"]
|
|
|
|
assert len(words) > 0
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|start}
|
|
|
|
# Remove words (or phrases) from the user's set of configured alert words.
|
2024-05-24 10:34:26 +02:00
|
|
|
result = client.remove_alert_words(words)
|
2022-07-27 19:30:03 +02:00
|
|
|
# {code_example|end}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2022-07-27 19:30:03 +02:00
|
|
|
validate_against_openapi_schema(result, "/users/me/alert_words", "delete", "200")
|
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:
|
2024-05-24 13:44:23 +02:00
|
|
|
user_ids = [6, 7, 8, 10]
|
|
|
|
ensure_users(user_ids, ["aaron", "zoe", "cordelia", "hamlet"])
|
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.",
|
2024-05-24 13:44:23 +02:00
|
|
|
"members": user_ids,
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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: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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2024-05-24 11:02:23 +02:00
|
|
|
validate_against_openapi_schema(result, "/user_groups/{user_group_id}", "patch", "200")
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
2021-02-12 08:20:45 +01:00
|
|
|
validate_against_openapi_schema(result, "/user_groups/{user_group_id}", "delete", "200")
|
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"])
|
2024-05-24 13:44:23 +02:00
|
|
|
user_ids_to_add = [11]
|
|
|
|
user_ids_to_remove = [8, 10]
|
2020-07-15 14:50:48 +02:00
|
|
|
# {code_example|start}
|
2019-04-22 22:18:15 +02:00
|
|
|
request = {
|
2024-05-24 13:44:23 +02:00
|
|
|
"delete": user_ids_to_remove,
|
|
|
|
"add": user_ids_to_add,
|
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}
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_success_response(result)
|
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()
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result, code="UNAUTHORIZED")
|
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({})
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result, code="REQUEST_VARIABLE_MISSING")
|
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")
|
2024-06-21 08:08:25 +02:00
|
|
|
assert_error_response(result)
|
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)
|
2024-05-16 15:59:27 +02:00
|
|
|
get_user_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)
|
2024-05-10 06:26:36 +02:00
|
|
|
add_apns_token(client)
|
|
|
|
remove_apns_token(client)
|
2024-05-10 06:45:01 +02:00
|
|
|
add_fcm_token(client)
|
|
|
|
remove_fcm_token(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")
|
2024-05-19 13:26:40 +02:00
|
|
|
archive_stream(client)
|
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)
|
2024-05-24 10:34:39 +02:00
|
|
|
filter_id = add_realm_filter(client)
|
|
|
|
update_realm_filter(client, filter_id)
|
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)
|
2024-05-24 10:34:39 +02:00
|
|
|
remove_realm_filter(client, filter_id)
|
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
|
|
|
|
2024-04-01 16:38:09 +02:00
|
|
|
def test_invitations(client: Client) -> None:
|
|
|
|
send_invitations(client)
|
2024-04-20 08:41:38 +02:00
|
|
|
revoke_email_invitation(client)
|
2024-04-09 17:36:23 +02:00
|
|
|
create_reusable_invitation_link(client)
|
2024-05-08 09:46:20 +02:00
|
|
|
revoke_reusable_invitation_link(client)
|
2024-04-01 16:38:09 +02:00
|
|
|
get_invitations(client)
|
2024-06-07 17:11:42 +02:00
|
|
|
resend_email_invitation(client)
|
2024-04-01 16:38:09 +02: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)
|
2024-04-01 16:38:09 +02:00
|
|
|
test_invitations(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)
|