mirror of https://github.com/zulip/zulip.git
api/update-message: Make code examples and 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 tools/lib/api_tests.
This commit is contained in:
parent
cf80587f47
commit
b1878f14a2
|
@ -13,5 +13,9 @@
|
|||
"msg":"",
|
||||
"id":134,
|
||||
"result":"success"
|
||||
},
|
||||
"update-message": {
|
||||
"msg":"",
|
||||
"result":"success"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,21 +27,7 @@ curl -X "PATCH" {{ api_url }}/v1/messages/<msg_id> \
|
|||
|
||||
<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")
|
||||
|
||||
# Edit a message
|
||||
print(client.update_message({
|
||||
"message_id": 131,
|
||||
"content": "New content"
|
||||
}))
|
||||
|
||||
```
|
||||
{generate_code_example|update-message|method}
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -89,12 +75,7 @@ You only have permission to edit a message if:
|
|||
|
||||
A typical successful JSON response may look like:
|
||||
|
||||
```
|
||||
{
|
||||
'msg':'',
|
||||
'result':'success'
|
||||
}
|
||||
```
|
||||
{generate_code_example|update-message|fixture}
|
||||
|
||||
A typical JSON response for when one doesn't have the permission to
|
||||
edit a particular message:
|
||||
|
|
|
@ -182,12 +182,20 @@ def update_message(client, message_id):
|
|||
# type: (Client, int) -> None
|
||||
|
||||
assert int(message_id)
|
||||
request = dict(
|
||||
message_id=message_id,
|
||||
content='new content',
|
||||
)
|
||||
|
||||
# {code_example|start}
|
||||
# Edit a message
|
||||
# (make sure that message_id below is set to the ID of the
|
||||
# message you wish to update)
|
||||
request = {
|
||||
"message_id": message_id,
|
||||
"content": "New content"
|
||||
}
|
||||
result = client.update_message(request)
|
||||
assert result['result'] == 'success'
|
||||
# {code_example|end}
|
||||
|
||||
fixture = FIXTURES['update-message']
|
||||
test_against_fixture(result, fixture)
|
||||
|
||||
# test it was actually updated
|
||||
url = 'messages/' + str(message_id)
|
||||
|
@ -196,12 +204,13 @@ def update_message(client, message_id):
|
|||
method='GET'
|
||||
)
|
||||
assert result['result'] == 'success'
|
||||
assert result['raw_content'] == 'new content'
|
||||
assert result['raw_content'] == request['content']
|
||||
|
||||
TEST_FUNCTIONS = {
|
||||
'render-message': render_message,
|
||||
'stream-message': stream_message,
|
||||
'private-message': private_message,
|
||||
'update-message': update_message,
|
||||
}
|
||||
|
||||
# SETUP METHODS FOLLOW
|
||||
|
|
Loading…
Reference in New Issue