From 7ac378294c1785f8746f2c064e07638837ad9bb1 Mon Sep 17 00:00:00 2001 From: SATOH Fumiyasu Date: Thu, 9 May 2024 05:56:56 +0900 Subject: [PATCH] test: doctest: rest/docs/domains.rst: Sort owners by user_id MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The Mailman REST API at `/3.0/domains//owners` does NOT ensure order of owner entries in a response. Thus the doctest in `src/mailman/rest/docs/domains.rst` sometimes fails. Failed CI jobs for example: * [pgsql-39 (#6523349845) · Jobs · GNU Mailman / Mailman Core · GitLab](https://gitlab.com/mailman/mailman/-/jobs/6523349845) * [pgsql-310 (#6493325803) · Jobs · GNU Mailman / Mailman Core · GitLab](https://gitlab.com/mailman/mailman/-/jobs/6493325803) * [pgsql-311 (#6075425574) · Jobs · GNU Mailman / Mailman Core · GitLab](https://gitlab.com/mailman/mailman/-/jobs/6075425574) Closes #1150 --- src/mailman/rest/docs/domains.rst | 6 ++++-- src/mailman/testing/documentation.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/mailman/rest/docs/domains.rst b/src/mailman/rest/docs/domains.rst index b0fe8920d..936de6e72 100644 --- a/src/mailman/rest/docs/domains.rst +++ b/src/mailman/rest/docs/domains.rst @@ -279,7 +279,8 @@ Anne and Bart volunteer to be a domain owners. server: ... status: 204 - >>> dump_json('http://localhost:9001/3.0/domains/my.example.com/owners') + >>> dump_json('http://localhost:9001/3.0/domains/my.example.com/owners', + ... sort_entries='user_id') entry 0: created_on: 2005-08-01T07:49:23 http_etag: ... @@ -327,7 +328,8 @@ New domains can be created with owners. The new domain has the expected owners. - >>> dump_json('http://localhost:9001/3.0/domains/your.example.com/owners') + >>> dump_json('http://localhost:9001/3.0/domains/your.example.com/owners', + ... sort_entries='user_id') entry 0: created_on: 2005-08-01T07:49:23 http_etag: ... diff --git a/src/mailman/testing/documentation.py b/src/mailman/testing/documentation.py index 3aff3988e..a69c8cb90 100644 --- a/src/mailman/testing/documentation.py +++ b/src/mailman/testing/documentation.py @@ -124,7 +124,8 @@ def _print_dict(data, depth=0): print(' ' * depth + '{}: {}'.format(item, value)) -def dump_json(url, data=None, method=None, username=None, password=None): +def dump_json(url, data=None, method=None, username=None, password=None, + sort_entries=None): """Print the JSON dictionary read from a URL. :param url: The url to open, read, and print. @@ -138,7 +139,9 @@ def dump_json(url, data=None, method=None, username=None, password=None): :type username: str :param password: The HTTP Basic Auth password. None means use the value from the configuration. - :type username: str + :type password: str + :param sort_entries: The key to sort entiries. + :type sort_entries: str """ results = call_http(url, data, method, username, password) if results is None: @@ -146,7 +149,10 @@ def dump_json(url, data=None, method=None, username=None, password=None): for key in sorted(results): value = results[key] if key == 'entries': - for i, entry in enumerate(value): + entries = value + if sort_entries: + entries = sorted(entries, key=lambda x: x[sort_entries]) + for i, entry in enumerate(entries): # entry is a dictionary. print('entry %d:' % i) for entry_key in sorted(entry): -- 2.11.4.GIT