mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
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:
@@ -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:
|
||||
|
||||
@@ -147,5 +147,9 @@
|
||||
"stream_id":6
|
||||
}
|
||||
]
|
||||
},
|
||||
"create-user": {
|
||||
"msg":"",
|
||||
"result":"success"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user