mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 16:37:23 +00:00
api/get-subscribed-streams: Make code examples/fixtures testable.
This commit uses the Markdown extension defined in zerver/lib/bugdown/api_generate_examples to generate the example fixture and code example, so that both are tested in tools/lib/api_tests.
This commit is contained in:
@@ -22,5 +22,88 @@
|
|||||||
"stream_id":15,
|
"stream_id":15,
|
||||||
"result":"success",
|
"result":"success",
|
||||||
"msg":""
|
"msg":""
|
||||||
|
},
|
||||||
|
"get-subscribed-streams": {
|
||||||
|
"msg":"",
|
||||||
|
"result":"success",
|
||||||
|
"subscriptions":[
|
||||||
|
{
|
||||||
|
"audible_notifications":true,
|
||||||
|
"color":"#e79ab5",
|
||||||
|
"description":"A Scandinavian country",
|
||||||
|
"desktop_notifications":true,
|
||||||
|
"email_address":"Denmark+187b4125ed36d6af8b5d03ef4f65c0cf@zulipdev.com:9981",
|
||||||
|
"in_home_view":true,
|
||||||
|
"invite_only":false,
|
||||||
|
"name":"Denmark",
|
||||||
|
"pin_to_top":false,
|
||||||
|
"push_notifications":false,
|
||||||
|
"stream_id":1,
|
||||||
|
"subscribers":[
|
||||||
|
"ZOE@zulip.com",
|
||||||
|
"hamlet@zulip.com",
|
||||||
|
"iago@zulip.com",
|
||||||
|
"othello@zulip.com",
|
||||||
|
"prospero@zulip.com"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"audible_notifications":true,
|
||||||
|
"color":"#e79ab5",
|
||||||
|
"description":"Located in the United Kingdom",
|
||||||
|
"desktop_notifications":true,
|
||||||
|
"email_address":"Scotland+f5786390183e60a1ccb18374f9d05649@zulipdev.com:9981",
|
||||||
|
"in_home_view":true,
|
||||||
|
"invite_only":false,
|
||||||
|
"name":"Scotland",
|
||||||
|
"pin_to_top":false,
|
||||||
|
"push_notifications":false,
|
||||||
|
"stream_id":3,
|
||||||
|
"subscribers":[
|
||||||
|
"ZOE@zulip.com",
|
||||||
|
"iago@zulip.com",
|
||||||
|
"othello@zulip.com",
|
||||||
|
"prospero@zulip.com"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"audible_notifications":true,
|
||||||
|
"color":"#e79ab5",
|
||||||
|
"description":"A city in Italy",
|
||||||
|
"desktop_notifications":true,
|
||||||
|
"email_address":"Verona+faaa92dc82cf143174ddc098a1c832ef@zulipdev.com:9981",
|
||||||
|
"in_home_view":true,
|
||||||
|
"invite_only":false,
|
||||||
|
"name":"Verona",
|
||||||
|
"pin_to_top":false,
|
||||||
|
"push_notifications":false,
|
||||||
|
"stream_id":5,
|
||||||
|
"subscribers":[
|
||||||
|
"AARON@zulip.com",
|
||||||
|
"ZOE@zulip.com",
|
||||||
|
"cordelia@zulip.com",
|
||||||
|
"hamlet@zulip.com",
|
||||||
|
"iago@zulip.com",
|
||||||
|
"othello@zulip.com",
|
||||||
|
"prospero@zulip.com"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"audible_notifications":false,
|
||||||
|
"color":"#76ce90",
|
||||||
|
"description":"New stream for testing",
|
||||||
|
"desktop_notifications":false,
|
||||||
|
"email_address":"new%0032stream+e1917b4fc733268e91fcc57cf79a9249@zulipdev.com:9981",
|
||||||
|
"in_home_view":true,
|
||||||
|
"invite_only":false,
|
||||||
|
"name":"new stream",
|
||||||
|
"pin_to_top":false,
|
||||||
|
"push_notifications":false,
|
||||||
|
"stream_id":6,
|
||||||
|
"subscribers":[
|
||||||
|
"iago@zulip.com"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,17 +24,8 @@ curl {{ api_url }}/v1/users/me/subscriptions \
|
|||||||
|
|
||||||
<div data-language="python" markdown="1">
|
<div data-language="python" markdown="1">
|
||||||
|
|
||||||
```python
|
{generate_code_example|get-subscribed-streams|method}
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import zulip
|
|
||||||
|
|
||||||
# Download ~/zuliprc-dev from your dev server
|
|
||||||
client = zulip.Client(config_file="~/zuliprc-dev")
|
|
||||||
|
|
||||||
# Get all streams that the user is subscribed to
|
|
||||||
print(client.list_subscriptions())
|
|
||||||
```
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-language="javascript" markdown="1">
|
<div data-language="javascript" markdown="1">
|
||||||
@@ -95,54 +86,6 @@ This request takes no arguments.
|
|||||||
|
|
||||||
A typical successful JSON response may look like:
|
A typical successful JSON response may look like:
|
||||||
|
|
||||||
```
|
{generate_code_example|get-subscribed-streams|fixture}
|
||||||
{
|
|
||||||
'result':'success',
|
|
||||||
'subscriptions':[
|
|
||||||
{
|
|
||||||
'desktop_notifications':False,
|
|
||||||
'pin_to_top':False,
|
|
||||||
'subscribers':[
|
|
||||||
'ZOE@zulip.com',
|
|
||||||
'hamlet@zulip.com',
|
|
||||||
'iago@zulip.com',
|
|
||||||
'othello@zulip.com',
|
|
||||||
'prospero@zulip.com',
|
|
||||||
'sample-bot@localhost'
|
|
||||||
],
|
|
||||||
'invite_only':True,
|
|
||||||
'email_address':'Denmark+cb16118453aa4e76cb36e394a153a1a3@zulipdev.com:9991',
|
|
||||||
'name':'Denmark',
|
|
||||||
'color':'#76ce90',
|
|
||||||
'description':'A Scandinavian country',
|
|
||||||
'in_home_view':True,
|
|
||||||
'push_notifications':False,
|
|
||||||
'stream_id':15,
|
|
||||||
'audible_notifications':False
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'desktop_notifications':False,
|
|
||||||
'pin_to_top':False,
|
|
||||||
'subscribers':[
|
|
||||||
'ZOE@zulip.com',
|
|
||||||
'iago@zulip.com',
|
|
||||||
'othello@zulip.com',
|
|
||||||
'prospero@zulip.com',
|
|
||||||
'sample-bot@localhost'
|
|
||||||
],
|
|
||||||
'invite_only':False,
|
|
||||||
'email_address':'Scotland+463ab6b458e2d0364aab52ca55b70ffb@zulipdev.com:9991',
|
|
||||||
'name':'Scotland',
|
|
||||||
'color':'#fae589',
|
|
||||||
'description':'Located in the United Kingdom',
|
|
||||||
'in_home_view':True,
|
|
||||||
'push_notifications':False,
|
|
||||||
'stream_id':17,
|
|
||||||
'audible_notifications':False
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'msg':''
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
{!invalid-api-key-json-response.md!}
|
{!invalid-api-key-json-response.md!}
|
||||||
|
|||||||
@@ -96,8 +96,15 @@ def get_user_agent(client):
|
|||||||
def list_subscriptions(client):
|
def list_subscriptions(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
|
||||||
|
# {code_example|start}
|
||||||
|
# Get all streams that the user is subscribed to
|
||||||
result = client.list_subscriptions()
|
result = client.list_subscriptions()
|
||||||
assert result['result'] == 'success'
|
# {code_example|end}
|
||||||
|
|
||||||
|
fixture = FIXTURES['get-subscribed-streams']
|
||||||
|
test_against_fixture(result, fixture, check_if_equal=['msg', 'result'],
|
||||||
|
check_if_exists=['subscriptions'])
|
||||||
|
|
||||||
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 streams[0]['description'] == 'New stream for testing'
|
assert streams[0]['description'] == 'New stream for testing'
|
||||||
|
|
||||||
@@ -218,6 +225,7 @@ TEST_FUNCTIONS = {
|
|||||||
'private-message': private_message,
|
'private-message': private_message,
|
||||||
'update-message': update_message,
|
'update-message': update_message,
|
||||||
'get-stream-id': get_stream_id,
|
'get-stream-id': get_stream_id,
|
||||||
|
'get-subscribed-streams': list_subscriptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
# SETUP METHODS FOLLOW
|
# SETUP METHODS FOLLOW
|
||||||
|
|||||||
Reference in New Issue
Block a user