generated from Luis/nextjs-python-web-template
Better emulate metadata
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import List, Optional
|
||||
|
||||
import httpx
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, Query
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ...errors import ClanError
|
||||
@@ -291,3 +292,31 @@ def get_all_eventmessages(
|
||||
) -> List[sql_models.Eventmessage]:
|
||||
eventmessages = sql_crud.get_eventmessages(db, skip=skip, limit=limit)
|
||||
return eventmessages
|
||||
|
||||
|
||||
##############################
|
||||
# #
|
||||
# EMULATED API ENDPOINTS #
|
||||
# #
|
||||
##############################
|
||||
@router.get("/emulate", response_class=HTMLResponse)
|
||||
@router.get("/emu", response_class=HTMLResponse)
|
||||
def get_emulated_enpoints() -> HTMLResponse:
|
||||
from clan_cli.config import ap_url, c1_url, c2_url, dlg_url
|
||||
|
||||
html_content = f"""
|
||||
<html>
|
||||
<head>
|
||||
<title>Emulated API</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Emulated API</h1>
|
||||
<p>Emulated API endpoints for testing purposes.</p>
|
||||
<p>DLG: <a href="{dlg_url}" >{dlg_url} </a></p>
|
||||
<p>AP: <a href="{ap_url}">{ap_url}</a></p>
|
||||
<p>C1: <a href="{c1_url}">{c1_url} </a></p>
|
||||
<p>C2: <a href="{c2_url}">{c2_url}</a></p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
return HTMLResponse(content=html_content, status_code=200)
|
||||
|
||||
@@ -15,6 +15,7 @@ import uvicorn
|
||||
from pydantic import AnyUrl, IPvAnyAddress
|
||||
from pydantic.tools import parse_obj_as
|
||||
|
||||
import clan_cli.config as config
|
||||
from clan_cli.emulate_fastapi import apps, get_health
|
||||
from clan_cli.errors import ClanError
|
||||
|
||||
@@ -128,8 +129,8 @@ def start_server(args: argparse.Namespace) -> None:
|
||||
cmd = ["pytest", "-s", str(test_db_api)]
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
config.host = args.host
|
||||
if args.emulate:
|
||||
urls = list()
|
||||
# start servers as processes (dlg, ap, c1 and c2 for tests)
|
||||
for app, port in apps:
|
||||
proc = mp.Process(
|
||||
@@ -143,9 +144,7 @@ def start_server(args: argparse.Namespace) -> None:
|
||||
daemon=True,
|
||||
)
|
||||
proc.start()
|
||||
urls.append(f"http://{args.host}:{port}")
|
||||
# check server health
|
||||
for url in urls:
|
||||
url = f"http://{args.host}:{port}"
|
||||
res = get_health(url=url + "/health")
|
||||
if res is None:
|
||||
raise Exception(f"Couldn't reach {url} after starting server")
|
||||
|
||||
Reference in New Issue
Block a user