Skip to content

Commit

Permalink
removed requests package (#185)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bigcat88 authored Dec 17, 2023
1 parent 4d27356 commit 7889dee
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion docs/NextcloudTalkBot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)**.
Expand Down
8 changes: 4 additions & 4 deletions examples/as_app/talk_bot/lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 10 additions & 10 deletions tests/_app_security_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""):
Expand All @@ -14,43 +14,43 @@ 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"),
"EX-APP-ID": environ.get("APP_ID", "nc_py_api"),
"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
7 changes: 3 additions & 4 deletions tests/_talk_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__":
Expand Down
7 changes: 3 additions & 4 deletions tests/_talk_bot_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__":
Expand Down

0 comments on commit 7889dee

Please sign in to comment.