mirror of https://github.com/zulip/zulip.git
api/get-all-users: Make fixtures/examples testable.
api/get-all-users now uses the Markdown extension in bugdown/api_code_examples to generate code examples and fixtures from tests.
This commit is contained in:
parent
929724e5e7
commit
66ca0c725f
|
@ -192,5 +192,41 @@
|
||||||
"invalid-api-key": {
|
"invalid-api-key": {
|
||||||
"msg":"Invalid API key",
|
"msg":"Invalid API key",
|
||||||
"result":"error"
|
"result":"error"
|
||||||
|
},
|
||||||
|
"get-all-users": {
|
||||||
|
"members":[
|
||||||
|
{
|
||||||
|
"avatar_url":"https:\/\/secure.gravatar.com\/avatar\/818c212b9f8830dfef491b3f7da99a14?d=identicon&version=1",
|
||||||
|
"bot_type":null,
|
||||||
|
"email":"AARON@zulip.com",
|
||||||
|
"full_name":"aaron",
|
||||||
|
"is_active":true,
|
||||||
|
"is_admin":false,
|
||||||
|
"is_bot":false,
|
||||||
|
"user_id":1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"avatar_url":"https:\/\/secure.gravatar.com\/avatar\/77c3871a68c8d70356156029fd0a4999?d=identicon&version=1",
|
||||||
|
"bot_type":null,
|
||||||
|
"email":"cordelia@zulip.com",
|
||||||
|
"full_name":"Cordelia Lear",
|
||||||
|
"is_active":true,
|
||||||
|
"is_admin":false,
|
||||||
|
"is_bot":false,
|
||||||
|
"user_id":3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"avatar_url":"https:\/\/secure.gravatar.com\/avatar\/0cbf08f3a355995fa2ec542246e35123?d=identicon&version=1",
|
||||||
|
"bot_type":null,
|
||||||
|
"email":"newbie@zulip.com",
|
||||||
|
"full_name":"New User",
|
||||||
|
"is_active":true,
|
||||||
|
"is_admin":false,
|
||||||
|
"is_bot":false,
|
||||||
|
"user_id":24
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"msg":"",
|
||||||
|
"result":"success"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,24 +30,7 @@ curl {{ api_url }}/v1/users?client_gravatar=true \
|
||||||
|
|
||||||
<div data-language="python" markdown="1">
|
<div data-language="python" markdown="1">
|
||||||
|
|
||||||
```python
|
{generate_code_example|get-all-users|example}
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import zulip
|
|
||||||
|
|
||||||
# Download ~/zuliprc-dev from your dev server
|
|
||||||
client = zulip.Client(config_file="~/zuliprc-dev")
|
|
||||||
|
|
||||||
# Get all users in the realm
|
|
||||||
print(client.get_members())
|
|
||||||
|
|
||||||
# You may pass the `client_gravatar` query parameter as follows:
|
|
||||||
print(client.call_endpoint(
|
|
||||||
url='users?client_gravatar=true',
|
|
||||||
method='GET',
|
|
||||||
))
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -105,52 +88,4 @@ zulip(config).then((client) => {
|
||||||
|
|
||||||
A typical successful JSON response may look like:
|
A typical successful JSON response may look like:
|
||||||
|
|
||||||
```
|
{generate_code_example|get-all-users|fixture}
|
||||||
{
|
|
||||||
'msg':'',
|
|
||||||
'members':[
|
|
||||||
{
|
|
||||||
'email':'ZOE@zulip.com',
|
|
||||||
'is_bot':False,
|
|
||||||
'avatar_url':'https://secure.gravatar.com/avatar/0f030c97ab51312c7bbffd3966198ced?d=identicon&version=1',
|
|
||||||
'full_name':'Zoe',
|
|
||||||
'is_active':True,
|
|
||||||
'is_admin':False,
|
|
||||||
'bot_type':None,
|
|
||||||
'user_id':23
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'email':'AARON@zulip.com',
|
|
||||||
'is_bot':False,
|
|
||||||
'avatar_url':'https://secure.gravatar.com/avatar/818c212b9f8830dfef491b3f7da99a14?d=identicon&version=1',
|
|
||||||
'full_name':'aaron',
|
|
||||||
'is_active':True,
|
|
||||||
'is_admin':False,
|
|
||||||
'bot_type':None,
|
|
||||||
'user_id':22
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'bot_owner':'iago@zulip.com',
|
|
||||||
'email':'sample-bot@localhost',
|
|
||||||
'is_bot':True,
|
|
||||||
'avatar_url':'https://secure.gravatar.com/avatar/0ea4ba8ec99b1fe07f62785a7c584cd3?d=identicon&version=1',
|
|
||||||
'full_name':'sample',
|
|
||||||
'is_active':True,
|
|
||||||
'is_admin':False,
|
|
||||||
'bot_type':1,
|
|
||||||
'user_id':45
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'email':'iago@zulip.com',
|
|
||||||
'is_bot':False,
|
|
||||||
'avatar_url':'https://secure.gravatar.com/avatar/af4f06322c177ef4e1e9b2c424986b54?d=identicon&version=1',
|
|
||||||
'full_name':'Iago',
|
|
||||||
'is_active':True,
|
|
||||||
'is_admin':True,
|
|
||||||
'bot_type':None,
|
|
||||||
'user_id':26
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'result':'success'
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
|
@ -67,14 +67,36 @@ def create_user(client):
|
||||||
def get_members(client):
|
def get_members(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
|
||||||
|
# {code_example|start}
|
||||||
|
# Get all users in the realm
|
||||||
result = client.get_members()
|
result = client.get_members()
|
||||||
assert result['result'] == 'success'
|
# {code_example|end}
|
||||||
|
|
||||||
|
fixture = FIXTURES['get-all-users']
|
||||||
|
test_against_fixture(result, fixture, check_if_equal=['msg', 'result'],
|
||||||
|
check_if_exists=['members'])
|
||||||
members = [m for m in result['members'] if m['email'] == 'newbie@zulip.com']
|
members = [m for m in result['members'] if m['email'] == 'newbie@zulip.com']
|
||||||
assert len(members) == 1
|
assert len(members) == 1
|
||||||
iago = members[0]
|
newbie = members[0]
|
||||||
|
assert not newbie['is_admin']
|
||||||
|
assert newbie['full_name'] == 'New User'
|
||||||
|
|
||||||
assert not iago['is_admin']
|
member_fixture = fixture['members'][0]
|
||||||
assert iago['full_name'] == 'New User'
|
member_result = result['members'][0]
|
||||||
|
test_against_fixture(member_result, member_fixture,
|
||||||
|
check_if_exists=member_fixture.keys())
|
||||||
|
|
||||||
|
# {code_example|start}
|
||||||
|
# You may pass the `client_gravatar` query parameter as follows:
|
||||||
|
result = client.call_endpoint(
|
||||||
|
url='users?client_gravatar=true',
|
||||||
|
method='GET',
|
||||||
|
)
|
||||||
|
# {code_example|end}
|
||||||
|
|
||||||
|
test_against_fixture(result, fixture, check_if_equal=['msg', 'result'],
|
||||||
|
check_if_exists=['members'])
|
||||||
|
assert result['members'][0]['avatar_url'] is None
|
||||||
|
|
||||||
def get_profile(client):
|
def get_profile(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
@ -298,6 +320,7 @@ TEST_FUNCTIONS = {
|
||||||
'get-profile': get_profile,
|
'get-profile': get_profile,
|
||||||
'add-subscriptions': add_subscriptions,
|
'add-subscriptions': add_subscriptions,
|
||||||
'remove-subscriptions': remove_subscriptions,
|
'remove-subscriptions': remove_subscriptions,
|
||||||
|
'get-all-users': get_members,
|
||||||
}
|
}
|
||||||
|
|
||||||
# SETUP METHODS FOLLOW
|
# SETUP METHODS FOLLOW
|
||||||
|
|
Loading…
Reference in New Issue