mirror of https://github.com/zulip/zulip.git
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:
parent
806476173f
commit
be0a04f33e
|
@ -110,28 +110,9 @@ the streams specified:
|
||||||
A typical response for when the requesting user does not have access to
|
A typical response for when the requesting user does not have access to
|
||||||
a private stream and `authorization_errors_fatal` is `True`:
|
a private stream and `authorization_errors_fatal` is `True`:
|
||||||
|
|
||||||
```
|
{generate_code_example|add-subscriptions|fixture(unauthorized_errors_fatal_true)}
|
||||||
{
|
|
||||||
"msg":"Unable to access stream (yaar).",
|
|
||||||
"result":"error"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
A typical response for when the requesting user does not have access to
|
A typical response for when the requesting user does not have access to
|
||||||
a private stream and `authorization_errors_fatal` is `False`:
|
a private stream and `authorization_errors_fatal` is `False`:
|
||||||
|
|
||||||
```
|
{generate_code_example|add-subscriptions|fixture(unauthorized_errors_fatal_false)}
|
||||||
{
|
|
||||||
"unauthorized":[
|
|
||||||
"yaar"
|
|
||||||
],
|
|
||||||
"subscribed":{
|
|
||||||
|
|
||||||
},
|
|
||||||
"msg":"",
|
|
||||||
"result":"success",
|
|
||||||
"already_subscribed":{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
|
@ -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": {
|
"remove-subscriptions": {
|
||||||
"msg":"",
|
"msg":"",
|
||||||
|
|
|
@ -16,7 +16,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, \
|
||||||
test_update_message_edit_permission_error, \
|
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'
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
|
||||||
django.setup()
|
django.setup()
|
||||||
|
@ -50,6 +50,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_user_not_authorized_error(nonadmin_client)
|
||||||
|
test_authorization_errors_fatal(client, nonadmin_client)
|
||||||
|
|
||||||
# Test error payloads
|
# Test error payloads
|
||||||
client = Client(
|
client = Client(
|
||||||
|
|
|
@ -59,6 +59,41 @@ def test_add_subscriptions_already_subscribed(client):
|
||||||
fixture = FIXTURES['add-subscriptions']['already_subscribed']
|
fixture = FIXTURES['add-subscriptions']['already_subscribed']
|
||||||
test_against_fixture(result, fixture)
|
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):
|
def create_user(client):
|
||||||
# type: (Client) -> None
|
# type: (Client) -> None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue