From 7889dee0e582a1e7b57bd27a2716abdaded593e4 Mon Sep 17 00:00:00 2001 From: Alexander Piskun <13381981+bigcat88@users.noreply.github.com> Date: Sun, 17 Dec 2023 17:46:43 +0300 Subject: [PATCH] removed `requests` package (#185) Changes proposed in this pull request: * I forgot why there was a dependency on "requests" package, so removed it, as we use "httpx" package. --------- Signed-off-by: Alexander Piskun --- CHANGELOG.md | 2 +- README.md | 2 +- docs/NextcloudTalkBot.rst | 2 +- examples/as_app/talk_bot/lib/main.py | 8 ++++---- pyproject.toml | 1 - tests/_app_security_checks.py | 20 ++++++++++---------- tests/_talk_bot.py | 7 +++---- tests/_talk_bot_async.py | 7 +++---- 8 files changed, 23 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61a44127..b19ccfab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -## [0.7.0 - 2022-12-2x] +## [0.7.0 - 2022-12-17] ### Added diff --git a/README.md b/README.md index e6dfa1b0..cfc2763e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Python library that provides a robust and well-documented API that allows develo * **Reliable**: Minimum number of incompatible changes. * **Robust**: All code is covered with tests as much as possible. * **Easy**: Designed to be easy to use with excellent documentation. - * **Sync+Async**: Provides both sync and async APIs. + * **Sync + Async**: Provides both sync and async APIs. ### Capabilities | **_Capability_** | Nextcloud 26 | Nextcloud 27 | Nextcloud 28 | diff --git a/docs/NextcloudTalkBot.rst b/docs/NextcloudTalkBot.rst index 87925401..48214817 100644 --- a/docs/NextcloudTalkBot.rst +++ b/docs/NextcloudTalkBot.rst @@ -43,7 +43,7 @@ Afterward, using FastAPI, you can define endpoints that will be invoked by Talk: message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)], background_tasks: BackgroundTasks, ): - return requests.Response() + return Response() .. note:: You must include to each endpoint your bot provides the **Depends(talk_bot_app)**. diff --git a/examples/as_app/talk_bot/lib/main.py b/examples/as_app/talk_bot/lib/main.py index bbafa72c..769bccbe 100644 --- a/examples/as_app/talk_bot/lib/main.py +++ b/examples/as_app/talk_bot/lib/main.py @@ -4,8 +4,8 @@ from contextlib import asynccontextmanager from typing import Annotated -import requests -from fastapi import BackgroundTasks, Depends, FastAPI +import httpx +from fastapi import BackgroundTasks, Depends, FastAPI, Response from nc_py_api import NextcloudApp, talk_bot from nc_py_api.ex_app import run_app, set_handlers, talk_bot_app @@ -29,7 +29,7 @@ def convert_currency(amount, from_currency, to_currency): base_url = "https://api.exchangerate-api.com/v4/latest/" # Fetch latest exchange rates - response = requests.get(base_url + from_currency, timeout=60) + response = httpx.get(base_url + from_currency, timeout=60) data = response.json() if "rates" in data: @@ -72,7 +72,7 @@ async def currency_talk_bot( # As during converting, we do not process converting locally, we perform this in background, in the background task. background_tasks.add_task(currency_talk_bot_process_request, message) # Return Response immediately for Nextcloud, that we are ok. - return requests.Response() + return Response() def enabled_handler(enabled: bool, nc: NextcloudApp) -> str: diff --git a/pyproject.toml b/pyproject.toml index 252a89df..158d0163 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,6 @@ dependencies = [ "httpx>=0.24.1", "pydantic>=2.1.1", "python-dotenv>=1", - "requests>=2.31", "xmltodict>=0.13", ] [project.optional-dependencies] diff --git a/tests/_app_security_checks.py b/tests/_app_security_checks.py index 6f0a552d..ce497669 100644 --- a/tests/_app_security_checks.py +++ b/tests/_app_security_checks.py @@ -2,7 +2,7 @@ from os import environ from sys import argv -import requests +import httpx def sign_request(req_headers: dict, secret=None, user: str = ""): @@ -14,7 +14,7 @@ def sign_request(req_headers: dict, secret=None, user: str = ""): if __name__ == "__main__": request_url = argv[1] + "/sec_check?value=1" headers = {} - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 401 # Missing headers headers.update({ "AA-VERSION": environ.get("AA_VERSION", "1.0.0"), @@ -22,35 +22,35 @@ def sign_request(req_headers: dict, secret=None, user: str = ""): "EX-APP-VERSION": environ.get("APP_VERSION", "1.0.0"), }) sign_request(headers) - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 200 # Invalid AA-SIGNATURE sign_request(headers, secret="xxx") - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 401 sign_request(headers) - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 200 # Invalid EX-APP-ID old_app_name = headers["EX-APP-ID"] headers["EX-APP-ID"] = "unknown_app" sign_request(headers) - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 401 headers["EX-APP-ID"] = old_app_name sign_request(headers) - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 200 # Invalid EX-APP-VERSION sign_request(headers) - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 200 old_version = headers["EX-APP-VERSION"] headers["EX-APP-VERSION"] = "999.0.0" sign_request(headers) - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 401 headers["EX-APP-VERSION"] = old_version sign_request(headers) - result = requests.put(request_url, headers=headers) + result = httpx.put(request_url, headers=headers) assert result.status_code == 200 diff --git a/tests/_talk_bot.py b/tests/_talk_bot.py index 6d1d0173..5096f2e6 100644 --- a/tests/_talk_bot.py +++ b/tests/_talk_bot.py @@ -3,8 +3,7 @@ import gfixture_set_env # noqa import pytest -import requests -from fastapi import BackgroundTasks, Depends, FastAPI, HTTPException, Request +from fastapi import BackgroundTasks, Depends, FastAPI, HTTPException, Request, Response from starlette.datastructures import URL from nc_py_api import talk_bot @@ -52,14 +51,14 @@ def talk_bot_coverage( background_tasks: BackgroundTasks, ): background_tasks.add_task(coverage_talk_bot_process_request, message, request) - return requests.Response() + return Response() # in real program this is not needed, as bot enabling handler is called in the bots process itself and will reset it. @APP.delete("/reset_bot_secret") def reset_bot_secret(): os.environ.pop(talk_bot.__get_bot_secret("/talk_bot_coverage")) - return requests.Response() + return Response() if __name__ == "__main__": diff --git a/tests/_talk_bot_async.py b/tests/_talk_bot_async.py index 6885c8e4..b4f9c7b5 100644 --- a/tests/_talk_bot_async.py +++ b/tests/_talk_bot_async.py @@ -3,8 +3,7 @@ import gfixture_set_env # noqa import pytest -import requests -from fastapi import BackgroundTasks, Depends, FastAPI, Request +from fastapi import BackgroundTasks, Depends, FastAPI, Request, Response from nc_py_api import talk_bot from nc_py_api.ex_app import atalk_bot_app, run_app @@ -40,14 +39,14 @@ async def talk_bot_coverage( background_tasks: BackgroundTasks, ): background_tasks.add_task(coverage_talk_bot_process_request, message, request) - return requests.Response() + return Response() # in real program this is not needed, as bot enabling handler is called in the bots process itself and will reset it. @APP.delete("/reset_bot_secret") async def reset_bot_secret(): os.environ.pop(talk_bot.__get_bot_secret("/talk_bot_coverage")) - return requests.Response() + return Response() if __name__ == "__main__":