Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import time
from typing import Any, Dict, Optional

from libs.db import get_db_safe
from src.libs.db import get_db_safe
from utils import parse_json_body, error_response, cors_headers, check_required_fields, extract_id_from_result, get_blt_api_url
from libs.constant import __HASHING_ITERATIONS
from libs.jwt_utils import create_access_token, decode_jwt
from libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index
from src.libs.constant import __HASHING_ITERATIONS
from src.libs.jwt_utils import create_access_token, decode_jwt
from src.libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index
from services.email_service import EmailService
from workers import Response
from models import User
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Any, Dict
from utils import error_response, parse_pagination_params, parse_json_body, convert_d1_results
from libs.db import get_db_safe
from src.libs.db import get_db_safe
from models import Bug
from workers import Response
import logging
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Any, Dict
from utils import error_response, parse_pagination_params, convert_d1_results
from libs.db import get_db_safe
from src.libs.db import get_db_safe
from workers import Response
from models import Domain

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from typing import Any, Dict, List
from utils import convert_d1_results, error_response, paginated_response, parse_pagination_params, success_response
from workers import Response
from libs.db import get_db_safe
from libs.data_protection import decrypt_sensitive
from src.libs.db import get_db_safe
from src.libs.data_protection import decrypt_sensitive

async def handle_organizations(
request: Any,
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from typing import Any, Dict
from utils import json_response, error_response, convert_single_d1_result
from libs.db import get_db_safe
from src.libs.db import get_db_safe


# Lightweight server-side cache (per worker isolate) for /stats.
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import time
from typing import Any, Dict
from utils import error_response, parse_pagination_params, convert_d1_results, parse_json_body, check_required_fields
from libs.db import get_db_safe
from libs.constant import __HASHING_ITERATIONS
from libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index
from src.libs.db import get_db_safe
from src.libs.constant import __HASHING_ITERATIONS
from src.libs.data_protection import encrypt_sensitive, decrypt_sensitive, blind_index
from workers import Response
from models import User, Bug, Domain, UserFollow
import logging
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
make_routes_handler
)
from utils import json_response, error_response, cors_headers
from libs.db import get_db_safe
from src.libs.db import get_db_safe

# Initialize the router
router = Router()
Expand Down
2 changes: 1 addition & 1 deletion src/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
tag = await Tag.create(db, name='xss')
"""

from libs.orm import Model
from src.libs.orm import Model


class Domain(Model):
Expand Down
4 changes: 4 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def __init__(self, body, status=200, headers=None):
self.body = body
self.status = status
self.headers = headers or {}
try:
self.data = json.loads(body) if body else None
except (TypeError, ValueError):
self.data = None


def cors_headers() -> Dict[str, str]:
Expand Down
16 changes: 14 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Pytest configuration file to set up test environment.
"""

import json
import sys
import types
from pathlib import Path
Expand All @@ -19,14 +20,25 @@
class WorkerEntrypoint: # pragma: no cover - shim for imports only
pass

class _WorkersResponse: # pragma: no cover - shim for imports only
def __init__(self, data=None, status=200, headers=None, body=None):
self.data = data
self.status = status
self.headers = headers or {}
self.body = body

class Response: # pragma: no cover - shim for imports only
@staticmethod
def json(data, status=200, headers=None):
return {"status": status, "headers": headers or {}, "data": data}
return _WorkersResponse(data=data, status=status, headers=headers or {}, body=json.dumps(data))

@staticmethod
def new(body=None, status=200, headers=None):
return {"status": status, "headers": headers or {}, "body": body}
try:
data = json.loads(body) if body else None
except (TypeError, ValueError):
data = None
return _WorkersResponse(data=data, status=status, headers=headers or {}, body=body)

setattr(workers_mod, "WorkerEntrypoint", WorkerEntrypoint)
setattr(workers_mod, "Response", Response)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))

from libs.orm import (
from src.libs.orm import (
QuerySet,
Model,
_validate_identifier,
Expand Down
Loading