mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
python_examples: Specify which user the hard-coded user ids refer to.
We add an ensure_users function and use it in tests which have hard-coded user ids, to make it clear to which users the ids refer to and have it verified. This makes it easier to see what's happening in these tests and to keep track of any renumberings of user ids due to changes in how we populate the database.
This commit is contained in:
committed by
Tim Abbott
parent
e058558a52
commit
8e1a7cfb52
@@ -1,4 +1,4 @@
|
||||
from typing import Dict, Any, Optional, Iterable, Callable, Set
|
||||
from typing import Dict, Any, Optional, Iterable, Callable, Set, List
|
||||
|
||||
import json
|
||||
import os
|
||||
@@ -8,6 +8,8 @@ from functools import wraps
|
||||
from zerver.lib import mdiff
|
||||
from zerver.lib.openapi import validate_against_openapi_schema
|
||||
|
||||
from zerver.models import get_realm, get_user
|
||||
|
||||
from zulip import Client
|
||||
|
||||
ZULIP_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
@@ -36,6 +38,14 @@ def openapi_test_function(endpoint: str) -> Callable[[Callable[..., Any]], Calla
|
||||
return _record_calls_wrapper
|
||||
return wrapper
|
||||
|
||||
def ensure_users(ids_list: List[int], user_names: List[str]) -> None:
|
||||
# Ensure that the list of user ids (ids_list)
|
||||
# matches the users we want to refer to (user_names).
|
||||
realm = get_realm("zulip")
|
||||
user_ids = [get_user(name + '@zulip.com', realm).id for name in user_names]
|
||||
|
||||
assert ids_list == user_ids
|
||||
|
||||
def load_api_fixtures():
|
||||
# type: () -> Dict[str, Any]
|
||||
with open(FIXTURE_PATH, 'r') as fp:
|
||||
@@ -949,6 +959,8 @@ def remove_alert_words(client):
|
||||
@openapi_test_function("/user_groups/create:post")
|
||||
def create_user_group(client):
|
||||
# type: (Client) -> None
|
||||
ensure_users([1, 2, 3, 4], ['aaron', 'zoe', 'cordelia', 'hamlet'])
|
||||
|
||||
# {code_example|start}
|
||||
request = {
|
||||
'name': 'marketing',
|
||||
@@ -989,6 +1001,8 @@ def remove_user_group(client, group_id):
|
||||
@openapi_test_function("/user_groups/{group_id}/members:post")
|
||||
def update_user_group_members(client, group_id):
|
||||
# type: (Client, int) -> None
|
||||
ensure_users([3, 4, 5], ['cordelia', 'hamlet', 'iago'])
|
||||
|
||||
request = {
|
||||
'group_id': group_id,
|
||||
'delete': [3, 4],
|
||||
|
||||
Reference in New Issue
Block a user