add webhook to docseal

This commit is contained in:
2025-11-03 20:08:49 -03:00
parent eca3ac42dc
commit fef60f2ae0
22 changed files with 290 additions and 29 deletions

View File

@@ -1,5 +1,8 @@
import base64
import json
import os
from dataclasses import dataclass
from http import HTTPMethod
import jsonlines
import pytest
@@ -17,6 +20,7 @@ def pytest_configure():
os.environ['DOCSEAL_KEY'] = 'gUWhWtYBgTaP8fc1q5GZ6JuUHaZzMgZna6KFBHz3Gzk'
os.environ['USER_TABLE'] = PYTEST_TABLE_NAME
os.environ['COURSE_TABLE'] = PYTEST_TABLE_NAME
os.environ['ENROLLMENT_TABLE'] = PYTEST_TABLE_NAME
os.environ['ORDER_TABLE'] = PYTEST_TABLE_NAME
os.environ['ENROLLMENT_TABLE'] = PYTEST_TABLE_NAME
os.environ['BUCKET_NAME'] = 'saladeaula.digital'
@@ -36,6 +40,78 @@ def lambda_context() -> LambdaContext:
return LambdaContext()
class HttpApiProxy:
def __call__(
self,
raw_path: str,
method: str = HTTPMethod.GET,
body: dict = {},
*,
headers: dict = {},
auth_flow_type: str = 'USER_AUTH',
queryStringParameters: dict = {},
**kwargs,
) -> dict:
return {
'version': '2.0',
'routeKey': '$default',
'rawPath': raw_path,
'rawQueryString': 'parameter1=value1&parameter1=value2&parameter2=value',
'cookies': ['cookie1', 'cookie2'],
'headers': headers,
'queryStringParameters': queryStringParameters,
'requestContext': {
'accountId': '123456789012',
'apiId': 'api-id',
'authorizer': {
'lambda': {
'user': {
'name': 'Sérgio R Siqueira',
'email': 'sergio@somosbeta.com.br',
'email_verified': 'true',
'custom:user_id': '5OxmMjL-ujoR5IMGegQz',
'sub': 'c4f30dbd-083e-4b84-aa50-c31afe9b9c01',
},
'auth_flow_type': auth_flow_type,
},
'jwt': {
'claims': {'claim1': 'value1', 'claim2': 'value2'},
'scopes': ['scope1', 'scope2'],
},
},
'domainName': 'id.execute-api.us-east-1.amazonaws.com',
'domainPrefix': 'id',
'http': {
'method': str(method),
'path': raw_path,
'protocol': 'HTTP/1.1',
'sourceIp': '192.168.0.1/32',
'userAgent': 'agent',
},
'requestId': 'id',
'routeKey': '$default',
'stage': '$default',
'time': '12/Mar/2020:19:03:58 +0000',
'timeEpoch': 1583348638390,
},
'body': _base64_dict(body),
'pathParameters': {'parameter1': 'value1'},
'isBase64Encoded': True,
'stageVariables': {'stageVariable1': 'value1', 'stageVariable2': 'value2'},
}
def _base64_dict(obj: dict = {}) -> str | None:
if not obj:
return None
return base64.b64encode(json.dumps(obj).encode()).decode()
@pytest.fixture
def http_api_proxy():
return HttpApiProxy()
@pytest.fixture
def dynamodb_client():
from boto3clients import dynamodb_client as client
@@ -80,3 +156,10 @@ def seeds(dynamodb_client):
TableName=PYTEST_TABLE_NAME,
Item=serialize(line),
)
@pytest.fixture
def app():
import app
return app