diff --git a/backend/test_bing.py b/backend/test_bing.py deleted file mode 100644 index a0bc8d2..0000000 --- a/backend/test_bing.py +++ /dev/null @@ -1,21 +0,0 @@ -import httpx -import re -from urllib.parse import quote - -url = 'https://www.bing.com/search?q=' + quote('华为手机推荐') + '&setmkt=zh-CN' -headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'} - -with httpx.Client(timeout=30, follow_redirects=True) as client: - resp = client.get(url, headers=headers) - html = resp.text - print('Status:', resp.status_code) - print('Size:', len(html)) - print('First 500 chars:', html[:500]) - - # Try to find result titles - titles = re.findall(r']*href="https?://[^"]*"[^>]*>(.*?)', html, re.DOTALL) - print('\nPotential titles:', len(titles)) - for t in titles[:10]: - clean = re.sub(r'<[^>]+>', '', t).strip() - if clean and len(clean) > 5 and '微软' not in clean and 'Bing' not in clean: - print(' -', clean[:80]) diff --git a/backend/test_llm_connection.py b/backend/test_llm_connection.py deleted file mode 100644 index be98676..0000000 --- a/backend/test_llm_connection.py +++ /dev/null @@ -1,38 +0,0 @@ -import httpx -import asyncio - - -async def test(): - url = "https://coding.dashscope.aliyuncs.com/v1/chat/completions" - headers = { - "Authorization": "Bearer sk-sp-c76f198d1b2840c5b5a58dfd4c0cd218", - "Content-Type": "application/json" - } - payload = { - "model": "qwen3-coder-plus", - "messages": [{"role": "user", "content": "你好,请用一句话确认连接正常"}], - "max_tokens": 100 - } - async with httpx.AsyncClient(timeout=30) as client: - resp = await client.post(url, json=payload, headers=headers) - print(f"Status: {resp.status_code}") - if resp.status_code == 200: - data = resp.json() - print(f"Model: {data['model']}") - print(f"Content: {data['choices'][0]['message']['content']}") - print("✅ 百炼 Coding Plan API 连通成功!") - else: - print(f"Error: {resp.text}") - # 如果 qwen3-coder-plus 不行,尝试其他模型 - for model in ["qwen3.5-plus", "qwen3-coder-next", "qwen3-max-2026-01-23"]: - payload["model"] = model - resp2 = await client.post(url, json=payload, headers=headers) - print(f"\nTrying {model}: Status {resp2.status_code}") - if resp2.status_code == 200: - data = resp2.json() - print(f"✅ {model} works! Content: {data['choices'][0]['message']['content']}") - break - else: - print(f"Error: {resp2.text[:200]}") - -asyncio.run(test()) diff --git a/backend/test_wiki.py b/backend/test_wiki.py deleted file mode 100644 index 45bde6f..0000000 --- a/backend/test_wiki.py +++ /dev/null @@ -1,24 +0,0 @@ -import asyncio -import httpx - -async def test_wiki(): - from app.workers.platforms.search_engine import search_wikipedia - result = await search_wikipedia("华为手机", max_chars=1000) - print("Wikipedia result length:", len(result)) - print("First 500 chars:", result[:500]) - print("Contains 华为:", "华为" in result) - -async def test_health(): - try: - async with httpx.AsyncClient() as c: - r = await c.get("http://localhost:8000/health") - print("Health status:", r.status_code, r.text) - except Exception as e: - print("Health check failed:", e) - -async def main(): - await test_health() - print("---") - await test_wiki() - -asyncio.run(main()) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index dc3c003..183de4c 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -22,6 +22,7 @@ pytest_plugins = [ "tests.fixtures.database", "tests.fixtures.brands", "tests.fixtures.client", + "tests.fixtures.content", ] diff --git a/backend/tests/fixtures/content.py b/backend/tests/fixtures/content.py new file mode 100644 index 0000000..5d0261f --- /dev/null +++ b/backend/tests/fixtures/content.py @@ -0,0 +1,71 @@ +import uuid +from datetime import datetime, timezone + +import pytest_asyncio + +from app.models.content import Content +from app.models.diagnosis_record import DiagnosisRecord +from app.models.attribution_record import AttributionRecord + +from .auth import _to_uuid + + +@pytest_asyncio.fixture +async def test_content(async_session, test_brand): + content = Content( + id=uuid.uuid4(), + brand_id=_to_uuid(test_brand.id), + title="测试内容标题", + body="这是一段测试内容,用于验证内容管线功能。", + platform="wechat", + status="draft", + content_type="article", + ) + async_session.add(content) + await async_session.commit() + await async_session.refresh(content) + return content + + +@pytest_asyncio.fixture +async def test_diagnosis_record(async_session, test_brand): + record = DiagnosisRecord( + id=uuid.uuid4(), + brand_id=_to_uuid(test_brand.id), + overall_score=45.0, + mention_rate=30.0, + recommendation_rank=50.0, + sentiment_score=60.0, + citation_quality=40.0, + competitive_position=35.0, + status="completed", + ) + async_session.add(record) + await async_session.commit() + await async_session.refresh(record) + return record + + +@pytest_asyncio.fixture +async def test_attribution_record(async_session, test_brand, test_diagnosis_record): + record = AttributionRecord( + id=uuid.uuid4(), + brand_id=_to_uuid(test_brand.id), + diagnosis_id=str(test_diagnosis_record.id), + attribution_window_days=28, + before_scores={ + "mention_rate": 30.0, + "recommendation_rank": 50.0, + "sentiment_score": 60.0, + "citation_quality": 40.0, + "competitive_position": 35.0, + }, + after_scores=None, + status="tracking", + start_at=datetime.now(timezone.utc), + window_end_at=datetime(2026, 6, 30, tzinfo=timezone.utc), + ) + async_session.add(record) + await async_session.commit() + await async_session.refresh(record) + return record