api/create-user: 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:
Eeshan Garg
2018-01-31 01:06:57 -03:30
committed by showell
parent fe98a59f5c
commit 2bea4b70de
3 changed files with 20 additions and 29 deletions

View File

@@ -31,22 +31,7 @@ curl {{ api_url }}/v1/users \
<div data-language="python" markdown="1">
```python
#!/usr/bin/env python
import zulip
# You need a zuliprc-admin with administrator credentials
client = zulip.Client(config_file="~/zuliprc-admin")
# Create a user
print(client.create_user({
'email': 'newbie@zulip.com',
'password': 'temp',
'full_name': 'New User',
'short_name': 'newbie'
}))
```
{generate_code_example|create-user|method(admin_config=True)}
</div>
@@ -87,12 +72,8 @@ zulip(config).then((client) => {
A typical successful JSON response may look like:
```
{
'result':'success',
'msg':''
}
```
{generate_code_example|create-user|fixture}
A typical JSON response for when another user with the same
email address already exists in the realm:

View File

@@ -147,5 +147,9 @@
"stream_id":6
}
]
},
"create-user": {
"msg":"",
"result":"success"
}
}

View File

@@ -31,14 +31,19 @@ def add_subscriptions(client):
def create_user(client):
# type: (Client) -> None
request = dict(
email='newbie@zulip.com',
full_name='New User',
short_name='Newbie',
password='temp',
)
# {code_example|start}
# Create a user
request = {
'email': 'newbie@zulip.com',
'password': 'temp',
'full_name': 'New User',
'short_name': 'newbie'
}
result = client.create_user(request)
assert result['result'] == 'success'
# {code_example|end}
fixture = FIXTURES['create-user']
test_against_fixture(result, fixture)
def get_members(client):
# type: (Client) -> None
@@ -239,6 +244,7 @@ TEST_FUNCTIONS = {
'get-stream-id': get_stream_id,
'get-subscribed-streams': list_subscriptions,
'get-all-streams': get_streams,
'create-user': create_user,
}
# SETUP METHODS FOLLOW