api docs: Test sample fixture for user not authorized error.

This commit adds tests for the fixture for when a user is not
authorized (perhaps because the query requires the use of admin
privileges) for a particular query.
This commit is contained in:
Eeshan Garg 2018-02-16 17:28:03 -03:30 committed by Tim Abbott
parent 124c672a7c
commit 06bf47d2f5
5 changed files with 24 additions and 9 deletions

View File

@ -12,3 +12,10 @@ A typical failed JSON response for when a required request argument
is not supplied: is not supplied:
{generate_code_example|missing-request-argument-error|fixture} {generate_code_example|missing-request-argument-error|fixture}
## User not authorized for query
A typical failed JSON response for when the user is not authorized
for a query:
{generate_code_example|user-not-authorized-error|fixture}

View File

@ -259,5 +259,10 @@
"code":"BAD_REQUEST", "code":"BAD_REQUEST",
"msg":"You don't have permission to edit this message", "msg":"You don't have permission to edit this message",
"result":"error" "result":"error"
},
"user-not-authorized-error": {
"code":"BAD_REQUEST",
"msg":"User not authorized for this query",
"result":"error"
} }
} }

View File

@ -82,10 +82,4 @@ A typical successful JSON response may look like:
An example of a JSON response for when the user is not authorized An example of a JSON response for when the user is not authorized
to use the `include_all_active` parameter: to use the `include_all_active` parameter:
``` {generate_code_example|user-not-authorized-error|fixture}
{
'code':'BAD_REQUEST',
'result':'error',
'msg':'User not authorized for this query'
}
```

View File

@ -14,8 +14,9 @@ os.chdir(ZULIP_PATH)
from zulip import Client 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 test_update_message_edit_permission_error, \
test_user_not_authorized_error
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
django.setup() django.setup()
@ -48,6 +49,7 @@ with test_server_running(external_host='zulipdev.com:9981'):
# Run tests that require non-admin client # Run tests that require non-admin client
test_update_message_edit_permission_error(client, nonadmin_client) test_update_message_edit_permission_error(client, nonadmin_client)
test_user_not_authorized_error(nonadmin_client)
# Test error payloads # Test error payloads
client = Client( client = Client(

View File

@ -152,6 +152,13 @@ def get_streams(client):
check_if_exists=['streams']) check_if_exists=['streams'])
assert len(result['streams']) == 4 assert len(result['streams']) == 4
def test_user_not_authorized_error(nonadmin_client):
# type: (Client) -> None
result = nonadmin_client.get_streams(include_all_active=True)
fixture = FIXTURES['user-not-authorized-error']
test_against_fixture(result, fixture)
def get_subscribers(client): def get_subscribers(client):
# type: (Client) -> None # type: (Client) -> None