Skip to content

Commit 4d4d302

Browse files
committed
ENH: implementation of the 'help' API
1 parent 7a484dc commit 4d4d302

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

src/save_and_restore_api/_api_async.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ async def search(self, allRequestParams):
6363
method, url, url_params = self._prepare_search(allRequestParams=allRequestParams)
6464
return await self.send_request(method, url, url_params=url_params)
6565

66+
# =============================================================================================
67+
# HELP-RESOURCE API METHODS
68+
# =============================================================================================
69+
70+
async def help(self, what, *, lang=None):
71+
# Reusing docstrings from the threaded version
72+
method, url, url_params = self._prepare_help(what=what, lang=lang)
73+
return await self.send_request(method, url, url_params=url_params)
74+
6675
# =============================================================================================
6776
# AUTHENTICATION-CONTROLLER API METHODS
6877
# =============================================================================================

src/save_and_restore_api/_api_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ def _prepare_search(self, *, allRequestParams):
185185
url_params = allRequestParams
186186
return method, url, url_params
187187

188+
# =============================================================================================
189+
# HELP-RESOURCE API METHODS
190+
# =============================================================================================
191+
192+
def _prepare_help(self, *, what, lang):
193+
method, url = "GET", f"/help/{what}"
194+
url_params = {"lang": lang} if lang else None
195+
return method, url, url_params
196+
188197
# =============================================================================================
189198
# AUTHENTICATION-CONTROLLER API METHODS
190199
# =============================================================================================

src/save_and_restore_api/_api_threads.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ def search(self, allRequestParams):
7979
method, url, url_params = self._prepare_search(allRequestParams=allRequestParams)
8080
return self.send_request(method, url, url_params=url_params)
8181

82+
# =============================================================================================
83+
# HELP-RESOURCE API METHODS
84+
# =============================================================================================
85+
86+
def help(self, what, *, lang=None):
87+
"""
88+
Download help pages, e.g. /help/SearchHelp
89+
90+
API: GET /help/{what}?lang={lang}
91+
"""
92+
method, url, url_params = self._prepare_help(what=what, lang=lang)
93+
return self.send_request(method, url, url_params=url_params)
94+
8295
# =============================================================================================
8396
# AUTHENTICATION-CONTROLLER API METHODS
8497
# =============================================================================================

tests/test_misc.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,32 @@ async def testing():
191191

192192
asyncio.run(testing())
193193

194+
# =============================================================================================
195+
# HELP-RESOURCE API METHODS
196+
# =============================================================================================
197+
198+
# fmt: off
199+
@pytest.mark.parametrize("library", ["THREADS", "ASYNC"])
200+
# fmt: on
201+
def test_help_01(library):
202+
"""
203+
Tests for the 'help' API.
204+
"""
205+
if not _is_async(library):
206+
with SaveRestoreAPI_Threads(base_url=base_url, timeout=2) as SR:
207+
response = SR.help(what="SearchHelp")
208+
isinstance(response, str)
209+
assert "Save-and-restore Search Help Reference" in response
210+
211+
else:
212+
async def testing():
213+
async with SaveRestoreAPI_Async(base_url=base_url, timeout=2) as SR:
214+
response = await SR.help(what="SearchHelp")
215+
isinstance(response, str)
216+
assert "Save-and-restore Search Help Reference" in response
217+
218+
asyncio.run(testing())
219+
194220

195221
# =============================================================================================
196222
# TESTS FOR AUTHENTICATION-CONTROLLER API METHODS

0 commit comments

Comments
 (0)