From 3c4e1ff670e234712e0340b3df725e115080970e Mon Sep 17 00:00:00 2001 From: Sergey Vanyushkin Date: Thu, 4 Jan 2024 23:13:02 +0000 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D0=B5=D0=BF=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../servicemanager/api/routes.py | 4 +--- .../servicemanager/frontend/routes.py | 15 ++++++++------- .../servicemanager/frontend/templates/test.html | 3 +++ .../servicemanager/main.py | 13 +++++++------ .../servicemanager/settings.py | 1 + .../tests/test_frontend.py | 4 ++-- .../tests/test_main.py | 2 +- 7 files changed, 23 insertions(+), 19 deletions(-) diff --git a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/api/routes.py b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/api/routes.py index d4f863e..0233c60 100644 --- a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/api/routes.py +++ b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/api/routes.py @@ -1,11 +1,9 @@ from fastapi import APIRouter - api_router = APIRouter() + @api_router.get("/ping") async def pong(): """Тестовый роут""" return {"ping": "pong!"} - - diff --git a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/routes.py b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/routes.py index bea5bc9..513cd20 100644 --- a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/routes.py +++ b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/routes.py @@ -1,14 +1,17 @@ import os -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates - 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") @@ -16,6 +19,4 @@ templates = Jinja2Templates(directory="servicemanager/frontend/templates") @site_router.get("/testpage", response_class=HTMLResponse) async def read_item(request: Request): - return templates.TemplateResponse( - request=request, name="test.html" - ) + return templates.TemplateResponse(request=request, name="test.html") diff --git a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/templates/test.html b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/templates/test.html index 6cb687e..0e6d60d 100644 --- a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/templates/test.html +++ b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/frontend/templates/test.html @@ -1,8 +1,11 @@ + test page +

test_data

+ diff --git a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/main.py b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/main.py index 2451806..dd8f734 100644 --- a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/main.py +++ b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/main.py @@ -1,17 +1,18 @@ import asyncio import sys -from fastapi import FastAPI import uvicorn - from api.routes import api_router +from fastapi import FastAPI from frontend.routes import site_router + async def generate_test_data(): """ Создание БД и наполнение ее данными """ - print('generating data') + print("generating data") + def create_app(): """ @@ -21,12 +22,13 @@ def create_app(): app.include_router(api_router) app.include_router(site_router) - + return app + def run_app(): """ - Запуск локального вебсервера для тестов и проверки + Запуск локального вебсервера для тестов и проверки """ uvicorn.run( app="main:create_app", @@ -41,4 +43,3 @@ if __name__ == "__main__": if "--webserver" in sys.argv: run_app() - diff --git a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/settings.py b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/settings.py index 3900da2..c088755 100644 --- a/information_system_and_programming/term_5/db_management_and_automation/servicemanager/settings.py +++ b/information_system_and_programming/term_5/db_management_and_automation/servicemanager/settings.py @@ -17,4 +17,5 @@ class Settings(BaseSettings): model_config = SettingsConfigDict(env_file=".env") + settings = Settings() diff --git a/information_system_and_programming/term_5/db_management_and_automation/tests/test_frontend.py b/information_system_and_programming/term_5/db_management_and_automation/tests/test_frontend.py index d814e13..842068d 100644 --- a/information_system_and_programming/term_5/db_management_and_automation/tests/test_frontend.py +++ b/information_system_and_programming/term_5/db_management_and_automation/tests/test_frontend.py @@ -2,9 +2,9 @@ from starlette.testclient import TestClient from servicemanager.main import create_app - client = TestClient(create_app()) + def test_testpage(): response = client.get("/testpage") - assert response.status_code == 200 + assert response.status_code == 200 diff --git a/information_system_and_programming/term_5/db_management_and_automation/tests/test_main.py b/information_system_and_programming/term_5/db_management_and_automation/tests/test_main.py index d8d018c..1ea533d 100644 --- a/information_system_and_programming/term_5/db_management_and_automation/tests/test_main.py +++ b/information_system_and_programming/term_5/db_management_and_automation/tests/test_main.py @@ -2,9 +2,9 @@ from starlette.testclient import TestClient from servicemanager.main import create_app - client = TestClient(create_app()) + def test_ping(): response = client.get("/ping") assert response.status_code == 200