Move make_request function to a separate utils module

This commit is contained in:
2026-05-08 16:58:35 +02:00
parent 16bd8b25f2
commit 97f1a802fa
2 changed files with 64 additions and 30 deletions
@@ -13,38 +13,10 @@
# limitations under the License.
from src.jcloud_deployment_server.integrations.gitea.middlewares.signature import GiteaSignatureMiddleware
from starlette.requests import Request
from fastapi import HTTPException
from tests.utils.make_request import make_request, call_next
import pytest
import hashlib
import hmac
import os
class DummyResponse:
def __init__(self):
self.called = True
async def call_next(request):
return DummyResponse()
def make_request(body: bytes, headers = None) -> Request:
scope = {
'type': 'http',
'method': 'POST',
'path': '/gitea/webhook',
'headers': [
(k.lower().encode(), v.encode())
for k, v in (headers or {}).items()
]
}
async def receive():
return {
'type': 'http.request',
'body': body
}
return Request(scope, receive)
def make_signature(body: bytes, secret: bytes) -> str:
signature = hmac.new(
@@ -98,6 +70,7 @@ async def test_GiteaSignatureMiddleware_valid_signature(body, secret):
req = make_request(
body,
'/gitea/webhook',
headers
)
@@ -136,7 +109,8 @@ async def test_GiteaSignatureMiddleware_invalid_signature(signature, body, secre
req = make_request(
body,
headers
'/gitea/webhook',
headers,
)
res = await middleware.dispatch(req, call_next)