mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +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">
|
<div data-language="python" markdown="1">
|
||||||
|
|
||||||
```python
|
{generate_code_example|create-user|method(admin_config=True)}
|
||||||
#!/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'
|
|
||||||
}))
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -87,12 +72,8 @@ zulip(config).then((client) => {
|
|||||||
|
|
||||||
A typical successful JSON response may look like:
|
A typical successful JSON response may look like:
|
||||||
|
|
||||||
```
|
{generate_code_example|create-user|fixture}
|
||||||
{
|
|
||||||
'result':'success',
|
|
||||||
'msg':''
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
A typical JSON response for when another user with the same
|
A typical JSON response for when another user with the same
|
||||||
email address already exists in the realm:
|
email address already exists in the realm:
|
||||||
|
|||||||
@@ -147,5 +147,9 @@
|
|||||||
"stream_id":6
|
"stream_id":6
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"create-user": {
|
||||||
|
"msg":"",
|
||||||
|
"result":"success"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,14 +31,19 @@ def add_subscriptions(client):
|
|||||||
def create_user(client):
|
def create_user(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
|
||||||
request = dict(
|
# {code_example|start}
|
||||||
email='newbie@zulip.com',
|
# Create a user
|
||||||
full_name='New User',
|
request = {
|
||||||
short_name='Newbie',
|
'email': 'newbie@zulip.com',
|
||||||
password='temp',
|
'password': 'temp',
|
||||||
)
|
'full_name': 'New User',
|
||||||
|
'short_name': 'newbie'
|
||||||
|
}
|
||||||
result = client.create_user(request)
|
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):
|
def get_members(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
@@ -239,6 +244,7 @@ TEST_FUNCTIONS = {
|
|||||||
'get-stream-id': get_stream_id,
|
'get-stream-id': get_stream_id,
|
||||||
'get-subscribed-streams': list_subscriptions,
|
'get-subscribed-streams': list_subscriptions,
|
||||||
'get-all-streams': get_streams,
|
'get-all-streams': get_streams,
|
||||||
|
'create-user': create_user,
|
||||||
}
|
}
|
||||||
|
|
||||||
# SETUP METHODS FOLLOW
|
# SETUP METHODS FOLLOW
|
||||||
|
|||||||
Reference in New Issue
Block a user