From 2bea4b70de90acd24e4d4a0ae22118cadf5ef4b5 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Wed, 31 Jan 2018 01:06:57 -0330 Subject: [PATCH] api/create-user: Make code examples/fixtures testable. This commit uses the Markdown extension defined in zerver/lib/bugdown/api_generate_examples to generate the example fixture and code example, so that both are tested in zerver/lib/api_test_helpers. --- templates/zerver/api/create-user.md | 25 +++---------------------- templates/zerver/api/fixtures.json | 4 ++++ zerver/lib/api_test_helpers.py | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/templates/zerver/api/create-user.md b/templates/zerver/api/create-user.md index 1beeee060bd50..39d95443173d3 100644 --- a/templates/zerver/api/create-user.md +++ b/templates/zerver/api/create-user.md @@ -31,22 +31,7 @@ curl {{ api_url }}/v1/users \
-```python -#!/usr/bin/env python - -import zulip - -# You need a zuliprc-admin with administrator credentials -client = zulip.Client(config_file="~/zuliprc-admin") - -# Create a user -print(client.create_user({ - 'email': 'newbie@zulip.com', - 'password': 'temp', - 'full_name': 'New User', - 'short_name': 'newbie' -})) -``` +{generate_code_example|create-user|method(admin_config=True)}
@@ -87,12 +72,8 @@ zulip(config).then((client) => { A typical successful JSON response may look like: -``` -{ - 'result':'success', - 'msg':'' -} -``` +{generate_code_example|create-user|fixture} + A typical JSON response for when another user with the same email address already exists in the realm: diff --git a/templates/zerver/api/fixtures.json b/templates/zerver/api/fixtures.json index dce28592f7276..38ac68af8c855 100644 --- a/templates/zerver/api/fixtures.json +++ b/templates/zerver/api/fixtures.json @@ -147,5 +147,9 @@ "stream_id":6 } ] + }, + "create-user": { + "msg":"", + "result":"success" } } diff --git a/zerver/lib/api_test_helpers.py b/zerver/lib/api_test_helpers.py index 8be6127f95692..3108b7ee652d6 100644 --- a/zerver/lib/api_test_helpers.py +++ b/zerver/lib/api_test_helpers.py @@ -31,14 +31,19 @@ def add_subscriptions(client): def create_user(client): # type: (Client) -> None - request = dict( - email='newbie@zulip.com', - full_name='New User', - short_name='Newbie', - password='temp', - ) + # {code_example|start} + # Create a user + request = { + 'email': 'newbie@zulip.com', + 'password': 'temp', + 'full_name': 'New User', + 'short_name': 'newbie' + } result = client.create_user(request) - assert result['result'] == 'success' + # {code_example|end} + + fixture = FIXTURES['create-user'] + test_against_fixture(result, fixture) def get_members(client): # type: (Client) -> None @@ -239,6 +244,7 @@ def update_message(client, message_id): 'get-stream-id': get_stream_id, 'get-subscribed-streams': list_subscriptions, 'get-all-streams': get_streams, + 'create-user': create_user, } # SETUP METHODS FOLLOW