From ac5c355a6092a2df3f937ab9793f5af9f965fc84 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Wed, 7 Feb 2018 23:24:20 -0330 Subject: [PATCH] api/delete-queue: Make fixtures/examples testable. api/delete-queue now uses the Markdown extension in bugdown/api_code_examples to generate code examples and fixtures from tests. --- templates/zerver/api/delete-queue.md | 19 ++----------------- templates/zerver/api/fixtures.json | 4 ++++ zerver/lib/api_test_helpers.py | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/templates/zerver/api/delete-queue.md b/templates/zerver/api/delete-queue.md index 54eab7ce1f..f91feb4a31 100644 --- a/templates/zerver/api/delete-queue.md +++ b/templates/zerver/api/delete-queue.md @@ -25,17 +25,7 @@ curl -X "DELETE" {{ api_url }}/v1/events \
-```python -#!/usr/bin/env python - -import zulip - -# Download ~/zuliprc-dev from your dev server -client = zulip.Client(config_file="~/zuliprc-dev") - -# Delete a queue -print(client.deregister(queue_id="1515096410:1")) -``` +{generate_code_example|delete-queue|example}
@@ -80,12 +70,7 @@ zulip(config).then((client) => { A typical successful JSON response may look like: -``` -{ - 'msg':'', - 'result':'success' -} -``` +{generate_code_example|delete-queue|fixture} A typical JSON response for when the `queue_id` is non-existent or the associated queue has already been deleted: diff --git a/templates/zerver/api/fixtures.json b/templates/zerver/api/fixtures.json index 72803547c2..e4bf42bcd9 100644 --- a/templates/zerver/api/fixtures.json +++ b/templates/zerver/api/fixtures.json @@ -234,5 +234,9 @@ "msg":"", "queue_id":"1517975029:0", "result":"success" + }, + "delete-queue": { + "msg":"", + "result":"success" } } diff --git a/zerver/lib/api_test_helpers.py b/zerver/lib/api_test_helpers.py index e71ecf6222..e60195e9d2 100644 --- a/zerver/lib/api_test_helpers.py +++ b/zerver/lib/api_test_helpers.py @@ -327,6 +327,18 @@ def register_queue(client): return result['queue_id'] +def deregister_queue(client, queue_id): + # type: (Client, str) -> None + + # {code_example|start} + # Delete a queue (queue_id is the ID of the queue + # to be removed) + result = client.deregister(queue_id) + # {code_example|end} + + fixture = FIXTURES['delete-queue'] + test_against_fixture(result, fixture) + def test_invalid_api_key(client_with_invalid_key): # type: (Client) -> None result = client_with_invalid_key.list_subscriptions() @@ -348,6 +360,7 @@ TEST_FUNCTIONS = { 'remove-subscriptions': remove_subscriptions, 'get-all-users': get_members, 'register-queue': register_queue, + 'delete-queue': deregister_queue, } # SETUP METHODS FOLLOW @@ -396,7 +409,8 @@ def test_streams(client): def test_queues(client): # type: (Client) -> None - register_queue(client) + queue_id = register_queue(client) + deregister_queue(client, queue_id) def test_the_api(client): # type: (Client) -> None