Skip to content

Commit 7889dee

Browse files
authored
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 <bigcat88@icloud.com>
1 parent 4d27356 commit 7889dee

File tree

8 files changed

+23
-26
lines changed

8 files changed

+23
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [0.7.0 - 2022-12-2x]
5+
## [0.7.0 - 2022-12-17]
66

77
### Added
88

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Python library that provides a robust and well-documented API that allows develo
2121
* **Reliable**: Minimum number of incompatible changes.
2222
* **Robust**: All code is covered with tests as much as possible.
2323
* **Easy**: Designed to be easy to use with excellent documentation.
24-
* **Sync+Async**: Provides both sync and async APIs.
24+
* **Sync + Async**: Provides both sync and async APIs.
2525

2626
### Capabilities
2727
| **_Capability_** | Nextcloud 26 | Nextcloud 27 | Nextcloud 28 |

docs/NextcloudTalkBot.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Afterward, using FastAPI, you can define endpoints that will be invoked by Talk:
4343
message: Annotated[talk_bot.TalkBotMessage, Depends(talk_bot_app)],
4444
background_tasks: BackgroundTasks,
4545
):
46-
return requests.Response()
46+
return Response()
4747
4848
.. note::
4949
You must include to each endpoint your bot provides the **Depends(talk_bot_app)**.

examples/as_app/talk_bot/lib/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from contextlib import asynccontextmanager
55
from typing import Annotated
66

7-
import requests
8-
from fastapi import BackgroundTasks, Depends, FastAPI
7+
import httpx
8+
from fastapi import BackgroundTasks, Depends, FastAPI, Response
99

1010
from nc_py_api import NextcloudApp, talk_bot
1111
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):
2929
base_url = "https://api.exchangerate-api.com/v4/latest/"
3030

3131
# Fetch latest exchange rates
32-
response = requests.get(base_url + from_currency, timeout=60)
32+
response = httpx.get(base_url + from_currency, timeout=60)
3333
data = response.json()
3434

3535
if "rates" in data:
@@ -72,7 +72,7 @@ async def currency_talk_bot(
7272
# As during converting, we do not process converting locally, we perform this in background, in the background task.
7373
background_tasks.add_task(currency_talk_bot_process_request, message)
7474
# Return Response immediately for Nextcloud, that we are ok.
75-
return requests.Response()
75+
return Response()
7676

7777

7878
def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ dependencies = [
4848
"httpx>=0.24.1",
4949
"pydantic>=2.1.1",
5050
"python-dotenv>=1",
51-
"requests>=2.31",
5251
"xmltodict>=0.13",
5352
]
5453
[project.optional-dependencies]

tests/_app_security_checks.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from os import environ
33
from sys import argv
44

5-
import requests
5+
import httpx
66

77

88
def sign_request(req_headers: dict, secret=None, user: str = ""):
@@ -14,43 +14,43 @@ def sign_request(req_headers: dict, secret=None, user: str = ""):
1414
if __name__ == "__main__":
1515
request_url = argv[1] + "/sec_check?value=1"
1616
headers = {}
17-
result = requests.put(request_url, headers=headers)
17+
result = httpx.put(request_url, headers=headers)
1818
assert result.status_code == 401 # Missing headers
1919
headers.update({
2020
"AA-VERSION": environ.get("AA_VERSION", "1.0.0"),
2121
"EX-APP-ID": environ.get("APP_ID", "nc_py_api"),
2222
"EX-APP-VERSION": environ.get("APP_VERSION", "1.0.0"),
2323
})
2424
sign_request(headers)
25-
result = requests.put(request_url, headers=headers)
25+
result = httpx.put(request_url, headers=headers)
2626
assert result.status_code == 200
2727
# Invalid AA-SIGNATURE
2828
sign_request(headers, secret="xxx")
29-
result = requests.put(request_url, headers=headers)
29+
result = httpx.put(request_url, headers=headers)
3030
assert result.status_code == 401
3131
sign_request(headers)
32-
result = requests.put(request_url, headers=headers)
32+
result = httpx.put(request_url, headers=headers)
3333
assert result.status_code == 200
3434
# Invalid EX-APP-ID
3535
old_app_name = headers["EX-APP-ID"]
3636
headers["EX-APP-ID"] = "unknown_app"
3737
sign_request(headers)
38-
result = requests.put(request_url, headers=headers)
38+
result = httpx.put(request_url, headers=headers)
3939
assert result.status_code == 401
4040
headers["EX-APP-ID"] = old_app_name
4141
sign_request(headers)
42-
result = requests.put(request_url, headers=headers)
42+
result = httpx.put(request_url, headers=headers)
4343
assert result.status_code == 200
4444
# Invalid EX-APP-VERSION
4545
sign_request(headers)
46-
result = requests.put(request_url, headers=headers)
46+
result = httpx.put(request_url, headers=headers)
4747
assert result.status_code == 200
4848
old_version = headers["EX-APP-VERSION"]
4949
headers["EX-APP-VERSION"] = "999.0.0"
5050
sign_request(headers)
51-
result = requests.put(request_url, headers=headers)
51+
result = httpx.put(request_url, headers=headers)
5252
assert result.status_code == 401
5353
headers["EX-APP-VERSION"] = old_version
5454
sign_request(headers)
55-
result = requests.put(request_url, headers=headers)
55+
result = httpx.put(request_url, headers=headers)
5656
assert result.status_code == 200

tests/_talk_bot.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import gfixture_set_env # noqa
55
import pytest
6-
import requests
7-
from fastapi import BackgroundTasks, Depends, FastAPI, HTTPException, Request
6+
from fastapi import BackgroundTasks, Depends, FastAPI, HTTPException, Request, Response
87
from starlette.datastructures import URL
98

109
from nc_py_api import talk_bot
@@ -52,14 +51,14 @@ def talk_bot_coverage(
5251
background_tasks: BackgroundTasks,
5352
):
5453
background_tasks.add_task(coverage_talk_bot_process_request, message, request)
55-
return requests.Response()
54+
return Response()
5655

5756

5857
# in real program this is not needed, as bot enabling handler is called in the bots process itself and will reset it.
5958
@APP.delete("/reset_bot_secret")
6059
def reset_bot_secret():
6160
os.environ.pop(talk_bot.__get_bot_secret("/talk_bot_coverage"))
62-
return requests.Response()
61+
return Response()
6362

6463

6564
if __name__ == "__main__":

tests/_talk_bot_async.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import gfixture_set_env # noqa
55
import pytest
6-
import requests
7-
from fastapi import BackgroundTasks, Depends, FastAPI, Request
6+
from fastapi import BackgroundTasks, Depends, FastAPI, Request, Response
87

98
from nc_py_api import talk_bot
109
from nc_py_api.ex_app import atalk_bot_app, run_app
@@ -40,14 +39,14 @@ async def talk_bot_coverage(
4039
background_tasks: BackgroundTasks,
4140
):
4241
background_tasks.add_task(coverage_talk_bot_process_request, message, request)
43-
return requests.Response()
42+
return Response()
4443

4544

4645
# in real program this is not needed, as bot enabling handler is called in the bots process itself and will reset it.
4746
@APP.delete("/reset_bot_secret")
4847
async def reset_bot_secret():
4948
os.environ.pop(talk_bot.__get_bot_secret("/talk_bot_coverage"))
50-
return requests.Response()
49+
return Response()
5150

5251

5352
if __name__ == "__main__":

0 commit comments

Comments
 (0)