From be0a04f33e4b3dd39ce7174e16f8b7751033ec3a Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Fri, 16 Feb 2018 18:52:45 -0330 Subject: [PATCH] api docs: Test sample fixtures for unauthorized_errors_fatal. This commit adds tests for the sample fixtures for when unauthorized_errors_fatal is passed to client.add_subscriptions. --- templates/zerver/api/add-subscriptions.md | 23 ++------------- templates/zerver/api/fixtures.json | 17 +++++++++++ tools/test-api | 3 +- zerver/lib/api_test_helpers.py | 35 +++++++++++++++++++++++ 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/templates/zerver/api/add-subscriptions.md b/templates/zerver/api/add-subscriptions.md index 4c7a389745..19e5bea193 100644 --- a/templates/zerver/api/add-subscriptions.md +++ b/templates/zerver/api/add-subscriptions.md @@ -110,28 +110,9 @@ the streams specified: A typical response for when the requesting user does not have access to a private stream and `authorization_errors_fatal` is `True`: -``` -{ - "msg":"Unable to access stream (yaar).", - "result":"error" -} -``` +{generate_code_example|add-subscriptions|fixture(unauthorized_errors_fatal_true)} A typical response for when the requesting user does not have access to a private stream and `authorization_errors_fatal` is `False`: -``` -{ - "unauthorized":[ - "yaar" - ], - "subscribed":{ - - }, - "msg":"", - "result":"success", - "already_subscribed":{ - - } -} -``` +{generate_code_example|add-subscriptions|fixture(unauthorized_errors_fatal_false)} diff --git a/templates/zerver/api/fixtures.json b/templates/zerver/api/fixtures.json index 8ea5571e0c..87c9b3b57a 100644 --- a/templates/zerver/api/fixtures.json +++ b/templates/zerver/api/fixtures.json @@ -190,6 +190,23 @@ } }, + "unauthorized_errors_fatal_false": { + "already_subscribed":{ + + }, + "msg":"", + "result":"success", + "subscribed":{ + + }, + "unauthorized":[ + "private_stream" + ] + }, + "unauthorized_errors_fatal_true": { + "msg":"Unable to access stream (private_stream).", + "result":"error" + } }, "remove-subscriptions": { "msg":"", diff --git a/tools/test-api b/tools/test-api index 151cb2ed3f..769400ecd2 100755 --- a/tools/test-api +++ b/tools/test-api @@ -16,7 +16,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, \ test_update_message_edit_permission_error, \ - test_user_not_authorized_error + test_user_not_authorized_error, test_authorization_errors_fatal os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings' django.setup() @@ -50,6 +50,7 @@ with test_server_running(external_host='zulipdev.com:9981'): # Run tests that require non-admin client test_update_message_edit_permission_error(client, nonadmin_client) test_user_not_authorized_error(nonadmin_client) + test_authorization_errors_fatal(client, nonadmin_client) # Test error payloads client = Client( diff --git a/zerver/lib/api_test_helpers.py b/zerver/lib/api_test_helpers.py index 3ca5859213..886a6622af 100644 --- a/zerver/lib/api_test_helpers.py +++ b/zerver/lib/api_test_helpers.py @@ -59,6 +59,41 @@ def test_add_subscriptions_already_subscribed(client): fixture = FIXTURES['add-subscriptions']['already_subscribed'] test_against_fixture(result, fixture) +def test_authorization_errors_fatal(client, nonadmin_client): + # type: (Client, Client) -> None + client.add_subscriptions( + streams=[ + {'name': 'private_stream'} + ], + ) + + stream_id = client.get_stream_id('private_stream')['stream_id'] + client.call_endpoint( + 'streams/{}'.format(stream_id), + method='PATCH', + request={'is_private': True} + ) + + result = nonadmin_client.add_subscriptions( + streams=[ + {'name': 'private_stream'} + ], + authorization_errors_fatal=False, + ) + + fixture = FIXTURES['add-subscriptions']['unauthorized_errors_fatal_false'] + test_against_fixture(result, fixture) + + result = nonadmin_client.add_subscriptions( + streams=[ + {'name': 'private_stream'} + ], + authorization_errors_fatal=True, + ) + + fixture = FIXTURES['add-subscriptions']['unauthorized_errors_fatal_true'] + test_against_fixture(result, fixture) + def create_user(client): # type: (Client) -> None