Skip to content

Commit d0edb09

Browse files
PIG208timabbott
authored andcommitted
api: Replace function signatures for legacy zulip server.
To make sure that the API bindings is backward compatible with older versions of zulip server that uses functions with different signatures, we use a hack to replace the Client class with a legacy-compatible version of it.
1 parent 05b9850 commit d0edb09

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

zulip/zulip/__init__.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,3 +1733,50 @@ def hash_util_decode(string: str) -> str:
17331733
# Acknowledge custom string replacements in zulip/zulip's zerver/lib/url_encoding.py before unquoting.
17341734
# NOTE: urllib.parse.unquote already does .replace('%2E', '.').
17351735
return urllib.parse.unquote(string.replace(".", "%"))
1736+
1737+
1738+
########################################################################
1739+
# The below hackery is designed to allow running the Zulip's automated
1740+
# tests for its API documentation from old server versions against
1741+
# python-zulip-api. Generally, we expect those tests to be a way to
1742+
# validate that the Python bindings work correctly against old server
1743+
# versions.
1744+
#
1745+
# However, in cases where we've changed the interface of the Python
1746+
# bindings since the release of the relevant server version, such
1747+
# tests will fail, which is an artifact of the fact that the
1748+
# documentation that comes with that old server release is
1749+
# inconsistent with this library.
1750+
#
1751+
# The following logic is designed to work around that problem so that
1752+
# we can verify that you can use the latest version of the Python
1753+
# bindings with any server version (even if you have to read the
1754+
# current API documentation).
1755+
LEGACY_CLIENT_INTERFACE_FROM_SERVER_DOCS_VERSION = os.environ.get(
1756+
"LEGACY_CLIENT_INTERFACE_FROM_SERVER_DOCS_VERSION"
1757+
)
1758+
1759+
if LEGACY_CLIENT_INTERFACE_FROM_SERVER_DOCS_VERSION == "3":
1760+
# This block is support for testing Zulip 3.x, which documents old
1761+
# interfaces for the following functions:
1762+
class LegacyInterfaceClient(Client):
1763+
def update_user_group_members(self, group_data: Dict[str, Any]) -> Dict[str, Any]: # type: ignore # Intentional override; see comments above.
1764+
modern_group_data = group_data.copy()
1765+
group_id = group_data["group_id"]
1766+
del modern_group_data["group_id"]
1767+
return super().update_user_group_members(group_id, modern_group_data)
1768+
1769+
def get_realm_filters(self) -> Dict[str, Any]:
1770+
"""
1771+
Example usage:
1772+
1773+
>>> client.get_realm_filters()
1774+
{'result': 'success', 'msg': '', 'filters': [['#(?P<id>[0-9]+)', 'https://github.com/zulip/zulip/issues/%(id)s', 1]]}
1775+
"""
1776+
# This interface was removed in 4d482e0ef30297f716885fd8246f4638a856ba3b
1777+
return self.call_endpoint(
1778+
url="realm/filters",
1779+
method="GET",
1780+
)
1781+
1782+
Client = LegacyInterfaceClient # type: ignore # Intentional override; see comments above.

0 commit comments

Comments
 (0)