fix commits

develop
Сергей Ванюшкин 2024-01-05 22:25:07 +03:00
commit 9b8c3aa05a
7 changed files with 20 additions and 24 deletions

View File

@ -1,11 +1,9 @@
from fastapi import APIRouter from fastapi import APIRouter
api_router = APIRouter() api_router = APIRouter()
@api_router.get("/ping") @api_router.get("/ping")
async def pong(): async def pong():
"""Тестовый роут""" """Тестовый роут"""
return {"ping": "pong!"} return {"ping": "pong!"}

View File

@ -17,4 +17,5 @@ class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env") model_config = SettingsConfigDict(env_file=".env")
settings = Settings() settings = Settings()

View File

@ -1,14 +1,17 @@
import os import os
from fastapi import APIRouter, Request from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
site_router = APIRouter() site_router = APIRouter()
print(os.path.abspath(os.curdir))
site_router.mount("/static", StaticFiles(directory="servicemanager/frontend/static"), name="static") site_router.mount(
"/static",
StaticFiles(directory="servicemanager/frontend/static"),
name="static",
)
templates = Jinja2Templates(directory="servicemanager/frontend/templates") templates = Jinja2Templates(directory="servicemanager/frontend/templates")
@ -16,6 +19,4 @@ templates = Jinja2Templates(directory="servicemanager/frontend/templates")
@site_router.get("/testpage", response_class=HTMLResponse) @site_router.get("/testpage", response_class=HTMLResponse)
async def read_item(request: Request): async def read_item(request: Request):
return templates.TemplateResponse( return templates.TemplateResponse(request=request, name="test.html")
request=request, name="test.html"
)

View File

@ -1,8 +1,11 @@
<html> <html>
<head> <head>
<title>test page</title> <title>test page</title>
</head> </head>
<body> <body>
<h1>test_data</h1> <h1>test_data</h1>
</body> </body>
</html> </html>

View File

@ -1,10 +1,9 @@
import asyncio import asyncio
import sys import sys
from fastapi import FastAPI
import uvicorn import uvicorn
from api.routes import api_router from api.routes import api_router
from fastapi import FastAPI
from frontend.routes import site_router from frontend.routes import site_router
@ -12,12 +11,7 @@ async def generate_test_data():
""" """
Создание БД и наполнение ее данными Создание БД и наполнение ее данными
""" """
print('generating data') print("generating data")
from backend.queries.user import UserORM
await UserORM.create_tables()
await UserORM.insert_admin()
def create_app(): def create_app():
@ -28,13 +22,13 @@ def create_app():
app.include_router(api_router) app.include_router(api_router)
app.include_router(site_router) app.include_router(site_router)
return app return app
def run_app(): def run_app():
""" """
Запуск локального вебсервера для тестов и проверки Запуск локального вебсервера для тестов и проверки
""" """
uvicorn.run( uvicorn.run(
app="main:create_app", app="main:create_app",
@ -49,4 +43,3 @@ if __name__ == "__main__":
if "--webserver" in sys.argv: if "--webserver" in sys.argv:
run_app() run_app()

View File

@ -2,9 +2,9 @@ from starlette.testclient import TestClient
from servicemanager.main import create_app from servicemanager.main import create_app
client = TestClient(create_app()) client = TestClient(create_app())
def test_testpage(): def test_testpage():
response = client.get("/testpage") response = client.get("/testpage")
assert response.status_code == 200 assert response.status_code == 200

View File

@ -2,9 +2,9 @@ from starlette.testclient import TestClient
from servicemanager.main import create_app from servicemanager.main import create_app
client = TestClient(create_app()) client = TestClient(create_app())
def test_ping(): def test_ping():
response = client.get("/ping") response = client.get("/ping")
assert response.status_code == 200 assert response.status_code == 200