python-examples: Move variable assignment out of user-facing examples.

This commit is contained in:
Lauryn Menard 2024-05-24 14:10:40 +02:00 committed by Tim Abbott
parent 265f85fa95
commit 9fd21addad
1 changed files with 11 additions and 23 deletions

View File

@ -341,9 +341,8 @@ def get_members(client: Client) -> None:
@openapi_test_function("/users/{email}:get") @openapi_test_function("/users/{email}:get")
def get_user_by_email(client: Client) -> None: def get_user_by_email(client: Client) -> None:
# {code_example|start}
# Fetch details on a user given a user ID
email = "iago@zulip.com" email = "iago@zulip.com"
# {code_example|start}
result = client.call_endpoint( result = client.call_endpoint(
url=f"/users/{email}", url=f"/users/{email}",
method="GET", method="GET",
@ -698,9 +697,9 @@ def deactivate_own_user(client: Client, owner_client: Client) -> None:
@openapi_test_function("/get_stream_id:get") @openapi_test_function("/get_stream_id:get")
def get_stream_id(client: Client) -> int: def get_stream_id(client: Client) -> int:
name = "python-test"
# {code_example|start} # {code_example|start}
# Get the ID of a given channel name. # Get the ID of a given channel name.
name = "python-test"
result = client.get_stream_id(name) result = client.get_stream_id(name)
# {code_example|end} # {code_example|end}
validate_response_result(result) validate_response_result(result)
@ -718,10 +717,9 @@ def archive_stream(client: Client) -> None:
}, },
], ],
) )
# {code_example|start}
# Archive channel named "example to archive".
stream_id = client.get_stream_id("example to archive")["stream_id"] stream_id = client.get_stream_id("example to archive")["stream_id"]
# {code_example|start}
# Archive a channel, given the channel's ID.
result = client.delete_stream(stream_id) result = client.delete_stream(stream_id)
# {code_example|end} # {code_example|end}
validate_response_result(result) validate_response_result(result)
@ -989,12 +987,9 @@ def mark_stream_as_read(client: Client) -> None:
@openapi_test_function("/mark_topic_as_read:post") @openapi_test_function("/mark_topic_as_read:post")
def mark_topic_as_read(client: Client) -> None: def mark_topic_as_read(client: Client) -> None:
stream_id = client.get_subscriptions()["subscriptions"][0]["stream_id"] stream_id = client.get_subscriptions()["subscriptions"][0]["stream_id"]
# Grab an existing topic name
topic_name = client.get_stream_topics(stream_id)["topics"][0]["name"] topic_name = client.get_stream_topics(stream_id)["topics"][0]["name"]
# {code_example|start} # {code_example|start}
# Mark unread messages in a given topic, in the channel with ID 1, # Mark unread messages in a given topic, given a channel ID, as read.
# as read.
result = client.mark_topic_as_read(stream_id, topic_name) result = client.mark_topic_as_read(stream_id, topic_name)
# {code_example|end} # {code_example|end}
validate_response_result(result) validate_response_result(result)
@ -1539,12 +1534,10 @@ def set_typing_status(client: Client) -> None:
validate_response_result(result) validate_response_result(result)
validate_against_openapi_schema(result, "/typing", "post", "200") validate_against_openapi_schema(result, "/typing", "post", "200")
# {code_example|start}
# The user has started to type in topic "typing status"
# of the channel named "Denmark".
stream_id = client.get_stream_id("Denmark")["stream_id"] stream_id = client.get_stream_id("Denmark")["stream_id"]
topic = "typing status" topic = "typing status"
# {code_example|start}
# The user has started typing in a topic/channel.
request = { request = {
"type": "stream", "type": "stream",
"op": "start", "op": "start",
@ -1558,11 +1551,7 @@ def set_typing_status(client: Client) -> None:
validate_against_openapi_schema(result, "/typing", "post", "200") validate_against_openapi_schema(result, "/typing", "post", "200")
# {code_example|start} # {code_example|start}
# The user has finished typing in topic "typing status" # The user has finished typing in a topic/channel.
# of the channel named "Denmark".
stream_id = client.get_stream_id("Denmark")["stream_id"]
topic = "typing status"
request = { request = {
"type": "stream", "type": "stream",
"op": "stop", "op": "stop",
@ -1596,9 +1585,9 @@ def upload_custom_emoji(client: Client) -> None:
@openapi_test_function("/realm/emoji/{emoji_name}:delete") @openapi_test_function("/realm/emoji/{emoji_name}:delete")
def delete_custom_emoji(client: Client) -> None: def delete_custom_emoji(client: Client) -> None:
emoji_name = "my_custom_emoji"
# {code_example|start} # {code_example|start}
# Delete a custom emoji. # Delete a custom emoji.
emoji_name = "my_custom_emoji"
result = client.call_endpoint(f"realm/emoji/{emoji_name}", method="DELETE") result = client.call_endpoint(f"realm/emoji/{emoji_name}", method="DELETE")
# {code_example|end} # {code_example|end}
validate_response_result(result) validate_response_result(result)
@ -1617,11 +1606,10 @@ def get_alert_words(client: Client) -> None:
@openapi_test_function("/users/me/alert_words:post") @openapi_test_function("/users/me/alert_words:post")
def add_alert_words(client: Client) -> None: def add_alert_words(client: Client) -> None:
words = ["foo", "bar"]
# {code_example|start} # {code_example|start}
# Add words (or phrases) to the user's set of configured alert words. # Add words (or phrases) to the user's set of configured alert words.
word = ["foo", "bar"] result = client.add_alert_words(words)
result = client.add_alert_words(word)
# {code_example|end} # {code_example|end}
validate_response_result(result) validate_response_result(result)
validate_against_openapi_schema(result, "/users/me/alert_words", "post", "200") validate_against_openapi_schema(result, "/users/me/alert_words", "post", "200")