73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
"""
|
|
E2E 测试:Phase 23 - 内容管理 E2E
|
|
"""
|
|
import os
|
|
import pytest
|
|
import requests
|
|
|
|
BASE_URL = 'http://localhost:8085/api/v1'
|
|
E2E_PASSWORD = os.environ["E2E_PASSWORD"]
|
|
|
|
def get_admin_token():
|
|
r = requests.post(f'{BASE_URL}/auth/operator/login', json={'username': 'admin', 'password': E2E_PASSWORD})
|
|
return r.json()['data']['accessToken']
|
|
|
|
def auth_header(token):
|
|
return {'Authorization': f'Bearer {token}'}
|
|
|
|
def test_get_content_categories():
|
|
r = requests.get(f'{BASE_URL}/content/categories')
|
|
assert r.status_code == 200
|
|
data = r.json()['data']
|
|
assert isinstance(data, list)
|
|
|
|
def test_create_content_category():
|
|
token = get_admin_token()
|
|
r = requests.post(
|
|
f'{BASE_URL}/content/operator/categories',
|
|
headers=auth_header(token),
|
|
json={'name': '测试分类', 'code': 'test_cat_001', 'sortOrder': 0}
|
|
)
|
|
assert r.status_code == 200
|
|
assert r.json()['data']['code'] == 'test_cat_001'
|
|
|
|
def test_create_and_publish_article():
|
|
token = get_admin_token()
|
|
# 创建文章
|
|
create_r = requests.post(
|
|
f'{BASE_URL}/content/operator/articles',
|
|
headers=auth_header(token),
|
|
json={'title': '测试文章', 'summary': '测试摘要', 'content': '测试内容', 'sortOrder': 0}
|
|
)
|
|
assert create_r.status_code == 200
|
|
article_id = create_r.json()['data']['id']
|
|
assert create_r.json()['data']['status'] == 'draft'
|
|
# 发布
|
|
pub_r = requests.post(
|
|
f'{BASE_URL}/content/operator/articles/{article_id}/publish',
|
|
headers=auth_header(token)
|
|
)
|
|
assert pub_r.status_code == 200
|
|
assert pub_r.json()['data']['status'] == 'published'
|
|
# 用户端可访问
|
|
r = requests.get(f'{BASE_URL}/content/articles/{article_id}')
|
|
assert r.status_code == 200
|
|
# 下架
|
|
off_r = requests.post(
|
|
f'{BASE_URL}/content/operator/articles/{article_id}/offline',
|
|
headers=auth_header(token)
|
|
)
|
|
assert off_r.status_code == 200
|
|
assert off_r.json()['data']['status'] == 'offline'
|
|
|
|
def test_content_stats():
|
|
r = requests.get(f'{BASE_URL}/operator/analytics/v11/content')
|
|
assert r.status_code == 200
|
|
data = r.json()['data']
|
|
assert 'totalPublishedArticles' in data
|
|
assert 'totalViews' in data
|
|
assert 'topArticles' in data
|
|
|
|
if __name__ == '__main__':
|
|
pytest.main([__file__, '-v'])
|