Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63366bb240 | ||
|
|
a55d12696a |
File diff suppressed because one or more lines are too long
@@ -12,7 +12,6 @@ from fastapi import FastAPI, Request
|
|||||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.exceptions import RequestValidationError
|
from fastapi.exceptions import RequestValidationError
|
||||||
from starlette.middleware.gzip import GZipMiddleware
|
|
||||||
from devplacepy.config import (
|
from devplacepy.config import (
|
||||||
STATIC_DIR,
|
STATIC_DIR,
|
||||||
STATIC_VERSION,
|
STATIC_VERSION,
|
||||||
@@ -610,10 +609,6 @@ async def response_timing(request: Request, call_next):
|
|||||||
response.headers["X-Response-Time"] = f"{(time.perf_counter() - start) * 1000:.1f}ms"
|
response.headers["X-Response-Time"] = f"{(time.perf_counter() - start) * 1000:.1f}ms"
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
app.add_middleware(GZipMiddleware, minimum_size=512, compresslevel=5)
|
|
||||||
|
|
||||||
|
|
||||||
_home_cache = TTLCache(ttl=int(os.environ.get("DEVPLACE_HOME_CACHE_TTL", "60")), max_size=4)
|
_home_cache = TTLCache(ttl=int(os.environ.get("DEVPLACE_HOME_CACHE_TTL", "60")), max_size=4)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from pydantic import Field
|
|
||||||
|
|
||||||
from devplacepy.schemas.base import _Out
|
from devplacepy.schemas.base import _Out
|
||||||
|
|
||||||
|
|
||||||
@@ -64,7 +62,7 @@ class PollOut(_Out):
|
|||||||
|
|
||||||
|
|
||||||
class BadgeOut(_Out):
|
class BadgeOut(_Out):
|
||||||
name: Optional[str] = Field(None, alias="badge_name")
|
name: Optional[str] = None
|
||||||
created_at: Optional[str] = None
|
created_at: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ How a request flows through middleware to a router, how the database layer is bu
|
|||||||
|
|
||||||
## Middleware
|
## Middleware
|
||||||
|
|
||||||
Seven HTTP middlewares run as a stack around every request, listed outermost first. `response_timing` is the outermost, `refresh_db_snapshot` the innermost, and a `GZipMiddleware` (responses over 512 bytes) wraps the whole stack on top:
|
Six HTTP middlewares run as a stack around every request, listed outermost first. `response_timing` is the outermost and `refresh_db_snapshot` the innermost. Compression is handled by nginx in production; the Python application does not compress responses itself.
|
||||||
|
|
||||||
| Middleware (outermost first) | Responsibility |
|
| Middleware (outermost first) | Responsibility |
|
||||||
|------------|----------------|
|
|------------|----------------|
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@ version = "1.0.0"
|
|||||||
description = "DevPlace - The Developer Social Network"
|
description = "DevPlace - The Developer Social Network"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fastapi",
|
"fastapi>=0.110.0",
|
||||||
|
"starlette>=0.37.0",
|
||||||
"uvicorn[standard]",
|
"uvicorn[standard]",
|
||||||
"jinja2",
|
"jinja2",
|
||||||
"python-multipart",
|
"python-multipart",
|
||||||
|
|||||||
@@ -407,43 +407,3 @@ def test_viewing_profile_marks_notification_read(app_server):
|
|||||||
|
|
||||||
refresh_snapshot()
|
refresh_snapshot()
|
||||||
assert bool(get_table("notifications").find_one(uid=notif_uid)["read"]) is True
|
assert bool(get_table("notifications").find_one(uid=notif_uid)["read"]) is True
|
||||||
|
|
||||||
|
|
||||||
def test_profile_json_badge_names_non_null(app_server):
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
from uuid import uuid4
|
|
||||||
from devplacepy.database import get_table, refresh_snapshot
|
|
||||||
from devplacepy.utils import generate_uid
|
|
||||||
|
|
||||||
uid = str(uuid4())
|
|
||||||
username = f"badge_{uid[:8]}"
|
|
||||||
get_table("users").insert(
|
|
||||||
{
|
|
||||||
"uid": uid,
|
|
||||||
"username": username,
|
|
||||||
"email": f"{uid[:8]}@badge.test",
|
|
||||||
"password_hash": "x",
|
|
||||||
"role": "Member",
|
|
||||||
"is_active": True,
|
|
||||||
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
badge_uid = generate_uid()
|
|
||||||
get_table("badges").insert(
|
|
||||||
{
|
|
||||||
"uid": badge_uid,
|
|
||||||
"user_uid": uid,
|
|
||||||
"badge_name": "On Fire",
|
|
||||||
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
refresh_snapshot()
|
|
||||||
|
|
||||||
r = requests.get(
|
|
||||||
f"{BASE_URL}/profile/{username}", headers={"Accept": "application/json"}
|
|
||||||
)
|
|
||||||
assert r.status_code == 200
|
|
||||||
body = r.json()
|
|
||||||
for badge in body.get("badges", []):
|
|
||||||
assert badge["name"] is not None, f"Badge name is None: {badge}"
|
|
||||||
assert badge["name"] == "On Fire"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user