-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
66 lines (55 loc) · 2.6 KB
/
test_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import os
import pytest
from fastapi.testclient import TestClient
from unittest.mock import patch
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from main import app # Импорт приложения из файла main.py
client = TestClient(app)
# Тестовые данные
TEST_URL = "https://example.com"
TEST_PAGE_ID = "12345"
MOCK_S3_KEY = "exports/mock_file.json"
@pytest.fixture
def mock_s3_upload():
"""Мок для загрузки файла в S3"""
with patch("app.s3_client.upload_file") as mock_upload:
mock_upload.return_value = None
yield mock_upload
@pytest.fixture
def mock_requests_get():
"""Мок для requests.get"""
with patch("app.requests.get") as mock_get:
mock_get.return_value.status_code = 200
mock_get.return_value.text = "Mocked response content"
yield mock_get
# @pytest.fixture
# def mock_confluence_api():
# """Мок для ConfluenceAPI"""
# with patch("app.ConfluenceAPI") as MockConfluenceAPI:
# instance = MockConfluenceAPI.return_value
# instance.get_page_content.return_value = "Mocked Confluence content"
# yield instance
def test_process_url(mock_s3_upload, mock_requests_get):
response = client.post("/process-url/", json={"url": TEST_URL})
assert response.status_code == 200
assert response.json()["s3_key"].startswith("exports/")
# Проверяем, что загрузка в S3 была вызвана
mock_s3_upload.assert_called_once()
# def test_process_confluence(mock_s3_upload, mock_confluence_api):
# response = client.post("/process-confluence/", json={"page_id": TEST_PAGE_ID})
# assert response.status_code == 200
# assert response.json()["s3_key"].startswith("exports/")
# # Проверяем, что загрузка в S3 была вызвана
# mock_s3_upload.assert_called_once()
# mock_confluence_api.get_page_content.assert_called_once_with(page_id=TEST_PAGE_ID)
def test_invalid_url(mock_requests_get):
mock_requests_get.side_effect = Exception("Invalid URL")
response = client.post("/process-url/", json={"url": "invalid_url"})
assert response.status_code == 400
assert "Failed to fetch URL" in response.json()["detail"]
# def test_invalid_confluence_page(mock_confluence_api):
# mock_confluence_api.get_page_content.side_effect = Exception("Page not found")
# response = client.post("/process-confluence/", json={"page_id": "invalid_page"})
# assert response.status_code == 500
# assert "Error processing Confluence page" in response.json()["detail"]