diff --git a/templates/zerver/api/fixtures.json b/templates/zerver/api/fixtures.json index 5d6fff6a3c..23fde1f94e 100644 --- a/templates/zerver/api/fixtures.json +++ b/templates/zerver/api/fixtures.json @@ -254,5 +254,10 @@ "msg":"Missing 'content' argument", "result":"error", "var_name":"content" + }, + "update-message-edit-permission-error": { + "code":"BAD_REQUEST", + "msg":"You don't have permission to edit this message", + "result":"error" } } diff --git a/templates/zerver/api/update-message.md b/templates/zerver/api/update-message.md index e76a9441ce..788c185598 100644 --- a/templates/zerver/api/update-message.md +++ b/templates/zerver/api/update-message.md @@ -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 edit a particular message: -``` -{ - 'code':'BAD_REQUEST', - 'result':'error', - 'msg':"You don't have permission to edit this message" -} -``` +{generate_code_example|update-message-edit-permission-error|fixture} diff --git a/tools/test-api b/tools/test-api index 4d9408f495..dd7f641a33 100755 --- a/tools/test-api +++ b/tools/test-api @@ -15,6 +15,7 @@ from zulip import Client 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_update_message_edit_permission_error os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings' django.setup() @@ -35,6 +36,19 @@ with test_server_running(external_host='zulipdev.com:9981'): print("Running API tests...") 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 client = Client( email=email, diff --git a/zerver/lib/api_test_helpers.py b/zerver/lib/api_test_helpers.py index 4cc6e0dd6f..7c46b1fe51 100644 --- a/zerver/lib/api_test_helpers.py +++ b/zerver/lib/api_test_helpers.py @@ -331,6 +331,25 @@ def update_message(client, message_id): assert result['result'] == 'success' 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): # type: (Client) -> str