mirror of https://github.com/zulip/zulip.git
api docs: Test sample fixture for message edit permission error.
In templates/zerver/api/update-message.md, we have a sample fixture for when a zulip.Client does not have the permission to update/edit a particular message. This commit adds a test for that fixture. Also, tools/test-api now also uses a non-admin client for this test, which might come in handy in the future.
This commit is contained in:
parent
1c32163bb9
commit
124c672a7c
|
@ -254,5 +254,10 @@
|
||||||
"msg":"Missing 'content' argument",
|
"msg":"Missing 'content' argument",
|
||||||
"result":"error",
|
"result":"error",
|
||||||
"var_name":"content"
|
"var_name":"content"
|
||||||
|
},
|
||||||
|
"update-message-edit-permission-error": {
|
||||||
|
"code":"BAD_REQUEST",
|
||||||
|
"msg":"You don't have permission to edit this message",
|
||||||
|
"result":"error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,10 +80,4 @@ A typical successful JSON response may look like:
|
||||||
A typical JSON response for when one doesn't have the permission to
|
A typical JSON response for when one doesn't have the permission to
|
||||||
edit a particular message:
|
edit a particular message:
|
||||||
|
|
||||||
```
|
{generate_code_example|update-message-edit-permission-error|fixture}
|
||||||
{
|
|
||||||
'code':'BAD_REQUEST',
|
|
||||||
'result':'error',
|
|
||||||
'msg':"You don't have permission to edit this message"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ from zulip import Client
|
||||||
|
|
||||||
from tools.lib.test_server import test_server_running
|
from tools.lib.test_server import test_server_running
|
||||||
from zerver.lib.api_test_helpers import test_the_api, test_invalid_api_key
|
from zerver.lib.api_test_helpers import test_the_api, test_invalid_api_key
|
||||||
|
from zerver.lib.api_test_helpers import test_update_message_edit_permission_error
|
||||||
|
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
|
||||||
django.setup()
|
django.setup()
|
||||||
|
@ -35,6 +36,19 @@ with test_server_running(external_host='zulipdev.com:9981'):
|
||||||
print("Running API tests...")
|
print("Running API tests...")
|
||||||
test_the_api(client)
|
test_the_api(client)
|
||||||
|
|
||||||
|
email = 'newbie@zulip.com' # newbie is not an admin
|
||||||
|
realm = get_realm("zulip")
|
||||||
|
api_key = get_user(email, realm).api_key
|
||||||
|
site = 'http://zulip.zulipdev.com:9981'
|
||||||
|
nonadmin_client = Client(
|
||||||
|
email=email,
|
||||||
|
api_key=api_key,
|
||||||
|
site=site
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run tests that require non-admin client
|
||||||
|
test_update_message_edit_permission_error(client, nonadmin_client)
|
||||||
|
|
||||||
# Test error payloads
|
# Test error payloads
|
||||||
client = Client(
|
client = Client(
|
||||||
email=email,
|
email=email,
|
||||||
|
|
|
@ -331,6 +331,25 @@ def update_message(client, message_id):
|
||||||
assert result['result'] == 'success'
|
assert result['result'] == 'success'
|
||||||
assert result['raw_content'] == request['content']
|
assert result['raw_content'] == request['content']
|
||||||
|
|
||||||
|
def test_update_message_edit_permission_error(client, nonadmin_client):
|
||||||
|
# type: (Client, Client) -> None
|
||||||
|
request = {
|
||||||
|
"type": "stream",
|
||||||
|
"to": "Denmark",
|
||||||
|
"subject": "Castle",
|
||||||
|
"content": "Something is rotten in the state of Denmark."
|
||||||
|
}
|
||||||
|
result = client.send_message(request)
|
||||||
|
|
||||||
|
request = {
|
||||||
|
"message_id": result["id"],
|
||||||
|
"content": "New content"
|
||||||
|
}
|
||||||
|
result = nonadmin_client.update_message(request)
|
||||||
|
|
||||||
|
fixture = FIXTURES['update-message-edit-permission-error']
|
||||||
|
test_against_fixture(result, fixture)
|
||||||
|
|
||||||
def register_queue(client):
|
def register_queue(client):
|
||||||
# type: (Client) -> str
|
# type: (Client) -> str
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue