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.
This commit is contained in:
Eeshan Garg 2018-02-16 18:52:45 -03:30 committed by Tim Abbott
parent 806476173f
commit be0a04f33e
4 changed files with 56 additions and 22 deletions

View File

@ -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)}

View File

@ -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":"",

View File

@ -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(

View File

@ -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