mirror of https://github.com/zulip/zulip.git
api/get-all-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 zerver/lib/api_test_helpers.
This commit is contained in:
parent
dcf3a9cd18
commit
73a3755120
|
@ -105,5 +105,47 @@
|
|||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"get-all-streams": {
|
||||
"msg":"",
|
||||
"result":"success",
|
||||
"streams":[
|
||||
{
|
||||
"description":"A Scandinavian country",
|
||||
"invite_only":false,
|
||||
"name":"Denmark",
|
||||
"stream_id":1
|
||||
},
|
||||
{
|
||||
"description":"Yet another Italian city",
|
||||
"invite_only":false,
|
||||
"name":"Rome",
|
||||
"stream_id":2
|
||||
},
|
||||
{
|
||||
"description":"Located in the United Kingdom",
|
||||
"invite_only":false,
|
||||
"name":"Scotland",
|
||||
"stream_id":3
|
||||
},
|
||||
{
|
||||
"description":"A northeastern Italian city",
|
||||
"invite_only":false,
|
||||
"name":"Venice",
|
||||
"stream_id":4
|
||||
},
|
||||
{
|
||||
"description":"A city in Italy",
|
||||
"invite_only":false,
|
||||
"name":"Verona",
|
||||
"stream_id":5
|
||||
},
|
||||
{
|
||||
"description":"New stream for testing",
|
||||
"invite_only":false,
|
||||
"name":"new stream",
|
||||
"stream_id":6
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,21 +31,7 @@ curl {{ api_url }}/v1/streams?include_public=false \
|
|||
|
||||
<div data-language="python" markdown="1">
|
||||
|
||||
```
|
||||
#!/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 has access to
|
||||
print(client.get_streams())
|
||||
|
||||
# You may pass in one or more of the query parameters mentioned above
|
||||
# as keyword arguments, like so:
|
||||
print(client.get_streams(include_public=False))
|
||||
```
|
||||
{generate_code_example|get-all-streams|method}
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -91,44 +77,7 @@ zulip(config).then((client) => {
|
|||
|
||||
A typical successful JSON response may look like:
|
||||
|
||||
```
|
||||
{
|
||||
'result':'success',
|
||||
'streams':[
|
||||
{
|
||||
'stream_id':15,
|
||||
'name':'Denmark',
|
||||
'invite_only':False,
|
||||
'description':'A Scandinavian country'
|
||||
},
|
||||
{
|
||||
'stream_id':16,
|
||||
'name':'Rome',
|
||||
'invite_only':False,
|
||||
'description':'Yet another Italian city'
|
||||
},
|
||||
{
|
||||
'stream_id':17,
|
||||
'name':'Scotland',
|
||||
'invite_only':False,
|
||||
'description':'Located in the United Kingdom'
|
||||
},
|
||||
{
|
||||
'stream_id':18,
|
||||
'name':'Venice',
|
||||
'invite_only':False,
|
||||
'description':'A northeastern Italian city'
|
||||
},
|
||||
{
|
||||
'stream_id':19,
|
||||
'name':'Verona',
|
||||
'invite_only':False,
|
||||
'description':'A city in Italy'
|
||||
}
|
||||
],
|
||||
'msg':''
|
||||
}
|
||||
```
|
||||
{generate_code_example|get-all-streams|fixture}
|
||||
|
||||
An example of a JSON response for when the user is not authorized
|
||||
to use the `include_all_active` parameter:
|
||||
|
|
|
@ -76,8 +76,20 @@ def get_stream_id(client):
|
|||
def get_streams(client):
|
||||
# type: (Client) -> None
|
||||
|
||||
# {code_example|start}
|
||||
# Get all streams that the user has access to
|
||||
result = client.get_streams()
|
||||
assert result['result'] == 'success'
|
||||
|
||||
# You may pass in one or more of the query parameters mentioned above
|
||||
# as keyword arguments, like so:
|
||||
result = client.get_streams(include_public=True)
|
||||
# {code_example|end}
|
||||
|
||||
fixture = FIXTURES['get-all-streams']
|
||||
test_against_fixture(result, fixture, check_if_equal=['msg', 'result'],
|
||||
check_if_exists=['streams'])
|
||||
assert len(result['streams']) == len(fixture['streams'])
|
||||
|
||||
streams = [s for s in result['streams'] if s['name'] == 'new stream']
|
||||
assert streams[0]['description'] == 'New stream for testing'
|
||||
|
||||
|
@ -226,6 +238,7 @@ TEST_FUNCTIONS = {
|
|||
'update-message': update_message,
|
||||
'get-stream-id': get_stream_id,
|
||||
'get-subscribed-streams': list_subscriptions,
|
||||
'get-all-streams': get_streams,
|
||||
}
|
||||
|
||||
# SETUP METHODS FOLLOW
|
||||
|
|
Loading…
Reference in New Issue