Eslonf commited on
Commit
4372cc6
·
1 Parent(s): b213696

Add initial test for main page

Browse files
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  app/__pycache__/
2
  app/ml_model/__pycache__/
3
- app/routers/__pycache__/
 
 
1
  app/__pycache__/
2
  app/ml_model/__pycache__/
3
+ app/routers/__pycache__/
4
+ tests/__pycache__/
app/routers/generator_page.py CHANGED
@@ -11,7 +11,7 @@ templates = Jinja2Templates(directory="app/templates")
11
  @router.get("/", response_class=HTMLResponse)
12
  async def read_root(request: Request):
13
  """Отдает главную HTML-страницу."""
14
- return templates.TemplateResponse("index.html", {"request": request})
15
 
16
  @router.post("/generate-ad")
17
  async def generate_ad_task_endpoint(
 
11
  @router.get("/", response_class=HTMLResponse)
12
  async def read_root(request: Request):
13
  """Отдает главную HTML-страницу."""
14
+ return templates.TemplateResponse(request, "index.html")
15
 
16
  @router.post("/generate-ad")
17
  async def generate_ad_task_endpoint(
pytest.ini ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [pytest]
2
+ pythonpath = .
requirments.txt CHANGED
@@ -6,4 +6,6 @@ transformers
6
  torch --index-url https://download.pytorch.org/whl/cpu
7
  https://github.com/sergey21000/llama-cpp-python-wheels/releases/download/v0.3.16-cpu/llama_cpp_python-0.3.16-cp312-cp312-linux_x86_64.whl
8
  huggingface-hub
9
- Pillow
 
 
 
6
  torch --index-url https://download.pytorch.org/whl/cpu
7
  https://github.com/sergey21000/llama-cpp-python-wheels/releases/download/v0.3.16-cpu/llama_cpp_python-0.3.16-cp312-cp312-linux_x86_64.whl
8
  huggingface-hub
9
+ Pillow
10
+ pytest
11
+ httpx
tests/__pycache__/test_main.cpython-312-pytest-9.0.1.pyc DELETED
Binary file (2.21 kB)
 
tests/test_main.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi.testclient import TestClient
2
+ import pytest
3
+
4
+ from app.main import app
5
+
6
+ # --- Подготовка к тестам ---
7
+ # Создаем "виртуального клиента", который будет отправлять запросы к приложению.
8
+ client = TestClient(app)
9
+
10
+ def test_read_main_page():
11
+ """
12
+ Тест проверяет, что главная страница ("/") успешно загружается.
13
+ """
14
+ # 1. Действие:
15
+ # Отправляем GET-запрос на главную страницу.
16
+ response = client.get("/")
17
+
18
+ # 2. Проверка (Assert):
19
+ # Утверждаем, что сервер ответил кодом 200 (OK).
20
+ assert response.status_code == 200
21
+
22
+ # 3. Проверка содержимого:
23
+ assert "Генератор объявлений" in response.text