mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
api/remove-subscriptions: Make fixtures/examples testable.
api/remove-subscriptions now uses the Markdown extension in bugdown/api_code_examples to generate code example and fixtures from tests.
This commit is contained in:
@@ -178,5 +178,21 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"remove-subscriptions": {
|
||||||
|
"already_subscribed":{
|
||||||
|
|
||||||
|
},
|
||||||
|
"msg":"",
|
||||||
|
"not_subscribed":[
|
||||||
|
|
||||||
|
],
|
||||||
|
"removed":[
|
||||||
|
"new stream"
|
||||||
|
],
|
||||||
|
"result":"success",
|
||||||
|
"subscribed":{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,25 +36,7 @@ administrative privileges.
|
|||||||
|
|
||||||
<div data-language="python" markdown="1">
|
<div data-language="python" markdown="1">
|
||||||
|
|
||||||
```python
|
{generate_code_example|remove-subscriptions|example}
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import zulip
|
|
||||||
|
|
||||||
# Download ~/zuliprc-dev from your dev server
|
|
||||||
client = zulip.Client(config_file="~/zuliprc-dev")
|
|
||||||
|
|
||||||
# Unsubscribe from the stream "Denmark"
|
|
||||||
print(client.remove_subscriptions(
|
|
||||||
['Denmark']
|
|
||||||
))
|
|
||||||
|
|
||||||
# Unsubscribe Zoe from the stream "Denmark"
|
|
||||||
print(client.remove_subscriptions(
|
|
||||||
['Denmark'],
|
|
||||||
principals=['ZOE@zulip.com']
|
|
||||||
))
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -105,18 +87,7 @@ zulip(config).then((client) => {
|
|||||||
|
|
||||||
A typical successful JSON response may look like:
|
A typical successful JSON response may look like:
|
||||||
|
|
||||||
```
|
{generate_code_example|remove-subscriptions|fixture}
|
||||||
{
|
|
||||||
"result":"success",
|
|
||||||
"not_subscribed":[
|
|
||||||
|
|
||||||
],
|
|
||||||
"msg":"",
|
|
||||||
"removed":[
|
|
||||||
"Denmark"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
A typical JSON response for when you try to unsubscribe from a stream
|
A typical JSON response for when you try to unsubscribe from a stream
|
||||||
that doesn't exist:
|
that doesn't exist:
|
||||||
|
|||||||
@@ -160,8 +160,15 @@ def list_subscriptions(client):
|
|||||||
def remove_subscriptions(client):
|
def remove_subscriptions(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
|
||||||
result = client.remove_subscriptions(['new stream'])
|
# {code_example|start}
|
||||||
assert result['result'] == 'success'
|
# Unsubscribe from the stream "new stream"
|
||||||
|
result = client.remove_subscriptions(
|
||||||
|
['new stream']
|
||||||
|
)
|
||||||
|
# {code_example|end}
|
||||||
|
|
||||||
|
fixture = FIXTURES['remove-subscriptions']
|
||||||
|
test_against_fixture(result, fixture)
|
||||||
|
|
||||||
# test it was actually removed
|
# test it was actually removed
|
||||||
result = client.list_subscriptions()
|
result = client.list_subscriptions()
|
||||||
@@ -169,6 +176,10 @@ def remove_subscriptions(client):
|
|||||||
streams = [s for s in result['subscriptions'] if s['name'] == 'new stream']
|
streams = [s for s in result['subscriptions'] if s['name'] == 'new stream']
|
||||||
assert len(streams) == 0
|
assert len(streams) == 0
|
||||||
|
|
||||||
|
# TODO: Add example for 'principals' argument when the next zulip package
|
||||||
|
# release is made. The next release supports passing in 'principals' to
|
||||||
|
# remove_subscriptions.
|
||||||
|
|
||||||
def render_message(client):
|
def render_message(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
|
||||||
@@ -279,6 +290,7 @@ TEST_FUNCTIONS = {
|
|||||||
'create-user': create_user,
|
'create-user': create_user,
|
||||||
'get-profile': get_profile,
|
'get-profile': get_profile,
|
||||||
'add-subscriptions': add_subscriptions,
|
'add-subscriptions': add_subscriptions,
|
||||||
|
'remove-subscriptions': remove_subscriptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
# SETUP METHODS FOLLOW
|
# SETUP METHODS FOLLOW
|
||||||
@@ -322,6 +334,7 @@ def test_streams(client):
|
|||||||
get_stream_id(client)
|
get_stream_id(client)
|
||||||
get_streams(client)
|
get_streams(client)
|
||||||
get_subscribers(client)
|
get_subscribers(client)
|
||||||
|
remove_subscriptions(client)
|
||||||
|
|
||||||
def test_the_api(client):
|
def test_the_api(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
|||||||
Reference in New Issue
Block a user