mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
api/get-profile: 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:
@@ -151,5 +151,18 @@
|
||||
"create-user": {
|
||||
"msg":"",
|
||||
"result":"success"
|
||||
},
|
||||
"get-profile": {
|
||||
"client_id":"74c768b081076fdb3c4326256c17467e",
|
||||
"email":"iago@zulip.com",
|
||||
"full_name":"Iago",
|
||||
"is_admin":true,
|
||||
"is_bot":false,
|
||||
"max_message_id":30,
|
||||
"msg":"",
|
||||
"pointer":-1,
|
||||
"result":"success",
|
||||
"short_name":"iago",
|
||||
"user_id":5
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,18 +25,7 @@ curl {{ api_url }}/v1/users/me \
|
||||
|
||||
<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")
|
||||
|
||||
# Get the profile of the user/bot that requests this endpoint,
|
||||
# which is `client` in this case:
|
||||
print(client.get_profile())
|
||||
```
|
||||
{generate_code_example|get-profile|method}
|
||||
|
||||
</div>
|
||||
|
||||
@@ -80,20 +69,6 @@ The rest of the return values are quite self-descriptive.
|
||||
|
||||
A typical successful JSON response may look like:
|
||||
|
||||
```
|
||||
{
|
||||
'short_name':'sample-bot',
|
||||
'result':'success',
|
||||
'msg':'',
|
||||
'is_bot':True,
|
||||
'email':'sample-bot@localhost',
|
||||
'pointer':-1,
|
||||
'max_message_id':131,
|
||||
'full_name':'Sample',
|
||||
'user_id':45,
|
||||
'client_id':'77431db17e4f32068756902d7c09c8bb',
|
||||
'is_admin':False
|
||||
}
|
||||
```
|
||||
{generate_code_example|get-profile|fixture}
|
||||
|
||||
{!invalid-api-key-json-response.md!}
|
||||
|
||||
@@ -60,10 +60,18 @@ def get_members(client):
|
||||
def get_profile(client):
|
||||
# type: (Client) -> None
|
||||
|
||||
# {code_example|start}
|
||||
# Get the profile of the user/bot that requests this endpoint,
|
||||
# which is `client` in this case:
|
||||
result = client.get_profile()
|
||||
assert result['is_admin']
|
||||
assert result['email'] == 'iago@zulip.com'
|
||||
assert result['full_name'] == 'Iago'
|
||||
# {code_example|end}
|
||||
|
||||
fixture = FIXTURES['get-profile']
|
||||
check_if_equal = ['email', 'full_name', 'msg', 'result', 'short_name']
|
||||
check_if_exists = ['client_id', 'is_admin', 'is_bot', 'max_message_id',
|
||||
'pointer', 'user_id']
|
||||
test_against_fixture(result, fixture, check_if_equal=check_if_equal,
|
||||
check_if_exists=check_if_exists)
|
||||
|
||||
def get_stream_id(client):
|
||||
# type: (Client) -> None
|
||||
@@ -245,6 +253,7 @@ TEST_FUNCTIONS = {
|
||||
'get-subscribed-streams': list_subscriptions,
|
||||
'get-all-streams': get_streams,
|
||||
'create-user': create_user,
|
||||
'get-profile': get_profile,
|
||||
}
|
||||
|
||||
# SETUP METHODS FOLLOW
|
||||
|
||||
Reference in New Issue
Block a user