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:
Eeshan Garg
2018-02-06 00:17:40 -03:30
committed by Tim Abbott
parent f4cb5e70ed
commit 61e4fc3b74
3 changed files with 33 additions and 33 deletions

View File

@@ -178,5 +178,21 @@
]
}
}
},
"remove-subscriptions": {
"already_subscribed":{
},
"msg":"",
"not_subscribed":[
],
"removed":[
"new stream"
],
"result":"success",
"subscribed":{
}
}
}

View File

@@ -36,25 +36,7 @@ administrative privileges.
<div data-language="python" markdown="1">
```python
#!/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']
))
```
{generate_code_example|remove-subscriptions|example}
</div>
@@ -105,18 +87,7 @@ zulip(config).then((client) => {
A typical successful JSON response may look like:
```
{
"result":"success",
"not_subscribed":[
],
"msg":"",
"removed":[
"Denmark"
]
}
```
{generate_code_example|remove-subscriptions|fixture}
A typical JSON response for when you try to unsubscribe from a stream
that doesn't exist:

View File

@@ -160,8 +160,15 @@ def list_subscriptions(client):
def remove_subscriptions(client):
# type: (Client) -> None
result = client.remove_subscriptions(['new stream'])
assert result['result'] == 'success'
# {code_example|start}
# 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
result = client.list_subscriptions()
@@ -169,6 +176,10 @@ def remove_subscriptions(client):
streams = [s for s in result['subscriptions'] if s['name'] == 'new stream']
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):
# type: (Client) -> None
@@ -279,6 +290,7 @@ TEST_FUNCTIONS = {
'create-user': create_user,
'get-profile': get_profile,
'add-subscriptions': add_subscriptions,
'remove-subscriptions': remove_subscriptions,
}
# SETUP METHODS FOLLOW
@@ -322,6 +334,7 @@ def test_streams(client):
get_stream_id(client)
get_streams(client)
get_subscribers(client)
remove_subscriptions(client)
def test_the_api(client):
# type: (Client) -> None