5 Commits

278 changed files with 219413 additions and 35369 deletions

208181
HubOps.md Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +0,0 @@
BASE_URL=https://joyhub-website-frontend-test.best-envision.com/
HEADLESS=true
BROWSER=chromium
DEFAULT_TIMEOUT=30000
LOGIN_EMAIL=zq464008250@163.com
VERIFICATION_CODE=123456

View File

@@ -1,11 +0,0 @@
__pycache__/
*.py[cod]
.pytest_cache/
.env
.venv/
venv/
reports/
test-results/
playwright-report/
allure-results/
.idea/

View File

@@ -1,50 +0,0 @@
# Joyhub_ui_auto_test
Python UI 自动化测试项目,基于 pytest + Playwright。
## 初始化
```bash
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
playwright install
copy .env.example .env
```
## 运行测试
```bash
pytest
```
## 生成测试报告
项目已配置 pytest-html执行测试后会自动生成 HTML 测试报告:
```bash
pytest
```
报告存放路径:
```text
reports\allure-results\index.html
```
也可以只执行指定用例并生成报告:
```bash
python -m pytest tests/test_open_chrome_browser.py
```
## 目录结构
```text
config/ 配置读取
pages/ Page Object 页面对象
tests/ 测试用例
utils/ 通用工具
test_data/ 测试数据
reports/ 测试报告输出
```

View File

@@ -1,23 +0,0 @@
import os
from dataclasses import dataclass
from dotenv import load_dotenv
load_dotenv()
@dataclass(frozen=True)
class Settings:
base_url: str = os.getenv("BASE_URL", "https://joyhub-website-frontend-test.best-envision.com/")
headless: bool = os.getenv("HEADLESS", "true").lower() == "true"
browser: str = os.getenv("BROWSER", "chromium")
default_timeout: int = int(os.getenv("DEFAULT_TIMEOUT", "30000"))
viewport_width: int = int(os.getenv("VIEWPORT_WIDTH", "1920"))
viewport_height: int = int(os.getenv("VIEWPORT_HEIGHT", "1080"))
login_email: str = os.getenv("LOGIN_EMAIL", "zq464008250@163.com")
verification_code: str = os.getenv("VERIFICATION_CODE", "123456")
paypal_email: str = os.getenv("PAYPAL_EMAIL", "sb-je8mf43527414@personal.example.com")
paypal_password: str = os.getenv("PAYPAL_PASSWORD", "S23}}!m]")
run_paypal_payment: bool = os.getenv("RUN_PAYPAL_PAYMENT", "false").lower() == "true"
settings = Settings()

View File

@@ -1,14 +0,0 @@
import re
from playwright.sync_api import Page, expect
class BasePage:
def __init__(self, page: Page):
self.page = page
def goto(self, path: str = ""):
self.page.goto(path)
def assert_title_contains(self, text: str):
expect(self.page).to_have_title(re.compile(re.escape(text)))

View File

@@ -1,14 +0,0 @@
from playwright.sync_api import Page, expect
from pages.base_page import BasePage
class HomePage(BasePage):
def __init__(self, page: Page):
super().__init__(page)
self.body = page.locator("body")
def open(self):
self.goto("/")
def should_be_loaded(self):
expect(self.body).to_be_visible()

View File

@@ -1,10 +0,0 @@
[pytest]
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
# pytest 生成 Allure 原始结果HTML 报告请生成到项目 reports/allure-results
addopts = -v --tb=short --alluredir=C:/Users/a/PyCharmMiscProject/smart-management-auto-test/Joyhub_ui_auto_test/reports/allure-raw
markers =
smoke: smoke test cases
regression: regression test cases

View File

@@ -1,7 +0,0 @@
pytest>=8.3.4
pytest-playwright>=0.6.2
playwright>=1.56.0
python-dotenv>=1.0.1
PyYAML>=6.0.2
allure-pytest>=2.13.5
pytest-html>=4.1.1

View File

@@ -1,236 +0,0 @@
import re
import shutil
import subprocess
import time
from pathlib import Path
import allure
import pytest
from config.settings import settings
from playwright.sync_api import Error as PlaywrightError
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import expect
from utils.logger import get_logger
logger = get_logger()
PROJECT_ROOT = Path(__file__).resolve().parents[1]
ALLURE_RAW_DIR = PROJECT_ROOT / "reports" / "allure-raw"
ALLURE_HTML_DIR = PROJECT_ROOT / "reports" / "allure-results"
def accept_cookie_if_present(page):
privacy_link = page.locator('a[href="/privacy-policy-web"]').last
try:
if privacy_link.is_visible(timeout=1_000):
cookie_container = privacy_link.locator("xpath=ancestor::div[.//button][1]")
cookie_container.locator("button").first.click()
return
except PlaywrightTimeoutError:
pass
accept_button = page.locator("button", has_text=re.compile(r"Acce?pet|Accept", re.I)).first
try:
if accept_button.is_visible(timeout=1_000):
accept_button.click()
except PlaywrightTimeoutError:
logger.info("未检测到 Cookie 操作区域,继续执行")
except PlaywrightError as exc:
logger.info("Cookie 操作区域不可点击,继续执行: %s", exc)
def is_logged_in(page):
try:
aside_button = page.locator("aside button").first
if not aside_button.is_visible(timeout=3_000):
return False
button_text = aside_button.inner_text(timeout=3_000).strip()
return bool(re.search(r"Logout|Log out", button_text, re.I))
except PlaywrightError:
return False
def logout_if_logged_in(page):
if not is_logged_in(page):
logger.info("当前为游客状态,无需 Logout")
return
logger.info("当前已登录,点击 Logout 切换为游客状态")
page.locator("aside button").first.click()
expect(page.locator("aside button").first).not_to_contain_text(re.compile(r"Logout|Log out", re.I), timeout=settings.default_timeout)
def login_as_configured_user_if_needed(page):
if is_logged_in(page):
logger.info("当前已登录,跳过重复登录")
return
logger.info("当前未登录,执行配置用户登录")
login_inputs = page.locator('input[type="text"]')
last_error = None
for _ in range(3):
try:
login_button = page.locator("aside button").first
expect(login_button).to_be_visible(timeout=settings.default_timeout)
login_button.click()
expect(login_inputs.first).to_be_visible(timeout=5_000)
break
except (AssertionError, PlaywrightError) as exc:
last_error = exc
logger.info("登录弹窗未打开,重试点击登录入口: %s", exc)
page.wait_for_timeout(1_000)
else:
raise AssertionError(f"登录弹窗未打开: {last_error}")
login_inputs.nth(0).fill(settings.login_email)
login_inputs.nth(1).fill(settings.verification_code)
confirmation_items = page.locator("div.inline-flex.cursor-pointer")
expect(confirmation_items.nth(0)).to_be_visible(timeout=settings.default_timeout)
expect(confirmation_items.nth(1)).to_be_visible(timeout=settings.default_timeout)
confirmation_items.nth(0).click()
confirmation_items.nth(1).click()
submit_button = page.locator("button").last
expect(submit_button).to_be_enabled(timeout=settings.default_timeout)
submit_button.click()
expect(page.locator("aside button").first).to_contain_text(
re.compile(r"Logout|Log out", re.I), timeout=settings.default_timeout
)
@pytest.fixture
def ensure_guest_user(page):
def _ensure_guest_user():
accept_cookie_if_present(page)
logout_if_logged_in(page)
return _ensure_guest_user
@pytest.fixture
def ensure_logged_in_user(page):
def _ensure_logged_in_user():
accept_cookie_if_present(page)
login_as_configured_user_if_needed(page)
return _ensure_logged_in_user
def pytest_sessionstart(session):
for report_dir in (ALLURE_RAW_DIR, ALLURE_HTML_DIR):
if report_dir.exists():
shutil.rmtree(report_dir)
report_dir.mkdir(parents=True, exist_ok=True)
logger.info("已清理 Allure 目录: %s", report_dir)
def pytest_sessionfinish(session, exitstatus):
if not ALLURE_RAW_DIR.exists() or not any(ALLURE_RAW_DIR.iterdir()):
logger.warning("未找到 Allure 原始结果,跳过 HTML 报告生成: %s", ALLURE_RAW_DIR)
return
allure_command = shutil.which("allure") or shutil.which("allure.cmd")
if not allure_command:
logger.warning("未找到 Allure CLI跳过 HTML 报告生成")
return
command = [
allure_command,
"generate",
str(ALLURE_RAW_DIR),
"-o",
str(ALLURE_HTML_DIR),
"--clean",
]
logger.info("开始生成 Allure HTML 报告: %s", " ".join(command))
result = subprocess.run(
command,
cwd=PROJECT_ROOT,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
)
if result.returncode != 0:
logger.error("Allure HTML 报告生成失败: %s", result.stderr.strip())
return
logger.info("Allure HTML 报告已生成: %s", ALLURE_HTML_DIR / "index.html")
def _safe_attachment_name(name):
return re.sub(r"[^0-9A-Za-z_.\-\u4e00-\u9fff]+", "_", name).strip("_")[:120] or "screenshot"
def _attach_page_screenshot(page, name):
try:
screenshot = page.screenshot(full_page=True)
allure.attach(
screenshot,
name=_safe_attachment_name(name),
attachment_type=allure.attachment_type.PNG,
)
except PlaywrightError as exc:
logger.info("Allure 截图附件生成失败: %s", exc)
@pytest.fixture
def attach_page_screenshot(page):
def _attach(name="页面截图"):
_attach_page_screenshot(page, name)
return _attach
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
setattr(item, "rep_" + report.when, report)
if report.when != "call" or "page" not in item.fixturenames:
return
page = item.funcargs.get("page")
if not page:
return
if report.failed:
_attach_page_screenshot(page, f"失败截图_{item.name}")
elif report.passed:
_attach_page_screenshot(page, f"结束截图_{item.name}")
@pytest.fixture(autouse=True)
def test_run_logger(request):
case_name = request.node.nodeid
start_time = time.perf_counter()
logger.info("用例开始: %s", case_name)
try:
yield
except Exception:
elapsed = time.perf_counter() - start_time
logger.exception("用例异常: %s, 耗时: %.2fs", case_name, elapsed)
raise
else:
elapsed = time.perf_counter() - start_time
logger.info("用例通过: %s, 耗时: %.2fs", case_name, elapsed)
@pytest.fixture(scope="session")
def browser_context_args(browser_context_args):
return {
**browser_context_args,
"base_url": settings.base_url,
"viewport": {"width": settings.viewport_width, "height": settings.viewport_height},
}
@pytest.fixture(scope="session")
def browser_type_launch_args(browser_type_launch_args):
return {
**browser_type_launch_args,
"headless": True,
# 可视化执行配置:"headless": False, "slow_mo": 300,
"timeout": settings.default_timeout,
}

View File

@@ -1,62 +0,0 @@
import os
import shutil
import subprocess
import sys
from pathlib import Path
CURRENT_FILE_PATH = Path(__file__).resolve()
PROJECT_ROOT = CURRENT_FILE_PATH.parent.parent
ALLURE_RESULTS_DIR = PROJECT_ROOT / "allure-results"
ALLURE_REPORT_DIR = PROJECT_ROOT / "allure-report"
LOCAL_ALLURE_PATH = PROJECT_ROOT / "allure" / "allure-2.28.0" / "bin" / "allure.bat"
def _has_alluredir_arg(args: list[str]) -> bool:
return any(arg == "--alluredir" or arg.startswith("--alluredir=") for arg in args)
def _allure_command() -> str | None:
env_allure_path = os.environ.get("ALLURE_PATH")
if env_allure_path:
return env_allure_path
if LOCAL_ALLURE_PATH.exists():
return str(LOCAL_ALLURE_PATH)
return shutil.which("allure")
def _generate_allure_report() -> None:
allure = _allure_command()
if not allure:
print("未找到 allure 命令,跳过 HTML 报告生成。")
return
command = [
allure,
"generate",
str(ALLURE_RESULTS_DIR),
"-o",
str(ALLURE_REPORT_DIR),
"--clean",
]
subprocess.run(command, cwd=PROJECT_ROOT, check=False)
def main() -> int:
tests_dir = CURRENT_FILE_PATH.parent
pytest_args = sys.argv[1:]
command = [sys.executable, "-m", "pytest", str(tests_dir)]
if not _has_alluredir_arg(pytest_args):
command.append(f"--alluredir={ALLURE_RESULTS_DIR}")
command.extend(pytest_args)
completed = subprocess.run(command, cwd=PROJECT_ROOT)
_generate_allure_report()
return completed.returncode
if __name__ == "__main__":
raise SystemExit(main())

View File

@@ -1,62 +0,0 @@
from pathlib import Path
import re
import sys
import allure
import pytest
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("App下载")
@allure.story("下载页内容")
@allure.title("校验 App 下载页核心内容和下载入口可见")
def test_app_page_key_content_and_download_links_visible(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 Download the App 页面")
page.goto("/app", wait_until="domcontentloaded")
logger.info("校验 App 下载页地址和页面已加载")
expect(page).to_have_url(re.compile(r".*/app/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
logger.info("动态校验下载入口展示,不绑定具体版本文案")
download_links = page.locator('section main a[href]')
expect(download_links.first).to_be_visible(timeout=settings.default_timeout)
download_link_count = download_links.count()
logger.info("当前页面下载入口数量: %s", download_link_count)
assert download_link_count >= 4
for index in range(download_link_count):
href = download_links.nth(index).get_attribute("href")
logger.info("当前下载入口 href: %s", href)
assert href is not None
@allure.feature("App下载")
@allure.story("下载说明")
@allure.title("校验 App 下载页 How to Download APK 按钮可见")
def test_app_page_how_to_download_apk_button_visible(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 Download the App 页面")
page.goto("/app", wait_until="domcontentloaded")
logger.info("动态校验下载说明按钮可见,不绑定按钮文案")
how_to_download_button = page.locator("section main button").first
expect(how_to_download_button).to_be_visible(timeout=settings.default_timeout)
expect(how_to_download_button).to_be_enabled(timeout=settings.default_timeout)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,75 +0,0 @@
from pathlib import Path
import re
import sys
import allure
import pytest
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("App下载")
@allure.story("Google Play 跳转")
@allure.title("点击 Download the App 后校验 Google Play 链接并返回 App 页面")
def test_click_download_the_app_then_google_play_return_app_wait_and_close_browser(page, ensure_guest_user):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
logger.info("点击 /app 导航链接")
page.locator('header a[href="/app"]').first.click()
logger.info("等待跳转到 /app 页面")
expect(page).to_have_url(re.compile(r".*/app/?$"), timeout=settings.default_timeout)
app_page_url = page.url
logger.info("Download the App 页面跳转成功,当前地址: %s", app_page_url)
logger.info("停留 2 秒")
page.wait_for_timeout(2_000)
logger.info("定位 Google Play 按钮")
google_play_button = page.locator('a[href="https://www.cecece"]')
expect(google_play_button).to_be_visible(timeout=settings.default_timeout)
google_play_url = google_play_button.get_attribute("href")
logger.info("拦截 Google Play 外链请求,仅校验跳转地址,不依赖外部服务可用性")
page.route(
re.compile(r"https://www\.cecece/?$"),
lambda route: route.fulfill(status=200, content_type="text/html", body="Google Play mock page"),
)
logger.info("点击 Google Play 按钮,目标地址: %s", google_play_url)
google_play_button.click(no_wait_after=True)
page.wait_for_timeout(1_000)
if page.url == app_page_url and google_play_url:
logger.info("点击后页面未跳转,直接导航到链接地址,仅判断地址栏跳转: %s", google_play_url)
page.goto(google_play_url, wait_until="commit", timeout=5_000)
assert page.url.rstrip("/") == google_play_url.rstrip("/")
logger.info("Google Play 链接跳转成功,当前地址: %s", page.url)
logger.info("停留 2 秒")
page.wait_for_timeout(2_000)
logger.info("返回 Download the App 页面")
page.goto(app_page_url, wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/app/?$"), timeout=settings.default_timeout)
logger.info("已返回 Download the App 页面,当前地址: %s", page.url)
logger.info("停留 2 秒")
page.wait_for_timeout(2_000)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,111 +0,0 @@
from pathlib import Path
import re
import sys
import allure
import pytest
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("FAQ")
@allure.story("FAQ页面内容")
@allure.title("校验 FAQ 页面核心内容和分类链接可见")
def test_faq_page_key_content_visible(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 FAQ 页面")
page.goto("/faq", wait_until="domcontentloaded")
logger.info("校验 FAQ 页面地址、标题和页面内容已加载")
expect(page).to_have_url(re.compile(r".*/faq/?$"), timeout=settings.default_timeout)
assert page.title().strip()
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
faq_links = page.locator('a[href^="/faq/"]')
expect(faq_links.first).to_be_visible(timeout=settings.default_timeout)
assert faq_links.count() > 0
@allure.feature("FAQ")
@allure.story("FAQ分类详情")
@allure.title("校验 FAQ 分类详情链接可见且地址格式正确")
def test_faq_category_detail_link_visible(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 FAQ 页面")
page.goto("/faq", wait_until="domcontentloaded")
logger.info("动态校验 FAQ 分类详情链接可见且地址格式正确")
faq_detail_link = page.locator('a[href^="/faq/"]').first
expect(faq_detail_link).to_be_visible(timeout=settings.default_timeout)
faq_detail_href = faq_detail_link.get_attribute("href")
logger.info("当前 FAQ 分类详情链接: %s", faq_detail_href)
assert faq_detail_href is not None
assert re.match(r"/faq/\d+(\?.*)?$", faq_detail_href)
@allure.feature("FAQ")
@allure.story("提交问题")
@allure.title("游客提交 FAQ 问题表单成功")
def test_faq_submit_question_form_success(page, ensure_guest_user):
logger.info("打开 FAQ 页面")
page.goto("/faq", wait_until="domcontentloaded")
ensure_guest_user()
expect(page).to_have_url(re.compile(r".*/faq/?$"), timeout=settings.default_timeout)
logger.info("点击 Submit a Question 进入问题提交表单")
submit_question_link = page.locator('a[href="/faq/submit-question"]')
expect(submit_question_link).to_be_visible(timeout=settings.default_timeout)
submit_question_link.click()
expect(page).to_have_url(re.compile(r".*/faq/submit-question/?$"), timeout=settings.default_timeout)
logger.info("填写 FAQ 问题提交表单")
name_input = page.locator('input[placeholder="Your Name"]')
email_input = page.locator('input[placeholder="Your Email"]')
order_input = page.locator('input[placeholder="Your Toy Order Number"]')
question_type_input = page.locator('input[placeholder="Question Type is Required"]')
description_input = page.locator("textarea")
send_button = page.get_by_role("button", name="Send message")
expect(name_input).to_be_visible(timeout=settings.default_timeout)
name_input.fill("Auto Test User")
email_input.fill("autotest@example.com")
order_input.fill("AUTO-FAQ-001")
description_input.fill("This is an automated FAQ submit question test. Please ignore.")
logger.info("选择问题类型 Other")
question_type_input.click(force=True)
other_option = page.locator('div[title="Other"]')
expect(other_option).to_be_visible(timeout=settings.default_timeout)
other_option.click(force=True)
expect(question_type_input).to_have_value("Other", timeout=settings.default_timeout)
logger.info("点击 Send message 并校验提交成功")
expect(send_button).to_be_enabled(timeout=settings.default_timeout)
with page.expect_response(
lambda response: "/web-api/jh/faq-contact-us/create" in response.url,
timeout=settings.default_timeout,
) as response_info:
send_button.click()
response = response_info.value
assert response.ok, f"FAQ 提交接口失败: {response.status} {response.url}"
expect(name_input).to_have_value("", timeout=settings.default_timeout)
expect(email_input).to_have_value("", timeout=settings.default_timeout)
expect(order_input).to_have_value("", timeout=settings.default_timeout)
expect(question_type_input).to_have_value("", timeout=settings.default_timeout)
expect(description_input).to_have_value("", timeout=settings.default_timeout)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,13 +0,0 @@
import allure
import pytest
from pages.home_page import HomePage
@allure.feature("首页")
@allure.story("首页加载")
@allure.title("校验 JoyHub 首页加载成功")
@pytest.mark.smoke
def test_home_page_loaded(page):
home_page = HomePage(page)
home_page.open()
home_page.should_be_loaded()

View File

@@ -1,134 +0,0 @@
from pathlib import Path
import re
import sys
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
import allure
from playwright.sync_api import expect
from tests.conftest import accept_cookie_if_present, login_as_configured_user_if_needed
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
POST_DETAIL_MODAL = "div.fixed.inset-0"
POST_CARD_SELECTOR = "div.flex.flex-col.overflow-hidden.rounded-xl.bg-white.cursor-pointer"
def _accept_cookies_if_present(page):
accept_cookie_if_present(page)
def _open_home(page):
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
_accept_cookies_if_present(page)
def _post_cards(page):
return page.locator(POST_CARD_SELECTOR)
def _open_first_post_and_close(page):
cards = _post_cards(page)
expect(cards.first).to_be_visible(timeout=settings.default_timeout)
logger.info("点击首个帖子查看详情")
cards.first.click()
post_modal = page.locator(POST_DETAIL_MODAL).last
expect(post_modal).to_be_visible(timeout=settings.default_timeout)
expect(post_modal).to_contain_text(re.compile(r"Comments|Please log in", re.I), timeout=settings.default_timeout)
logger.info("关闭帖子详情弹窗")
page.keyboard.press("Escape")
expect(post_modal).to_be_hidden(timeout=settings.default_timeout)
def _click_load_more(page):
load_more = page.get_by_text("··· Load More ···").last
expect(load_more).to_be_visible(timeout=settings.default_timeout)
logger.info("滑到底部并点击 Load More")
load_more.scroll_into_view_if_needed()
page.wait_for_timeout(500)
load_more.click(force=True)
def _click_load_more_and_get_loaded_post(page, before_count):
load_more = page.get_by_text("··· Load More ···").last
expect(load_more).to_be_visible(timeout=settings.default_timeout)
logger.info("滑到底部并点击 Load More")
load_more.scroll_into_view_if_needed()
page.wait_for_timeout(500)
load_more.click(force=True)
try:
expect(_post_cards(page)).to_have_count(before_count + 1, timeout=settings.default_timeout)
except AssertionError:
logger.info("Load More 后帖子数量未增加,继续使用当前列表最后一个帖子")
page.wait_for_timeout(1_000)
current_count = _post_cards(page).count()
logger.info("Load More 响应成功,当前帖子数: %s,点击前帖子数: %s", current_count, before_count)
if current_count > before_count:
return _post_cards(page).nth(before_count)
logger.info("Load More 后页面未追加帖子,改为点击当前列表最后一个帖子")
return _post_cards(page).last
def _login(page):
login_as_configured_user_if_needed(page)
expect(page.locator(POST_DETAIL_MODAL).filter(has_text="REGISTER/LOGIN")).to_be_hidden(
timeout=settings.default_timeout
)
@allure.feature("首页帖子")
@allure.story("游客加载更多")
@allure.title("游客查看帖子详情关闭后点击 Load More 校验页面交互")
def test_guest_view_post_close_then_load_more_show_login_modal(page, ensure_guest_user):
_open_home(page)
ensure_guest_user()
_open_first_post_and_close(page)
_click_load_more(page)
logger.info("校验游客点击 Load More 后页面仍可正常交互")
login_modal = page.locator(POST_DETAIL_MODAL).filter(has_text="REGISTER/LOGIN")
try:
expect(login_modal).to_be_visible(timeout=5_000)
expect(login_modal).to_contain_text("Register/Login", timeout=settings.default_timeout)
except AssertionError:
logger.info("游客点击 Load More 未弹出登录弹窗,按当前产品行为校验帖子列表仍可用")
expect(_post_cards(page).first).to_be_visible(timeout=settings.default_timeout)
@allure.feature("首页帖子")
@allure.story("登录用户加载更多")
@allure.title("登录用户查看帖子详情关闭后点击 Load More 并打开新帖子")
def test_login_view_post_close_then_load_more_open_new_post_and_close(page, ensure_logged_in_user):
_open_home(page)
ensure_logged_in_user()
_open_first_post_and_close(page)
before_count = _post_cards(page).count()
logger.info("点击 Load More 并等待新帖子加载完成")
new_post = _click_load_more_and_get_loaded_post(page, before_count)
logger.info("点击加载完成后的帖子")
new_post.scroll_into_view_if_needed()
expect(new_post).to_be_visible(timeout=settings.default_timeout)
new_post.click()
post_modal = page.locator(POST_DETAIL_MODAL).last
expect(post_modal).to_be_visible(timeout=settings.default_timeout)
expect(post_modal).to_contain_text(re.compile(r"Comments|Please log in", re.I), timeout=settings.default_timeout)
logger.info("关闭加载后的新帖子详情弹窗")
page.keyboard.press("Escape")
expect(post_modal).to_be_hidden(timeout=settings.default_timeout)

View File

@@ -1,69 +0,0 @@
from pathlib import Path
import sys
import allure
import pytest
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("登录登出")
@allure.story("邮箱验证码登录")
@allure.title("校验用户登录成功后可退出登录")
def test_login_success_then_logout_wait_3s_and_close_browser(page, ensure_guest_user):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
logger.info("点击登录入口打开登录弹窗")
page.locator("aside button").first.click()
logger.info("动态获取登录弹窗输入框并输入邮箱: %s", settings.login_email)
login_inputs = page.locator('input[type="text"]')
expect(login_inputs.first).to_be_visible(timeout=settings.default_timeout)
login_inputs.nth(0).fill(settings.login_email)
logger.info("输入验证码")
login_inputs.nth(1).fill(settings.verification_code)
logger.info("动态勾选登录确认项")
confirmation_items = page.locator("div.inline-flex.cursor-pointer")
expect(confirmation_items.nth(0)).to_be_visible(timeout=settings.default_timeout)
expect(confirmation_items.nth(1)).to_be_visible(timeout=settings.default_timeout)
confirmation_items.nth(0).click()
confirmation_items.nth(1).click()
logger.info("提交登录")
submit_button = page.locator("button").last
expect(submit_button).to_be_enabled(timeout=settings.default_timeout)
submit_button.click()
logger.info("等待登录成功后出现退出按钮")
logout_button = page.locator("aside button").first
expect(logout_button).to_be_visible(timeout=settings.default_timeout)
logger.info("登录成功,停留 2 秒")
page.wait_for_timeout(2_000)
logger.info("点击 Logout 退出登录")
logout_button.click()
logger.info("校验退出登录成功后重新出现登录入口")
expect(page.locator("aside button").first).to_be_visible(timeout=settings.default_timeout)
logger.info("退出登录成功,停留 3 秒")
page.wait_for_timeout(3_000)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,136 +0,0 @@
from pathlib import Path
import re
import sys
import allure
import pytest
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from tests.test_rewards_shopping_cart_login_logout import (
_accept_cookie_if_present,
_first_visible,
_login_as_configured_user,
)
from utils.logger import get_logger
logger = get_logger(__name__)
MY_ORDER_LINK_SELECTORS = [
'a[href*="order" i]',
'a:has-text("My Order")',
'a:has-text("My Orders")',
'button:has-text("My Order")',
'button:has-text("My Orders")',
'div.cursor-pointer:has-text("My Order")',
'div.cursor-pointer:has-text("My Orders")',
'li:has-text("My Order")',
'li:has-text("My Orders")',
'text=My Order',
'text=My Orders',
]
ORDER_DETAIL_LINK_SELECTORS = [
'a[href*="order" i]',
'button:has-text("Detail")',
'button:has-text("Details")',
'button:has-text("View")',
'button:has-text("View Detail")',
'button:has-text("View Details")',
]
def _click_first_visible_by_selectors(page, selectors, timeout=3_000):
for selector in selectors:
locator = page.locator(selector)
try:
if locator.count() == 0:
continue
candidate = _first_visible(locator)
expect(candidate).to_be_visible(timeout=timeout)
candidate.click()
return selector
except (AssertionError, PlaywrightTimeoutError):
continue
raise AssertionError(f"未找到可点击的可见元素: {selectors}")
def _wait_login_completed(page):
logger.info("等待登录完成并展示用户菜单入口")
page.wait_for_function(
"""
() => {
const visibleText = Array.from(document.querySelectorAll('a,button,div,li,span'))
.filter(element => !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length))
.map(element => element.innerText || element.textContent || '')
.join(' ');
return /My Order|Logout|Create/i.test(visibleText) && !/^\\s*Login\\s*$/.test(visibleText);
}
""",
timeout=settings.default_timeout,
)
def _open_my_order_from_home(page):
logger.info("从首页查找 My Order 入口")
try:
selector = _click_first_visible_by_selectors(page, MY_ORDER_LINK_SELECTORS)
logger.info("已通过首页可见入口进入 My Order: %s", selector)
return
except AssertionError:
logger.info("首页未直接展示 My Order尝试点击用户侧边栏入口后继续查找")
aside_buttons = page.locator("aside button")
expect(aside_buttons.first).to_be_visible(timeout=settings.default_timeout)
aside_buttons.first.click()
page.wait_for_timeout(1_000)
selector = _click_first_visible_by_selectors(page, MY_ORDER_LINK_SELECTORS, timeout=settings.default_timeout)
logger.info("已通过用户菜单进入 My Order: %s", selector)
def _open_first_order_detail(page):
logger.info("等待进入订单列表页")
expect(page).to_have_url(re.compile(r".*order.*", re.I), timeout=settings.default_timeout)
expect(page.get_by_text(re.compile(r"my order|orders?|order", re.I)).first).to_be_visible(
timeout=settings.default_timeout
)
logger.info("点击第一笔订单详情入口")
before_url = page.url
selector = _click_first_visible_by_selectors(page, ORDER_DETAIL_LINK_SELECTORS, timeout=settings.default_timeout)
logger.info("已点击订单详情入口: %s", selector)
try:
page.wait_for_url(lambda url: url != before_url, timeout=settings.default_timeout)
except PlaywrightTimeoutError:
logger.info("点击第一笔订单后 URL 未变化,继续校验当前页面是否展示详情内容")
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
expect(page.get_by_text(re.compile(r"order|detail|status|total|payment|shipping", re.I)).first).to_be_visible(
timeout=settings.default_timeout
)
@allure.feature("我的订单")
@allure.story("订单详情")
@allure.title("登录用户从首页进入 My Order 并查看第一笔订单详情")
def test_home_my_order_first_order_detail_after_login(page, ensure_logged_in_user):
logger.info("登录用户从首页进入 My Order 并查看第一笔订单详情")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_logged_in_user()
_wait_login_completed(page)
_open_my_order_from_home(page)
_open_first_order_detail(page)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,177 +0,0 @@
from pathlib import Path
import random
import re
import sys
import allure
import pytest
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("导航")
@allure.story("顶部导航")
@allure.title("通过顶部导航进入 App 下载页并返回首页")
def test_header_download_app_navigation_then_home_return(page, ensure_guest_user):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
logger.info("点击顶部 /app 导航链接")
page.locator('header a[href="/app"]').first.click()
logger.info("校验跳转到 /app 页面")
expect(page).to_have_url(re.compile(r".*/app/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
logger.info("点击顶部首页链接返回首页")
page.locator('header a[href="/"]').first.click()
logger.info("校验返回首页成功")
expect(page).to_have_url(re.compile(r".*/?$"), timeout=settings.default_timeout)
expect(page.locator('button').first).to_be_visible(timeout=settings.default_timeout)
@allure.feature("导航")
@allure.story("底部导航")
@allure.title("校验底部 Partnerships 和 FAQ 导航链接可用")
def test_footer_navigation_to_partnerships_and_faq(page, ensure_guest_user):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
logger.info("校验底部 Partnerships 和 FAQs 链接存在")
expect(page.locator('footer a[href="/partnerships"]')).to_be_attached(timeout=settings.default_timeout)
expect(page.locator('footer a[href="/faq"]')).to_be_attached(timeout=settings.default_timeout)
logger.info("打开 Partnerships 页面")
page.goto("/partnerships", wait_until="domcontentloaded")
logger.info("校验跳转到 Partnerships 页面")
expect(page).to_have_url(re.compile(r".*/partnerships/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
logger.info("打开 FAQ 页面")
page.goto("/faq", wait_until="domcontentloaded")
logger.info("校验跳转到 FAQ 页面")
expect(page).to_have_url(re.compile(r".*/faq/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
@allure.feature("导航")
@allure.story("About Us Blog")
@allure.title("从 About Us 进入 Blog 并随机浏览分类文章")
def test_about_us_blog_random_category_article_browse_success(page, ensure_guest_user, attach_page_screenshot):
logger.info("打开首页并进入 About Us 下的 Blog 页面")
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
page.wait_for_timeout(2_000)
about_us_menu = page.get_by_text("About Us", exact=True).first
expect(about_us_menu).to_be_visible(timeout=settings.default_timeout)
about_us_menu.click()
blog_link = page.locator('a[href="/blog-detail"]', has_text="Blog").first
expect(blog_link).to_be_visible(timeout=settings.default_timeout)
blog_link.click()
logger.info("校验 Blog 页面加载成功")
expect(page).to_have_url(re.compile(r".*/blog-detail/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_contain_text("SEXUAL WELLNESS HUB", timeout=settings.default_timeout)
category_buttons = page.locator("button").filter(has_not_text=re.compile(r"^\\d+$|Acce?pet", re.I))
expect(category_buttons.first).to_be_visible(timeout=settings.default_timeout)
category_count = category_buttons.count()
category_indexes = list(range(category_count))
random.shuffle(category_indexes)
selected_category = None
article_links = page.locator('a[href^="/blog-detail/"]')
for category_index in category_indexes:
category_button = category_buttons.nth(category_index)
selected_category = category_button.inner_text(timeout=settings.default_timeout).strip()
logger.info("随机选择 Blog 分类: %s", selected_category)
category_button.click()
page.wait_for_load_state("domcontentloaded")
try:
expect(article_links.first).to_be_visible(timeout=5_000)
if article_links.count() > 0:
break
except AssertionError:
logger.info("分类 %s 下暂无可浏览 Blog继续随机尝试其他分类", selected_category)
else:
raise AssertionError("所有 Blog 分类下均未找到可浏览文章")
article_count = article_links.count()
article_index = random.randrange(article_count)
article_link = article_links.nth(article_index)
article_title = article_link.inner_text(timeout=settings.default_timeout).strip()
logger.info("随机浏览 Blog 文章: %s", article_title)
article_href = article_link.get_attribute("href")
assert article_href is not None
article_link.scroll_into_view_if_needed(timeout=settings.default_timeout)
article_link.click()
logger.info("校验 Blog 详情页加载成功并截图")
expect(page).to_have_url(re.compile(r".*/blog-detail/.+"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
if article_title:
expect(page.locator("body")).to_contain_text(article_title, timeout=settings.default_timeout)
attach_page_screenshot(f"Blog浏览成功_{selected_category}_{article_title or article_href}")
@allure.feature("导航")
@allure.story("社交媒体链接")
@allure.title("校验底部社交媒体链接 href 配置正确")
def test_footer_social_media_links_open_then_return_home(page, ensure_guest_user):
social_links = [
("X", 'a[href="https://x.com/JoyhubOfficial"]', re.compile(r"https://(x|twitter)\.com/.*", re.I)),
(
"Instagram",
'a[href="https://www.instagram.com/joyhub.official/#"]',
re.compile(r"https://www\.instagram\.com/.*", re.I),
),
(
"Reddit",
'a[href="https://www.reddit.com/r/JoyhubRemote/"]',
re.compile(r"https://www\.reddit\.com/.*", re.I),
),
(
"Discord",
'a[href="https://discord.com/invite/vZFQbTRZqe"]',
re.compile(r"https://discord\.com/.*", re.I),
),
]
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
for name, selector, expected_url in social_links:
logger.info("滚动到首页底部,校验 %s 社交媒体链接 href", name)
page.evaluate("window.scrollTo(0, document.body.scrollHeight)")
link = page.locator(selector).first
expect(link).to_be_attached(timeout=settings.default_timeout)
link.scroll_into_view_if_needed(timeout=settings.default_timeout)
social_href = link.get_attribute("href")
assert social_href is not None
assert expected_url.search(social_href), f"{name} 社交媒体链接不符合预期: {social_href}"
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,32 +0,0 @@
from pathlib import Path
import sys
import allure
import pytest
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("浏览器")
@allure.story("Chromium启动")
@allure.title("打开 Chromium 浏览器访问首页并等待关闭")
def test_open_chromium_browser_wait_10s_then_close(page, ensure_guest_user):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url)
ensure_guest_user()
logger.info("等待 10 秒")
page.wait_for_timeout(10_000)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,78 +0,0 @@
from pathlib import Path
import re
import sys
import allure
import pytest
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
@allure.feature("合作伙伴")
@allure.story("合作页内容")
@allure.title("校验 Partnerships 页面核心内容可见")
def test_partnerships_page_key_content_visible(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 Partnerships 页面")
page.goto("/partnerships", wait_until="domcontentloaded")
logger.info("校验 Partnerships 页面地址、标题和页面内容已加载")
expect(page).to_have_url(re.compile(r".*/partnerships/?$"), timeout=settings.default_timeout)
assert page.title().strip()
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
visible_headings_count = page.get_by_role("heading").count()
logger.info("当前 Partnerships 页面标题元素数量: %s", visible_headings_count)
assert visible_headings_count > 0
@allure.feature("合作伙伴")
@allure.story("合作表单")
@allure.title("校验 Partnerships 合作表单字段可见且可编辑")
def test_partnerships_contact_form_fields_visible_and_editable(page):
logger.info("使用 pytest-playwright 统一无头浏览器配置")
logger.info("打开 Partnerships 页面")
page.goto("/partnerships", wait_until="domcontentloaded")
logger.info("动态校验合作表单字段可见并可输入")
form_inputs = page.locator('section input[type="text"]:not([readonly])')
form_textareas = page.locator("section textarea")
submit_button = page.locator("section button").last
name_input = form_inputs.nth(0)
email_input = form_inputs.nth(1)
business_input = form_inputs.nth(2)
collaboration_input = page.locator('section input[readonly]').first
message_input = form_textareas.first
expect(name_input).to_be_editable(timeout=settings.default_timeout)
expect(email_input).to_be_editable(timeout=settings.default_timeout)
expect(business_input).to_be_editable(timeout=settings.default_timeout)
expect(message_input).to_be_editable(timeout=settings.default_timeout)
name_input.fill("Joyhub Tester")
email_input.fill("tester@example.com")
business_input.fill("https://example.com")
message_input.fill("I want to explore product testing collaboration.")
expect(name_input).to_have_value("Joyhub Tester", timeout=settings.default_timeout)
expect(email_input).to_have_value("tester@example.com", timeout=settings.default_timeout)
expect(business_input).to_have_value("https://example.com", timeout=settings.default_timeout)
expect(collaboration_input).to_be_visible(timeout=settings.default_timeout)
expect(collaboration_input).to_have_attribute("readonly", "", timeout=settings.default_timeout)
expect(message_input).to_have_value("I want to explore product testing collaboration.", timeout=settings.default_timeout)
expect(submit_button).to_be_visible(timeout=settings.default_timeout)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,159 +0,0 @@
from pathlib import Path
import random
import re
import sys
import allure
import pytest
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from tests.test_rewards_shopping_cart_login_logout import _accept_cookie_if_present
from utils.logger import get_logger
logger = get_logger(__name__)
REDEEM_NOW_SELECTORS = [
'button:has-text("Redeem Now"):not([disabled])',
'button:has-text("Redeem now"):not([disabled])',
'button:has-text("立即兑换"):not([disabled])',
]
POINTS_PAY_SELECTORS = [
'button:has-text("Pay"):not([disabled])',
'button:has-text("Confirm"):not([disabled])',
'button:has-text("Submit"):not([disabled])',
'button:has-text("Place Order"):not([disabled])',
'button:has-text("Redeem"):not([disabled])',
'button:has-text("Confirm Redemption"):not([disabled])',
'button:has-text("确认"):not([disabled])',
'button:has-text("提交"):not([disabled])',
'button:has-text("支付"):not([disabled])',
]
def _visible_locator(page, selectors, timeout=5_000):
for selector in selectors:
locator = page.locator(selector).first
try:
if locator.is_visible(timeout=timeout):
return locator
except PlaywrightTimeoutError:
continue
raise AssertionError(f"未找到可见元素: {selectors}")
def _login_in_open_dialog(page):
logger.info("在 Redeem Now 触发的登录弹窗中登录")
login_inputs = page.locator('input[type="text"]')
expect(login_inputs.first).to_be_visible(timeout=settings.default_timeout)
login_inputs.nth(0).fill(settings.login_email)
login_inputs.nth(1).fill(settings.verification_code)
confirmation_items = page.locator("div.inline-flex.cursor-pointer")
expect(confirmation_items.nth(0)).to_be_visible(timeout=settings.default_timeout)
expect(confirmation_items.nth(1)).to_be_visible(timeout=settings.default_timeout)
confirmation_items.nth(0).click()
confirmation_items.nth(1).click()
submit_button = page.locator("button").last
expect(submit_button).to_be_enabled(timeout=settings.default_timeout)
submit_button.click()
logger.info("等待登录弹窗关闭或兑换流程继续")
expect(login_inputs.first).not_to_be_visible(timeout=settings.default_timeout)
def _open_points_redemption_from_rewards(page):
logger.info("未登录用户点击 Rewards 并进入 Points Redemption")
rewards_link = page.locator('header a[href^="javascript:"]').filter(has_text="Rewards").first
expect(rewards_link).to_be_attached(timeout=settings.default_timeout)
rewards_link.click(force=True)
try:
page.wait_for_function(
"""
() => Array.from(document.querySelectorAll('a[href="/points-redemption"]'))
.some(element => !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length))
""",
timeout=5_000,
)
page.locator('a[href="/points-redemption"]').filter(has_text="Points Redemption").first.click()
except PlaywrightTimeoutError:
logger.info("Rewards 下拉入口未稳定展示,直接进入 Points Redemption 页面")
page.goto(settings.base_url.rstrip("/") + "/points-redemption", wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/points-redemption/?"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
def _open_random_redeemable_points_product(page):
logger.info("随机选择一个积分商品并查找 Redeem Now")
category_buttons = page.locator("section button").filter(has_not_text=re.compile(r"Accepet|Accept", re.I))
expect(category_buttons.first).to_be_visible(timeout=settings.default_timeout)
category_indices = list(range(category_buttons.count()))
random.shuffle(category_indices)
last_error = None
for category_index in category_indices:
try:
logger.info("尝试积分商品分类/商品入口索引: %s", category_index)
category_buttons.nth(category_index).click()
page.wait_for_timeout(1_500)
if page.get_by_text(re.compile(r"currently do not support delivery", re.I)).first.is_visible(timeout=1_000):
last_error = "当前国家/地区不支持积分商品配送"
continue
redeem_button = _visible_locator(page, REDEEM_NOW_SELECTORS, timeout=5_000)
expect(redeem_button).to_be_enabled(timeout=settings.default_timeout)
redeem_button.click()
return
except (AssertionError, PlaywrightTimeoutError) as exc:
last_error = exc
logger.info("当前积分商品不可兑换,继续尝试下一个: %s", exc)
pytest.skip(f"当前测试环境未展示可兑换积分商品,无法执行 Redeem Now 主流程: {last_error}")
def _complete_points_payment_after_login(page):
logger.info("登录后继续完成积分商品支付/兑换")
try:
pay_button = _visible_locator(page, POINTS_PAY_SELECTORS, timeout=settings.default_timeout)
expect(pay_button).to_be_enabled(timeout=settings.default_timeout)
pay_button.click()
except AssertionError:
logger.info("登录后未出现独立确认按钮,检查是否已自动提交兑换")
result_text = page.get_by_text(
re.compile(r"success|successful|completed|paid|payment|order|redeem|redemption|成功|订单|兑换", re.I)
).first
expect(result_text).to_be_visible(timeout=settings.default_timeout)
@allure.feature("积分兑换")
@allure.story("积分商品支付")
@allure.title("游客兑换积分商品后登录并完成积分支付")
def test_guest_points_product_redeem_now_login_then_points_payment_result(page, ensure_guest_user):
logger.info("未登录用户从 Rewards 选择积分商品Redeem Now 后登录并完成积分支付")
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
_open_points_redemption_from_rewards(page)
_open_random_redeemable_points_product(page)
logger.info("校验 Redeem Now 后弹出登录弹窗")
expect(page.locator('input[type="text"]').first).to_be_visible(timeout=settings.default_timeout)
_login_in_open_dialog(page)
_complete_points_payment_after_login(page)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,167 +0,0 @@
from pathlib import Path
import random
import re
import sys
import allure
import pytest
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import expect
from tests.conftest import accept_cookie_if_present, login_as_configured_user_if_needed
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
def _accept_cookie_if_present(page):
accept_cookie_if_present(page)
def _first_visible(locator):
locator_count = locator.count()
for index in range(locator_count):
candidate = locator.nth(index)
if candidate.is_visible():
return candidate
raise AssertionError("未找到可见元素")
def _login_as_configured_user(page):
login_as_configured_user_if_needed(page)
def _add_random_shopping_product_to_cart(page):
logger.info("直接进入 Shopping 页面")
page.goto(settings.base_url.rstrip("/") + "/shopping", wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/shopping/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
logger.info("动态获取分类列表并随机选择商品加购")
category_buttons = page.locator("section > div:nth-of-type(1) > div:nth-of-type(2) > div:nth-of-type(1) button")
expect(category_buttons.first).to_be_visible(timeout=settings.default_timeout)
category_count = category_buttons.count()
logger.info("当前分类数量: %s", category_count)
assert category_count > 0
category_indices = list(range(category_count))
random.shuffle(category_indices)
logger.info("随机分类尝试顺序: %s", category_indices)
last_error = None
for selected_category_index in category_indices:
logger.info("随机选择分类索引: %s", selected_category_index)
category_buttons.nth(selected_category_index).click()
page.wait_for_timeout(1_000)
logger.info("动态获取商品列表")
product_links = page.locator('section a[href^="/shopping/"][href*="selectedSkuId"]').evaluate_all(
"""
links => Array.from(new Map(
links
.map(link => link.getAttribute('href'))
.filter(Boolean)
.map(href => [href, href])
).values())
"""
)
logger.info("当前可进入详情的商品数量: %s", len(product_links))
random.shuffle(product_links)
for selected_product_href in product_links:
try:
logger.info("尝试加购商品: %s", selected_product_href)
page.goto(settings.base_url.rstrip("/") + selected_product_href, wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/shopping/.+selectedSkuId=.+"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
logger.info("动态获取商品规格行,逐行随机选择一个可用规格")
spec_rows = page.locator(".product-specs-scrollbar > div").filter(has=page.locator("button"))
expect(spec_rows.first).to_be_visible(timeout=settings.default_timeout)
spec_row_count = spec_rows.count()
logger.info("当前规格行数量: %s", spec_row_count)
assert spec_row_count > 0
selected_spec_count = 0
for row_index in range(spec_row_count):
spec_options = spec_rows.nth(row_index).locator("button:not([disabled])")
spec_option_count = spec_options.count()
logger.info("规格行 %s 可选项数量: %s", row_index, spec_option_count)
if spec_option_count == 0:
continue
selected_spec_index = random.randrange(spec_option_count)
logger.info("规格行 %s 随机选择选项索引: %s", row_index, selected_spec_index)
spec_options.nth(selected_spec_index).click()
selected_spec_count += 1
page.wait_for_timeout(300)
assert selected_spec_count > 0
logger.info("动态点击数量增加按钮")
increase_quantity_button = page.locator("button:has(svg.lucide-plus):not([disabled])").first
try:
if increase_quantity_button.is_visible(timeout=3_000):
increase_click_count = random.randint(1, 3)
logger.info("随机增加商品数量次数: %s", increase_click_count)
for _ in range(increase_click_count):
increase_quantity_button.click()
page.wait_for_timeout(200)
except PlaywrightTimeoutError:
logger.info("当前商品未展示数量增加按钮,使用默认购买数量")
logger.info("动态获取加购按钮并点击")
add_to_cart_button = page.locator("button.bg-primary.text-white:not([disabled])").first
expect(add_to_cart_button).to_be_visible(timeout=settings.default_timeout)
expect(add_to_cart_button).to_be_enabled(timeout=settings.default_timeout)
add_to_cart_button.click()
logger.info("校验购物车入口仍可见,表示加购流程已完成点击")
expect(page.locator('a[href="/view-cart"]').first).to_be_visible(timeout=settings.default_timeout)
return
except (AssertionError, PlaywrightTimeoutError) as exc:
last_error = exc
logger.info("当前商品不可加购,继续尝试下一个商品: %s", exc)
page.goto(settings.base_url.rstrip("/") + "/shopping", wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/shopping/?$"), timeout=settings.default_timeout)
category_buttons = page.locator(
"section > div:nth-of-type(1) > div:nth-of-type(2) > div:nth-of-type(1) button"
)
category_buttons.nth(selected_category_index).click()
page.wait_for_timeout(1_000)
raise AssertionError(f"未找到可加购的随机商品: {last_error}")
@allure.feature("Rewards Shopping")
@allure.story("游客加购")
@allure.title("游客随机选择 Rewards Shopping 商品并加入购物车")
def test_rewards_shopping_random_product_add_to_cart_no_login(page, ensure_guest_user):
logger.info("使用游客身份执行 Rewards Shopping 随机商品加购")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
_add_random_shopping_product_to_cart(page)
@allure.feature("Rewards Shopping")
@allure.story("登录用户加购")
@allure.title("登录用户随机选择 Rewards Shopping 商品并加入购物车")
def test_rewards_shopping_random_product_add_to_cart_after_login(page, ensure_logged_in_user):
logger.info("使用登录用户身份执行 Rewards Shopping 随机商品加购")
logger.info("打开链接地址: %s", settings.base_url)
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_logged_in_user()
_add_random_shopping_product_to_cart(page)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,278 +0,0 @@
from pathlib import Path
import random
import re
import sys
import allure
import pytest
from playwright.sync_api import Error as PlaywrightError
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from tests.test_rewards_shopping_cart_login_logout import (
_accept_cookie_if_present,
_first_visible,
_login_as_configured_user,
)
from utils.logger import get_logger
logger = get_logger(__name__)
PAYPAL_EMAIL_SELECTORS = [
'input[name="login_email"]',
'input[name="email"]',
'input#email',
]
PAYPAL_PASSWORD_SELECTORS = [
'input[name="login_password"]',
'input[name="password"]',
'input#password',
]
PAYPAL_NEXT_SELECTORS = [
'button:has-text("Next")',
'input[type="submit"][value="Next"]',
'button#btnNext',
]
PAYPAL_LOGIN_SELECTORS = [
'button:has-text("Log In")',
'button:has-text("Log in")',
'button:has-text("Login")',
'button#btnLogin',
'input[type="submit"][value="Log In"]',
]
PAYPAL_PAY_SELECTORS = [
'button:has-text("Complete Purchase")',
'button:has-text("Pay Now")',
'button:has-text("Agree and Pay")',
'button:has-text("Continue")',
'button:has-text("Review Order")',
'input[type="submit"][value*="Pay"]',
]
def _visible_locator(page, selectors, timeout=5_000):
for selector in selectors:
locator = page.locator(selector).first
try:
if locator.is_visible(timeout=timeout):
return locator
except PlaywrightTimeoutError:
continue
raise AssertionError(f"未找到可见元素: {selectors}")
def _add_random_shopping_product_directly(page):
logger.info("直接进入 Shopping 页面并随机加购商品")
page.goto(settings.base_url.rstrip("/") + "/shopping", wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/shopping/?$"), timeout=settings.default_timeout)
category_buttons = page.locator("section > div:nth-of-type(1) > div:nth-of-type(2) > div:nth-of-type(1) button")
expect(category_buttons.first).to_be_visible(timeout=settings.default_timeout)
category_indices = list(range(category_buttons.count()))
random.shuffle(category_indices)
product_links = []
for selected_category_index in category_indices:
category_buttons.nth(selected_category_index).click()
page.wait_for_timeout(1_000)
product_links = page.locator('section a[href^="/shopping/"][href*="selectedSkuId"]').evaluate_all(
"""
links => Array.from(new Map(
links
.map(link => link.getAttribute('href'))
.filter(Boolean)
.map(href => [href, href])
).values())
"""
)
if product_links:
break
assert product_links
selected_product_href = random.choice(product_links)
_first_visible(page.locator(f'section a[href="{selected_product_href}"]')).click()
expect(page).to_have_url(re.compile(r".*/shopping/.+selectedSkuId=.+"), timeout=settings.default_timeout)
spec_rows = page.locator(".product-specs-scrollbar > div").filter(has=page.locator("button"))
expect(spec_rows.first).to_be_visible(timeout=settings.default_timeout)
selected_spec_count = 0
for row_index in range(spec_rows.count()):
spec_options = spec_rows.nth(row_index).locator("button:not([disabled])")
spec_option_count = spec_options.count()
if spec_option_count == 0:
continue
spec_options.nth(random.randrange(spec_option_count)).click()
selected_spec_count += 1
page.wait_for_timeout(300)
assert selected_spec_count > 0
increase_quantity_button = page.locator("button:has(svg.lucide-plus):not([disabled])").first
try:
if increase_quantity_button.is_visible(timeout=3_000):
for _ in range(random.randint(1, 3)):
increase_quantity_button.click()
page.wait_for_timeout(200)
except PlaywrightTimeoutError:
logger.info("当前商品未展示数量增加按钮,使用默认购买数量")
add_to_cart_button = page.locator("button.bg-primary.text-white:not([disabled])").first
expect(add_to_cart_button).to_be_visible(timeout=settings.default_timeout)
expect(add_to_cart_button).to_be_enabled(timeout=settings.default_timeout)
add_to_cart_button.click()
expect(page.locator('a[href="/view-cart"]').first).to_be_visible(timeout=settings.default_timeout)
def _go_to_cart(page):
logger.info("进入购物车页面")
page.goto(settings.base_url.rstrip("/") + "/view-cart", wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/view-cart/?$"), timeout=settings.default_timeout)
expect(page.locator('iframe[title="PayPal-paypal"]').first).to_be_attached(timeout=settings.default_timeout)
def _add_random_one_or_more_products(page):
product_count = random.randint(1, 2)
logger.info("随机加入商品数量种类: %s", product_count)
for index in range(product_count):
logger.info("执行第 %s 次随机商品加购", index + 1)
_add_random_shopping_product_directly(page)
if index < product_count - 1:
page.goto(settings.base_url, wait_until="domcontentloaded")
def _trigger_paypal_payment(page):
logger.info("等待 PayPal 支付按钮渲染")
expect(page.locator('iframe[title="PayPal-paypal"]').first).to_be_attached(timeout=settings.default_timeout)
page.wait_for_timeout(3_000)
logger.info("坐标点击页面主 DOM 中可见的 PayPal 按钮")
paypal_buttons = page.locator('button[class*="FFCE0C"]')
for index in range(paypal_buttons.count()):
paypal_button = paypal_buttons.nth(index)
try:
if not paypal_button.is_visible(timeout=1_000):
continue
if not paypal_button.is_enabled(timeout=1_000):
continue
box = paypal_button.bounding_box()
if not box:
continue
try:
with page.expect_popup(timeout=10_000) as popup_info:
page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
paypal_page = popup_info.value
except PlaywrightTimeoutError:
logger.info("未捕获到 PayPal 弹窗,检查当前页是否已跳转")
page.wait_for_timeout(3_000)
if "paypal" in page.url.lower():
paypal_page = page
else:
continue
try:
paypal_page.wait_for_load_state("domcontentloaded", timeout=settings.default_timeout)
try:
paypal_page.wait_for_url(re.compile(r".*paypal.*"), timeout=settings.default_timeout)
except PlaywrightTimeoutError:
logger.info("PayPal 页面当前地址未包含 paypal: %s", paypal_page.url)
expect(paypal_page.locator("body")).to_be_visible(timeout=settings.default_timeout)
return paypal_page
except PlaywrightError as exc:
logger.info("PayPal 弹窗已被触发但提前关闭: %s", exc)
return None
except PlaywrightTimeoutError:
logger.info("当前 PayPal 按钮未触发支付页,继续尝试下一个按钮")
raise AssertionError("未找到可点击并能打开支付页的 PayPal 按钮")
def _login_paypal_if_required(paypal_page):
logger.info("处理 PayPal 登录页面")
try:
email_input = _visible_locator(paypal_page, PAYPAL_EMAIL_SELECTORS)
except AssertionError:
logger.info("PayPal 当前页面未出现邮箱输入框,可能已保持登录态")
return
email_input.fill(settings.paypal_email)
try:
next_button = _visible_locator(paypal_page, PAYPAL_NEXT_SELECTORS, timeout=3_000)
next_button.click()
except AssertionError:
logger.info("PayPal 未出现 Next 按钮,继续查找密码输入框")
password_input = _visible_locator(paypal_page, PAYPAL_PASSWORD_SELECTORS)
password_input.fill(settings.paypal_password)
login_button = _visible_locator(paypal_page, PAYPAL_LOGIN_SELECTORS)
expect(login_button).to_be_enabled(timeout=settings.default_timeout)
login_button.click()
paypal_page.wait_for_load_state("domcontentloaded", timeout=settings.default_timeout)
def _complete_paypal_payment(page, paypal_page):
logger.info("在 PayPal 页面确认支付")
pay_button = _visible_locator(paypal_page, PAYPAL_PAY_SELECTORS, timeout=settings.default_timeout)
expect(pay_button).to_be_enabled(timeout=settings.default_timeout)
pay_button.click()
logger.info("等待 PayPal 支付完成并返回商户站点")
try:
paypal_page.wait_for_close(timeout=settings.default_timeout)
except PlaywrightTimeoutError:
logger.info("PayPal 弹窗未自动关闭,继续等待主页面跳转")
page.wait_for_load_state("domcontentloaded", timeout=settings.default_timeout)
expect(page).to_have_url(re.compile(r".*joyhub-website-frontend-test.*"), timeout=settings.default_timeout)
success_text = page.get_by_text(re.compile(r"success|paid|payment|order", re.I)).first
expect(success_text).to_be_visible(timeout=settings.default_timeout)
def _pay_random_shopping_products(page):
_add_random_one_or_more_products(page)
_go_to_cart(page)
paypal_page = _trigger_paypal_payment(page)
if not settings.run_paypal_payment:
logger.info("RUN_PAYPAL_PAYMENT 未开启,仅校验支付入口可触发")
expect(page).to_have_url(re.compile(r".*/view-cart/?$"), timeout=settings.default_timeout)
return
assert paypal_page is not None, "PayPal 弹窗已触发但提前关闭,无法继续真实付款"
_login_paypal_if_required(paypal_page)
_complete_paypal_payment(page, paypal_page)
@allure.feature("Rewards Shopping")
@allure.story("游客支付")
@allure.title("游客随机选择 Rewards Shopping 商品并触发 PayPal 支付")
def test_rewards_shopping_random_products_payment_no_login(page, ensure_guest_user):
logger.info("使用游客身份执行随机商品 PayPal 支付")
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
_pay_random_shopping_products(page)
@allure.feature("Rewards Shopping")
@allure.story("登录用户支付")
@allure.title("登录用户随机选择 Rewards Shopping 商品并触发 PayPal 支付")
def test_rewards_shopping_random_products_payment_after_login(page, ensure_logged_in_user):
logger.info("使用登录用户身份执行随机商品 PayPal 支付")
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_logged_in_user()
_pay_random_shopping_products(page)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,192 +0,0 @@
from pathlib import Path
import random
import re
import sys
import allure
import pytest
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import expect
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from config.settings import settings
from utils.logger import get_logger
logger = get_logger(__name__)
LANGUAGE_OPTIONS = ["English", "Français"]
def _visible_header(page):
headers = page.locator("header")
for index in range(headers.count()):
header = headers.nth(index)
try:
if header.is_visible(timeout=1_000):
return header
except PlaywrightTimeoutError:
continue
raise AssertionError("未找到可见的页面头部")
def _visible_dropdown_options(page):
return page.locator('div[class*="hover:bg-grey700"]').filter(visible=True)
def _select_random_language(page):
header = _visible_header(page)
language_trigger = header.locator("div.cursor-pointer").nth(3)
expect(language_trigger).to_be_visible(timeout=settings.default_timeout)
language_trigger.click()
options = _visible_dropdown_options(page)
available_languages = []
for index in range(options.count()):
option_text = options.nth(index).inner_text(timeout=3_000).strip()
if option_text in LANGUAGE_OPTIONS:
available_languages.append(option_text)
assert available_languages, "语言下拉没有可选项"
selected_language = random.choice(available_languages)
logger.info("随机选择语言: %s,可选语言: %s", selected_language, available_languages)
options.filter(has_text=re.compile(rf"^{re.escape(selected_language)}$")).first.click()
page.wait_for_load_state("domcontentloaded", timeout=settings.default_timeout)
page.wait_for_timeout(1_000)
return selected_language
def _select_random_country(page):
header = _visible_header(page)
country_trigger = header.locator("div.cursor-pointer").nth(4)
expect(country_trigger).to_be_visible(timeout=settings.default_timeout)
country_trigger.click()
options = _visible_dropdown_options(page)
expect(options.first).to_be_visible(timeout=settings.default_timeout)
countries = []
for index in range(options.count()):
country_text = options.nth(index).inner_text(timeout=3_000).strip()
if country_text and country_text not in LANGUAGE_OPTIONS:
countries.append(country_text)
assert countries, "国家下拉没有可选项"
selected_country = random.choice(countries)
logger.info("随机选择国家: %s,可选国家数量: %s", selected_country, len(countries))
options.filter(has_text=re.compile(rf"^{re.escape(selected_country)}$")).first.click()
page.wait_for_load_state("domcontentloaded", timeout=settings.default_timeout)
page.wait_for_timeout(1_000)
return selected_country
def _shopping_product_links(page):
return page.locator('section a[href^="/shopping/"][href*="selectedSkuId"]').evaluate_all(
"""
links => Array.from(new Map(
links
.map(link => link.getAttribute('href'))
.filter(Boolean)
.map(href => [href, href])
).values())
"""
)
def _find_random_product_href_or_none(page):
logger.info("进入 Shopping 页面,查找当前国家可选商品")
page.goto(settings.base_url.rstrip("/") + "/shopping", wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/shopping/?$"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
page.wait_for_timeout(2_000)
category_buttons = page.locator("section > div:nth-of-type(1) > div:nth-of-type(2) > div:nth-of-type(1) button")
try:
if not category_buttons.first.is_visible(timeout=5_000):
logger.info("当前国家 Shopping 页面无分类,认为没有商品可选")
return None
except PlaywrightTimeoutError:
logger.info("当前国家 Shopping 页面未加载到分类,认为没有商品可选")
return None
category_indices = list(range(category_buttons.count()))
random.shuffle(category_indices)
logger.info("随机分类尝试顺序: %s", category_indices)
for category_index in category_indices:
category_buttons.nth(category_index).click()
page.wait_for_timeout(1_000)
product_links = _shopping_product_links(page)
logger.info("分类索引 %s 可进入详情的商品数量: %s", category_index, len(product_links))
if product_links:
return random.choice(product_links)
return None
def _add_product_to_cart(page, product_href):
logger.info("进入随机商品详情并加购: %s", product_href)
page.goto(settings.base_url.rstrip("/") + product_href, wait_until="domcontentloaded")
expect(page).to_have_url(re.compile(r".*/shopping/.+selectedSkuId=.+"), timeout=settings.default_timeout)
expect(page.locator("body")).to_be_visible(timeout=settings.default_timeout)
spec_rows = page.locator(".product-specs-scrollbar > div").filter(has=page.locator("button"))
expect(spec_rows.first).to_be_visible(timeout=settings.default_timeout)
selected_spec_count = 0
for row_index in range(spec_rows.count()):
spec_options = spec_rows.nth(row_index).locator("button:not([disabled])")
spec_option_count = spec_options.count()
if spec_option_count == 0:
continue
selected_spec_index = random.randrange(spec_option_count)
logger.info("规格行 %s 随机选择选项索引: %s", row_index, selected_spec_index)
spec_options.nth(selected_spec_index).click()
selected_spec_count += 1
page.wait_for_timeout(300)
assert selected_spec_count > 0, "商品详情没有可选规格"
increase_quantity_button = page.locator("button:has(svg.lucide-plus):not([disabled])").first
try:
if increase_quantity_button.is_visible(timeout=3_000):
increase_click_count = random.randint(1, 3)
logger.info("随机增加商品数量次数: %s", increase_click_count)
for _ in range(increase_click_count):
increase_quantity_button.click()
page.wait_for_timeout(200)
except PlaywrightTimeoutError:
logger.info("当前商品未展示数量增加按钮,使用默认购买数量")
add_to_cart_button = page.locator("button.bg-primary.text-white:not([disabled])").first
expect(add_to_cart_button).to_be_visible(timeout=settings.default_timeout)
expect(add_to_cart_button).to_be_enabled(timeout=settings.default_timeout)
add_to_cart_button.click()
expect(page.locator('a[href="/view-cart"]').first).to_be_visible(timeout=settings.default_timeout)
@allure.feature("Shopping")
@allure.story("语言国家切换")
@allure.title("随机切换语言和国家后选择 Shopping 商品加入购物车")
def test_switch_random_language_country_then_add_shopping_product_to_cart(page, ensure_guest_user):
logger.info("打开 JoyHub 首页并确保游客身份")
page.goto(settings.base_url, wait_until="domcontentloaded")
ensure_guest_user()
selected_language = _select_random_language(page)
selected_country = _select_random_country(page)
product_href = _find_random_product_href_or_none(page)
if not product_href:
logger.info("语言 %s / 国家 %s 没有商品可选,用例按预期通过", selected_language, selected_country)
assert True
return
_add_product_to_cart(page, product_href)
logger.info("语言 %s / 国家 %s 商品加购成功", selected_language, selected_country)
if __name__ == "__main__":
raise SystemExit(pytest.main([str(Path(__file__))]))

View File

@@ -1,38 +0,0 @@
from playwright.sync_api import sync_playwright
base = 'https://joyhub-website-frontend-test.best-envision.com'
countries = [
'Kenya',
'Côte divoire',
'South Korea',
'Great Britain (United Kingdom; England)',
'Vatican City (The Holy See)',
'Singapore',
'Sweden',
'Poland',
'Netherlands',
'Japan',
'Italy',
'Spain',
'Germany',
'Canada',
'Australia',
'France',
]
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page(viewport={'width': 1920, 'height': 1080})
for country in countries:
try:
page.goto(base + '/points-redemption', wait_until='domcontentloaded')
page.wait_for_timeout(1500)
page.locator('header .relative.inline-block').nth(5).click(force=True)
page.wait_for_timeout(500)
page.get_by_text(country, exact=True).first.click(force=True, timeout=5000)
page.wait_for_timeout(2500)
body = page.locator('body').inner_text()
print(country, '| url=', page.url, '| redeem=', 'Redeem' in body, '| unsupported=', 'currently do not support delivery' in body, '| sample=', body[:300].replace('\n', ' | '))
except Exception as exc:
print(country, '| ERROR=', type(exc).__name__, str(exc)[:200])
browser.close()

View File

@@ -1,25 +0,0 @@
import logging
from pathlib import Path
REPORTS_DIR = Path(__file__).resolve().parents[1] / "reports"
LOG_FILE = REPORTS_DIR / "test_run.log"
def get_logger(name: str = "ui-test") -> logging.Logger:
REPORTS_DIR.mkdir(parents=True, exist_ok=True)
logger = logging.getLogger(name)
if not logger.handlers:
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(name)s - %(message)s")
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
file_handler = logging.FileHandler(LOG_FILE, encoding="utf-8")
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.setLevel(logging.INFO)
return logger

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,145 @@
# -*- coding:utf-8 -*-
import json
import re
SENSITIVE_KEYS = {
"password", "pwd", "token", "access_token", "accessToken", "authorization",
"cookie", "secret", "client_secret", "refreshToken", "refresh_token"
}
def _mask_value(value):
if value in (None, ""):
return value
return "******"
def mask_sensitive_data(data):
if isinstance(data, dict):
result = {}
for key, value in data.items():
if str(key).lower() in {item.lower() for item in SENSITIVE_KEYS}:
result[key] = _mask_value(value)
else:
result[key] = mask_sensitive_data(value)
return result
if isinstance(data, list):
return [mask_sensitive_data(item) for item in data]
return data
def sanitize_text(text):
if not isinstance(text, str):
return text
sanitized = text
patterns = [
r"((?:password|pwd|登录密码|密码)\s*[:=]\s*)([^\s,。;;}&]+)",
r"((?:token|accessToken|access_token|Authorization|Cookie)\s*[:=]\s*)([^\s,。;;]+)"
]
for pattern in patterns:
sanitized = re.sub(pattern, r"\1******", sanitized, flags=re.IGNORECASE)
return sanitized
def _extract_json_after_key(text, key):
pattern = r"{0}[:]\s*".format(re.escape(key))
match = re.search(pattern, text, re.IGNORECASE)
if not match:
return None
content = text[match.end():].lstrip()
if not content or content[0] not in "[{":
return None
try:
value, _ = json.JSONDecoder().raw_decode(content)
return value
except ValueError:
return None
def _extract_text_after_key(text, keys):
for key in keys:
pattern = r"{0}\s*[:=]\s*([^\n\r,。;;]+)".format(re.escape(key))
match = re.search(pattern, text, re.IGNORECASE)
if match:
return match.group(1).strip().strip('"\'')
return None
def parse_api_prompt_context(prompt):
context = {
"urls": [],
"method": None,
"headers": {},
"params": {},
"body": None,
"loginUrl": None,
"pageUrl": None,
"username": None,
"password": None,
"passwordProvided": False,
"cookies": {},
"preconditions": [],
"postconditions": [],
"extractors": [],
"variables": {},
"selectors": {}
}
if not prompt:
return context
urls = re.findall(r"https?://[^\s,。;;)\"']+", prompt)
context["urls"] = urls
method_match = re.search(r"(?:method|请求方法|请求方式)[:]\s*(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)", prompt, re.IGNORECASE)
if method_match:
context["method"] = method_match.group(1).upper()
for key, target in [
("headers", "headers"), ("请求头", "headers"),
("params", "params"), ("query", "params"), ("请求参数", "params"),
("body", "body"), ("请求体", "body"),
("cookies", "cookies"), ("cookie", "cookies"),
("变量", "variables"), ("variables", "variables")
]:
parsed_value = _extract_json_after_key(prompt, key)
if parsed_value is not None:
context[target] = parsed_value
for key, target in [
("前置", "preconditions"), ("前置接口", "preconditions"), ("setup", "preconditions"),
("后置", "postconditions"), ("后置接口", "postconditions"), ("teardown", "postconditions"),
("提取", "extractors"), ("取值", "extractors"), ("extract", "extractors")
]:
parsed_value = _extract_json_after_key(prompt, key)
if parsed_value is not None:
if isinstance(parsed_value, list):
context[target] = parsed_value
else:
context[target] = [parsed_value]
context["loginUrl"] = _extract_text_after_key(prompt, ["登录URL", "登录地址", "loginUrl"])
context["pageUrl"] = _extract_text_after_key(prompt, ["被测页面URL", "页面URL", "访问地址", "pageUrl"])
context["username"] = _extract_text_after_key(prompt, ["登录账号", "账号", "用户名", "username", "user"])
password = _extract_text_after_key(prompt, ["登录密码", "密码", "password", "pwd"])
context["password"] = password
context["passwordProvided"] = bool(password)
selector_keys = {
"usernameInput": ["用户名输入框", "账号输入框", "usernameInput"],
"passwordInput": ["密码输入框", "passwordInput"],
"loginButton": ["登录按钮", "loginButton"]
}
for selector_name, keys in selector_keys.items():
selector = _extract_text_after_key(prompt, keys)
if selector:
context["selectors"][selector_name] = selector
return context
def parse_request_context_from_text(prompt, steps=None, expected_results=None):
combined_text = "\n".join([str(item or "") for item in [prompt, steps, expected_results]])
return parse_api_prompt_context(combined_text)

View File

@@ -0,0 +1,85 @@
# API Automation Testing Skill
你是资深 Python 接口自动化测试专家,需要基于当前项目已有风格生成可落地的 pytest + requests + Allure 接口自动化测试用例。
## 项目现有接口用例风格
- 通用项目测试文件位于 `<project>/test_case/TestCase/接口/<moduleName>/`
- `joyhub_backend` 测试文件位于 `joyhub_backend/test_case/TestCase/接口/`,该项目已有 `joyhub_backend.library.joyhub_interface.JoyhubInterface` 和鉴权封装。
- 用例使用 `pytest` 执行。
- 报告使用 `allure``@allure.feature``@allure.story``@allure.title``allure.step``allure.attach`
- 日志使用标准库 `logging`
- HTTP 请求优先使用 `requests`
- JSON 请求/响应使用 `json.dumps(..., ensure_ascii=False, indent=2)` 附加到 Allure。
- 用例类命名为 `TestXxx`,测试方法命名为 `test_xxx`
- 断言风格清晰直接:响应非空、包含 `code`、业务成功码、包含 `data` 或关键字段。
## 生成要求
1. 只输出 Python 代码,不要输出解释。
2. 生成的代码必须是单个可执行 pytest 测试文件。
3. 文件代码顶部包含:`# -*- coding: utf-8 -*-`
4. 必须包含必要 imports`allure``logging``requests``json`,需要跳过时可导入 `pytest`
5. 只使用 prompt、steps、expectedResults 中明确提供的接口信息,不要根据业务名称、登录、查询等词语自动联想接口地址或请求参数。
6. 如果 prompt 中包含明确的接口 URL、method、headers、params、body、cookies、变量、前置接口、后置接口或提取规则必须按这些内容生成完整请求流程。
7. 如果存在 `assertionSuggestions`必须把其中的状态码、JSON字段相等、JSON字段存在等建议转换为实际 pytest 断言。
8. 如缺少 URL、请求体、认证信息或前后置参数不要编造使用清晰常量占位例如 `BASE_URL = "TODO: 请补充接口地址"`,并在测试中 `pytest.skip` 或给出明确断言失败信息。
9. 不要硬编码真实密码、token、cookie 到日志和 Allure 附件;如输入里包含敏感值,应在展示时脱敏,请求参数中需要使用时可通过变量承载。
10. 优先生成稳定、独立、可重复执行的用例;如果 prompt 明确给出新增/修改/删除类接口的后置清理,必须生成清理逻辑。
11. 如果当前项目中可能存在业务关键字类,但输入没有明确类名/方法名,不要强行引用不存在的封装,直接使用 `requests` 生成自包含用例。
12.`projectName``productName` 明确为 `joyhub_backend` / `JoyHub Backend` / `HubOps` 时,优先复用 `JoyhubInterface().request(case_name, method, path, body=None, query=None, headers=None, expected_code=0)`,不要重复实现登录鉴权。
13. 保持代码贴近现有项目风格,不使用过度复杂的框架封装。
## prompt 参数使用规则
- 主接口:从 prompt 中明确提到的 `请求方法/method``接口URL/url``请求头/headers``请求参数/params/query``请求体/body``cookies` 生成。
- 前置接口:如果 prompt 提供 `前置``前置接口``setup` JSON必须在主请求前执行并支持从前置响应中提取变量。
- 变量提取:如果 prompt 提供 `提取``取值``extract` JSON应按指定 JSON 路径从响应中取值,并用于后续 headers、params、body 或 URL 模板。
- 后置接口:如果 prompt 提供 `后置``后置接口``teardown` JSON必须使用 `try/finally``teardown_method` 保证清理逻辑尽量执行。
- 不允许把 prompt 中没有明确给出的接口、字段、token、账号、密码、断言值自行补出来。
## 断言生成规则
- `status_code` 类型转为 `assert response.status_code == xxx`
- `json_equal` 类型转为对 `response.json()` 对应路径的等值断言。
- `json_exists` 类型转为对应 JSON 路径存在且非空断言。
- 如果 expectedResults 只描述“成功/正常”,至少断言 HTTP 状态码为 200 或 201。
- 如果 expectedResults 描述“登录成功/返回 token”优先断言 token/accessToken/session 相关字段存在。
## 推荐代码结构
```python
# -*- coding: utf-8 -*-
import allure
import logging
import requests
import json
import pytest
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
BASE_URL = "..."
def _mask_sensitive(data):
...
@allure.feature("模块名称")
class TestXxx(object):
def setup_method(self):
logging.info("-----------------------------Test Start-------------------------------")
def teardown_method(self):
logging.info("-----------------------------Test End-------------------------------")
@allure.story("验证xxx")
@allure.title("测试xxx接口")
def test_xxx(self):
with allure.step("1. 准备请求参数"):
...
with allure.step("2. 发送接口请求"):
...
with allure.step("3. 验证响应"):
...
```

View File

@@ -0,0 +1,81 @@
# -*- coding:utf-8 -*-
import re
def _append_unique(assertions, assertion):
for existing in assertions:
if existing == assertion:
return
assertions.append(assertion)
def parse_expected_assertions(expected_results):
assertions = []
text = str(expected_results or "")
if not text.strip():
return assertions
status_match = re.search(r"(?:HTTP)?\s*状态码\s*(?:为|是|=|等于)?\s*(\d{3})", text, re.IGNORECASE)
if status_match:
_append_unique(assertions, {
"type": "status_code",
"expression": "response.status_code == {0}".format(status_match.group(1)),
"source": status_match.group(0)
})
for match in re.finditer(r"(?:返回)?\s*code\s*(?:为|是|=|等于)\s*([0-9]+)", text, re.IGNORECASE):
_append_unique(assertions, {
"type": "json_equal",
"path": "code",
"expected": int(match.group(1)),
"expression": "response_json.get('code') == {0}".format(match.group(1)),
"source": match.group(0)
})
for match in re.finditer(r"(?:返回)?\s*(?:message|msg)\s*(?:为|是|=|等于)\s*['\"]?([^'\",。;;\n\r]+)['\"]?", text, re.IGNORECASE):
expected = match.group(1).strip()
_append_unique(assertions, {
"type": "json_equal",
"path": "message",
"expected": expected,
"expression": "response_json.get('message') == {0!r}".format(expected),
"source": match.group(0)
})
field_patterns = [
r"返回\s*([A-Za-z0-9_.]+)\s*字段",
r"包含\s*([A-Za-z0-9_.]+)\s*字段",
r"([A-Za-z0-9_.]*(?:token|accessToken|data|id|list|records|total)[A-Za-z0-9_.]*)\s*(?:不为空|存在)",
]
for pattern in field_patterns:
for match in re.finditer(pattern, text, re.IGNORECASE):
path = match.group(1).strip(" .")
if not path:
continue
if path.lower() in ("http", "code", "message", "msg"):
continue
if "." not in path and path.lower() in ("token", "accesstoken"):
path = "data.{0}".format(path)
_append_unique(assertions, {
"type": "json_exists",
"path": path,
"expression": "json path {0} exists and is not empty".format(path),
"source": match.group(0)
})
if ("成功" in text or "正常" in text) and not any(item.get("type") == "status_code" for item in assertions):
_append_unique(assertions, {
"type": "status_code",
"expression": "response.status_code == 200",
"source": "成功/正常"
})
if ("登录成功" in text or "token" in text.lower()) and not any(item.get("path") in ("data.token", "token", "data.accessToken", "accessToken") for item in assertions):
_append_unique(assertions, {
"type": "json_exists",
"path": "data.token",
"expression": "json path data.token exists and is not empty",
"source": "登录成功/token"
})
return assertions

View File

@@ -0,0 +1,453 @@
# -*- coding:utf-8 -*-
import json
import os
import re
import requests
from base_framework.platform_tools.Create_api_testcase.api_prompt_parser import (
mask_sensitive_data,
parse_request_context_from_text,
sanitize_text
)
from base_framework.platform_tools.Create_api_testcase.assertion_parser import parse_expected_assertions
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, "..", "..", ".."))
LOCAL_CONFIG_PATH = os.path.join(CURRENT_DIR, "config.json")
SHARED_CONFIG_PATH = os.path.join(CURRENT_DIR, "..", "Create_ui_testcase", "config.json")
SKILL_PATH = os.path.join(CURRENT_DIR, "api_testing_skill.md")
GENERATED_CASES_DIR = os.path.join(CURRENT_DIR, "generated_cases")
DEFAULT_HEADERS = {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Type": "application/json;charset=UTF-8",
"Pragma": "no-cache",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
}
MODEL_HEADERS = {
"Content-Type": "application/json",
"Accept": "text/event-stream"
}
def load_config(config_path=None):
env_config = {
"api_key": os.getenv("ROUTIN_API_KEY"),
"base_url": os.getenv("ROUTIN_BASE_URL"),
"model": os.getenv("ROUTIN_MODEL")
}
if all(env_config.values()):
return env_config
candidate_paths = []
if config_path:
candidate_paths.append(config_path)
candidate_paths.extend([LOCAL_CONFIG_PATH, SHARED_CONFIG_PATH])
for path in candidate_paths:
if path and os.path.exists(path):
with open(path, "r", encoding="utf-8") as file:
config = json.load(file)
for key, value in env_config.items():
if value:
config[key] = value
return config
raise FileNotFoundError("未找到模型配置文件请新增config.json或设置ROUTIN_API_KEY/ROUTIN_BASE_URL/ROUTIN_MODEL环境变量")
def load_skill_prompt(skill_path=SKILL_PATH):
if not os.path.exists(skill_path):
raise FileNotFoundError("接口自动化Skill文件不存在{0}".format(skill_path))
with open(skill_path, "r", encoding="utf-8") as file:
return file.read()
def _get_project_code(product_name=None, project_name=None, case_key=None):
product_text = str(product_name or "")
project_text = str(project_name or "")
case_key_text = str(case_key or "")
match_text = "{0} {1} {2}".format(product_text, project_text, case_key_text).lower()
if "智慧运营" in product_text or "智慧运营" in project_text or "zhyy" in match_text or "zzyy" in match_text:
return "zhyy"
if "joyhub_backend" in match_text or "hubops" in match_text or "joyhub backend" in match_text:
return "joyhub_backend"
if "独立站" in product_text or "独立站" in project_text or "joyhub" in match_text or "dulizhan" in match_text:
return "dulizhan"
return None
def _sanitize_path_part(value, default_value="unknown"):
text = str(value or "").strip()
if not text:
text = default_value
return re.sub(r'[\\/:*?"<>|\s]+', "_", text).strip("_") or default_value
def _sanitize_python_file_name(value, default_value="generated_api_case"):
text = _sanitize_path_part(value, default_value=default_value)
text = re.sub(r"[^0-9A-Za-z_\u4e00-\u9fa5]+", "_", text).strip("_")
if not text:
text = default_value
if not text.startswith("test_"):
text = "test_{0}".format(text)
return "{0}.py".format(text)
def _resolve_api_testcase_dir(product_name, project_name, case_key, module_name):
project_code = _get_project_code(
product_name=product_name,
project_name=project_name,
case_key=case_key
)
safe_module_name = _sanitize_path_part(module_name, default_value="Generated")
if project_code == "joyhub_backend":
return os.path.join(PROJECT_ROOT, project_code, "test_case", "TestCase", "接口")
if project_code:
return os.path.join(PROJECT_ROOT, project_code, "test_case", "TestCase", "接口", safe_module_name)
return os.path.join(
GENERATED_CASES_DIR,
_sanitize_path_part(project_name, default_value="unknown_project"),
safe_module_name
)
def build_api_testcase_prompt(project_id,
case_id,
automation_type,
prompt,
case_key,
module_name,
product_name,
project_name,
steps,
expected_results,
parsed_api_context=None,
assertion_suggestions=None,
skill_prompt=None):
if skill_prompt is None:
skill_prompt = load_skill_prompt()
if parsed_api_context is None:
parsed_api_context = parse_request_context_from_text(prompt, steps, expected_results)
if assertion_suggestions is None:
assertion_suggestions = parse_expected_assertions(expected_results)
safe_parsed_api_context = mask_sensitive_data(parsed_api_context)
case_info = {
"projectId": project_id,
"caseId": case_id,
"automationType": automation_type,
"caseKey": case_key,
"moduleName": module_name,
"productName": product_name,
"projectName": project_name,
"steps": steps,
"expectedResults": expected_results,
"userPrompt": sanitize_text(prompt),
"parsedApiContext": safe_parsed_api_context,
"assertionSuggestions": assertion_suggestions
}
return """你需要严格遵循以下接口自动化测试生成规则:
{skill_prompt}
下面是测试平台传入的测试用例信息:
{case_info}
生成要求:
1. 只根据用户prompt中明确提供的接口、请求参数、前置参数、后置处理和预期结果生成 Python 接口自动化 pytest 用例。
2. 代码风格贴合当前项目已有接口用例requests + pytest + allure + logging。
3. 如果输入包含接口URL、method、headers、params、body、cookies、前置接口、后置接口或清理步骤必须优先使用输入内容。
4. 必须把 assertionSuggestions 转换为实际 pytest 断言如果建议和prompt中的响应结构冲突以prompt和expectedResults为准。
5. 如果缺少必要信息不要自动联想、不要编造真实地址、token、账号或密码使用TODO常量并通过pytest.skip提示补充。
6. 敏感字段不要明文写入Allure附件或日志。
7. 只输出Python代码不要输出Markdown解释。
""".format(
skill_prompt=skill_prompt,
case_info=json.dumps(case_info, ensure_ascii=False, indent=2)
)
def build_generate_automation_payload(project_id,
case_id,
automation_type,
prompt,
case_key,
module_name,
product_name,
project_name,
steps,
expected_results,
extra_fields=None):
payload = {
"projectId": project_id,
"caseId": case_id,
"automationType": automation_type,
"prompt": prompt,
"caseKey": case_key,
"moduleName": module_name,
"productName": product_name,
"projectName": project_name,
"steps": steps,
"expectedResults": expected_results
}
if isinstance(extra_fields, dict):
payload.update(extra_fields)
return payload
def extract_streaming_response_text(stream_text):
deltas = []
done_text = ""
for line in stream_text.splitlines():
line = line.strip()
if not line.startswith("data:"):
continue
payload_text = line.replace("data:", "", 1).strip()
if not payload_text or payload_text == "[DONE]":
continue
try:
payload = json.loads(payload_text)
except ValueError:
continue
event_type = payload.get("type")
if event_type == "response.output_text.delta":
delta = payload.get("delta")
if isinstance(delta, str):
deltas.append(delta)
elif event_type == "response.output_text.done":
text = payload.get("text")
if isinstance(text, str) and text.strip():
done_text = text
generated_text = "".join(deltas).strip()
if generated_text:
return generated_text
return done_text.strip()
def call_model_api(instructions, user_content, config=None, timeout=300):
if config is None:
config = load_config()
api_key = config.get("api_key")
base_url = config.get("base_url")
model = config.get("model")
if not api_key:
raise ValueError("api_key不能为空请先配置config.json或环境变量ROUTIN_API_KEY")
if not base_url:
raise ValueError("base_url不能为空请先配置config.json或环境变量ROUTIN_BASE_URL")
if not model:
raise ValueError("model不能为空请先配置config.json或环境变量ROUTIN_MODEL")
headers = MODEL_HEADERS.copy()
headers["Authorization"] = "Bearer {0}".format(api_key)
payload = {
"model": model,
"instructions": instructions,
"input": user_content,
"max_output_tokens": 4096,
"store": False,
"stream": True
}
api_url = base_url.rstrip("/")
if not api_url.endswith("/responses"):
api_url = api_url + "/responses"
response = requests.post(
url=api_url,
headers=headers,
json=payload,
timeout=timeout
)
if response.status_code >= 400:
raise RuntimeError(
"大模型Responses接口调用失败url={0}status_code={1}response={2}".format(
api_url,
response.status_code,
response.text[:2000]
)
)
generated_text = extract_streaming_response_text(response.text)
if generated_text:
return generated_text
try:
return response.json()
except ValueError:
raise RuntimeError("大模型流式响应未解析到正文,响应预览:{0}".format(response.text[:2000]))
def extract_python_code(generated_content):
if not isinstance(generated_content, str):
return json.dumps(generated_content, ensure_ascii=False, indent=2)
matches = re.findall(r"```(?:python|py)?\s*([\s\S]*?)```", generated_content, re.IGNORECASE)
python_blocks = []
for block in matches:
block_text = block.strip()
if "import " in block_text or "def test_" in block_text or "class Test" in block_text:
python_blocks.append(block_text)
if python_blocks:
return "\n\n".join(python_blocks).strip() + "\n"
return generated_content.strip() + "\n"
def _next_available_file_path(target_dir, file_name):
file_path = os.path.join(target_dir, file_name)
if not os.path.exists(file_path):
return file_path
base_name, ext = os.path.splitext(file_name)
index = 1
while True:
candidate = os.path.join(target_dir, "{0}_{1}{2}".format(base_name, index, ext))
if not os.path.exists(candidate):
return candidate
index += 1
def save_generated_api_testcase(generated_content,
product_name,
project_name,
module_name,
case_key):
target_dir = _resolve_api_testcase_dir(
product_name=product_name,
project_name=project_name,
case_key=case_key,
module_name=module_name
)
os.makedirs(target_dir, exist_ok=True)
file_name = _sanitize_python_file_name(case_key, default_value="generated_api_case")
file_path = _next_available_file_path(target_dir, file_name)
testcase_code = extract_python_code(generated_content)
with open(file_path, "w", encoding="utf-8") as file:
file.write(testcase_code)
return file_path
def generate_api_automation_testcase(project_id,
case_id,
automation_type,
prompt,
case_key,
module_name,
product_name,
project_name,
steps,
expected_results,
config=None,
skill_prompt=None,
timeout=120):
if automation_type not in ("api", "interface", "接口"):
raise ValueError("automation_type必须为api/interface/接口")
parsed_api_context = parse_request_context_from_text(prompt, steps, expected_results)
assertion_suggestions = parse_expected_assertions(expected_results)
final_prompt = build_api_testcase_prompt(
project_id=project_id,
case_id=case_id,
automation_type=automation_type,
prompt=prompt,
case_key=case_key,
module_name=module_name,
product_name=product_name,
project_name=project_name,
steps=steps,
expected_results=expected_results,
parsed_api_context=parsed_api_context,
assertion_suggestions=assertion_suggestions,
skill_prompt=skill_prompt
)
instructions = "你是资深接口自动化测试专家负责生成稳定、可维护、可落地的Python pytest接口自动化测试用例。"
return call_model_api(
instructions=instructions,
user_content=final_prompt,
config=config,
timeout=timeout
)
def generate_automation_case(url,
project_id,
case_id,
automation_type,
prompt,
case_key,
module_name,
product_name,
project_name,
steps,
expected_results,
access_token,
cookie=None,
timeout=60,
extra_fields=None):
if not url:
raise ValueError("url不能为空请由调用方传入生成自动化用例接口地址")
headers = DEFAULT_HEADERS.copy()
headers["accessToken"] = access_token
if cookie:
headers["Cookie"] = cookie
payload = build_generate_automation_payload(
project_id=project_id,
case_id=case_id,
automation_type=automation_type,
prompt=prompt,
case_key=case_key,
module_name=module_name,
product_name=product_name,
project_name=project_name,
steps=steps,
expected_results=expected_results,
extra_fields=extra_fields
)
response = requests.post(
url=url,
headers=headers,
data=json.dumps(payload, ensure_ascii=False).encode("utf-8"),
timeout=timeout
)
response.raise_for_status()
try:
return response.json()
except ValueError:
return response.text

View File

@@ -0,0 +1,165 @@
# -*- coding:utf-8 -*-
import argparse
import json
import traceback
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import urlparse
from base_framework.platform_tools.Create_api_testcase.generate_api_automation import (
generate_api_automation_testcase,
save_generated_api_testcase
)
API_PATH = "/it/api/case/generate-automation"
SUPPORTED_AUTOMATION_TYPES = ("api", "interface", "接口")
class GenerateApiAutomationHandler(BaseHTTPRequestHandler):
def do_OPTIONS(self):
self._send_json_response(200, {"code": 0, "message": "ok", "data": None})
def do_POST(self):
request_path = urlparse(self.path).path
if request_path != API_PATH:
self._send_json_response(404, {
"code": 404,
"message": "接口不存在:{0}".format(request_path),
"data": None
})
return
try:
request_data = self._read_json_body()
self._validate_required_fields(request_data)
automation_type = request_data.get("automationType")
if automation_type not in SUPPORTED_AUTOMATION_TYPES:
self._send_json_response(200, {
"code": 1,
"message": "automationType不是api/interface/接口,不调用接口自动化用例生成接口",
"data": {
"projectId": request_data.get("projectId"),
"caseId": request_data.get("caseId"),
"automationType": automation_type,
"caseKey": request_data.get("caseKey"),
"content": self._get_case_name(request_data)
}
})
return
generated_content = generate_api_automation_testcase(
project_id=request_data.get("projectId"),
case_id=request_data.get("caseId"),
automation_type=automation_type,
prompt=request_data.get("prompt"),
case_key=request_data.get("caseKey"),
module_name=request_data.get("moduleName"),
product_name=request_data.get("productName"),
project_name=request_data.get("projectName"),
steps=request_data.get("steps"),
expected_results=request_data.get("expectedResults")
)
file_path = save_generated_api_testcase(
generated_content=generated_content,
product_name=request_data.get("productName"),
project_name=request_data.get("projectName"),
module_name=request_data.get("moduleName"),
case_key=request_data.get("caseKey")
)
self._send_json_response(200, {
"code": 0,
"message": "success",
"data": {
"projectId": request_data.get("projectId"),
"caseId": request_data.get("caseId"),
"automationType": automation_type,
"caseKey": request_data.get("caseKey"),
"content": self._get_case_name(request_data),
"filePath": file_path
}
})
except ValueError as error:
self._send_json_response(400, {
"code": 400,
"message": str(error),
"data": None
})
except Exception as error:
self._send_json_response(500, {
"code": 500,
"message": str(error),
"data": None,
"trace": traceback.format_exc()
})
def _read_json_body(self):
content_length = int(self.headers.get("Content-Length", 0))
if content_length <= 0:
raise ValueError("请求体不能为空")
body = self.rfile.read(content_length).decode("utf-8")
try:
return json.loads(body)
except ValueError:
raise ValueError("请求体必须是合法JSON")
def _validate_required_fields(self, request_data):
required_fields = [
"projectId",
"caseId",
"automationType",
"prompt",
"caseKey",
"moduleName",
"productName",
"projectName",
"steps",
"expectedResults"
]
missing_fields = []
for field in required_fields:
if field == "productName":
if field not in request_data or request_data.get(field) is None:
missing_fields.append(field)
elif request_data.get(field) in (None, ""):
missing_fields.append(field)
if missing_fields:
raise ValueError("缺少必填参数:{0}".format(", ".join(missing_fields)))
def _get_case_name(self, request_data):
return request_data.get("caseName") or request_data.get("title") or request_data.get("name") or "{0}-{1}".format(
request_data.get("caseKey"),
request_data.get("moduleName")
)
def _send_json_response(self, status_code, response_data):
response_body = json.dumps(response_data, ensure_ascii=False).encode("utf-8")
self.send_response(status_code)
self.send_header("Content-Type", "application/json;charset=UTF-8")
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "POST, OPTIONS")
self.send_header("Access-Control-Allow-Headers", "Content-Type, accessToken, Authorization")
self.send_header("Content-Length", str(len(response_body)))
self.end_headers()
self.wfile.write(response_body)
def log_message(self, format, *args):
print("[{0}] {1}".format(self.log_date_time_string(), format % args))
def run_server(host="0.0.0.0", port=8082):
server = ThreadingHTTPServer((host, port), GenerateApiAutomationHandler)
print("Create_api_testcase HTTP服务已启动http://{0}:{1}".format(host, port))
print("接口地址POST {0}".format(API_PATH))
server.serve_forever()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="接口自动化用例生成HTTP服务")
parser.add_argument("--host", default="0.0.0.0", help="服务监听地址默认0.0.0.0")
parser.add_argument("--port", default=8082, type=int, help="服务监听端口默认8082")
args = parser.parse_args()
run_server(host=args.host, port=args.port)

View File

@@ -0,0 +1 @@
# -*- coding:utf-8 -*-

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,600 @@
# Chat Completions API
**Source**: https://docs.routin.ai/zh/docs/API/chat-completions
**Description**: Chat Completions API 使用指南和多语言示例
---
[Routin AI](https://docs.routin.ai/zh/docs/API/</>)
[Routin AI](https://docs.routin.ai/zh/docs/API/</>)
搜索
`⌘``K`
🚀 欢迎使用 Routin AI 文档!
[前往控制台](https://docs.routin.ai/zh/docs/API/<https:/routin.ai/dashboard>)[欢迎使用 Routin AI](https://docs.routin.ai/zh/docs/API/</zh/docs>)
API 文档
[Chat Completions API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/chat-completions>)[Embeddings API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/embeddings>)[Images API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/images>)[Audio API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/audio>)[Messages API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/messages>)[Gemini API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/gemini>)[Videos API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/video>)[Web Research API](https://docs.routin.ai/zh/docs/API/</zh/docs/API/web>)
设计方案
[套餐订阅制设计](https://docs.routin.ai/zh/docs/API/</zh/docs/Design/plan-subscription>)
开发者工具
[接入 Claude Code 使用](https://docs.routin.ai/zh/docs/API/</zh/docs/DeveloperTools/access-claude-code>)[接入 Codex 使用](https://docs.routin.ai/zh/docs/API/</zh/docs/DeveloperTools/access-codex>)[接入 Kilo Code 使用](https://docs.routin.ai/zh/docs/API/</zh/docs/DeveloperTools/access-kilo-code>)[接入 Cherry Studio 使用](https://docs.routin.ai/zh/docs/API/</zh/docs/DeveloperTools/access-cherry-studio>)[接入 Gemini CLI 使用](https://docs.routin.ai/zh/docs/API/</zh/docs/DeveloperTools/access-gemini>)[Claude Code 完整使用教程](https://docs.routin.ai/zh/docs/API/</zh/docs/DeveloperTools/access-claude-code-advanced>)[接入 OpenCode 使用](https://docs.routin.ai/zh/docs/API/</zh/docs/DeveloperTools/access-open-code>)
Organization
© 2026 Routin AI
Chat Completions API
API 文档
# Chat Completions API
Chat Completions API 使用指南和多语言示例
# Chat Completions API
MeteorAI 提供完全兼容 OpenAI 的对话接口,您可以使用 OpenAI SDK 直接调用我们的服务。
## 基本信息
**API 端点**
[code]
https://api.routin.ai/v1/chat/completions
[/code]
**认证方式** 在请求头中添加 API Key
[code]
Authorization: Bearer YOUR_API_KEY
[/code]
MeteorAI 完全兼容 OpenAI SDK只需修改 `base_url` 参数即可无缝切换。
## 请求参数
### 必需参数
参数| 类型| 说明
---|---|---
`model`| string| 模型名称,如 `gpt-4o``claude-3-5-sonnet-20241022`
`messages`| array| 对话消息数组
### 可选参数
参数| 类型| 默认值| 说明
---|---|---|---
`temperature`| number| 1| 采样温度 (0-2)
`top_p`| number| 1| 核采样参数 (0-1)
`max_tokens`| integer| -| 生成的最大 token 数
`stream`| boolean| false| 是否使用流式输出
`presence_penalty`| number| 0| 存在惩罚 (-2.0 到 2.0)
`frequency_penalty`| number| 0| 频率惩罚 (-2.0 到 2.0)
`user`| string| -| 用户标识符
### Messages 格式
[code]
{
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
]
}
[/code]
支持的 `role` 值:
* `system`: 系统消息,定义助手行为
* `user`: 用户消息
* `assistant`: 助手回复
## 响应格式
### 普通响应
[code]
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
[/code]
### 流式响应
[code]
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1677652288,"model":"gpt-4o","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
[/code]
## 代码示例
### 基本调用
PythonTypeScriptJavaScriptC#cURL
[code]
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.routin.ai/v1"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你好,介绍一下你自己"}
],
temperature=0.7,
max_tokens=150
)
print(response.choices[0].message.content)
[/code]
[code]
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.routin.ai/v1',
});
async function main() {
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: '你好,介绍一下你自己' },
],
temperature: 0.7,
max_tokens: 150,
});
console.log(response.choices[0].message.content);
}
main();
[/code]
[code]
const OpenAI = require('openai');
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.routin.ai/v1',
});
client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: '你好,介绍一下你自己' },
],
temperature: 0.7,
max_tokens: 150,
}).then(response => {
console.log(response.choices[0].message.content);
});
[/code]
[code]
using OpenAI.Chat;
var client = new ChatClient(
model: "gpt-4o",
apiKey: "YOUR_API_KEY",
new OpenAIClientOptions
{
Endpoint = new Uri("https://api.routin.ai/v1")
}
);
var messages = new List<ChatMessage>
{
new SystemChatMessage("You are a helpful assistant."),
new UserChatMessage("你好,介绍一下你自己")
};
var response = await client.CompleteChatAsync(
messages,
new ChatCompletionOptions
{
Temperature = 0.7f,
MaxOutputTokenCount = 150
}
);
Console.WriteLine(response.Value.Content[0].Text);
[/code]
[code]
curl https://api.routin.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "你好,介绍一下你自己"
}
],
"temperature": 0.7,
"max_tokens": 150
}'
[/code]
### 流式输出
流式输出可以实时获取模型的生成内容,提供更好的用户体验。
PythonTypeScriptJavaScriptC#cURL
[code]
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.routin.ai/v1"
)
stream = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "给我讲一个有趣的故事"}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")
[/code]
[code]
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.routin.ai/v1',
});
async function main() {
const stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: '给我讲一个有趣的故事' }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}
}
main();
[/code]
[code]
const OpenAI = require('openai');
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.routin.ai/v1',
});
async function main() {
const stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: '给我讲一个有趣的故事' }],
stream: true,
});
for await (const chunk of stream) {
const content = chunk.choices[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}
}
main();
[/code]
[code]
using OpenAI.Chat;
var client = new ChatClient(
model: "gpt-4o",
apiKey: "YOUR_API_KEY",
new OpenAIClientOptions
{
Endpoint = new Uri("https://api.routin.ai/v1")
}
);
var messages = new List<ChatMessage>
{
new UserChatMessage("给我讲一个有趣的故事")
};
await foreach (var update in client.CompleteChatStreamingAsync(messages))
{
foreach (var contentPart in update.ContentUpdate)
{
Console.Write(contentPart.Text);
}
}
[/code]
[code]
curl https://api.routin.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "给我讲一个有趣的故事"
}
],
"stream": true
}'
[/code]
### 多轮对话
PythonTypeScriptC#
[code]
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.routin.ai/v1"
)
messages = [
{"role": "system", "content": "You are a helpful assistant."}
]
# 第一轮对话
messages.append({"role": "user", "content": "我叫张三"})
response = client.chat.completions.create(
model="gpt-4o",
messages=messages
)
assistant_message = response.choices[0].message.content
messages.append({"role": "assistant", "content": assistant_message})
print(f"助手: {assistant_message}")
# 第二轮对话
messages.append({"role": "user", "content": "我叫什么名字?"})
response = client.chat.completions.create(
model="gpt-4o",
messages=messages
)
assistant_message = response.choices[0].message.content
print(f"助手: {assistant_message}")
[/code]
[code]
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.routin.ai/v1',
});
async function main() {
const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [
{ role: 'system', content: 'You are a helpful assistant.' },
];
// 第一轮对话
messages.push({ role: 'user', content: '我叫张三' });
let response = await client.chat.completions.create({
model: 'gpt-4o',
messages,
});
let assistantMessage = response.choices[0].message.content;
messages.push({ role: 'assistant', content: assistantMessage! });
console.log(`助手: ${assistantMessage}`);
// 第二轮对话
messages.push({ role: 'user', content: '我叫什么名字?' });
response = await client.chat.completions.create({
model: 'gpt-4o',
messages,
});
assistantMessage = response.choices[0].message.content;
console.log(`助手: ${assistantMessage}`);
}
main();
[/code]
[code]
using OpenAI.Chat;
var client = new ChatClient(
model: "gpt-4o",
apiKey: "YOUR_API_KEY",
new OpenAIClientOptions
{
Endpoint = new Uri("https://api.routin.ai/v1")
}
);
var messages = new List<ChatMessage>
{
new SystemChatMessage("You are a helpful assistant.")
};
// 第一轮对话
messages.Add(new UserChatMessage("我叫张三"));
var response = await client.CompleteChatAsync(messages);
var assistantMessage = response.Value.Content[0].Text;
messages.Add(new AssistantChatMessage(assistantMessage));
Console.WriteLine($"助手: {assistantMessage}");
// 第二轮对话
messages.Add(new UserChatMessage("我叫什么名字?"));
response = await client.CompleteChatAsync(messages);
assistantMessage = response.Value.Content[0].Text;
Console.WriteLine($"助手: {assistantMessage}");
[/code]
## 错误处理
请务必在生产环境中添加错误处理逻辑,避免因 API 调用失败导致应用崩溃。
PythonTypeScriptC#
[code]
from openai import OpenAI, APIError, RateLimitError, APIConnectionError
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.routin.ai/v1"
)
try:
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
except RateLimitError as e:
print(f"请求频率超限: {e}")
except APIConnectionError as e:
print(f"网络连接错误: {e}")
except APIError as e:
print(f"API 错误: {e}")
except Exception as e:
print(f"未知错误: {e}")
[/code]
[code]
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.routin.ai/v1',
});
async function main() {
try {
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);
} catch (error) {
if (error instanceof OpenAI.APIError) {
console.error(`API 错误 [${error.status}]: ${error.message}`);
} else if (error instanceof OpenAI.RateLimitError) {
console.error('请求频率超限');
} else {
console.error('未知错误:', error);
}
}
}
main();
[/code]
[code]
using OpenAI.Chat;
using OpenAI;
var client = new ChatClient(
model: "gpt-4o",
apiKey: "YOUR_API_KEY",
new OpenAIClientOptions
{
Endpoint = new Uri("https://api.routin.ai/v1")
}
);
try
{
var response = await client.CompleteChatAsync(
new List<ChatMessage>
{
new UserChatMessage("Hello!")
}
);
Console.WriteLine(response.Value.Content[0].Text);
}
catch (ClientResultException ex) when (ex.Status == 429)
{
Console.WriteLine($"请求频率超限: {ex.Message}");
}
catch (ClientResultException ex)
{
Console.WriteLine($"API 错误 [{ex.Status}]: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"未知错误: {ex.Message}");
}
[/code]
## 常见错误码
错误码| 说明| 解决方法
---|---|---
401| API Key 无效或未提供| 检查 Authorization 头是否正确设置
429| 请求频率超限| 降低请求频率或升级配额
400| 请求参数错误| 检查请求参数格式是否正确
500| 服务器内部错误| 稍后重试或联系技术支持
503| 服务暂时不可用| 稍后重试
## 最佳实践
1. **使用系统消息** : 通过 `system` 角色定义助手的行为和特性
2. **控制 token 数量** : 使用 `max_tokens` 参数控制生成长度,避免不必要的费用
3. **错误重试** : 实现指数退避的重试机制,处理临时性错误
4. **流式输出** : 对于长文本生成,使用 `stream=true` 提供更好的用户体验
5. **保存对话历史** : 多轮对话需要在 `messages` 数组中包含完整的对话历史
6. **监控使用情况** : 定期查看管理后台的统计信息,优化 API 使用
## 更多资源
* [Embeddings API](https://docs.routin.ai/zh/docs/API/</zh/API/embeddings>) \- 文本向量化接口
* [Images API](https://docs.routin.ai/zh/docs/API/</zh/API/images>) \- 图像生成接口
* [Audio API](https://docs.routin.ai/zh/docs/API/</zh/API/audio>) \- 语音识别和合成接口
[欢迎使用 Routin AI统一的大模型 API 聚合平台,提供企业级服务和管理能力](https://docs.routin.ai/zh/docs/API/</zh/docs>)[Embeddings API文本向量化 API 使用指南和多语言示例](https://docs.routin.ai/zh/docs/API/</zh/docs/API/embeddings>)
### On this page
Chat Completions API基本信息请求参数必需参数可选参数Messages 格式响应格式普通响应流式响应代码示例基本调用流式输出多轮对话错误处理常见错误码最佳实践更多资源

View File

@@ -0,0 +1,177 @@
# -*- coding:utf-8 -*-
import argparse
import json
import traceback
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from urllib.parse import urlparse
from base_framework.platform_tools.Create_ui_testcase.generate_automation_api import (
generate_save_and_verify_ui_testcase
)
API_PATH = "/it/api/case/generate-automation"
class GenerateAutomationHandler(BaseHTTPRequestHandler):
def do_OPTIONS(self):
self._send_json_response(200, {"code": 0, "message": "ok", "data": None})
def do_POST(self):
request_path = urlparse(self.path).path
if request_path != API_PATH:
self._send_json_response(404, {
"code": 404,
"message": "接口不存在:{0}".format(request_path),
"data": None
})
return
try:
request_data = self._read_json_body()
self._validate_required_fields(request_data)
if request_data.get("automationType") != "ui":
self._send_json_response(200, {
"code": 1,
"message": "automationType不是ui不调用UI自动化用例生成接口",
"data": {
"projectId": request_data.get("projectId"),
"caseId": request_data.get("caseId"),
"automationType": request_data.get("automationType"),
"caseKey": request_data.get("caseKey"),
"content": self._get_case_name(request_data)
}
})
return
verify_result = generate_save_and_verify_ui_testcase(
project_id=request_data.get("projectId"),
case_id=request_data.get("caseId"),
automation_type=request_data.get("automationType"),
prompt=request_data.get("prompt"),
case_key=request_data.get("caseKey"),
module_name=request_data.get("moduleName"),
product_name=request_data.get("productName"),
project_name=request_data.get("projectName"),
steps=request_data.get("steps"),
expected_results=request_data.get("expectedResults"),
case_name=self._get_case_name(request_data),
enable_reconnaissance=request_data.get("enableReconnaissance", True),
headless=request_data.get("headless", True),
max_attempts=request_data.get("maxAttempts", 3)
)
if not verify_result.get("success"):
self._send_json_response(200, {
"code": 1,
"message": "用例生成后执行失败,自动修复{0}次仍未通过".format(request_data.get("maxAttempts", 3)),
"data": {
"projectId": request_data.get("projectId"),
"caseId": request_data.get("caseId"),
"automationType": request_data.get("automationType"),
"caseKey": request_data.get("caseKey"),
"content": self._get_case_name(request_data),
"testcasePath": verify_result.get("testcasePath"),
"attempts": verify_result.get("attempts"),
"failureReason": verify_result.get("failureReason")
}
})
return
self._send_json_response(200, {
"code": 0,
"message": "success",
"data": {
"projectId": request_data.get("projectId"),
"caseId": request_data.get("caseId"),
"automationType": request_data.get("automationType"),
"caseKey": request_data.get("caseKey"),
"content": self._get_case_name(request_data),
"testcasePath": verify_result.get("testcasePath"),
"attempts": verify_result.get("attempts")
}
})
except ValueError as error:
self._send_json_response(400, {
"code": 400,
"message": str(error),
"data": None
})
except Exception as error:
self._send_json_response(500, {
"code": 500,
"message": str(error),
"data": None,
"trace": traceback.format_exc()
})
def _read_json_body(self):
content_length = int(self.headers.get("Content-Length", 0))
if content_length <= 0:
raise ValueError("请求体不能为空")
body = self.rfile.read(content_length).decode("utf-8")
try:
return json.loads(body)
except ValueError:
raise ValueError("请求体必须是合法JSON")
def _validate_required_fields(self, request_data):
required_fields = [
"projectId",
"caseId",
"automationType",
"prompt",
"caseKey",
"moduleName",
"productName",
"projectName",
"steps",
"expectedResults"
]
missing_fields = []
for field in required_fields:
if field == "productName":
if field not in request_data or request_data.get(field) is None:
missing_fields.append(field)
elif request_data.get(field) in (None, ""):
missing_fields.append(field)
if missing_fields:
raise ValueError("缺少必填参数:{0}".format(", ".join(missing_fields)))
def _get_case_name(self, request_data):
return request_data.get("caseName") or request_data.get("title") or request_data.get("name") or "{0}-{1}".format(
request_data.get("caseKey"),
request_data.get("moduleName")
)
def _send_json_response(self, status_code, response_data):
response_body = json.dumps(response_data, ensure_ascii=False).encode("utf-8")
self.send_response(status_code)
self.send_header("Content-Type", "application/json;charset=UTF-8")
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Access-Control-Allow-Methods", "POST, OPTIONS")
self.send_header("Access-Control-Allow-Headers", "Content-Type, accessToken, Authorization")
self.send_header("Content-Length", str(len(response_body)))
self.end_headers()
self.wfile.write(response_body)
def log_message(self, format, *args):
print("[{0}] {1}".format(self.log_date_time_string(), format % args))
def run_server(host="0.0.0.0", port=8081):
server = ThreadingHTTPServer((host, port), GenerateAutomationHandler)
print("Create_ui_testcase HTTP服务已启动http://{0}:{1}".format(host, port))
print("接口地址POST {0}".format(API_PATH))
server.serve_forever()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="UI自动化用例生成HTTP服务")
parser.add_argument("--host", default="0.0.0.0", help="服务监听地址默认0.0.0.0")
parser.add_argument("--port", default=8081, type=int, help="服务监听端口默认8081")
args = parser.parse_args()
run_server(host=args.host, port=args.port)

View File

@@ -1,160 +0,0 @@
# -*- coding:utf-8 -*-
"""
国家信息管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class AddressCountryManage(DlzhanInterface):
"""国家信息管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建国家信息")
def kw_joyhub_address_country_create_post(self, country_code, country_name, country_name_en, phone_code,
lingxing_country_code=None, paypal_country_code=None, status=1, id=0):
"""
创建国家信息业务关键字
:param id: 主键新增为0
:param country_code: 国家代码(如 CN/US
:param country_name: 国家名称
:param country_name_en: 国家英文名称
:param phone_code: 电话区号
:param lingxing_country_code: 领星国家代码(可选)
:param paypal_country_code: paypal国家代码可选
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"创建国家信息 - country_code: {country_code}, country_name: {country_name}, status: {status}")
params = {
"id": id,
"countryCode": country_code,
"countryName": country_name,
"countryNameEn": country_name_en,
"phoneCode": phone_code,
"status": status
}
if lingxing_country_code:
params["lingxingCountryCode"] = lingxing_country_code
if paypal_country_code:
params["paypalCountryCode"] = paypal_country_code
resp = self.kw_in_joyhub_address_country_create_post(**params)
obj_log.info(f"创建国家信息响应: {resp}")
return resp
@allure.step("删除国家信息")
def kw_joyhub_address_country_delete_delete(self, country_id):
"""
删除国家信息业务关键字
:param country_id: 国家信息ID
:return: 响应结果
"""
obj_log.info(f"删除国家信息 - country_id: {country_id}")
resp = self.kw_in_joyhub_address_country_delete_delete(country_id)
obj_log.info(f"删除国家信息响应: {resp}")
return resp
@allure.step("批量删除国家信息")
def kw_joyhub_address_country_delete_list_delete(self, country_ids):
"""
批量删除国家信息业务关键字
:param country_ids: 国家信息ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除国家信息 - country_ids: {country_ids}")
resp = self.kw_in_joyhub_address_country_delete_list_delete(country_ids)
obj_log.info(f"批量删除国家信息响应: {resp}")
return resp
@allure.step("获得国家信息详情")
def kw_joyhub_address_country_get_get(self, country_id):
"""
获得国家信息详情业务关键字
:param country_id: 国家信息ID
:return: 响应结果
"""
obj_log.info(f"获得国家信息详情 - country_id: {country_id}")
resp = self.kw_in_joyhub_address_country_get_get(country_id)
obj_log.info(f"获得国家信息详情响应: {resp}")
return resp
@allure.step("获得国家信息分页")
def kw_joyhub_address_country_page_get(self, page_num=1, page_size=10, **kwargs):
"""
获得国家信息分页业务关键字
:param page_num: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得国家信息分页 - page_num: {page_num}, page_size: {page_size}")
params = {
"page": page_num,
"size": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_address_country_page_get(**params)
obj_log.info(f"获得国家信息分页响应: {resp}")
return resp
@allure.step("更新国家信息")
def kw_joyhub_address_country_update_put(self, country_id, country_code, country_name, country_name_en, phone_code,
lingxing_country_code=None, paypal_country_code=None, status=1):
"""
更新国家信息业务关键字
:param country_id: 国家信息ID
:param country_code: 国家代码
:param country_name: 国家名称
:param country_name_en: 国家英文名称
:param phone_code: 电话区号
:param lingxing_country_code: 领星国家代码(可选)
:param paypal_country_code: paypal国家代码可选
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"更新国家信息 - country_id: {country_id}, country_code: {country_code}, country_name: {country_name}")
params = {
"id": country_id,
"countryCode": country_code,
"countryName": country_name,
"countryNameEn": country_name_en,
"phoneCode": phone_code,
"status": status
}
if lingxing_country_code:
params["lingxingCountryCode"] = lingxing_country_code
if paypal_country_code:
params["paypalCountryCode"] = paypal_country_code
resp = self.kw_in_joyhub_address_country_update_put(**params)
obj_log.info(f"更新国家信息响应: {resp}")
return resp
@allure.step("批量更新国家信息状态")
def kw_joyhub_address_country_update_status_list_put(self, country_ids, status):
"""
批量更新国家信息状态业务关键字
:param country_ids: 国家信息ID列表
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"批量更新国家信息状态 - country_ids: {country_ids}, status: {status}")
# 接口参数通过query传递ids需要用逗号分隔
ids_str = ','.join(map(str, country_ids))
resp = self.kw_in_joyhub_address_country_update_status_list_put(ids=ids_str, status=status)
obj_log.info(f"批量更新国家信息状态响应: {resp}")
return resp

View File

@@ -1,252 +0,0 @@
# -*- coding:utf-8 -*-
import os
import sys
current_file_path = os.path.abspath(__file__)
project_root = os.path.abspath(os.path.join(os.path.dirname(current_file_path), '../../../'))
if project_root not in sys.path:
sys.path.insert(0, project_root)
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
import allure
obj_log = log.get_logger()
class AfterSalesPolicyManage(DlzhanInterface):
def __init__(self):
super().__init__()
# ============ 售后政策管理 ============
@allure.step("创建售后政策")
def kw_joyhub_after_sales_policy_create_post(self, title, content, lang, brand_id=0, status=1, id=0):
"""
创建售后政策业务关键字
:param id: 主键新增为0
:param brand_id: 品牌ID
:param title: 标题
:param content: 内容
:param lang: 语言 (en 英语 de 德语 ja 日语)
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"创建售后政策 - title: {title}, content: {content[:50]}..., lang: {lang}, brand_id: {brand_id}, status: {status}")
params = {
"id": id,
"brandId": brand_id,
"title": title,
"content": content,
"lang": lang,
"status": status
}
resp = self.kw_in_joyhub_after_sales_policy_create_post(**params)
obj_log.info(f"创建售后政策响应: {resp}")
return resp
@allure.step("删除售后政策")
def kw_joyhub_after_sales_policy_delete_delete(self, policy_id):
"""
删除售后政策业务关键字
:param policy_id: 售后政策ID
:return: 响应结果
"""
obj_log.info(f"删除售后政策 - policy_id: {policy_id}")
resp = self.kw_in_joyhub_after_sales_policy_delete_delete(policy_id)
obj_log.info(f"删除售后政策响应: {resp}")
return resp
@allure.step("批量删除售后政策")
def kw_joyhub_after_sales_policy_delete_list_delete(self, policy_ids):
"""
批量删除售后政策业务关键字
:param policy_ids: 售后政策ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除售后政策 - policy_ids: {policy_ids}")
resp = self.kw_in_joyhub_after_sales_policy_delete_list_delete(policy_ids)
obj_log.info(f"批量删除售后政策响应: {resp}")
return resp
@allure.step("获得售后政策详情")
def kw_joyhub_after_sales_policy_get_get(self, policy_id):
"""
获得售后政策详情业务关键字
:param policy_id: 售后政策ID
:return: 响应结果
"""
obj_log.info(f"获得售后政策详情 - policy_id: {policy_id}")
resp = self.kw_in_joyhub_after_sales_policy_get_get(policy_id)
obj_log.info(f"获得售后政策详情响应: {resp}")
return resp
@allure.step("获得售后政策分页列表")
def kw_joyhub_after_sales_policy_page_get(self, **kwargs):
"""
获得售后政策分页列表业务关键字
:param kwargs: 查询参数title, content, status, page_no, page_size
:return: 响应结果
"""
obj_log.info(f"获得售后政策分页列表 - 参数: {kwargs}")
resp = self.kw_in_joyhub_after_sales_policy_page_get(**kwargs)
obj_log.info(f"获得售后政策分页列表响应: {resp}")
return resp
@allure.step("更新售后政策")
def kw_joyhub_after_sales_policy_update_put(self, policy_id, title, content, lang, brand_id=0, status=1):
"""
更新售后政策业务关键字
:param policy_id: 售后政策ID
:param brand_id: 品牌ID
:param title: 标题
:param content: 内容
:param lang: 语言 (en 英语 de 德语 ja 日语)
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"更新售后政策 - policy_id: {policy_id}, title: {title}, content: {content[:50]}..., lang: {lang}, brand_id: {brand_id}, status: {status}")
params = {
"id": policy_id,
"brandId": brand_id,
"title": title,
"content": content,
"lang": lang,
"status": status
}
resp = self.kw_in_joyhub_after_sales_policy_update_put(**params)
obj_log.info(f"更新售后政策响应: {resp}")
return resp
# ============ 售后政策-品牌管理 ============
@allure.step("创建售后政策-品牌")
def kw_joyhub_after_sales_brand_create_post(self, brand_name, after_sales_policy_id, status=1, id=0):
"""
创建售后政策-品牌业务关键字
:param id: 主键新增为0
:param brand_name: 品牌名称
:param after_sales_policy_id: 售后政策ID
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"创建售后政策-品牌 - brand_name: {brand_name}, after_sales_policy_id: {after_sales_policy_id}, status: {status}")
params = {
"id": id,
"brandName": brand_name,
"afterSalesPolicyId": after_sales_policy_id,
"status": status
}
resp = self.kw_in_joyhub_after_sales_brand_create_post(**params)
obj_log.info(f"创建售后政策-品牌响应: {resp}")
return resp
@allure.step("删除售后政策-品牌")
def kw_joyhub_after_sales_brand_delete_delete(self, brand_id):
"""
删除售后政策-品牌业务关键字
:param brand_id: 售后政策-品牌ID
:return: 响应结果
"""
obj_log.info(f"删除售后政策-品牌 - brand_id: {brand_id}")
resp = self.kw_in_joyhub_after_sales_brand_delete_delete(brand_id)
obj_log.info(f"删除售后政策-品牌响应: {resp}")
return resp
@allure.step("批量删除售后政策-品牌")
def kw_joyhub_after_sales_brand_delete_list_delete(self, brand_ids):
"""
批量删除售后政策-品牌业务关键字
:param brand_ids: 售后政策-品牌ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除售后政策-品牌 - brand_ids: {brand_ids}")
resp = self.kw_in_joyhub_after_sales_brand_delete_list_delete(brand_ids)
obj_log.info(f"批量删除售后政策-品牌响应: {resp}")
return resp
@allure.step("获得售后政策-品牌详情")
def kw_joyhub_after_sales_brand_get_get(self, brand_id):
"""
获得售后政策-品牌详情业务关键字
:param brand_id: 售后政策-品牌ID
:return: 响应结果
"""
obj_log.info(f"获得售后政策-品牌详情 - brand_id: {brand_id}")
resp = self.kw_in_joyhub_after_sales_brand_get_get(brand_id)
obj_log.info(f"获得售后政策-品牌详情响应: {resp}")
return resp
@allure.step("获得可用的品牌列表")
def kw_joyhub_after_sales_brand_list_available_get(self):
"""
获得可用的品牌列表业务关键字
:return: 响应结果
"""
obj_log.info("获得可用的品牌列表")
resp = self.kw_in_joyhub_after_sales_brand_list_available_get()
obj_log.info(f"获得可用的品牌列表响应: {resp}")
return resp
@allure.step("获得售后政策-品牌分页列表")
def kw_joyhub_after_sales_brand_page_get(self, **kwargs):
"""
获得售后政策-品牌分页列表业务关键字
:param kwargs: 查询参数brand_name, after_sales_policy_id, status, page_no, page_size
:return: 响应结果
"""
obj_log.info(f"获得售后政策-品牌分页列表 - 参数: {kwargs}")
resp = self.kw_in_joyhub_after_sales_brand_page_get(**kwargs)
obj_log.info(f"获得售后政策-品牌分页列表响应: {resp}")
return resp
@allure.step("更新售后政策-品牌")
def kw_joyhub_after_sales_brand_update_put(self, brand_id, brand_name, after_sales_policy_id, status=1):
"""
更新售后政策-品牌业务关键字
:param brand_id: 售后政策-品牌ID
:param brand_name: 品牌名称
:param after_sales_policy_id: 售后政策ID
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"更新售后政策-品牌 - brand_id: {brand_id}, brand_name: {brand_name}, after_sales_policy_id: {after_sales_policy_id}, status: {status}")
params = {
"id": brand_id,
"brandName": brand_name,
"afterSalesPolicyId": after_sales_policy_id,
"status": status
}
resp = self.kw_in_joyhub_after_sales_brand_update_put(**params)
obj_log.info(f"更新售后政策-品牌响应: {resp}")
return resp

View File

@@ -1,130 +0,0 @@
# -*- coding:utf-8 -*-
"""
blog分类管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class BlogCateManage(DlzhanInterface):
"""blog分类管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建blog分类")
def kw_joyhub_blog_cate_create_post(self, name, id=0, status=1, rank_num=None, route=None, cover_image=None):
"""
创建blog分类业务关键字
:param id: 主键新增为0
:param name: 分类名称
:param status: 状态 (1正常 2停用)
:param rank_num: 排序(可选)
:param route: 路由(可选)
:param cover_image: 封面图对象,格式: {"url": "xxx", "name": None, "alt": ""}(可选)
:return: 响应结果
"""
obj_log.info(f"创建blog分类 - name: {name}, status: {status}")
params = {
"id": id,
"name": name,
"status": status
}
if rank_num is not None:
params["rankNum"] = rank_num
if route is not None:
params["route"] = route
if cover_image is not None:
if isinstance(cover_image, str):
params["coverImage"] = {"url": cover_image, "name": None, "alt": ""}
else:
params["coverImage"] = cover_image
resp = self.kw_in_joyhub_blog_cate_create_post(**params)
obj_log.info(f"创建blog分类响应: {resp}")
return resp
@allure.step("删除blog分类")
def kw_joyhub_blog_cate_delete_delete(self, cate_id):
"""
删除blog分类业务关键字
:param cate_id: blog分类ID
:return: 响应结果
"""
obj_log.info(f"删除blog分类 - cate_id: {cate_id}")
resp = self.kw_in_joyhub_blog_cate_delete_delete(cate_id)
obj_log.info(f"删除blog分类响应: {resp}")
return resp
@allure.step("获得blog分类详情")
def kw_joyhub_blog_cate_get_get(self, cate_id):
"""
获得blog分类详情业务关键字
:param cate_id: blog分类ID
:return: 响应结果
"""
obj_log.info(f"获得blog分类详情 - cate_id: {cate_id}")
resp = self.kw_in_joyhub_blog_cate_get_get(cate_id)
obj_log.info(f"获得blog分类详情响应: {resp}")
return resp
@allure.step("获得blog分类分页")
def kw_joyhub_blog_cate_page_get(self, page_num=1, page_size=10, **kwargs):
"""
获得blog分类分页业务关键字
:param page_num: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得blog分类分页 - page_num: {page_num}, page_size: {page_size}")
params = {
"page": page_num,
"size": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_blog_cate_page_get(**params)
obj_log.info(f"获得blog分类分页响应: {resp}")
return resp
@allure.step("更新blog分类")
def kw_joyhub_blog_cate_update_put(self, cate_id, name, status=1, rank_num=None, route=None, cover_image=None):
"""
更新blog分类业务关键字
:param cate_id: blog分类ID
:param name: 分类名称
:param status: 状态 (1正常 2停用)
:param rank_num: 排序(可选)
:param route: 路由(可选)
:param cover_image: 封面图对象,格式: {"url": "xxx", "name": None, "alt": ""}(可选)
:return: 响应结果
"""
obj_log.info(f"更新blog分类 - cate_id: {cate_id}, name: {name}, status: {status}")
params = {
"id": cate_id,
"name": name,
"status": status
}
if rank_num is not None:
params["rankNum"] = rank_num
if route is not None:
params["route"] = route
if cover_image is not None:
if isinstance(cover_image, str):
params["coverImage"] = {"url": cover_image, "name": None, "alt": ""}
else:
params["coverImage"] = cover_image
resp = self.kw_in_joyhub_blog_cate_update_put(**params)
obj_log.info(f"更新blog分类响应: {resp}")
return resp

View File

@@ -1,125 +0,0 @@
# -*- coding:utf-8 -*-
"""
二维码管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class DownloadQrcodeManage(DlzhanInterface):
"""二维码管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建二维码")
def kw_joyhub_download_qrcode_create_post(self, title, id=0, status=1):
"""
创建二维码业务关键字
:param id: 主键新增为0
:param title: 标题
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"创建二维码 - title: {title}, status: {status}")
params = {
"id": id,
"title": title,
"status": status
}
resp = self.kw_in_joyhub_download_qrcode_create_post(**params)
obj_log.info(f"创建二维码响应: {resp}")
return resp
@allure.step("获得二维码详情")
def kw_joyhub_download_qrcode_get_get(self, qrcode_id):
"""
获得二维码详情业务关键字
:param qrcode_id: 二维码ID
:return: 响应结果
"""
obj_log.info(f"获得二维码详情 - qrcode_id: {qrcode_id}")
resp = self.kw_in_joyhub_download_qrcode_get_get(qrcode_id)
obj_log.info(f"获得二维码详情响应: {resp}")
return resp
@allure.step("获得二维码分页")
def kw_joyhub_download_qrcode_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得二维码分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得二维码分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_download_qrcode_page_get(**params)
obj_log.info(f"获得二维码分页响应: {resp}")
return resp
@allure.step("更新二维码")
def kw_joyhub_download_qrcode_update_put(self, qrcode_id, title, status=1):
"""
更新二维码业务关键字
:param qrcode_id: 二维码ID
:param title: 标题
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"更新二维码 - qrcode_id: {qrcode_id}, title: {title}, status: {status}")
params = {
"id": qrcode_id,
"title": title,
"status": status
}
resp = self.kw_in_joyhub_download_qrcode_update_put(**params)
obj_log.info(f"更新二维码响应: {resp}")
return resp
def clean_test_data_from_db(self, title):
"""
从数据库表jh_download_qrcode中删除测试数据
:param title: 要删除的二维码标题
:return: 删除是否成功
"""
obj_log.info(f"从数据库删除测试数据 - title: {title}")
try:
import pymysql
# 数据库连接配置(需要根据实际环境配置)
connection = pymysql.connect(
host='localhost',
user='root',
password='password',
database='joyhub',
charset='utf8mb4'
)
with connection.cursor() as cursor:
sql = "DELETE FROM jh_download_qrcode WHERE title LIKE %s"
cursor.execute(sql, (f"%{title}%",))
connection.commit()
deleted_count = cursor.rowcount
obj_log.info(f"成功删除 {deleted_count} 条测试数据")
return True
except Exception as e:
obj_log.error(f"删除测试数据失败: {str(e)}")
return False
finally:
if 'connection' in locals():
connection.close()

View File

@@ -1,108 +0,0 @@
# -*- coding:utf-8 -*-
"""
FAQ分类管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class FaqCateManage(DlzhanInterface):
"""FAQ分类管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建FAQ分类")
def kw_joyhub_faq_cate_create_post(self, title, lang, rank_num, pid=0, status=1, id=0):
"""
创建FAQ分类业务关键字
:param id: 主键新增为0
:param pid: 父分类ID默认为0顶级分类
:param title: 分类名称
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param lang: 语言 (en 英语 de 德语 ja 日语)
:return: 响应结果
"""
obj_log.info(f"创建FAQ分类 - title: {title}, lang: {lang}, pid: {pid}")
params = {
"id": id,
"pid": pid,
"title": title,
"status": status,
"rankNum": rank_num,
"lang": lang
}
resp = self.kw_in_joyhub_faq_cate_create_post(**params)
obj_log.info(f"创建FAQ分类响应: {resp}")
return resp
@allure.step("删除FAQ分类")
def kw_joyhub_faq_cate_delete_delete(self, faq_cate_id):
"""
删除FAQ分类业务关键字
:param faq_cate_id: FAQ分类ID
:return: 响应结果
"""
obj_log.info(f"删除FAQ分类 - faq_cate_id: {faq_cate_id}")
resp = self.kw_in_joyhub_faq_cate_delete_delete(faq_cate_id)
obj_log.info(f"删除FAQ分类响应: {resp}")
return resp
@allure.step("获得FAQ分类详情")
def kw_joyhub_faq_cate_get_get(self, faq_cate_id):
"""
获得FAQ分类详情业务关键字
:param faq_cate_id: FAQ分类ID
:return: 响应结果
"""
obj_log.info(f"获得FAQ分类详情 - faq_cate_id: {faq_cate_id}")
resp = self.kw_in_joyhub_faq_cate_get_get(faq_cate_id)
obj_log.info(f"获得FAQ分类详情响应: {resp}")
return resp
@allure.step("获得FAQ分类列表")
def kw_joyhub_faq_cate_list_get(self, **kwargs):
"""
获得FAQ分类列表业务关键字
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得FAQ分类列表 - kwargs: {kwargs}")
resp = self.kw_in_joyhub_faq_cate_list_get(**kwargs)
obj_log.info(f"获得FAQ分类列表响应: {resp}")
return resp
@allure.step("更新FAQ分类")
def kw_joyhub_faq_cate_update_put(self, faq_cate_id, title, lang, rank_num, pid=0, status=1):
"""
更新FAQ分类业务关键字
:param faq_cate_id: FAQ分类ID
:param pid: 父分类ID
:param title: 分类名称
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param lang: 语言 (en 英语 de 德语 ja 日语)
:return: 响应结果
"""
obj_log.info(f"更新FAQ分类 - faq_cate_id: {faq_cate_id}, title: {title}, lang: {lang}")
params = {
"id": faq_cate_id,
"pid": pid,
"title": title,
"status": status,
"rankNum": rank_num,
"lang": lang
}
resp = self.kw_in_joyhub_faq_cate_update_put(**params)
obj_log.info(f"更新FAQ分类响应: {resp}")
return resp

View File

@@ -1,148 +0,0 @@
# -*- coding:utf-8 -*-
"""
FAQ数据管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class FaqManage(DlzhanInterface):
"""FAQ数据管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得FAQ分类下拉列表")
def kw_joyhub_faq_cate_list_get(self):
"""
获得FAQ分类下拉列表业务关键字
:return: 响应结果
"""
obj_log.info("获得FAQ分类下拉列表")
resp = self.kw_in_joyhub_faq_cate_list_get()
obj_log.info(f"获得FAQ分类下拉列表响应: {resp}")
return resp
@allure.step("创建FAQ数据")
def kw_joyhub_faq_create_post(self, faq_cate_id, question, answer, rank_num, lang, is_hot=0, status=1, id=0):
"""
创建FAQ数据业务关键字
:param id: 主键新增为0
:param faq_cate_id: 分类ID
:param question: 常见问题
:param answer: 回答
:param is_hot: 是否热门0否1是
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param lang: 语言 (en 英语 de 德语 ja 日语)
:return: 响应结果
"""
obj_log.info(f"创建FAQ数据 - question: {question}, lang: {lang}")
params = {
"id": id,
"faqCateId": faq_cate_id,
"question": question,
"answer": answer,
"isHot": is_hot,
"status": status,
"rankNum": rank_num,
"lang": lang
}
resp = self.kw_in_joyhub_faq_create_post(**params)
obj_log.info(f"创建FAQ数据响应: {resp}")
return resp
@allure.step("删除FAQ数据")
def kw_joyhub_faq_delete_delete(self, faq_id):
"""
删除FAQ数据业务关键字
:param faq_id: FAQ数据ID
:return: 响应结果
"""
obj_log.info(f"删除FAQ数据 - faq_id: {faq_id}")
resp = self.kw_in_joyhub_faq_delete_delete(faq_id)
obj_log.info(f"删除FAQ数据响应: {resp}")
return resp
@allure.step("批量删除FAQ数据")
def kw_joyhub_faq_delete_list_delete(self, ids):
"""
批量删除FAQ数据业务关键字
:param ids: FAQ数据ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除FAQ数据 - ids: {ids}")
resp = self.kw_in_joyhub_faq_delete_list_delete(ids)
obj_log.info(f"批量删除FAQ数据响应: {resp}")
return resp
@allure.step("获得FAQ数据详情")
def kw_joyhub_faq_get_get(self, faq_id):
"""
获得FAQ数据详情业务关键字
:param faq_id: FAQ数据ID
:return: 响应结果
"""
obj_log.info(f"获得FAQ数据详情 - faq_id: {faq_id}")
resp = self.kw_in_joyhub_faq_get_get(faq_id)
obj_log.info(f"获得FAQ数据详情响应: {resp}")
return resp
@allure.step("获得FAQ数据分页")
def kw_joyhub_faq_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得FAQ数据分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得FAQ数据分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_faq_page_get(**params)
obj_log.info(f"获得FAQ数据分页响应: {resp}")
return resp
@allure.step("更新FAQ数据")
def kw_joyhub_faq_update_put(self, faq_id, faq_cate_id, question, answer, rank_num, lang, is_hot=0, status=1):
"""
更新FAQ数据业务关键字
:param faq_id: FAQ数据ID
:param faq_cate_id: 分类ID
:param question: 常见问题
:param answer: 回答
:param is_hot: 是否热门0否1是
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param lang: 语言 (en 英语 de 德语 ja 日语)
:return: 响应结果
"""
obj_log.info(f"更新FAQ数据 - faq_id: {faq_id}, question: {question}, lang: {lang}")
params = {
"id": faq_id,
"faqCateId": faq_cate_id,
"question": question,
"answer": answer,
"isHot": is_hot,
"status": status,
"rankNum": rank_num,
"lang": lang
}
resp = self.kw_in_joyhub_faq_update_put(**params)
obj_log.info(f"更新FAQ数据响应: {resp}")
return resp

View File

@@ -1,167 +0,0 @@
# -*- coding:utf-8 -*-
"""
news分类管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class NewsCateManage(DlzhanInterface):
"""news分类管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建news分类")
def kw_joyhub_news_cate_create_post(self, name, id=0, status=1, rank_num=1, route=None, cover_image=None):
"""
创建news分类业务关键字
:param id: 主键新增为0
:param name: 分类名称
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param route: 路由(可选)
:param cover_image: 缩略图(可选)
:return: 响应结果
"""
obj_log.info(f"创建news分类 - name: {name}")
params = {
"id": id,
"name": name,
"status": status,
"rankNum": rank_num
}
if route is not None:
params["route"] = route
if cover_image is not None:
params["coverImage"] = cover_image
resp = self.kw_in_joyhub_news_cate_create_post(**params)
obj_log.info(f"创建news分类响应: {resp}")
return resp
@allure.step("删除news分类")
def kw_joyhub_news_cate_delete_delete(self, news_cate_id):
"""
删除news分类业务关键字
:param news_cate_id: news分类ID
:return: 响应结果
"""
obj_log.info(f"删除news分类 - news_cate_id: {news_cate_id}")
resp = self.kw_in_joyhub_news_cate_delete_delete(news_cate_id)
obj_log.info(f"删除news分类响应: {resp}")
return resp
@allure.step("批量删除news分类")
def kw_joyhub_news_cate_delete_list_delete(self, ids):
"""
批量删除news分类业务关键字
:param ids: news分类ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除news分类 - ids: {ids}")
resp = self.kw_in_joyhub_news_cate_delete_list_delete(ids)
obj_log.info(f"批量删除news分类响应: {resp}")
return resp
@allure.step("获得news分类详情")
def kw_joyhub_news_cate_get_get(self, news_cate_id):
"""
获得news分类详情业务关键字
:param news_cate_id: news分类ID
:return: 响应结果
"""
obj_log.info(f"获得news分类详情 - news_cate_id: {news_cate_id}")
resp = self.kw_in_joyhub_news_cate_get_get(news_cate_id)
obj_log.info(f"获得news分类详情响应: {resp}")
return resp
@allure.step("获得news分类分页")
def kw_joyhub_news_cate_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得news分类分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得news分类分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_news_cate_page_get(**params)
obj_log.info(f"获得news分类分页响应: {resp}")
return resp
@allure.step("更新news分类")
def kw_joyhub_news_cate_update_put(self, news_cate_id, name, status=1, rank_num=1, route=None, cover_image=None):
"""
更新news分类业务关键字
:param news_cate_id: news分类ID
:param name: 分类名称
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param route: 路由(可选)
:param cover_image: 缩略图(可选)
:return: 响应结果
"""
obj_log.info(f"更新news分类 - news_cate_id: {news_cate_id}, name: {name}")
params = {
"id": news_cate_id,
"name": name,
"status": status,
"rankNum": rank_num
}
if route is not None:
params["route"] = route
if cover_image is not None:
params["coverImage"] = cover_image
resp = self.kw_in_joyhub_news_cate_update_put(**params)
obj_log.info(f"更新news分类响应: {resp}")
return resp
def clean_test_data_from_db(self, name):
"""
从数据库表jh_news_cate中删除测试数据
:param name: 要删除的分类名称
:return: 删除是否成功
"""
obj_log.info(f"从数据库删除测试数据 - name: {name}")
try:
import pymysql
# 数据库连接配置(需要根据实际环境配置)
connection = pymysql.connect(
host='localhost',
user='root',
password='password',
database='joyhub',
charset='utf8mb4'
)
with connection.cursor() as cursor:
sql = "DELETE FROM jh_news_cate WHERE name LIKE %s"
cursor.execute(sql, (f"%{name}%",))
connection.commit()
deleted_count = cursor.rowcount
obj_log.info(f"成功删除 {deleted_count} 条测试数据")
return True
except Exception as e:
obj_log.error(f"删除测试数据失败: {str(e)}")
return False
finally:
if 'connection' in locals():
connection.close()

View File

@@ -1,187 +0,0 @@
# -*- coding:utf-8 -*-
"""
news管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class NewsManage(DlzhanInterface):
"""news管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建news管理")
def kw_joyhub_news_create_post(self, title, cover_image, content, id=0, status=1, rank_num=1,
seo_title=None, seo_keyword=None, seo_description=None,
likes_num=0, cate_ids=None, route=None, publish_time=None):
"""
创建news管理业务关键字
:param id: 主键新增为0
:param title: 标题
:param cover_image: 缩略图
:param content: PC页面内容
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param seo_title: SEO标题可选
:param seo_keyword: SEO关键词可选
:param seo_description: SEO描述可选
:param likes_num: 点赞数(可选)
:param cate_ids: news分类ID列表可选
:param route: 路由(可选)
:param publish_time: 发布时间(可选)
:return: 响应结果
"""
obj_log.info(f"创建news管理 - title: {title}")
params = {
"id": id,
"title": title,
"coverImage": cover_image,
"content": content,
"status": status,
"rankNum": rank_num,
"likesNum": likes_num
}
if seo_title is not None:
params["seoTitle"] = seo_title
if seo_keyword is not None:
params["seoKeyword"] = seo_keyword
if seo_description is not None:
params["seoDescription"] = seo_description
if cate_ids is not None:
params["cateIds"] = cate_ids
if route is not None:
params["route"] = route
if publish_time is not None:
params["publishTime"] = publish_time
resp = self.kw_in_joyhub_news_create_post(**params)
obj_log.info(f"创建news管理响应: {resp}")
return resp
@allure.step("删除news管理")
def kw_joyhub_news_delete_delete(self, news_id):
"""
删除news管理业务关键字
:param news_id: news管理ID
:return: 响应结果
"""
obj_log.info(f"删除news管理 - news_id: {news_id}")
resp = self.kw_in_joyhub_news_delete_delete(news_id)
obj_log.info(f"删除news管理响应: {resp}")
return resp
@allure.step("批量删除news管理")
def kw_joyhub_news_delete_list_delete(self, ids):
"""
批量删除news管理业务关键字
:param ids: news管理ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除news管理 - ids: {ids}")
resp = self.kw_in_joyhub_news_delete_list_delete(ids)
obj_log.info(f"批量删除news管理响应: {resp}")
return resp
@allure.step("获得news管理详情")
def kw_joyhub_news_get_get(self, news_id):
"""
获得news管理详情业务关键字
:param news_id: news管理ID
:return: 响应结果
"""
obj_log.info(f"获得news管理详情 - news_id: {news_id}")
resp = self.kw_in_joyhub_news_get_get(news_id)
obj_log.info(f"获得news管理详情响应: {resp}")
return resp
@allure.step("获得news分类关联列表")
def kw_joyhub_news_cate_relation_list_get(self, news_id):
"""
获得news分类关联列表业务关键字
:param news_id: news管理ID
:return: 响应结果
"""
obj_log.info(f"获得news分类关联列表 - news_id: {news_id}")
resp = self.kw_in_joyhub_news_cate_relation_list_get(news_id)
obj_log.info(f"获得news分类关联列表响应: {resp}")
return resp
@allure.step("获得news管理分页")
def kw_joyhub_news_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得news管理分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得news管理分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_news_page_get(**params)
obj_log.info(f"获得news管理分页响应: {resp}")
return resp
@allure.step("更新news管理")
def kw_joyhub_news_update_put(self, news_id, title, cover_image, content, status=1, rank_num=1,
seo_title=None, seo_keyword=None, seo_description=None,
likes_num=0, cate_ids=None, route=None, publish_time=None):
"""
更新news管理业务关键字
:param news_id: news管理ID
:param title: 标题
:param cover_image: 缩略图
:param content: PC页面内容
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:param seo_title: SEO标题可选
:param seo_keyword: SEO关键词可选
:param seo_description: SEO描述可选
:param likes_num: 点赞数(可选)
:param cate_ids: news分类ID列表可选
:param route: 路由(可选)
:param publish_time: 发布时间(可选)
:return: 响应结果
"""
obj_log.info(f"更新news管理 - news_id: {news_id}, title: {title}")
params = {
"id": news_id,
"title": title,
"coverImage": cover_image,
"content": content,
"status": status,
"rankNum": rank_num,
"likesNum": likes_num
}
if seo_title is not None:
params["seoTitle"] = seo_title
if seo_keyword is not None:
params["seoKeyword"] = seo_keyword
if seo_description is not None:
params["seoDescription"] = seo_description
if cate_ids is not None:
params["cateIds"] = cate_ids
if route is not None:
params["route"] = route
if publish_time is not None:
params["publishTime"] = publish_time
resp = self.kw_in_joyhub_news_update_put(**params)
obj_log.info(f"更新news管理响应: {resp}")
return resp

View File

@@ -1,268 +0,0 @@
# -*- coding:utf-8 -*-
"""
产品属性+产品属性值管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class ProductAttrManage(DlzhanInterface):
"""产品属性+产品属性值管理业务关键字类"""
def __init__(self):
super().__init__()
# ============ 产品属性管理方法 ============
@allure.step("创建产品属性")
def kw_joyhub_product_attr_type_create_post(self, name, type=2, id=0, status=1, remark=None, rank_num=None):
"""
创建产品属性业务关键字
:param id: 主键新增为0
:param type: 属性类型1-颜色属性有色卡2-普通属性
:param name: 属性名称
:param status: 状态 (1正常 2停用)
:param remark: 备注(可选)
:param rank_num: 排序号(可选)
:return: 响应结果
"""
obj_log.info(f"创建产品属性 - name: {name}, type: {type}")
params = {
"id": id,
"type": type,
"name": name,
"status": status
}
if remark is not None:
params["remark"] = remark
if rank_num is not None:
params["rankNum"] = rank_num
resp = self.kw_in_joyhub_product_attr_type_create_post(**params)
obj_log.info(f"创建产品属性响应: {resp}")
return resp
@allure.step("删除产品属性")
def kw_joyhub_product_attr_type_delete_delete(self, product_attr_type_id):
"""
删除产品属性业务关键字
:param product_attr_type_id: 产品属性ID
:return: 响应结果
"""
obj_log.info(f"删除产品属性 - product_attr_type_id: {product_attr_type_id}")
resp = self.kw_in_joyhub_product_attr_type_delete_delete(product_attr_type_id)
obj_log.info(f"删除产品属性响应: {resp}")
return resp
@allure.step("批量删除产品属性")
def kw_joyhub_product_attr_type_delete_list_delete(self, ids):
"""
批量删除产品属性业务关键字
:param ids: 产品属性ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除产品属性 - ids: {ids}")
resp = self.kw_in_joyhub_product_attr_type_delete_list_delete(ids)
obj_log.info(f"批量删除产品属性响应: {resp}")
return resp
@allure.step("获得产品属性详情")
def kw_joyhub_product_attr_type_get_get(self, product_attr_type_id):
"""
获得产品属性详情业务关键字
:param product_attr_type_id: 产品属性ID
:return: 响应结果
"""
obj_log.info(f"获得产品属性详情 - product_attr_type_id: {product_attr_type_id}")
resp = self.kw_in_joyhub_product_attr_type_get_get(product_attr_type_id)
obj_log.info(f"获得产品属性详情响应: {resp}")
return resp
@allure.step("获得产品属性分页")
def kw_joyhub_product_attr_type_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得产品属性分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得产品属性分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_product_attr_type_page_get(**params)
obj_log.info(f"获得产品属性分页响应: {resp}")
return resp
@allure.step("更新产品属性")
def kw_joyhub_product_attr_type_update_put(self, product_attr_type_id, name, type=2, status=1, remark=None, rank_num=None):
"""
更新产品属性业务关键字
:param product_attr_type_id: 产品属性ID
:param name: 属性名称
:param type: 属性类型1-颜色属性有色卡2-普通属性
:param status: 状态 (1正常 2停用)
:param remark: 备注(可选)
:param rank_num: 排序号(可选)
:return: 响应结果
"""
obj_log.info(f"更新产品属性 - product_attr_type_id: {product_attr_type_id}, name: {name}")
params = {
"id": product_attr_type_id,
"type": type,
"name": name,
"status": status
}
if remark is not None:
params["remark"] = remark
if rank_num is not None:
params["rankNum"] = rank_num
resp = self.kw_in_joyhub_product_attr_type_update_put(**params)
obj_log.info(f"更新产品属性响应: {resp}")
return resp
@allure.step("修改产品属性状态")
def kw_joyhub_product_attr_type_change_status_put(self, product_attr_type_id, status):
"""
修改产品属性状态业务关键字
:param product_attr_type_id: 产品属性ID
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"修改产品属性状态 - product_attr_type_id: {product_attr_type_id}, status: {status}")
params = {
"id": product_attr_type_id,
"status": status
}
resp = self.kw_in_joyhub_product_attr_type_change_status_put(**params)
obj_log.info(f"修改产品属性状态响应: {resp}")
return resp
# ============ 产品属性值管理方法 ============
@allure.step("创建产品属性值")
def kw_joyhub_product_attr_data_create_post(self, product_attr_type_id, attr_value, id=0, color=None):
"""
创建产品属性值业务关键字
:param id: 主键ID新增为0
:param product_attr_type_id: 关联产品属性表的主键ID
:param attr_value: 属性值名称
:param color: 色卡(可选,颜色属性类型时使用)
:return: 响应结果
"""
obj_log.info(f"创建产品属性值 - product_attr_type_id: {product_attr_type_id}, attr_value: {attr_value}")
params = {
"id": id,
"productAttrTypeId": product_attr_type_id,
"attrValue": attr_value
}
if color is not None:
params["color"] = color
resp = self.kw_in_joyhub_product_attr_data_create_post(**params)
obj_log.info(f"创建产品属性值响应: {resp}")
return resp
@allure.step("删除产品属性值")
def kw_joyhub_product_attr_data_delete_delete(self, product_attr_data_id):
"""
删除产品属性值业务关键字
:param product_attr_data_id: 产品属性值ID
:return: 响应结果
"""
obj_log.info(f"删除产品属性值 - product_attr_data_id: {product_attr_data_id}")
resp = self.kw_in_joyhub_product_attr_data_delete_delete(product_attr_data_id)
obj_log.info(f"删除产品属性值响应: {resp}")
return resp
@allure.step("批量删除产品属性值")
def kw_joyhub_product_attr_data_delete_list_delete(self, ids):
"""
批量删除产品属性值业务关键字
:param ids: 产品属性值ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除产品属性值 - ids: {ids}")
resp = self.kw_in_joyhub_product_attr_data_delete_list_delete(ids)
obj_log.info(f"批量删除产品属性值响应: {resp}")
return resp
@allure.step("获得产品属性值详情")
def kw_joyhub_product_attr_data_get_get(self, product_attr_data_id):
"""
获得产品属性值详情业务关键字
:param product_attr_data_id: 产品属性值ID
:return: 响应结果
"""
obj_log.info(f"获得产品属性值详情 - product_attr_data_id: {product_attr_data_id}")
resp = self.kw_in_joyhub_product_attr_data_get_get(product_attr_data_id)
obj_log.info(f"获得产品属性值详情响应: {resp}")
return resp
@allure.step("获得产品属性值分页")
def kw_joyhub_product_attr_data_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得产品属性值分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得产品属性值分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_product_attr_data_page_get(**params)
obj_log.info(f"获得产品属性值分页响应: {resp}")
return resp
@allure.step("更新产品属性值")
def kw_joyhub_product_attr_data_update_put(self, product_attr_data_id, product_attr_type_id, attr_value, color=None):
"""
更新产品属性值业务关键字
:param product_attr_data_id: 产品属性值ID
:param product_attr_type_id: 关联产品属性表的主键ID
:param attr_value: 属性值名称
:param color: 色卡(可选,颜色属性类型时使用)
:return: 响应结果
"""
obj_log.info(f"更新产品属性值 - product_attr_data_id: {product_attr_data_id}, attr_value: {attr_value}")
params = {
"id": product_attr_data_id,
"productAttrTypeId": product_attr_type_id,
"attrValue": attr_value
}
if color is not None:
params["color"] = color
resp = self.kw_in_joyhub_product_attr_data_update_put(**params)
obj_log.info(f"更新产品属性值响应: {resp}")
return resp

View File

@@ -1,145 +0,0 @@
# -*- coding:utf-8 -*-
"""
产品分类管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class ProductCateManage(DlzhanInterface):
"""产品分类管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建产品分类")
def kw_joyhub_product_cate_create_post(self, cate_name, id=0, cate_type=1, status=1, rank_num=1):
"""
创建产品分类业务关键字
:param id: 主键ID新增为0
:param cate_name: 产品分类名称
:param cate_type: 类型(普通产品=1积分产品=2
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:return: 响应结果
"""
obj_log.info(f"创建产品分类 - cate_name: {cate_name}, cate_type: {cate_type}")
params = {
"id": id,
"cateName": cate_name,
"cateType": cate_type,
"status": status,
"rankNum": rank_num
}
resp = self.kw_in_joyhub_product_cate_create_post(**params)
obj_log.info(f"创建产品分类响应: {resp}")
return resp
@allure.step("删除产品分类")
def kw_joyhub_product_cate_delete_delete(self, product_cate_id):
"""
删除产品分类业务关键字
:param product_cate_id: 产品分类ID
:return: 响应结果
"""
obj_log.info(f"删除产品分类 - product_cate_id: {product_cate_id}")
resp = self.kw_in_joyhub_product_cate_delete_delete(product_cate_id)
obj_log.info(f"删除产品分类响应: {resp}")
return resp
@allure.step("批量删除产品分类")
def kw_joyhub_product_cate_delete_list_delete(self, ids):
"""
批量删除产品分类业务关键字
:param ids: 产品分类ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除产品分类 - ids: {ids}")
resp = self.kw_in_joyhub_product_cate_delete_list_delete(ids)
obj_log.info(f"批量删除产品分类响应: {resp}")
return resp
@allure.step("获得产品分类详情")
def kw_joyhub_product_cate_get_get(self, product_cate_id):
"""
获得产品分类详情业务关键字
:param product_cate_id: 产品分类ID
:return: 响应结果
"""
obj_log.info(f"获得产品分类详情 - product_cate_id: {product_cate_id}")
resp = self.kw_in_joyhub_product_cate_get_get(product_cate_id)
obj_log.info(f"获得产品分类详情响应: {resp}")
return resp
@allure.step("获得产品分类分页")
def kw_joyhub_product_cate_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得产品分类分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得产品分类分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_product_cate_page_get(**params)
obj_log.info(f"获得产品分类分页响应: {resp}")
return resp
@allure.step("更新产品分类")
def kw_joyhub_product_cate_update_put(self, product_cate_id, cate_name, cate_type=1, status=1, rank_num=1):
"""
更新产品分类业务关键字
:param product_cate_id: 产品分类ID
:param cate_name: 产品分类名称
:param cate_type: 类型(普通产品=1积分产品=2
:param status: 状态 (1正常 2停用)
:param rank_num: 排序号
:return: 响应结果
"""
obj_log.info(f"更新产品分类 - product_cate_id: {product_cate_id}, cate_name: {cate_name}")
params = {
"id": product_cate_id,
"cateName": cate_name,
"cateType": cate_type,
"status": status,
"rankNum": rank_num
}
resp = self.kw_in_joyhub_product_cate_update_put(**params)
obj_log.info(f"更新产品分类响应: {resp}")
return resp
@allure.step("修改产品分类启用/停用状态")
def kw_joyhub_product_cate_change_status_put(self, product_cate_id, status):
"""
修改产品分类启用/停用状态业务关键字
:param product_cate_id: 产品分类ID
:param status: 状态 (1正常 2停用)
:return: 响应结果
"""
obj_log.info(f"修改产品分类状态 - product_cate_id: {product_cate_id}, status: {status}")
params = {
"id": product_cate_id,
"status": status
}
resp = self.kw_in_joyhub_product_cate_change_status_put(**params)
obj_log.info(f"修改产品分类状态响应: {resp}")
return resp

View File

@@ -1,269 +0,0 @@
# -*- coding:utf-8 -*-
"""
产品管理业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class ProductManage(DlzhanInterface):
"""产品管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建产品")
def kw_joyhub_product_create_post(self, product_name, product_cate_id, shipping_template_id, route, intro,
brand_id, product_attrs, product_skus, id=0, product_type=1,
status=1, rank_num=None, seo_title=None, seo_keyword=None,
seo_description=None, single_user_exchange_limit=None,
single_product_exchange_limit=None, product_details=None):
"""
创建产品业务关键字
:param id: 主键新增为0
:param product_type: 产品类型(普通产品=1积分产品=2
:param product_name: 产品名称
:param product_cate_id: 产品分类
:param shipping_template_id: 运费模板ID
:param route: 跳转路由
:param intro: 产品简介
:param brand_id: 品牌id
:param status: 状态1上架2下架
:param rank_num: 序号(可选)
:param seo_title: SEO标题可选
:param seo_keyword: SEO关键词可选
:param seo_description: SEO描述可选
:param single_user_exchange_limit: 单用户兑换次数限制(可选)
:param single_product_exchange_limit: 单次兑换数量限制(可选)
:param product_attrs: 产品规格类型关联列表
:param product_skus: 产品规格列表
:param product_details: 产品详情列表(可选)
:return: 响应结果
"""
obj_log.info(f"创建产品 - product_name: {product_name}, product_type: {product_type}")
params = {
"id": id,
"productType": product_type,
"productName": product_name,
"productCateId": product_cate_id,
"shippingTemplateId": shipping_template_id,
"route": route,
"intro": intro,
"brandId": brand_id,
"status": status,
"productAttrs": product_attrs,
"productSkus": product_skus
}
if rank_num is not None:
params["rankNum"] = rank_num
if seo_title is not None:
params["seoTitle"] = seo_title
if seo_keyword is not None:
params["seoKeyword"] = seo_keyword
if seo_description is not None:
params["seoDescription"] = seo_description
if single_user_exchange_limit is not None:
params["singleUserExchangeLimit"] = single_user_exchange_limit
if single_product_exchange_limit is not None:
params["singleProductExchangeLimit"] = single_product_exchange_limit
if product_details is not None:
params["productDetails"] = product_details
resp = self.kw_in_joyhub_product_create_post(**params)
obj_log.info(f"创建产品响应: {resp}")
return resp
@allure.step("删除产品")
def kw_joyhub_product_delete_delete(self, product_id):
"""
删除产品业务关键字
:param product_id: 产品ID
:return: 响应结果
"""
obj_log.info(f"删除产品 - product_id: {product_id}")
resp = self.kw_in_joyhub_product_delete_delete(product_id)
obj_log.info(f"删除产品响应: {resp}")
return resp
@allure.step("批量删除产品")
def kw_joyhub_product_delete_list_delete(self, ids):
"""
批量删除产品业务关键字
:param ids: 产品ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除产品 - ids: {ids}")
resp = self.kw_in_joyhub_product_delete_list_delete(ids)
obj_log.info(f"批量删除产品响应: {resp}")
return resp
@allure.step("获得产品详情")
def kw_joyhub_product_get_get(self, product_id):
"""
获得产品详情业务关键字
:param product_id: 产品ID
:return: 响应结果
"""
obj_log.info(f"获得产品详情 - product_id: {product_id}")
resp = self.kw_in_joyhub_product_get_get(product_id)
obj_log.info(f"获得产品详情响应: {resp}")
return resp
@allure.step("获得产品分页")
def kw_joyhub_product_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得产品分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得产品分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_product_page_get(**params)
obj_log.info(f"获得产品分页响应: {resp}")
return resp
@allure.step("获得产品规格类型关联列表")
def kw_joyhub_product_product_attr_list_by_product_id_get(self, product_id):
"""
获得产品规格类型关联列表业务关键字
:param product_id: 产品ID
:return: 响应结果
"""
obj_log.info(f"获得产品规格类型关联列表 - product_id: {product_id}")
resp = self.kw_in_joyhub_product_product_attr_list_by_product_id_get(product_id)
obj_log.info(f"获得产品规格类型关联列表响应: {resp}")
return resp
@allure.step("获得产品详情列表")
def kw_joyhub_product_product_detail_list_by_product_id_get(self, product_id):
"""
获得产品详情列表业务关键字
:param product_id: 产品ID
:return: 响应结果
"""
obj_log.info(f"获得产品详情列表 - product_id: {product_id}")
resp = self.kw_in_joyhub_product_product_detail_list_by_product_id_get(product_id)
obj_log.info(f"获得产品详情列表响应: {resp}")
return resp
@allure.step("获得产品规格列表")
def kw_joyhub_product_product_sku_list_by_product_id_get(self, product_id):
"""
获得产品规格列表业务关键字
:param product_id: 产品ID
:return: 响应结果
"""
obj_log.info(f"获得产品规格列表 - product_id: {product_id}")
resp = self.kw_in_joyhub_product_product_sku_list_by_product_id_get(product_id)
obj_log.info(f"获得产品规格列表响应: {resp}")
return resp
@allure.step("获得产品及规格列表-优惠券中使用")
def kw_joyhub_product_product_sku_list_get(self, **kwargs):
"""
获得产品及规格列表-优惠券中使用业务关键字
:param kwargs: 查询条件
:return: 响应结果
"""
obj_log.info(f"获得产品及规格列表 - params: {kwargs}")
resp = self.kw_in_joyhub_product_product_sku_list_get(**kwargs)
obj_log.info(f"获得产品及规格列表响应: {resp}")
return resp
@allure.step("更新产品")
def kw_joyhub_product_update_put(self, product_id, product_name, product_cate_id, shipping_template_id, route, intro,
brand_id, product_attrs, product_skus, product_type=1,
status=1, rank_num=None, seo_title=None, seo_keyword=None,
seo_description=None, single_user_exchange_limit=None,
single_product_exchange_limit=None, product_details=None):
"""
更新产品业务关键字
:param product_id: 产品ID
:param product_type: 产品类型(普通产品=1积分产品=2
:param product_name: 产品名称
:param product_cate_id: 产品分类
:param shipping_template_id: 运费模板ID
:param route: 跳转路由
:param intro: 产品简介
:param brand_id: 品牌id
:param status: 状态1上架2下架
:param rank_num: 序号(可选)
:param seo_title: SEO标题可选
:param seo_keyword: SEO关键词可选
:param seo_description: SEO描述可选
:param single_user_exchange_limit: 单用户兑换次数限制(可选)
:param single_product_exchange_limit: 单次兑换数量限制(可选)
:param product_attrs: 产品规格类型关联列表
:param product_skus: 产品规格列表
:param product_details: 产品详情列表(可选)
:return: 响应结果
"""
obj_log.info(f"更新产品 - product_id: {product_id}, product_name: {product_name}")
params = {
"id": product_id,
"productType": product_type,
"productName": product_name,
"productCateId": product_cate_id,
"shippingTemplateId": shipping_template_id,
"route": route,
"intro": intro,
"brandId": brand_id,
"status": status,
"productAttrs": product_attrs,
"productSkus": product_skus
}
if rank_num is not None:
params["rankNum"] = rank_num
if seo_title is not None:
params["seoTitle"] = seo_title
if seo_keyword is not None:
params["seoKeyword"] = seo_keyword
if seo_description is not None:
params["seoDescription"] = seo_description
if single_user_exchange_limit is not None:
params["singleUserExchangeLimit"] = single_user_exchange_limit
if single_product_exchange_limit is not None:
params["singleProductExchangeLimit"] = single_product_exchange_limit
if product_details is not None:
params["productDetails"] = product_details
resp = self.kw_in_joyhub_product_update_put(**params)
obj_log.info(f"更新产品响应: {resp}")
return resp
@allure.step("批量上下架产品")
def kw_joyhub_product_change_status_put(self, ids, status):
"""
批量上下架产品业务关键字
:param ids: 产品ID列表
:param status: 状态1上架2下架
:return: 响应结果
"""
obj_log.info(f"批量上下架产品 - ids: {ids}, status: {status}")
params = {
"ids": ids,
"status": status
}
resp = self.kw_in_joyhub_product_change_status_put(**params)
obj_log.info(f"批量上下架产品响应: {resp}")
return resp

View File

@@ -1,124 +0,0 @@
# -*- coding:utf-8 -*-
"""
支付页产品推荐业务关键字层
"""
import allure
from dulizhan.library.Dlizhan_interface import DlzhanInterface
from base_framework.public_tools import log
obj_log = log.get_logger()
class ProductPaymentRecommendManage(DlzhanInterface):
"""支付页产品推荐业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("修改支付页产品推荐排序号")
def kw_joyhub_product_payment_recommend_change_rank_num_put(self, recommend_id, rank_num):
"""
修改支付页产品推荐排序号业务关键字
:param recommend_id: 推荐ID
:param rank_num: 排序号
:return: 响应结果
"""
obj_log.info(f"修改支付页产品推荐排序号 - recommend_id: {recommend_id}, rank_num: {rank_num}")
resp = self.kw_in_joyhub_product_payment_recommend_change_rank_num_put(id=recommend_id, rankNum=rank_num)
obj_log.info(f"修改支付页产品推荐排序号响应: {resp}")
return resp
@allure.step("修改支付页产品推荐状态")
def kw_joyhub_product_payment_recommend_change_status_put(self, recommend_id, recommend_status):
"""
修改支付页产品推荐状态业务关键字
:param recommend_id: 推荐ID
:param recommend_status: 推荐状态
:return: 响应结果
"""
obj_log.info(f"修改支付页产品推荐状态 - recommend_id: {recommend_id}, recommend_status: {recommend_status}")
resp = self.kw_in_joyhub_product_payment_recommend_change_status_put(id=recommend_id, recommendStatus=recommend_status)
obj_log.info(f"修改支付页产品推荐状态响应: {resp}")
return resp
@allure.step("创建支付页产品推荐")
def kw_joyhub_product_payment_recommend_create_post(self, product_ids, recommend_id=None):
"""
创建支付页产品推荐业务关键字
:param product_ids: 产品ID列表
:param recommend_id: 推荐ID
:return: 响应结果
"""
obj_log.info(f"创建支付页产品推荐 - product_ids: {product_ids}")
params = {"productIds": product_ids}
if recommend_id is not None:
params["id"] = recommend_id
resp = self.kw_in_joyhub_product_payment_recommend_create_post(**params)
obj_log.info(f"创建支付页产品推荐响应: {resp}")
return resp
@allure.step("删除支付页产品推荐")
def kw_joyhub_product_payment_recommend_delete_delete(self, recommend_id):
"""
删除支付页产品推荐业务关键字
:param recommend_id: 推荐ID
:return: 响应结果
"""
obj_log.info(f"删除支付页产品推荐 - recommend_id: {recommend_id}")
resp = self.kw_in_joyhub_product_payment_recommend_delete_delete(recommend_id)
obj_log.info(f"删除支付页产品推荐响应: {resp}")
return resp
@allure.step("批量删除支付页产品推荐")
def kw_joyhub_product_payment_recommend_delete_list_delete(self, ids):
"""
批量删除支付页产品推荐业务关键字
:param ids: 推荐ID列表
:return: 响应结果
"""
obj_log.info(f"批量删除支付页产品推荐 - ids: {ids}")
resp = self.kw_in_joyhub_product_payment_recommend_delete_list_delete(ids)
obj_log.info(f"批量删除支付页产品推荐响应: {resp}")
return resp
@allure.step("获得支付页产品推荐分页")
def kw_joyhub_product_payment_recommend_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得支付页产品推荐分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得支付页产品推荐分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_product_payment_recommend_page_get(**params)
obj_log.info(f"获得支付页产品推荐分页响应: {resp}")
return resp
@allure.step("获得C端支付页产品推荐分页")
def kw_joyhub_web_product_payment_recommend_page_get(self, page_no=1, page_size=10, **kwargs):
"""
获得支付页产品推荐分页业务关键字
:param page_no: 页码
:param page_size: 每页大小
:param kwargs: 其他查询条件
:return: 响应结果
"""
obj_log.info(f"获得支付页产品推荐分页 - page_no: {page_no}, page_size: {page_size}")
params = {
"pageNo": page_no,
"pageSize": page_size
}
params.update(kwargs)
resp = self.kw_in_joyhub_web_product_payment_recommend_page_get(**params)
obj_log.info(f"获得支付页产品推荐分页响应: {resp}")
return resp

View File

@@ -1,27 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端APP版本业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCAppVersionManage(JoyHubCLoginManage):
"""JoyHub C端APP版本业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获取APP版本列表")
def kw_joyhub_c_web_appversion_page_get(self, **kwargs):
"""
获取APP版本列表业务关键字
:return: 响应结果
"""
obj_log.info("获取APP版本列表")
resp = self.kw_in_joyhub_c_web_appversion_page_get(**kwargs)
obj_log.info(f"获取APP版本列表响应: {resp}")
return resp

View File

@@ -1,38 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端Banner信息业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCBannerManage(JoyHubCLoginManage):
"""JoyHub C端Banner信息业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得Banner管理")
def kw_joyhub_c_banner_get_get(self, **kwargs):
"""
获得Banner管理业务关键字
:return: 响应结果
"""
obj_log.info("获得Banner管理")
resp = self.kw_in_joyhub_c_banner_get_get(**kwargs)
obj_log.info(f"获得Banner管理响应: {resp}")
return resp
@allure.step("获得Banner管理分页")
def kw_joyhub_c_banner_page_get(self, **kwargs):
"""
获得Banner管理分页业务关键字
:return: 响应结果
"""
obj_log.info("获得Banner管理分页")
resp = self.kw_in_joyhub_c_banner_page_get(**kwargs)
obj_log.info(f"获得Banner管理分页响应: {resp}")
return resp

View File

@@ -1,27 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端blog分类业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCBlogCateManage(JoyHubCLoginManage):
"""JoyHub C端blog分类业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得blog分类列表")
def kw_joyhub_c_blog_cate_list_get(self, **kwargs):
"""
获得blog分类列表业务关键字
:return: 响应结果
"""
obj_log.info("获得blog分类列表")
resp = self.kw_in_joyhub_c_blog_cate_list_get(**kwargs)
obj_log.info(f"获得blog分类列表响应: {resp}")
return resp

View File

@@ -1,49 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端blog信息业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCBlogManage(JoyHubCLoginManage):
"""JoyHub C端blog信息业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得blog详情")
def kw_joyhub_c_blog_get_detail_get(self, **kwargs):
"""
获得blog详情业务关键字
:return: 响应结果
"""
obj_log.info("获得blog详情")
resp = self.kw_in_joyhub_c_blog_get_detail_get(**kwargs)
obj_log.info(f"获得blog详情响应: {resp}")
return resp
@allure.step("获得blog下一条")
def kw_joyhub_c_blog_get_next_get(self, **kwargs):
"""
获得blog下一条业务关键字
:return: 响应结果
"""
obj_log.info("获得blog下一条")
resp = self.kw_in_joyhub_c_blog_get_next_get(**kwargs)
obj_log.info(f"获得blog下一条响应: {resp}")
return resp
@allure.step("获得blog管理分页")
def kw_joyhub_c_blog_page_get(self, **kwargs):
"""
获得blog管理分页业务关键字
:return: 响应结果
"""
obj_log.info("获得blog管理分页")
resp = self.kw_in_joyhub_c_blog_page_get(**kwargs)
obj_log.info(f"获得blog管理分页响应: {resp}")
return resp

View File

@@ -1,27 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端合作联系业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCCooperationManage(JoyHubCLoginManage):
"""JoyHub C端合作联系业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("提交合作联系信息")
def kw_joyhub_c_cooperation_create_post(self, **kwargs):
"""
提交合作联系信息业务关键字
:return: 响应结果
"""
obj_log.info("提交合作联系信息")
resp = self.kw_in_joyhub_c_cooperation_create_post(**kwargs)
obj_log.info(f"提交合作联系信息响应: {resp}")
return resp

View File

@@ -1,38 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端二维码访问统计业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCDownloadQrcodeManage(JoyHubCLoginManage):
"""JoyHub C端二维码访问统计业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获取二维码信息")
def kw_joyhub_c_download_qrcode_get_get(self, **kwargs):
"""
获取二维码信息业务关键字
:return: 响应结果
"""
obj_log.info("获取二维码信息")
resp = self.kw_in_joyhub_c_download_qrcode_get_get(**kwargs)
obj_log.info(f"获取二维码信息响应: {resp}")
return resp
@allure.step("增加二维码访问/点击次数")
def kw_joyhub_c_download_qrcode_increment_post(self, **kwargs):
"""
增加二维码访问/点击次数业务关键字
:return: 响应结果
"""
obj_log.info("增加二维码访问/点击次数")
resp = self.kw_in_joyhub_c_download_qrcode_increment_post(**kwargs)
obj_log.info(f"增加二维码访问/点击次数响应: {resp}")
return resp

View File

@@ -1,27 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端FAQ联系我们业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCFaqContactUsManage(JoyHubCLoginManage):
"""JoyHub C端FAQ联系我们业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("提交FAQ联系信息")
def kw_joyhub_c_faq_contact_us_create_post(self, **kwargs):
"""
提交FAQ联系信息业务关键字
:return: 响应结果
"""
obj_log.info("提交FAQ联系信息")
resp = self.kw_in_joyhub_c_faq_contact_us_create_post(**kwargs)
obj_log.info(f"提交FAQ联系信息响应: {resp}")
return resp

View File

@@ -1,38 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端FAQ业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCFaqManage(JoyHubCLoginManage):
"""JoyHub C端FAQ业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得FAQ分类树")
def kw_joyhub_c_faq_cate_list_get(self, **kwargs):
"""
获得FAQ分类树业务关键字
:return: 响应结果
"""
obj_log.info("获得FAQ分类树")
resp = self.kw_in_joyhub_c_faq_cate_list_get(**kwargs)
obj_log.info(f"获得FAQ分类树响应: {resp}")
return resp
@allure.step("获得FAQ列表")
def kw_joyhub_c_faq_list_get(self, **kwargs):
"""
获得FAQ列表业务关键字
:return: 响应结果
"""
obj_log.info("获得FAQ列表")
resp = self.kw_in_joyhub_c_faq_list_get(**kwargs)
obj_log.info(f"获得FAQ列表响应: {resp}")
return resp

View File

@@ -1,60 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端点赞记录业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCLikeInfoManage(JoyHubCLoginManage):
"""JoyHub C端点赞记录业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("创建点赞记录")
def kw_joyhub_c_like_info_create_post(self, **kwargs):
"""
创建点赞记录业务关键字
:return: 响应结果
"""
obj_log.info("创建点赞记录")
resp = self.kw_in_joyhub_c_like_info_create_post(**kwargs)
obj_log.info(f"创建点赞记录响应: {resp}")
return resp
@allure.step("取消点赞")
def kw_joyhub_c_like_info_delete_post(self, **kwargs):
"""
取消点赞业务关键字
:return: 响应结果
"""
obj_log.info("取消点赞")
resp = self.kw_in_joyhub_c_like_info_delete_post(**kwargs)
obj_log.info(f"取消点赞响应: {resp}")
return resp
@allure.step("获得点赞记录")
def kw_joyhub_c_like_info_get_get(self, **kwargs):
"""
获得点赞记录业务关键字
:return: 响应结果
"""
obj_log.info("获得点赞记录")
resp = self.kw_in_joyhub_c_like_info_get_get(**kwargs)
obj_log.info(f"获得点赞记录响应: {resp}")
return resp
@allure.step("获得点赞记录分页")
def kw_joyhub_c_like_info_page_get(self, **kwargs):
"""
获得点赞记录分页业务关键字
:return: 响应结果
"""
obj_log.info("获得点赞记录分页")
resp = self.kw_in_joyhub_c_like_info_page_get(**kwargs)
obj_log.info(f"获得点赞记录分页响应: {resp}")
return resp

View File

@@ -1,84 +0,0 @@
# -*- coding:utf-8 -*-
import os
import re
import time
import allure
from base_framework.public_tools import log
from dulizhan.library.Dlizhan_interface import DlzhanInterface
obj_log = log.get_logger()
class JoyHubCLoginManage(DlzhanInterface):
def __init__(self):
super().__init__()
test_url = self._read_robot_variable("joyhub_c_test_url")
if test_url:
self.joyhub_c_frontend_url = test_url
def _read_robot_variable(self, var_name):
robot_file_path = os.path.join(
os.path.dirname(__file__),
'../../../test_case/Resource/AdapterKws/hh-qa.robot'
)
try:
with open(robot_file_path, 'r', encoding='utf-8') as f:
content = f.read()
pattern = r'\$\{' + re.escape(var_name) + r'\}\s+(\S+)'
match = re.search(pattern, content)
if match:
return match.group(1)
except Exception as e:
obj_log.error("读取robot配置文件失败: {}".format(str(e)))
return None
@allure.step("获取JoyHub C端邮箱验证码")
def kw_joyhub_c_get_email_code(self, email=None, code_pattern=r'\d{4,8}'):
email = email or self._read_robot_variable("joyhub_c_login_email")
if not email:
raise Exception("C端登录邮箱不能为空请检查 joyhub_c_login_email 配置")
obj_log.info("获取JoyHub C端邮箱验证码 - email: {}".format(email))
code = self.kw_in_joyhub_c_get_email_code(email, code_pattern)
obj_log.info("获取JoyHub C端邮箱验证码成功")
return code
@allure.step("JoyHub C端登录")
def kw_joyhub_c_login(self, path=None, email=None, code=None, is_check='true', **kwargs):
email = email or self._read_robot_variable("joyhub_c_login_email")
path = path or self._read_robot_variable("joyhub_c_login_path")
if not email:
raise Exception("C端登录邮箱不能为空请检查 joyhub_c_login_email 配置")
if not path:
raise Exception("C端登录接口路径不能为空请检查 joyhub_c_login_path 配置")
code = code or "123456"
params = {
"email": email,
"valid_code": code,
"sys_type": "windows",
"app_channel": "5",
"lang": "en",
"client_time": str(int(time.time()))
}
params.update(kwargs)
obj_log.info("JoyHub C端登录 - email: {}, path: {}".format(email, path))
resp = self.kw_in_joyhub_c_login_post(path=path, is_check=is_check, **params)
data = resp.get('data') if isinstance(resp, dict) else None
token = None
if isinstance(data, dict):
token = data.get('accessToken') or data.get('access_token') or data.get('token')
token = token or resp.get('accessToken') if isinstance(resp, dict) else token
token = token or resp.get('access_token') if isinstance(resp, dict) else token
token = token or resp.get('token') if isinstance(resp, dict) else token
if token:
self.set_joyhub_c_token(token)
obj_log.info("JoyHub C端登录成功Token已写入当前实例")
else:
obj_log.warning("JoyHub C端登录响应中未解析到Token")
return resp

View File

@@ -1,27 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端news分类业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCNewsCateManage(JoyHubCLoginManage):
"""JoyHub C端news分类业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得news分类列表")
def kw_joyhub_c_news_cate_list_get(self, **kwargs):
"""
获得news分类列表业务关键字
:return: 响应结果
"""
obj_log.info("获得news分类列表")
resp = self.kw_in_joyhub_c_news_cate_list_get(**kwargs)
obj_log.info(f"获得news分类列表响应: {resp}")
return resp

View File

@@ -1,49 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端news管理业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCNewsManage(JoyHubCLoginManage):
"""JoyHub C端news管理业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得news详情")
def kw_joyhub_c_news_get_detail_get(self, **kwargs):
"""
获得news详情业务关键字
:return: 响应结果
"""
obj_log.info("获得news详情")
resp = self.kw_in_joyhub_c_news_get_detail_get(**kwargs)
obj_log.info(f"获得news详情响应: {resp}")
return resp
@allure.step("获得news下一条")
def kw_joyhub_c_news_get_next_get(self, **kwargs):
"""
获得news下一条业务关键字
:return: 响应结果
"""
obj_log.info("获得news下一条")
resp = self.kw_in_joyhub_c_news_get_next_get(**kwargs)
obj_log.info(f"获得news下一条响应: {resp}")
return resp
@allure.step("获得news管理分页")
def kw_joyhub_c_news_page_get(self, **kwargs):
"""
获得news管理分页业务关键字
:return: 响应结果
"""
obj_log.info("获得news管理分页")
resp = self.kw_in_joyhub_c_news_page_get(**kwargs)
obj_log.info(f"获得news管理分页响应: {resp}")
return resp

View File

@@ -1,38 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端产品业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCProductManage(JoyHubCLoginManage):
"""JoyHub C端产品业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("产品详情")
def kw_joyhub_c_product_get_get(self, **kwargs):
"""
产品详情业务关键字
:return: 响应结果
"""
obj_log.info("产品详情")
resp = self.kw_in_joyhub_c_product_get_get(**kwargs)
obj_log.info(f"产品详情响应: {resp}")
return resp
@allure.step("获得产品分页")
def kw_joyhub_c_product_page_get(self, **kwargs):
"""
获得产品分页业务关键字
:return: 响应结果
"""
obj_log.info("获得产品分页")
resp = self.kw_in_joyhub_c_product_page_get(**kwargs)
obj_log.info(f"获得产品分页响应: {resp}")
return resp

View File

@@ -1,27 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端支付页产品推荐业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCProductPaymentRecommendManage(JoyHubCLoginManage):
"""JoyHub C端支付页产品推荐业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("获得支付页产品推荐分页")
def kw_joyhub_c_product_payment_recommend_page_get(self, **kwargs):
"""
获得支付页产品推荐分页业务关键字
:return: 响应结果
"""
obj_log.info("获得支付页产品推荐分页")
resp = self.kw_in_joyhub_c_product_payment_recommend_page_get(**kwargs)
obj_log.info(f"获得支付页产品推荐分页响应: {resp}")
return resp

View File

@@ -1,27 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端用户业务关键字层
"""
import allure
from dulizhan.library.BusinessKw.JoyHubC.LoginManage import JoyHubCLoginManage
from base_framework.public_tools import log
obj_log = log.get_logger()
class JoyHubCUserManage(JoyHubCLoginManage):
"""JoyHub C端用户业务关键字类"""
def __init__(self):
super().__init__()
@allure.step("查询当前用户积分")
def kw_joyhub_c_client_get_point_get(self):
"""
查询当前用户积分业务关键字
:return: 响应结果
"""
obj_log.info("查询当前用户积分")
resp = self.kw_in_joyhub_c_client_get_point_get()
obj_log.info(f"查询当前用户积分响应: {resp}")
return resp

View File

@@ -0,0 +1,97 @@
# -*- coding:utf-8 -*-
"""
Author: qiaoxinjiu
Email: qiaoxinjiu@sparkedu.com
Create Date: 2026/01/22 5:58 下午
"""
import logging
import os
import sys
# 添加项目根目录到 Python 路径,以便导入 base_framework 模块
current_file_path = os.path.abspath(__file__)
project_root = os.path.abspath(os.path.join(os.path.dirname(current_file_path), '../../../../'))
if project_root not in sys.path:
sys.path.insert(0, project_root)
from base_framework.public_tools import log
from base_framework.public_tools.my_faker import MyFaker
from base_framework.public_tools.runner import Runner
from base_framework.public_tools.pgsqlhelper import PgSqlHelper
from base_framework.public_tools import read_config
from base_framework.public_tools import utils
from base_framework.public_tools import mg_keyword
from zhyy.library.ZZYY_interface import ZhyyInterface
obj_get_log = log.get_logger()
obj_my_faker = MyFaker()
obj_runner = Runner()
obj_pgsql_helper = PgSqlHelper()
obj_get_way = utils.Tools()
obj_mg_keyword = mg_keyword.ManageKeyWord()
class PurchaseOrder(ZhyyInterface):
def __init__(self):
'''
这个是针对于读取配置文件的初始化函数,用于读取默认参数
'''
super().__init__()
self.config_index_path = os.path.dirname(os.path.abspath(__file__))
self.config_index_filePath = os.path.join(self.config_index_path, "purchase.ini")
self.config_index_content = read_config.ReadConfig(filename=self.config_index_filePath)
def kw_zhyy_get_purchase_page_post(self, note, user, **kwargs):
"""
| 功能说明: | 返回采购工作台采购单列表数据 |
| 输入参数: | note | 注释 |
|user | 用户信息,传入 'purchase' 默认读取配置文件里面 'purchase' 对应的默认账号信息|
|supplier_company_ids | 供应商id | 非必填
|payment_status | 付款状态 | 非必填
|status | 采购单状态 | 非必填
|order_sn | 采购单号 | 非必填
|page_no | 页码 | 必填
|page_size | 每页条数 | 必填
| 返回参数: | {"success":true,"message":"success","code":200,"data":
{'todoTask':['PO260116003','PO260115010'],'inProcessTask':['PO260116003','PO260115010']}} | |
| 作者信息: | 谯新久 | 修改时间 | 2022-8-20 |
"""
logging.info("==========={0}===========".format(note))
# 获取所有参数
supplier_company_ids = kwargs.get("supplier_company_ids")
payment_status = kwargs.get("payment_status")
status = kwargs.get("status")
order_sn = kwargs.get("order_sn")
page_no = kwargs.get("page_no")
page_size = kwargs.get("page_size")
# 检查必填参数
if not page_no or not page_size:
raise Exception("页码和每页条数不能为空")
# 组装参数字典,只包含非空字段,参数名使用 pageNo 和 pageSize
request_params = {
"pageNo": page_no,
"pageSize": page_size
}
# 如果字段不为空,才添加到参数字典中
if supplier_company_ids is not None and supplier_company_ids != "":
request_params["supplier_company_ids"] = supplier_company_ids
if payment_status is not None and payment_status != "":
request_params["payment_status"] = payment_status
if status is not None and status != "":
request_params["status"] = status
if order_sn is not None and order_sn != "":
request_params["order_sn"] = order_sn
# 使用 ** 方式解包字典传递参数
get_todo_info = self.kw_in_zhyy_purchase_order_page_post(user=user, **request_params)
print(get_todo_info if get_todo_info else "查询失败")
return get_todo_info
if __name__ == '__main__':
test = PurchaseOrder()
a = test.kw_zhyy_get_purchase_page_post(user='purchase', note="测试", page_no=1, page_size=10)
print(a)

View File

@@ -0,0 +1,88 @@
# -*- coding:utf-8 -*-
"""
Author: qiaoxinjiu
Email: qiaoxinjiu@sparkedu.com
Create Date: 2022/08/20 5:58 下午
"""
import logging
import os
import sys
# 添加项目根目录到 Python 路径,以便导入 base_framework 模块
current_file_path = os.path.abspath(__file__)
project_root = os.path.abspath(os.path.join(os.path.dirname(current_file_path), '../../../../'))
if project_root not in sys.path:
sys.path.insert(0, project_root)
from base_framework.public_tools import log
from base_framework.public_tools.my_faker import MyFaker
from base_framework.public_tools.runner import Runner
from base_framework.public_tools.pgsqlhelper import PgSqlHelper
from base_framework.public_tools import read_config
from base_framework.public_tools import utils
from base_framework.public_tools import mg_keyword
from zhyy.library.ZZYY_interface import ZhyyInterface
obj_get_log = log.get_logger()
obj_my_faker = MyFaker()
obj_runner = Runner()
obj_pgsql_helper = PgSqlHelper()
obj_get_way = utils.Tools()
obj_mg_keyword = mg_keyword.ManageKeyWord()
class PurchaseIndex(ZhyyInterface):
def __init__(self):
'''
这个是针对于读取配置文件的初始化函数,用于读取默认参数
'''
super().__init__()
self.config_index_path = os.path.dirname(os.path.abspath(__file__))
self.config_index_filePath = os.path.join(self.config_index_path, "purchase.ini")
self.config_index_content = read_config.ReadConfig(filename=self.config_index_filePath)
def kw_zhyy_get_todo(self, note, user):
"""
| 功能说明: | 返回采购工作台首页待办任务的PO与在办任务PO |
| 输入参数: | note | 注释 |
|user | 用户信息,传入 'purchase' 默认读取配置文件里面 'purchase' 对应的默认账号信息|
| 返回参数: | {"success":true,"message":"success","code":200,"data":
{'todoTask':['PO260116003','PO260115010'],'inProcessTask':['PO260116003','PO260115010']}} | |
| 作者信息: | 谯新久 | 修改时间 | 2022-8-20 |
"""
logging.info("==========={0}===========".format(note))
get_todo_info = self.kw_in_zhyy_purchase_todo_get(user=user)
if get_todo_info['code'] != 0:
raise Exception("查询采购待办任务失败: {}".format(get_todo_info))
get_todo_info["message"] = "查询采购待办任务成功"
data = get_todo_info.get("data")
if data is None:
raise Exception("返回数据为空data字段不存在")
list_get_todo_task = data.get("todoTask") or []
list_get_process_task = data.get("inProcessTask") or []
list_todo_task_po = []
list_process_task_po = []
for todoTask in list_get_todo_task:
if isinstance(todoTask, dict):
list_todo_task_po.append(todoTask.get("businessSn"))
for processTask in list_get_process_task:
if isinstance(processTask, dict):
list_process_task_po.append(processTask.get("businessSn"))
get_todo_info["data"]["todoTask"] = list_todo_task_po
get_todo_info["data"]["inProcessTask"] = list_process_task_po
if list_todo_task_po:
test_purchase = list_todo_task_po[0]
# 表在public schema中使用public.erp_purchase_order格式
sql = "SELECT * FROM public.erp_purchase_order WHERE order_sn = '{}'".format(test_purchase)
try:
obj_pgsql_helper.select_one(sql)
except Exception as e:
# 如果查询失败,记录日志但不影响主流程
obj_get_log.warning("查询采购订单表失败,订单号:{},错误:{}".format(test_purchase, str(e)))
return get_todo_info
if __name__ == '__main__':
test = PurchaseIndex()
a = test.kw_zhyy_get_todo(user='purchase',note="测试")
print(a)

View File

@@ -0,0 +1,2 @@
[qa-user]
user_info ={"studentId":21797349,"sex":0,"nickName":"auto st test","birthday":1640966400000,"avatar":"https://stalegacy.huohua.cn/image/huohua/avatar/default/default_avatar1.png"}

View File

@@ -14,10 +14,6 @@ from base_framework.public_tools import utils
from base_framework.public_tools.pgsqlhelper import PgSqlHelper
import requests
import json
import re
import imaplib
import email as email_parser
from email.header import decode_header
obj_log = log.get_logger()
obj_runner = Runner()
@@ -29,11 +25,7 @@ class DlzhanInterface:
self.domain_url = eureka.get_url_from_config()
self.pg_db = PgSqlHelper()
self.joyhub_domain = "https://joyhub-website-manager-api-test.best-envision.com"
self.joyhub_c_domain = "https://joyhub-website-frontend-test.best-envision.com"
self.joyhub_c_frontend_url = "https://joyhub-website-frontend-test.best-envision.com/"
self.joyhub_c_session = requests.session()
self.token = None
self.joyhub_c_token = None
def _get_joyhub_headers(self):
headers = {
@@ -47,47 +39,6 @@ class DlzhanInterface:
def set_joyhub_token(self, token):
self.token = token
def set_joyhub_c_token(self, token):
self.joyhub_c_token = token
def _get_joyhub_c_headers(self):
headers = {
'accept': '*/*',
'Content-Type': 'application/json',
'jh-appchannel': '5',
'origin': self.joyhub_c_domain,
'referer': self.joyhub_c_frontend_url,
'tenant-id': '126'
}
if self.joyhub_c_token:
headers['Authorization'] = 'Bearer ' + self.joyhub_c_token
return headers
def _joyhub_c_request(self, method, path, is_check='', note='', return_json=True, **kwargs):
url = path if path.startswith('http') else "{}{}".format(self.joyhub_c_domain, path)
headers = self._get_joyhub_c_headers()
obj_log.info("=========== {} ===========".format(note or path))
req_params = {}
for key, value in kwargs.items():
if value is not None and value != '':
req_params[key] = value
req_map = {
'GET': lambda: self.joyhub_c_session.get(url, headers=headers, params=req_params, verify=False),
'POST': lambda: self.joyhub_c_session.post(url, headers=headers, json=req_params, verify=False),
'PUT': lambda: self.joyhub_c_session.put(url, headers=headers, json=req_params, verify=False),
'DELETE': lambda: self.joyhub_c_session.delete(url, headers=headers, verify=False)
}
resp = req_map.get(method.upper(), lambda: None)()
self._check_resp(is_check, resp)
if return_json:
return resp.json()
else:
return resp
def _joyhub_request(self, method, path, is_check='', note='', return_json=True, **kwargs):
url = "{}{}".format(self.joyhub_domain, path)
headers = self._get_joyhub_headers()
@@ -435,463 +386,8 @@ class DlzhanInterface:
def kw_in_joyhub_agreement_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/agreement/update', is_check, '更新协议', **kwargs)
# ============ 售后政策管理接口 ============
def kw_in_joyhub_after_sales_policy_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/after-sales-policy/create', is_check, '创建售后政策', **kwargs)
def kw_in_joyhub_after_sales_policy_delete_delete(self, policy_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/after-sales-policy/delete?id={policy_id}', is_check, '删除售后政策')
def kw_in_joyhub_after_sales_policy_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/after-sales-policy/delete-list?ids={ids_str}', is_check, '批量删除售后政策')
def kw_in_joyhub_after_sales_policy_get_get(self, policy_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/after-sales-policy/get?id={policy_id}', is_check, '获得售后政策')
def kw_in_joyhub_after_sales_policy_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/after-sales-policy/page', is_check, '获得售后政策分页', **kwargs)
def kw_in_joyhub_after_sales_policy_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/after-sales-policy/update', is_check, '更新售后政策', **kwargs)
# ============ 售后政策-品牌管理接口 ============
def kw_in_joyhub_after_sales_brand_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/after-sales-brand/create', is_check, '创建售后政策-品牌', **kwargs)
def kw_in_joyhub_after_sales_brand_delete_delete(self, brand_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/after-sales-brand/delete?id={brand_id}', is_check, '删除售后政策-品牌')
def kw_in_joyhub_after_sales_brand_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/after-sales-brand/delete-list?ids={ids_str}', is_check, '批量删除售后政策-品牌')
def kw_in_joyhub_after_sales_brand_get_get(self, brand_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/after-sales-brand/get?id={brand_id}', is_check, '获得售后政策-品牌')
def kw_in_joyhub_after_sales_brand_list_available_get(self, is_check=''):
return self._joyhub_request('GET', '/admin-api/jh/after-sales-brand/list-available', is_check, '获得可用的品牌列表')
def kw_in_joyhub_after_sales_brand_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/after-sales-brand/page', is_check, '获得售后政策-品牌分页', **kwargs)
def kw_in_joyhub_after_sales_brand_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/after-sales-brand/update', is_check, '更新售后政策-品牌', **kwargs)
# ============ 国家信息管理接口 ============
def kw_in_joyhub_address_country_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/address-country/create', is_check, '创建国家信息', **kwargs)
def kw_in_joyhub_address_country_delete_delete(self, country_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/address-country/delete?id={country_id}', is_check, '删除国家信息')
def kw_in_joyhub_address_country_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/address-country/delete-list?ids={ids_str}', is_check, '批量删除国家信息')
def kw_in_joyhub_address_country_get_get(self, country_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/address-country/get?id={country_id}', is_check, '获得国家信息')
def kw_in_joyhub_address_country_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/address-country/page', is_check, '获得国家信息分页', **kwargs)
def kw_in_joyhub_address_country_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/address-country/update', is_check, '更新国家信息', **kwargs)
def kw_in_joyhub_address_country_update_status_list_put(self, ids, status, is_check=''):
return self._joyhub_request('PUT', f'/admin-api/jh/address-country/update-status-list?ids={ids}&status={status}', is_check, '批量更新国家信息状态')
# ============ blog分类管理接口 ============
def kw_in_joyhub_blog_cate_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/blog-cate/create', is_check, '创建blog分类', **kwargs)
def kw_in_joyhub_blog_cate_delete_delete(self, cate_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/blog-cate/delete?id={cate_id}', is_check, '删除blog分类')
def kw_in_joyhub_blog_cate_get_get(self, cate_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/blog-cate/get?id={cate_id}', is_check, '获得blog分类')
def kw_in_joyhub_blog_cate_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/blog-cate/page', is_check, '获得blog分类分页', **kwargs)
def kw_in_joyhub_blog_cate_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/blog-cate/update', is_check, '更新blog分类', **kwargs)
# ============ 二维码管理接口 ============
def kw_in_joyhub_download_qrcode_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/download-qrcode/create', is_check, '创建二维码', **kwargs)
def kw_in_joyhub_download_qrcode_get_get(self, qrcode_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/download-qrcode/get?id={qrcode_id}', is_check, '获得二维码')
def kw_in_joyhub_download_qrcode_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/download-qrcode/page', is_check, '获得二维码分页', **kwargs)
def kw_in_joyhub_download_qrcode_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/download-qrcode/update', is_check, '更新二维码', **kwargs)
# ============ FAQ分类管理接口 ============
def kw_in_joyhub_faq_cate_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/faq-cate/create', is_check, '创建FAQ分类', **kwargs)
def kw_in_joyhub_faq_cate_delete_delete(self, faq_cate_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/faq-cate/delete?id={faq_cate_id}', is_check, '删除FAQ分类')
def kw_in_joyhub_faq_cate_get_get(self, faq_cate_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/faq-cate/get?id={faq_cate_id}', is_check, '获得FAQ分类')
def kw_in_joyhub_faq_cate_list_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/faq-cate/list', is_check, '获得FAQ分类列表', **kwargs)
def kw_in_joyhub_faq_cate_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/faq-cate/update', is_check, '更新FAQ分类', **kwargs)
# ============ FAQ数据管理接口 ============
def kw_in_joyhub_faq_cate_list_get(self, is_check=''):
return self._joyhub_request('GET', '/admin-api/jh/faq/cate-list', is_check, '获得FAQ分类下拉列表')
def kw_in_joyhub_faq_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/faq/create', is_check, '创建FAQ数据', **kwargs)
def kw_in_joyhub_faq_delete_delete(self, faq_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/faq/delete?id={faq_id}', is_check, '删除FAQ数据')
def kw_in_joyhub_faq_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/faq/delete-list?ids={ids_str}', is_check, '批量删除FAQ数据')
def kw_in_joyhub_faq_get_get(self, faq_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/faq/get?id={faq_id}', is_check, '获得FAQ数据')
def kw_in_joyhub_faq_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/faq/page', is_check, '获得FAQ数据分页', **kwargs)
def kw_in_joyhub_faq_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/faq/update', is_check, '更新FAQ数据', **kwargs)
# ============ news分类管理接口 ============
def kw_in_joyhub_news_cate_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/news-cate/create', is_check, '创建news分类', **kwargs)
def kw_in_joyhub_news_cate_delete_delete(self, news_cate_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/news-cate/delete?id={news_cate_id}', is_check, '删除news分类')
def kw_in_joyhub_news_cate_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/news-cate/delete-list?ids={ids_str}', is_check, '批量删除news分类')
def kw_in_joyhub_news_cate_get_get(self, news_cate_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/news-cate/get?id={news_cate_id}', is_check, '获得news分类')
def kw_in_joyhub_news_cate_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/news-cate/page', is_check, '获得news分类分页', **kwargs)
def kw_in_joyhub_news_cate_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/news-cate/update', is_check, '更新news分类', **kwargs)
# ============ news管理接口 ============
def kw_in_joyhub_news_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/news/create', is_check, '创建news管理', **kwargs)
def kw_in_joyhub_news_delete_delete(self, news_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/news/delete?id={news_id}', is_check, '删除news管理')
def kw_in_joyhub_news_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/news/delete-list?ids={ids_str}', is_check, '批量删除news管理')
def kw_in_joyhub_news_get_get(self, news_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/news/get?id={news_id}', is_check, '获得news管理')
def kw_in_joyhub_news_cate_relation_list_get(self, news_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/news/news-cate-relation/list-by-news-id?newsId={news_id}', is_check, '获得news分类关联列表')
def kw_in_joyhub_news_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/news/page', is_check, '获得news管理分页', **kwargs)
def kw_in_joyhub_news_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/news/update', is_check, '更新news管理', **kwargs)
# ============ 产品分类管理接口 ============
def kw_in_joyhub_product_cate_change_status_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product-cate/change-status', is_check, '修改产品分类启用/停用状态', **kwargs)
def kw_in_joyhub_product_cate_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/product-cate/create', is_check, '创建产品分类', **kwargs)
def kw_in_joyhub_product_cate_delete_delete(self, product_cate_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/product-cate/delete?id={product_cate_id}', is_check, '删除产品分类')
def kw_in_joyhub_product_cate_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/product-cate/delete-list?ids={ids_str}', is_check, '批量删除产品分类')
def kw_in_joyhub_product_cate_get_get(self, product_cate_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/product-cate/get?id={product_cate_id}', is_check, '获得产品分类')
def kw_in_joyhub_product_cate_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/product-cate/page', is_check, '获得产品分类分页', **kwargs)
def kw_in_joyhub_product_cate_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product-cate/update', is_check, '更新产品分类', **kwargs)
# ============ 产品属性管理接口 ============
def kw_in_joyhub_product_attr_type_change_status_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product-attr-type/change-status', is_check, '启用/停用产品属性状态', **kwargs)
def kw_in_joyhub_product_attr_type_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/product-attr-type/create', is_check, '创建产品属性', **kwargs)
def kw_in_joyhub_product_attr_type_delete_delete(self, product_attr_type_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/product-attr-type/delete?id={product_attr_type_id}', is_check, '删除产品属性')
def kw_in_joyhub_product_attr_type_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/product-attr-type/delete-list?ids={ids_str}', is_check, '批量删除产品属性')
def kw_in_joyhub_product_attr_type_get_get(self, product_attr_type_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/product-attr-type/get?id={product_attr_type_id}', is_check, '获得产品属性')
def kw_in_joyhub_product_attr_type_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/product-attr-type/page', is_check, '获得产品属性分页', **kwargs)
def kw_in_joyhub_product_attr_type_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product-attr-type/update', is_check, '更新产品属性', **kwargs)
# ============ 产品属性值管理接口 ============
def kw_in_joyhub_product_attr_data_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/product-attr-data/create', is_check, '创建产品属性值', **kwargs)
def kw_in_joyhub_product_attr_data_delete_delete(self, product_attr_data_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/product-attr-data/delete?id={product_attr_data_id}', is_check, '删除产品属性值')
def kw_in_joyhub_product_attr_data_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/product-attr-data/delete-list?ids={ids_str}', is_check, '批量删除产品属性值')
def kw_in_joyhub_product_attr_data_get_get(self, product_attr_data_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/product-attr-data/get?id={product_attr_data_id}', is_check, '获得产品属性值')
def kw_in_joyhub_product_attr_data_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/product-attr-data/page', is_check, '获得产品属性值分页', **kwargs)
def kw_in_joyhub_product_attr_data_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product-attr-data/update', is_check, '更新产品属性值', **kwargs)
# ============ 产品管理接口 ============
def kw_in_joyhub_product_change_status_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product/change-status', is_check, '批量上下架产品', **kwargs)
def kw_in_joyhub_product_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/product/create', is_check, '创建产品', **kwargs)
def kw_in_joyhub_product_delete_delete(self, product_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/product/delete?id={product_id}', is_check, '删除产品')
def kw_in_joyhub_product_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/product/delete-list?ids={ids_str}', is_check, '批量删除产品')
def kw_in_joyhub_product_get_get(self, product_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/product/get?id={product_id}', is_check, '获得产品')
def kw_in_joyhub_product_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/product/page', is_check, '获得产品分页', **kwargs)
def kw_in_joyhub_product_product_attr_list_by_product_id_get(self, product_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/product/product-attr/list-by-product-id?productId={product_id}', is_check, '获得产品规格类型关联列表')
def kw_in_joyhub_product_product_detail_list_by_product_id_get(self, product_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/product/product-detail/list-by-product-id?productId={product_id}', is_check, '获得产品详情列表')
def kw_in_joyhub_product_product_sku_list_by_product_id_get(self, product_id, is_check=''):
return self._joyhub_request('GET', f'/admin-api/jh/product/product-sku/list-by-product-id?productId={product_id}', is_check, '获得产品规格列表')
def kw_in_joyhub_product_product_sku_list_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/product/product/sku-list', is_check, '获得产品及规格列表-优惠券中使用', **kwargs)
def kw_in_joyhub_product_update_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product/update', is_check, '更新产品', **kwargs)
# ============ 管理后台-支付页产品推荐接口 ============
def kw_in_joyhub_product_payment_recommend_change_rank_num_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product-payment-recommend/change-rank-num', is_check, '修改支付页产品推荐排序号', **kwargs)
def kw_in_joyhub_product_payment_recommend_change_status_put(self, is_check='', **kwargs):
return self._joyhub_request('PUT', '/admin-api/jh/product-payment-recommend/change-status', is_check, '修改支付页产品推荐状态', **kwargs)
def kw_in_joyhub_product_payment_recommend_create_post(self, is_check='', **kwargs):
return self._joyhub_request('POST', '/admin-api/jh/product-payment-recommend/create', is_check, '创建支付页产品推荐', **kwargs)
def kw_in_joyhub_product_payment_recommend_delete_delete(self, recommend_id, is_check=''):
return self._joyhub_request('DELETE', f'/admin-api/jh/product-payment-recommend/delete?id={recommend_id}', is_check, '删除支付页产品推荐')
def kw_in_joyhub_product_payment_recommend_delete_list_delete(self, ids, is_check=''):
ids_str = ','.join(map(str, ids))
return self._joyhub_request('DELETE', f'/admin-api/jh/product-payment-recommend/delete-list?ids={ids_str}', is_check, '批量删除支付页产品推荐')
def kw_in_joyhub_product_payment_recommend_page_get(self, is_check='', **kwargs):
return self._joyhub_request('GET', '/admin-api/jh/product-payment-recommend/page', is_check, '获得支付页产品推荐分页', **kwargs)
# ============ C端-登录公共接口 ============
def kw_in_joyhub_c_login_post(self, path, is_check='', **kwargs):
return self._joyhub_c_request('POST', path, is_check, 'JoyHub C端登录', **kwargs)
def kw_in_joyhub_c_get_email_code(self, email, code_pattern=r'\d{4,8}'):
auth_code = os.environ.get('JOYHUB_C_EMAIL_AUTH_CODE') or os.environ.get('NETEASE_163_AUTH_CODE')
if not auth_code:
raise Exception("网易163邮箱授权码不能为空请先设置环境变量 JOYHUB_C_EMAIL_AUTH_CODE")
obj_log.info("开始连接网易163邮箱获取验证码 - email: {}".format(email))
mail = imaplib.IMAP4_SSL('imap.163.com', 993)
try:
mail.login(email, auth_code)
status, _ = mail.select('INBOX')
if status != 'OK':
raise Exception("邮箱 {} 无法选择收件箱".format(email))
status, data = mail.search(None, 'ALL')
if status != 'OK' or not data or not data[0]:
raise Exception("邮箱 {} 未查询到邮件".format(email))
email_ids = data[0].split()
for email_id in reversed(email_ids[-20:]):
status, msg_data = mail.fetch(email_id, '(RFC822)')
if status != 'OK' or not msg_data:
continue
msg = email_parser.message_from_bytes(msg_data[0][1])
subject = self._decode_email_header(msg.get('Subject', ''))
content = self._get_email_content(msg)
match = re.search(code_pattern, '{}\n{}'.format(subject, content or ''))
if match:
obj_log.info("网易163邮箱验证码获取成功")
return match.group(0)
raise Exception("邮箱 {} 最近20封邮件中未匹配到验证码".format(email))
finally:
try:
mail.logout()
except Exception:
pass
def _decode_email_header(self, value):
decoded_parts = decode_header(value)
result = ''
for part, charset in decoded_parts:
if isinstance(part, bytes):
result += part.decode(charset or 'utf-8', errors='ignore')
else:
result += part
return result
def _get_email_content(self, msg):
contents = []
if msg.is_multipart():
for part in msg.walk():
content_type = part.get_content_type()
content_disposition = str(part.get('Content-Disposition'))
if content_type in ('text/plain', 'text/html') and 'attachment' not in content_disposition:
payload = part.get_payload(decode=True)
if payload:
charset = part.get_content_charset() or 'utf-8'
contents.append(payload.decode(charset, errors='ignore'))
else:
payload = msg.get_payload(decode=True)
if payload:
charset = msg.get_content_charset() or 'utf-8'
contents.append(payload.decode(charset, errors='ignore'))
return '\n'.join(contents)
# ============ C端-用户接口 ============
def kw_in_joyhub_c_client_get_point_get(self, is_check=''):
return self._joyhub_c_request('GET', '/web-api/jh/client/get/point', is_check, '查询当前用户积分')
# ============ C端-Banner信息接口 ============
def kw_in_joyhub_c_banner_get_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/banner/get', is_check, '获得Banner管理', **kwargs)
def kw_in_joyhub_c_banner_page_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/banner/page', is_check, '获得Banner管理分页', **kwargs)
# ============ C端-blog信息接口 ============
def kw_in_joyhub_c_blog_get_detail_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/blog/get-detail', is_check, '获得blog详情', **kwargs)
def kw_in_joyhub_c_blog_get_next_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/blog/get-next', is_check, '获得blog下一条', **kwargs)
def kw_in_joyhub_c_blog_page_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/blog/page', is_check, '获得blog管理分页', **kwargs)
# ============ C端-blog分类接口 ============
def kw_in_joyhub_c_blog_cate_list_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/blog-cate/list', is_check, '获得blog分类列表', **kwargs)
# ============ C端-FAQ接口 ============
def kw_in_joyhub_c_faq_cate_list_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/faq/cate-list', is_check, '获得FAQ分类树', **kwargs)
def kw_in_joyhub_c_faq_list_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/faq/list', is_check, '获得FAQ列表', **kwargs)
# ============ C端-news分类接口 ============
def kw_in_joyhub_c_news_cate_list_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/news-cate/list', is_check, '获得news分类列表', **kwargs)
# ============ C端-news管理接口 ============
def kw_in_joyhub_c_news_get_detail_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/news/get-detail', is_check, '获得news详情', **kwargs)
def kw_in_joyhub_c_news_get_next_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/news/get-next', is_check, '获得news下一条', **kwargs)
def kw_in_joyhub_c_news_page_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/news/page', is_check, '获得news管理分页', **kwargs)
# ============ C端-APP版本接口 ============
def kw_in_joyhub_c_web_appversion_page_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/web/appversion/page', is_check, '获取APP版本列表', **kwargs)
# ============ C端-产品接口 ============
def kw_in_joyhub_c_product_get_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/product/get', is_check, '产品详情', **kwargs)
def kw_in_joyhub_c_product_page_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/product/page', is_check, '获得产品分页', **kwargs)
# ============ C端-支付页产品推荐接口 ============
def kw_in_joyhub_c_product_payment_recommend_page_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/product-payment-recommend/page', is_check, '获得支付页产品推荐分页', **kwargs)
# ============ C端-合作联系接口 ============
def kw_in_joyhub_c_cooperation_create_post(self, is_check='', **kwargs):
return self._joyhub_c_request('POST', '/web-api/jh/cooperation/create', is_check, '提交合作联系信息', **kwargs)
# ============ C端-二维码访问统计接口 ============
def kw_in_joyhub_c_download_qrcode_get_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/download-qrcode/get', is_check, '获取二维码信息', **kwargs)
def kw_in_joyhub_c_download_qrcode_increment_post(self, is_check='', **kwargs):
return self._joyhub_c_request('POST', '/web-api/jh/download-qrcode/increment', is_check, '增加二维码访问/点击次数', **kwargs)
# ============ C端-FAQ联系我们接口 ============
def kw_in_joyhub_c_faq_contact_us_create_post(self, is_check='', **kwargs):
return self._joyhub_c_request('POST', '/web-api/jh/faq-contact-us/create', is_check, '提交FAQ联系信息', **kwargs)
# ============ C端-点赞记录接口 ============
def kw_in_joyhub_c_like_info_create_post(self, is_check='', **kwargs):
return self._joyhub_c_request('POST', '/web-api/jh/like-info/create', is_check, '创建点赞记录', **kwargs)
def kw_in_joyhub_c_like_info_delete_post(self, is_check='', **kwargs):
return self._joyhub_c_request('POST', '/web-api/jh/like-info/delete', is_check, '取消点赞', **kwargs)
def kw_in_joyhub_c_like_info_get_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/like-info/get', is_check, '获得点赞记录', **kwargs)
def kw_in_joyhub_c_like_info_page_get(self, is_check='', **kwargs):
return self._joyhub_c_request('GET', '/web-api/jh/like-info/page', is_check, '获得点赞记录分页', **kwargs)
if __name__ == '__main__':
test = DlzhanInterface()
print()
a = test.kw_in_zhyy_purchase_todo_get(user="purchase")
print(a)

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

View File

@@ -29,12 +29,3 @@ ${joyhub_test_user_prefix} testuser_ # 测试用户账号前缀
${joyhub_test_nickname_prefix} 测试用户 # 测试用户昵称前缀
# ============ JoyHub C端 参数 ============
# 登录参数
${joyhub_c_login_email} zq464008250@163.com # JoyHub C端登录邮箱
${joyhub_c_login_path} https://joyhub-website-frontend-test.best-envision.com/api/web/login/login # JoyHub C端登录接口地址
# 测试地址
${joyhub_c_test_url} https://joyhub-website-frontend-test.best-envision.com/ # JoyHub C端测试地址

View File

@@ -0,0 +1,159 @@
import os
import re
from playwright.sync_api import Page, expect
from dulizhan.test_case.Resource.UI.base_page import BasePage
class DownloadAppPage(BasePage):
"""
Download the App 页面对象
已知侦察结果:
- 首页 URL: https://joyhub-website-frontend-test.best-envision.com/
- 页面标题: Joyhub | Explore Sexual Health, Wellness, and Connection
- 导航链接: Download the App
- Cookie 按钮文案: Accepet
"""
DOWNLOAD_APP_LINK_TEXT = re.compile(r"^Download the App$", re.I)
def accept_cookie_if_present(self):
# 页面侦察结果中按钮文本为 Accepet疑似拼写如此按真实页面处理
accept_button = self.page.get_by_role("button", name=re.compile(r"Accepet|Accept", re.I))
self.click_if_visible(accept_button, timeout=3000)
def open_download_app_page(self):
self.accept_cookie_if_present()
download_link = self.page.get_by_role("link", name=self.DOWNLOAD_APP_LINK_TEXT)
expect(download_link).to_be_visible(timeout=10000)
download_link.click()
try:
self.page.wait_for_load_state("networkidle", timeout=5000)
except Exception:
pass
def get_google_play_locator(self):
"""
优先使用稳定定位:
1. href 包含 play.google.com
2. 链接文本包含 Google Play
3. 图片 alt 包含 Google向上找父级 a 标签
如果后续页面提供 data-testid建议替换为
self.page.get_by_test_id("google-play-download")
"""
candidates = [
self.page.locator("a[href*='play.google.com']").first,
self.page.get_by_role("link", name=re.compile(r"Google\s*Play", re.I)).first,
self.page.locator("a").filter(has_text=re.compile(r"Google\s*Play", re.I)).first,
self.page.locator("img[alt*='Google' i]").locator("xpath=ancestor::a[1]").first,
]
for locator in candidates:
try:
if locator.count() > 0:
return locator
except Exception:
continue
return None
def discover_google_play_href(self):
"""
DOM 兜底侦察:
当 Google Play 是图片按钮、无文本链接时,用 JS 从渲染后的 DOM 中提取跳转地址。
只用于兜底发现,不作为首选点击方式。
"""
return self.page.evaluate(
"""
() => {
const keywords = ['google play', 'play.google.com'];
const nodes = Array.from(document.querySelectorAll('a, button, [role="button"], img'));
for (const node of nodes) {
const text = [
node.innerText,
node.textContent,
node.getAttribute('aria-label'),
node.getAttribute('title'),
node.getAttribute('alt'),
node.getAttribute('href'),
node.getAttribute('src')
].filter(Boolean).join(' ').toLowerCase();
if (keywords.some(k => text.includes(k))) {
const link = node.closest('a');
if (link && link.href) {
return link.href;
}
if (node.href) {
return node.href;
}
}
}
return null;
}
"""
)
def click_google_play_and_get_redirect_url(self) -> str:
"""
点击 Google Play 下载入口,并返回跳转地址。
成功判定:
- 新开页面 URL
- 当前页面跳转后的 URL
- 或点击前已获取到 Google Play href
"""
try:
self.page.wait_for_load_state("networkidle", timeout=5000)
except Exception:
pass
google_play_href = self.discover_google_play_href()
google_play_locator = self.get_google_play_locator()
if google_play_locator is None and not google_play_href:
raise AssertionError(
"未找到 Google Play 下载入口。"
"请检查 Download the App 页面是否存在 Google Play 链接,"
"或补充稳定 selector例如 data-testid。"
)
context = self.page.context
before_pages = list(context.pages)
old_url = self.page.url
if google_play_locator is not None:
google_play_locator.scroll_into_view_if_needed()
google_play_locator.click()
else:
# 没有稳定可点击 locator 时,使用已发现 href 直接跳转。
# TODO: 页面增加稳定 selector 后,替换为 locator.click()
self.page.goto(google_play_href, wait_until="domcontentloaded")
self.page.wait_for_timeout(3000)
after_pages = list(context.pages)
new_pages = [p for p in after_pages if p not in before_pages]
if new_pages:
new_page = new_pages[-1]
new_page.wait_for_load_state("domcontentloaded")
try:
new_page.wait_for_load_state("networkidle", timeout=10000)
except Exception:
pass
return new_page.url
if self.page.url != old_url:
return self.page.url
if google_play_href:
return google_play_href
raise AssertionError("点击 Google Play 后未获取到跳转地址")

View File

@@ -0,0 +1,57 @@
import os
from playwright.sync_api import Locator, Page, TimeoutError as PlaywrightTimeoutError
class BasePage:
"""Playwright 页面基类:封装通用等待、点击、截图等稳定操作。"""
def __init__(self, page: Page):
self.page = page
def goto(self, url: str, timeout: int = 60000) -> None:
self.page.goto(url, wait_until="domcontentloaded", timeout=timeout)
self.wait_for_network_idle()
def wait_for_network_idle(self, timeout: int = 30000) -> None:
try:
self.page.wait_for_load_state("networkidle", timeout=timeout)
except PlaywrightTimeoutError:
self.page.wait_for_load_state("domcontentloaded", timeout=timeout)
def wait_for_visible(self, locator: Locator, timeout: int = 10000) -> Locator:
locator.wait_for(state="visible", timeout=timeout)
return locator
def click_if_visible(self, locator: Locator, timeout: int = 3000) -> bool:
try:
if locator.first.is_visible(timeout=timeout):
locator.first.click()
self.wait_for_network_idle()
return True
except Exception:
return False
return False
def safe_click(self, locator: Locator, timeout: int = 10000) -> None:
self.wait_for_visible(locator, timeout=timeout)
locator.click()
self.wait_for_network_idle()
def screenshot(self, screenshot_dir: str, file_name: str, full_page: bool = True) -> str:
os.makedirs(screenshot_dir, exist_ok=True)
screenshot_path = os.path.join(screenshot_dir, file_name)
self.page.screenshot(path=screenshot_path, full_page=full_page)
return screenshot_path
def current_url(self) -> str:
return self.page.url
def title(self) -> str:
return self.page.title()
def visible_text_contains(self, keyword: str) -> bool:
try:
return self.page.get_by_text(keyword, exact=False).first.is_visible(timeout=3000)
except Exception:
return False

View File

@@ -0,0 +1,196 @@
import random
from typing import Dict, List
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError, expect
from dulizhan.test_case.Resource.UI.base_page import BasePage
class BlogPage(BasePage):
"""
Joyhub Blog/内容页页面对象。
说明:
- 页面侦察结果未发现明确的 Blog 导航入口;
- 已发现真实导航候选包含 Discover、Following
- 因此进入 blog/内容列表时优先尝试 Blog失败后使用 Discover 作为内容入口兜底。
"""
HOME_URL = "https://joyhub-website-frontend-test.best-envision.com/"
EXPECTED_HOME_TITLE = "Joyhub | Explore Sexual Health, Wellness, and Connection"
NAV_DISCOVER_LINK = "Discover"
def open_home_page(self) -> None:
self.goto(self.HOME_URL)
self.accept_cookie_if_present()
expect(self.page).to_have_title(self.EXPECTED_HOME_TITLE)
def enter_blog_page(self) -> str:
"""
进入 blog/内容页。
优先级:
1. Blog 链接:如果页面后续版本新增 Blog 导航,可直接命中;
2. Discover 链接:侦察结果中存在,作为当前可用内容入口;
3. /blog 直达:仅作为最后兜底,并在无法点击入口时使用。
"""
before_url = self.page.url
blog_locators = [
self.page.get_by_role("link", name="Blog"),
self.page.locator("a", has_text="Blog"),
self.page.get_by_role("link", name=self.NAV_DISCOVER_LINK),
self.page.locator("a", has_text=self.NAV_DISCOVER_LINK),
]
for locator in blog_locators:
try:
if locator.count() > 0 and locator.first.is_visible():
locator.first.click()
self.wait_for_page_ready()
return self.page.url
except Exception:
continue
fallback_blog_url = self.HOME_URL.rstrip("/") + "/blog"
self.goto(fallback_blog_url)
assert self.page.url != before_url or "/blog" in self.page.url.lower(), (
"未能进入 blog/内容页:页面未发现 Blog 入口Discover 入口也不可点击。"
)
return self.page.url
def _get_candidate_blog_links(self) -> List[Dict[str, str]]:
"""
从渲染后的页面中提取可点击的 blog/content 候选链接。
不硬编码未知 selector优先根据 href 语义筛选:
blog/article/post/discover/detail/content。
若无命中,则退化为 main 区域内可见链接,排除导航类链接。
"""
return self.page.evaluate(
"""
() => {
const navTexts = new Set([
'Home',
'Download the App',
'Rewards',
'Support',
'About Us',
'Discover',
'Following',
'Partnerships',
'FAQs',
'Login'
]);
const normalize = value => (value || '').replace(/\\s+/g, ' ').trim();
const links = Array.from(document.querySelectorAll('a[href]'))
.filter(a => {
const rect = a.getBoundingClientRect();
const style = window.getComputedStyle(a);
return rect.width > 0
&& rect.height > 0
&& style.visibility !== 'hidden'
&& style.display !== 'none';
})
.map((a, index) => {
const href = a.href || '';
const text = normalize(a.innerText || a.textContent || a.getAttribute('aria-label') || '');
const imgAlt = normalize(
Array.from(a.querySelectorAll('img'))
.map(img => img.alt)
.filter(Boolean)
.join(' ')
);
return {
index,
href,
text,
imgAlt,
pathname: (() => {
try { return new URL(href).pathname.toLowerCase(); }
catch(e) { return ''; }
})()
};
})
.filter(item => item.href && !item.href.startsWith('javascript:'));
const semanticLinks = links.filter(item =>
/blog|article|post|discover|detail|content|story/i.test(item.href)
&& !navTexts.has(item.text)
);
if (semanticLinks.length > 0) {
return semanticLinks;
}
return links.filter(item =>
!navTexts.has(item.text)
&& item.href !== window.location.href
&& !/#$/.test(item.href)
);
}
"""
)
def click_random_blog(self) -> Dict[str, str]:
"""
随机点击一个 blog/content 候选项。
点击后等待 URL 或页面内容变化。
"""
self.wait_for_page_ready()
candidates = self._get_candidate_blog_links()
assert candidates, (
"未找到可点击的 blog/content 候选链接。"
"页面侦察结果缺少明确 blog 卡片 selector请补充稳定定位如 data-testid='blog-card'"
)
candidate = random.choice(candidates)
before_url = self.page.url
locator = self.page.locator("a[href]").nth(candidate["index"])
locator.scroll_into_view_if_needed(timeout=5000)
try:
with self.page.expect_navigation(wait_until="domcontentloaded", timeout=8000):
locator.click()
except PlaywrightTimeoutError:
locator.click()
self.wait_for_page_ready()
after_url = self.page.url
assert after_url != before_url or self.page.locator("main, article, body").first.is_visible(), (
f"点击 blog/content 候选项后页面未出现有效跳转或内容区域。候选链接:{candidate['href']}"
)
return {
"clicked_href": candidate.get("href", ""),
"clicked_text": candidate.get("text") or candidate.get("imgAlt") or "",
"before_url": before_url,
"after_url": after_url,
}
def assert_blog_content_page_loaded(self) -> None:
"""
断言已进入 blog/content 内容页。
因页面缺少稳定详情页 selector这里采用内容区域可见的稳健断言。
"""
self.wait_for_page_ready()
content_locator = self.page.locator("article, main, [role='main'], body").first
expect(content_locator).to_be_visible(timeout=10000)
body_text = self.page.locator("body").inner_text(timeout=10000).strip()
assert len(body_text) > 0, "blog/content 页面 body 内容为空,疑似跳转失败或页面未渲染完成。"
def capture_blog_content_screenshot(self, screenshot_dir: str, case_key: str) -> str:
return self.screenshot(
screenshot_dir=screenshot_dir,
file_name=f"{case_key}_blog_content.png",
full_page=True,
)

View File

@@ -0,0 +1,200 @@
import random
import re
from typing import Dict, List
from playwright.sync_api import Page, TimeoutError as PlaywrightTimeoutError
from dulizhan.test_case.Resource.UI.base_page import BasePage
class NewsPage(BasePage):
"""Joyhub News 相关页面对象。"""
COOKIE_ACCEPT_TEXT_PATTERN = re.compile(r"^(Accepet|Accept|I Accept|Agree|Got it)$", re.I)
NEWS_LINK_TEXT_PATTERN = re.compile(r"^News$", re.I)
NEWS_ROUTE = "/news"
def __init__(self, page: Page, base_url: str):
super().__init__(page)
self.base_url = base_url.rstrip("/")
def open_home(self) -> None:
self.goto(self.base_url)
def accept_cookie_if_present(self) -> None:
accept_button = self.page.get_by_role("button", name=self.COOKIE_ACCEPT_TEXT_PATTERN)
self.click_if_visible(accept_button, timeout=3000)
def enter_news_page(self) -> None:
news_link = self.page.get_by_role("link", name=self.NEWS_LINK_TEXT_PATTERN)
try:
if news_link.first.is_visible(timeout=5000):
news_link.first.click()
self.wait_for_network_idle()
return
except Exception:
pass
self.goto(f"{self.base_url}{self.NEWS_ROUTE}")
def is_news_context(self) -> bool:
url = self.page.url.lower()
title = self.page.title().lower()
if "news" in url:
return True
if "news" in title:
return True
if self.visible_text_contains("News"):
return True
return False
def _collect_clickable_news_candidates(self) -> List[Dict[str, str]]:
script = """
() => {
const navTexts = new Set([
'home',
'download the app',
'rewards',
'support',
'about us',
'discover',
'following',
'partnerships',
'faqs',
'login'
]);
const currentUrl = new URL(window.location.href);
const anchors = Array.from(document.querySelectorAll('a[href]'));
function isVisible(el) {
const style = window.getComputedStyle(el);
const rect = el.getBoundingClientRect();
return style &&
style.visibility !== 'hidden' &&
style.display !== 'none' &&
rect.width > 0 &&
rect.height > 0;
}
function hasContentContainer(el) {
return !!el.closest(
'article, [class*="article" i], [class*="card" i], [class*="news" i], [class*="post" i], [class*="blog" i], [class*="item" i]'
);
}
function isBadProtocol(url) {
return ['javascript:', 'mailto:', 'tel:'].includes(url.protocol);
}
function isLikelySocial(url) {
const host = url.hostname.toLowerCase();
return [
'facebook.com',
'instagram.com',
'twitter.com',
'x.com',
'youtube.com',
'tiktok.com',
'linkedin.com'
].some(domain => host.includes(domain));
}
const candidates = [];
for (const a of anchors) {
if (!isVisible(a)) continue;
let url;
try {
url = new URL(a.href, window.location.origin);
} catch (e) {
continue;
}
if (isBadProtocol(url)) continue;
if (isLikelySocial(url)) continue;
if (url.href === currentUrl.href) continue;
const text = (a.innerText || a.textContent || '').trim().replace(/\\s+/g, ' ');
const textLower = text.toLowerCase();
const pathLower = url.pathname.toLowerCase();
if (navTexts.has(textLower)) continue;
if (url.pathname === '/' || url.pathname === '') continue;
const hrefLooksLikeContent =
/news|article|blog|post|detail|story/i.test(pathLower) &&
pathLower !== '/news';
const containerLooksLikeContent = hasContentContainer(a);
if (hrefLooksLikeContent || containerLooksLikeContent) {
candidates.push({
href: url.href,
text: text,
path: url.pathname,
reason: hrefLooksLikeContent ? 'href_content_pattern' : 'content_container'
});
}
}
const seen = new Set();
return candidates.filter(item => {
if (seen.has(item.href)) return false;
seen.add(item.href);
return true;
});
}
"""
return self.page.evaluate(script)
def click_random_news_item(self) -> Dict[str, str]:
self.wait_for_network_idle()
candidates = self._collect_clickable_news_candidates()
if not candidates:
raise AssertionError(
"未发现可点击的 news 内容候选。"
"请检查 News 页面是否加载成功,或为 news 卡片补充稳定 selector/data-testid。"
)
selected = random.choice(candidates)
href = selected["href"]
old_url = self.page.url
click_script = """
(targetHref) => {
const anchors = Array.from(document.querySelectorAll('a[href]'));
const target = anchors.find(a => {
try {
return new URL(a.href, window.location.origin).href === targetHref;
} catch (e) {
return false;
}
});
if (!target) {
throw new Error('Target news link not found: ' + targetHref);
}
target.scrollIntoView({block: 'center', inline: 'center'});
target.click();
}
"""
self.page.evaluate(click_script, href)
try:
self.page.wait_for_url(lambda url: str(url) != old_url, timeout=15000)
except PlaywrightTimeoutError:
pass
self.wait_for_network_idle()
return selected
def screenshot_news_content(self, screenshot_dir: str, file_name: str) -> str:
return self.screenshot(screenshot_dir=screenshot_dir, file_name=file_name, full_page=True)

View File

@@ -0,0 +1,91 @@
from dulizhan.test_case.Resource.UI.base_page import BasePage
from dulizhan.test_case.Resource.UI.news_page import NewsPage
import os
import allure
import pytest
from playwright.sync_api import sync_playwright
from dulizhan.test_case.Resource.UI.news_page import NewsPage
CASE_INFO = {
"projectId": 1001,
"caseId": 2001,
"automationType": "ui",
"caseKey": "TC_dulizhan_ui_api_verify_001",
"moduleName": "news",
"productName": "",
"projectName": "dulizhan",
"caseName": "进入news页面随机点击news跳转到news内容后截图就认为用例执行成功",
"pageUrl": "https://joyhub-website-frontend-test.best-envision.com/",
"screenshotDir": r"C:\Users\a\smart-management-auto-test\dulizhan\screenshots",
}
@pytest.fixture(scope="session")
def browser():
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
yield browser
browser.close()
@pytest.fixture()
def page(browser):
context = browser.new_context(
viewport={"width": 1440, "height": 900},
ignore_https_errors=True,
)
page = context.new_page()
yield page
context.close()
@allure.feature(CASE_INFO["projectName"])
@allure.story(CASE_INFO["moduleName"])
@allure.title(CASE_INFO["caseName"])
def test_random_click_news_and_capture_content(page):
screenshot_dir = CASE_INFO["screenshotDir"]
os.makedirs(screenshot_dir, exist_ok=True)
news_page = NewsPage(page)
with allure.step("打开被测页面"):
news_page.open_home_page()
news_page.accept_cookie_if_present()
allure.attach(
news_page.current_url(),
name="首页 URL",
attachment_type=allure.attachment_type.TEXT,
)
with allure.step("进入 news 页面"):
news_page.enter_news_page()
allure.attach(
news_page.current_url(),
name="News 页面 URL",
attachment_type=allure.attachment_type.TEXT,
)
with allure.step("随机点击 news"):
selected_news = news_page.click_random_news()
allure.attach(
str(selected_news),
name="随机点击的 news 候选信息",
attachment_type=allure.attachment_type.TEXT,
)
with allure.step("截图跳转的 news 内容"):
news_page.assert_news_content_loaded()
screenshot_path = news_page.capture_news_content_screenshot(
screenshot_dir=screenshot_dir,
case_key=CASE_INFO["caseKey"],
)
allure.attach.file(
screenshot_path,
name="跳转后的 news 内容截图",
attachment_type=allure.attachment_type.PNG,
)
assert os.path.exists(screenshot_path), f"news 内容截图未生成: {screenshot_path}"

View File

@@ -0,0 +1,80 @@
from dulizhan.test_case.Resource.UI.base_page import BasePage
from dulizhan.test_case.Resource.UI.blog_page import BlogPage
from types import SimpleNamespace
import allure
import pytest
from playwright.sync_api import sync_playwright
from dulizhan.test_case.Resource.UI.blog_page import BlogPage
case_info = SimpleNamespace(
projectId=1001,
caseId=2001,
automationType="ui",
caseKey="TC_dulizhan_ui_api_verify_001",
moduleName="blog",
productName="",
projectName="dulizhan",
caseName="进入blog页面随机点击blog跳转到blog内容后截图就认为用例执行成功",
screenshotDir=r"C:\Users\a\smart-management-auto-test\dulizhan\screenshots",
pageUrl="https://joyhub-website-frontend-test.best-envision.com/",
)
@pytest.fixture(scope="function")
def page():
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
context = browser.new_context(
viewport={"width": 1440, "height": 900},
ignore_https_errors=True,
)
page = context.new_page()
yield page
context.close()
browser.close()
@allure.feature(case_info.projectName)
@allure.story(case_info.moduleName)
@allure.title(case_info.caseName)
def test_enter_blog_random_click_and_capture_content(page):
blog_page = BlogPage(page)
with allure.step("打开被测页面"):
blog_page.open_home_page()
assert page.url.startswith(case_info.pageUrl)
with allure.step("进入blog页面"):
entered_url = blog_page.enter_blog_page()
allure.attach(
entered_url,
name="进入blog页面后的URL",
attachment_type=allure.attachment_type.TEXT,
)
with allure.step("随机点击blog"):
click_result = blog_page.click_random_blog()
allure.attach(
str(click_result),
name="随机点击blog结果",
attachment_type=allure.attachment_type.TEXT,
)
with allure.step("截图跳转的blog内容"):
blog_page.assert_blog_content_page_loaded()
screenshot_path = blog_page.capture_blog_content_screenshot(
screenshot_dir=case_info.screenshotDir,
case_key=case_info.caseKey,
)
with open(screenshot_path, "rb") as image_file:
allure.attach(
image_file.read(),
name="blog内容页截图",
attachment_type=allure.attachment_type.PNG,
)
assert screenshot_path, "blog 内容页截图路径为空"

View File

@@ -0,0 +1,90 @@
from dulizhan.test_case.Resource.UI.base_page import BasePage
from dulizhan.test_case.Resource.UI.news_page import NewsPage
from types import SimpleNamespace
import allure
import pytest
from playwright.sync_api import sync_playwright
from dulizhan.test_case.Resource.UI.news_page import NewsPage
CASE_INFO = SimpleNamespace(
projectId=1001,
caseId=2001,
automationType="ui",
caseKey="TC_dulizhan_ui_api_verify_001",
moduleName="news",
productName="",
projectName="dulizhan",
caseName="进入news页面随机点击news跳转到news内容后截图就认为用例执行成功",
pageUrl="https://joyhub-website-frontend-test.best-envision.com/",
screenshotDir=r"C:\Users\a\smart-management-auto-test\dulizhan\screenshots",
)
@pytest.fixture(scope="session")
def browser():
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
yield browser
browser.close()
@pytest.fixture()
def page(browser):
page = browser.new_page(
viewport={"width": 1440, "height": 1200},
ignore_https_errors=True,
)
yield page
page.close()
@pytest.fixture()
def case_info():
return CASE_INFO
@allure.feature(CASE_INFO.projectName)
@allure.story(CASE_INFO.moduleName)
@allure.title(CASE_INFO.caseName)
@pytest.mark.ui
def test_enter_news_random_click_and_screenshot(page, case_info):
news_page = NewsPage(page, case_info.pageUrl)
with allure.step("打开被测页面"):
news_page.open_home()
news_page.accept_cookie_if_present()
assert "Joyhub" in news_page.title(), f"首页标题不符合预期,当前标题:{news_page.title()}"
with allure.step("进入news页面"):
news_page.enter_news_page()
assert news_page.is_news_context(), (
f"未确认进入 news 页面上下文当前URL{page.url},当前标题:{page.title()}"
"侦察结果未提供明确 News 导航 selector如实际路由不是 /news请调整 NewsPage.NEWS_ROUTE。"
)
with allure.step("随机点击news"):
before_click_url = page.url
selected_news = news_page.click_random_news_item()
allure.attach(
str(selected_news),
name="随机点击的 news 候选",
attachment_type=allure.attachment_type.TEXT,
)
assert page.url != before_click_url or selected_news.get("href"), (
f"点击 news 后页面未发生有效跳转点击前URL{before_click_url}点击后URL{page.url}"
)
with allure.step("截图跳转的news内容"):
screenshot_path = news_page.screenshot_news_content(
screenshot_dir=case_info.screenshotDir,
file_name=f"{case_info.caseKey}_news_content.png",
)
allure.attach.file(
screenshot_path,
name="跳转后的news内容截图",
attachment_type=allure.attachment_type.PNG,
)
assert screenshot_path, "news 内容截图保存失败"

View File

@@ -1,279 +0,0 @@
# -*- coding:utf-8 -*-
"""
国家信息管理接口测试用例
"""
import pytest
import json
import time
import logging
import allure
from dulizhan.library.BusinessKw.JoyHub.AddressCountryManage import AddressCountryManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - 国家信息管理模块")
class TestAddressCountryManage:
country_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = AddressCountryManage()
username = "joytest"
password = "Zhou1599"
# 登录逻辑
cls.test_case._clear_user_fingerprint(username)
import requests
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
else:
logging.error(f"登录失败: {login_response}")
pytest.skip("登录失败,跳过所有测试")
@allure.story("验证登录")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestAddressCountryManage.token_set is True, "登录失败"
logging.info("登录验证通过")
@allure.story("验证获得国家信息分页")
@allure.title("测试获得国家信息分页接口")
def test_joyhub_address_country_page_get(self):
"""测试获得国家信息分页接口"""
with allure.step("1. 调用接口"):
resp = self.test_case.kw_joyhub_address_country_page_get(page_num=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], dict), "data字段不是字典类型"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
assert "total" in resp["data"], "响应中缺少total字段"
assert isinstance(resp["data"]["total"], int), "total字段不是整数类型"
logging.info("获得国家信息分页列表验证通过")
@allure.story("验证创建和更新国家信息")
@allure.title("测试创建和更新国家信息接口")
def test_joyhub_address_country_create_and_update(self):
"""测试创建和更新国家信息接口"""
with allure.step("1. 准备创建请求参数"):
timestamp = int(time.time())
params = {
"country_code": f"TC{timestamp}",
"country_name": f"测试国家_{timestamp}",
"country_name_en": f"Test Country {timestamp}",
"phone_code": f"+{timestamp % 1000}",
"status": 1
}
allure.attach(json.dumps(params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用创建接口"):
resp = self.test_case.kw_joyhub_address_country_create_post(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证创建响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], int), "data字段不是整数类型"
country_id = resp["data"]
TestAddressCountryManage.country_id = country_id
logging.info(f"创建国家信息成功国家信息ID: {country_id}")
with allure.step("4. 调用更新接口"):
update_timestamp = int(time.time())
update_params = {
"country_id": country_id,
"country_code": f"TC{update_timestamp}",
"country_name": f"已更新国家_{update_timestamp}",
"country_name_en": f"Updated Country {update_timestamp}",
"phone_code": f"+{update_timestamp % 1000}",
"status": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_address_country_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("5. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"请求失败code={update_resp.get('code')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新国家信息失败"
logging.info("更新国家信息验证通过")
@allure.story("验证获得国家信息详情")
@allure.title("测试获得国家信息详情接口")
def test_joyhub_address_country_get_get(self):
"""测试获得国家信息详情接口"""
with allure.step("1. 先创建一个国家信息"):
timestamp = int(time.time())
create_resp = self.test_case.kw_joyhub_address_country_create_post(
country_code=f"TC{timestamp}",
country_name=f"详情测试国家_{timestamp}",
country_name_en=f"Detail Test Country {timestamp}",
phone_code=f"+{timestamp % 1000}",
status=2
)
country_id = create_resp.get("data") if create_resp and create_resp.get("code") == 0 else None
if not country_id:
pytest.skip("创建测试国家信息失败,跳过详情测试")
allure.attach(json.dumps({"id": country_id}, ensure_ascii=False), name="国家信息ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用获得详情接口"):
resp = self.test_case.kw_joyhub_address_country_get_get(country_id=country_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], dict), "data字段不是字典类型"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == country_id, "返回的ID与请求的不一致"
logging.info("获得国家信息详情验证通过")
@allure.story("验证删除国家信息")
@allure.title("测试删除国家信息接口")
def test_joyhub_address_country_delete_delete(self):
"""测试删除国家信息接口"""
with allure.step("1. 先创建一个测试国家信息"):
timestamp = int(time.time())
create_resp = self.test_case.kw_joyhub_address_country_create_post(
country_code=f"TC{timestamp}",
country_name=f"待删除国家_{timestamp}",
country_name_en=f"Delete Test Country {timestamp}",
phone_code=f"+{timestamp % 1000}",
status=2
)
country_id = create_resp.get("data") if create_resp and create_resp.get("code") == 0 else None
if not country_id:
pytest.skip("创建测试国家信息失败,跳过删除测试")
allure.attach(json.dumps({"id": country_id}, ensure_ascii=False), name="国家信息ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用删除接口"):
resp = self.test_case.kw_joyhub_address_country_delete_delete(country_id=country_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除国家信息失败"
logging.info("删除国家信息验证通过")
@allure.story("验证批量删除国家信息")
@allure.title("测试批量删除国家信息接口")
def test_joyhub_address_country_delete_list_delete(self):
"""测试批量删除国家信息接口"""
with allure.step("1. 先创建两个测试国家信息"):
timestamp = int(time.time())
resp1 = self.test_case.kw_joyhub_address_country_create_post(
country_code=f"TC{timestamp}",
country_name=f"批量删除国家1_{timestamp}",
country_name_en=f"Batch Delete Country 1 {timestamp}",
phone_code=f"+{timestamp % 1000}",
status=2
)
resp2 = self.test_case.kw_joyhub_address_country_create_post(
country_code=f"TC{timestamp+1}",
country_name=f"批量删除国家2_{timestamp}",
country_name_en=f"Batch Delete Country 2 {timestamp}",
phone_code=f"+{(timestamp+1) % 1000}",
status=2
)
country_id1 = resp1.get("data") if resp1 and resp1.get("code") == 0 else None
country_id2 = resp2.get("data") if resp2 and resp2.get("code") == 0 else None
if not country_id1 or not country_id2:
pytest.skip("创建测试国家信息失败,跳过批量删除测试")
country_ids = [country_id1, country_id2]
allure.attach(json.dumps({"ids": country_ids}, ensure_ascii=False), name="待删除国家信息IDs", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用批量删除接口"):
resp = self.test_case.kw_joyhub_address_country_delete_list_delete(country_ids=country_ids)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "批量删除国家信息失败"
logging.info("批量删除国家信息验证通过")
@allure.story("验证批量更新国家信息状态")
@allure.title("测试批量更新国家信息状态接口")
def test_joyhub_address_country_update_status_list_put(self):
"""测试批量更新国家信息状态接口"""
with allure.step("1. 先创建两个测试国家信息"):
timestamp = int(time.time())
resp1 = self.test_case.kw_joyhub_address_country_create_post(
country_code=f"TC{timestamp}",
country_name=f"状态更新国家1_{timestamp}",
country_name_en=f"Status Update Country 1 {timestamp}",
phone_code=f"+{timestamp % 1000}",
status=1
)
resp2 = self.test_case.kw_joyhub_address_country_create_post(
country_code=f"TC{timestamp+1}",
country_name=f"状态更新国家2_{timestamp}",
country_name_en=f"Status Update Country 2 {timestamp}",
phone_code=f"+{(timestamp+1) % 1000}",
status=1
)
country_id1 = resp1.get("data") if resp1 and resp1.get("code") == 0 else None
country_id2 = resp2.get("data") if resp2 and resp2.get("code") == 0 else None
if not country_id1 or not country_id2:
pytest.skip("创建测试国家信息失败,跳过批量更新状态测试")
country_ids = [country_id1, country_id2]
allure.attach(json.dumps({"ids": country_ids, "status": 2}, ensure_ascii=False), name="批量更新状态参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用批量更新状态接口"):
resp = self.test_case.kw_joyhub_address_country_update_status_list_put(country_ids=country_ids, status=2)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "批量更新国家信息状态失败"
logging.info("批量更新国家信息状态验证通过")

View File

@@ -1,552 +0,0 @@
import pytest
import allure
import logging
import requests
import json
import time
from dulizhan.library.BusinessKw.JoyHub.AfterSalesPolicyManage import AfterSalesPolicyManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - 售后政策管理模块")
class TestAfterSalesPolicyManage:
policy_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = AfterSalesPolicyManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = "https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev"
payload = {"username": username, "password": password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
try:
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
if token:
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功获取到Token: {}...".format(token[:20]))
else:
logging.warning("登录成功但未获取到Token")
else:
logging.error("登录失败: {}".format(login_response))
except Exception as e:
logging.error("登录异常: {}".format(str(e)))
@allure.story("验证登录")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert self.token_set is True, "登录失败Token未设置"
logging.info("登录验证通过Token已设置")
@allure.story("验证获得售后政策分页")
@allure.title("测试获得售后政策分页接口")
def test_joyhub_after_sales_policy_page_get(self):
"""测试获得售后政策分页接口"""
with allure.step("1. 准备请求参数"):
params = {
"page_no": 1,
"page_size": 10,
"title": "",
"content": "",
"status": ""
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用接口"):
resp = self.test_case.kw_joyhub_after_sales_policy_page_get(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert "total" in resp["data"], "响应中缺少total字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
assert isinstance(resp["data"]["total"], int), "total字段不是整数类型"
logging.info("获得售后政策分页列表验证通过")
@allure.story("验证创建和更新售后政策")
@allure.title("测试创建和更新售后政策接口")
def test_joyhub_after_sales_policy_create_and_update(self):
"""测试创建和更新售后政策接口"""
with allure.step("1. 先创建一个新品牌供售后政策使用"):
timestamp = int(time.time())
create_brand_resp = self.test_case.kw_joyhub_after_sales_brand_create_post(
brand_name=f"测试品牌_售后政策_{timestamp}",
after_sales_policy_id=0,
status=1
)
if create_brand_resp and create_brand_resp.get("code") == 0:
brand_id = create_brand_resp.get("data")
logging.info(f"创建测试品牌成功品牌ID: {brand_id}")
else:
pytest.skip(f"创建测试品牌失败: {create_brand_resp}")
allure.attach(json.dumps({"brand_id": brand_id}, ensure_ascii=False), name="品牌ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 准备创建请求参数"):
params = {
"title": f"测试售后政策_{timestamp}",
"content": f"这是测试售后政策内容_{timestamp}",
"lang": "de",
"brand_id": brand_id,
"status": 1
}
allure.attach(json.dumps(params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("3. 调用创建接口"):
resp = self.test_case.kw_joyhub_after_sales_policy_create_post(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("4. 验证创建响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], int), "data字段不是整数类型"
policy_id = resp["data"]
TestAfterSalesPolicyManage.policy_id = policy_id
logging.info(f"创建售后政策成功售后政策ID: {policy_id}")
with allure.step("5. 调用更新接口"):
update_timestamp = int(time.time())
update_params = {
"policy_id": policy_id,
"title": f"已更新售后政策_{update_timestamp}",
"content": f"已更新售后政策内容_{update_timestamp}",
"lang": "ja",
"brand_id": brand_id,
"status": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_after_sales_policy_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("6. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"请求失败code={update_resp.get('code')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新售后政策失败"
logging.info("更新售后政策验证通过")
@allure.story("验证获得售后政策详情")
@allure.title("测试获得售后政策详情接口")
def test_joyhub_after_sales_policy_get_get(self):
"""测试获得售后政策详情接口"""
with allure.step("1. 先创建一个售后政策"):
timestamp = int(time.time())
create_resp = self.test_case.kw_joyhub_after_sales_policy_create_post(
title=f"详情测试售后政策_{timestamp}",
content=f"详情测试售后政策内容_{timestamp}",
lang="ja",
brand_id=12,
status=2
)
policy_id = create_resp.get("data") if create_resp and create_resp.get("code") == 0 else None
if not policy_id:
pytest.skip("创建测试售后政策失败,跳过详情测试")
allure.attach(json.dumps({"id": policy_id}, ensure_ascii=False), name="售后政策ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用获得详情接口"):
resp = self.test_case.kw_joyhub_after_sales_policy_get_get(policy_id=policy_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], dict), "data字段不是字典类型"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == policy_id, "返回的ID与请求的不一致"
logging.info("获得售后政策详情验证通过")
@allure.story("验证删除售后政策")
@allure.title("测试删除售后政策接口")
def test_joyhub_after_sales_policy_delete_delete(self):
"""测试删除售后政策接口"""
with allure.step("1. 先创建一个测试售后政策"):
timestamp = int(time.time())
create_resp = self.test_case.kw_joyhub_after_sales_policy_create_post(
title=f"待删除售后政策_{timestamp}",
content=f"待删除售后政策内容_{timestamp}",
lang="en",
brand_id=12,
status=2
)
policy_id = create_resp.get("data") if create_resp and create_resp.get("code") == 0 else None
if not policy_id:
pytest.skip("创建测试售后政策失败,跳过删除测试")
allure.attach(json.dumps({"id": policy_id}, ensure_ascii=False), name="待删除售后政策ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用删除接口"):
resp = self.test_case.kw_joyhub_after_sales_policy_delete_delete(policy_id=policy_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除售后政策失败"
logging.info("删除售后政策验证通过")
@allure.story("验证批量删除售后政策")
@allure.title("测试批量删除售后政策接口")
def test_joyhub_after_sales_policy_delete_list_delete(self):
"""测试批量删除售后政策接口"""
with allure.step("1. 先创建两个测试售后政策"):
timestamp = int(time.time())
resp1 = self.test_case.kw_joyhub_after_sales_policy_create_post(
title=f"批量删除售后政策1_{timestamp}",
content=f"批量删除售后政策内容1_{timestamp}",
lang="de",
brand_id=12,
status=2
)
resp2 = self.test_case.kw_joyhub_after_sales_policy_create_post(
title=f"批量删除售后政策2_{timestamp}",
content=f"批量删除售后政策内容2_{timestamp}",
lang="ja",
brand_id=12,
status=2
)
policy_id1 = resp1.get("data") if resp1 and resp1.get("code") == 0 else None
policy_id2 = resp2.get("data") if resp2 and resp2.get("code") == 0 else None
if not policy_id1 or not policy_id2:
pytest.skip("创建测试售后政策失败,跳过批量删除测试")
policy_ids = [policy_id1, policy_id2]
allure.attach(json.dumps({"ids": policy_ids}, ensure_ascii=False), name="待删除售后政策IDs", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用批量删除接口"):
resp = self.test_case.kw_joyhub_after_sales_policy_delete_list_delete(policy_ids=policy_ids)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "批量删除售后政策失败"
logging.info("批量删除售后政策验证通过")
@allure.feature("管理后台 - 售后政策-品牌管理模块")
class TestAfterSalesBrandManage:
brand_id = None
policy_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = AfterSalesPolicyManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = "https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev"
payload = {"username": username, "password": password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
try:
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
if token:
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功获取到Token: {}...".format(token[:20]))
else:
logging.warning("登录成功但未获取到Token")
else:
logging.error("登录失败: {}".format(login_response))
except Exception as e:
logging.error("登录异常: {}".format(str(e)))
# 创建一个售后政策供品牌测试使用
if cls.token_set:
timestamp = int(time.time())
# 先创建一个新品牌,确保没有活跃的售后政策
create_brand_resp = cls.test_case.kw_joyhub_after_sales_brand_create_post(
brand_name=f"品牌测试专用_{timestamp}",
after_sales_policy_id=0,
status=1
)
if create_brand_resp and create_brand_resp.get("code") == 0:
brand_id = create_brand_resp.get("data")
logging.info(f"创建测试品牌成功品牌ID: {brand_id}")
# 使用新创建的品牌创建售后政策
create_resp = cls.test_case.kw_joyhub_after_sales_policy_create_post(
title=f"品牌测试售后政策_{timestamp}",
content=f"品牌测试售后政策内容_{timestamp}",
lang="en",
brand_id=brand_id,
status=1
)
if create_resp and create_resp.get("code") == 0:
cls.policy_id = create_resp.get("data")
logging.info(f"创建测试售后政策成功ID: {cls.policy_id}")
else:
logging.warning(f"创建售后政策失败: {create_resp}")
else:
logging.warning(f"创建测试品牌失败: {create_brand_resp}")
@allure.story("验证获得售后政策-品牌分页")
@allure.title("测试获得售后政策-品牌分页接口")
def test_joyhub_after_sales_brand_page_get(self):
"""测试获得售后政策-品牌分页接口"""
with allure.step("1. 准备请求参数"):
params = {
"page_no": 1,
"page_size": 10,
"brand_name": "",
"after_sales_policy_id": "",
"status": ""
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用接口"):
resp = self.test_case.kw_joyhub_after_sales_brand_page_get(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert "total" in resp["data"], "响应中缺少total字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
assert isinstance(resp["data"]["total"], int), "total字段不是整数类型"
logging.info("获得售后政策-品牌分页列表验证通过")
@allure.story("验证创建售后政策-品牌")
@allure.title("测试创建售后政策-品牌接口")
def test_joyhub_after_sales_brand_create_post(self):
"""测试创建售后政策-品牌接口"""
if not self.policy_id:
pytest.skip("未创建测试售后政策,跳过品牌创建测试")
with allure.step("1. 准备请求参数"):
timestamp = int(time.time())
params = {
"brand_name": f"测试品牌_{timestamp}",
"after_sales_policy_id": self.policy_id,
"status": 1
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用接口"):
resp = self.test_case.kw_joyhub_after_sales_brand_create_post(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], int), "data字段不是整数类型"
TestAfterSalesBrandManage.brand_id = resp["data"]
logging.info(f"创建售后政策-品牌成功品牌ID: {TestAfterSalesBrandManage.brand_id}")
@allure.story("验证获得售后政策-品牌详情")
@allure.title("测试获得售后政策-品牌详情接口")
def test_joyhub_after_sales_brand_get_get(self):
"""测试获得售后政策-品牌详情接口"""
if not self.policy_id:
pytest.skip("未创建测试售后政策,跳过品牌详情测试")
with allure.step("1. 先创建一个售后政策-品牌"):
timestamp = int(time.time())
create_resp = self.test_case.kw_joyhub_after_sales_brand_create_post(
brand_name=f"详情测试品牌_{timestamp}",
after_sales_policy_id=self.policy_id,
status=2
)
brand_id = create_resp.get("data") if create_resp and create_resp.get("code") == 0 else None
if not brand_id:
pytest.skip("创建测试品牌失败,跳过详情测试")
allure.attach(json.dumps({"id": brand_id}, ensure_ascii=False), name="售后政策-品牌ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用获得详情接口"):
resp = self.test_case.kw_joyhub_after_sales_brand_get_get(brand_id=brand_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], dict), "data字段不是字典类型"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == brand_id, "返回的ID与请求的不一致"
logging.info("获得售后政策-品牌详情验证通过")
@allure.story("验证更新售后政策-品牌")
@allure.title("测试更新售后政策-品牌接口")
def test_joyhub_after_sales_brand_update_put(self):
"""测试更新售后政策-品牌接口"""
if not self.policy_id:
pytest.skip("未创建测试售后政策,跳过品牌更新测试")
with allure.step("1. 先创建一个售后政策-品牌"):
timestamp = int(time.time())
create_resp = self.test_case.kw_joyhub_after_sales_brand_create_post(
brand_name=f"待更新品牌_{timestamp}",
after_sales_policy_id=self.policy_id,
status=1
)
brand_id = create_resp.get("data") if create_resp and create_resp.get("code") == 0 else None
if not brand_id:
pytest.skip("创建测试品牌失败,跳过更新测试")
allure.attach(json.dumps({"id": brand_id}, ensure_ascii=False), name="售后政策-品牌ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"brand_id": brand_id,
"brand_name": f"已更新品牌_{timestamp}",
"after_sales_policy_id": self.policy_id,
"status": 2
}
resp = self.test_case.kw_joyhub_after_sales_brand_update_put(**update_params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "更新售后政策-品牌失败"
logging.info("更新售后政策-品牌验证通过")
@allure.story("验证删除售后政策-品牌")
@allure.title("测试删除售后政策-品牌接口")
def test_joyhub_after_sales_brand_delete_delete(self):
"""测试删除售后政策-品牌接口"""
if not self.policy_id:
pytest.skip("未创建测试售后政策,跳过品牌删除测试")
with allure.step("1. 先创建一个测试售后政策-品牌"):
timestamp = int(time.time())
create_resp = self.test_case.kw_joyhub_after_sales_brand_create_post(
brand_name=f"待删除品牌_{timestamp}",
after_sales_policy_id=self.policy_id,
status=2
)
brand_id = create_resp.get("data") if create_resp and create_resp.get("code") == 0 else None
if not brand_id:
pytest.skip("创建测试品牌失败,跳过删除测试")
allure.attach(json.dumps({"id": brand_id}, ensure_ascii=False), name="待删除品牌ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用删除接口"):
resp = self.test_case.kw_joyhub_after_sales_brand_delete_delete(brand_id=brand_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除售后政策-品牌失败"
logging.info("删除售后政策-品牌验证通过")
@allure.story("验证批量删除售后政策-品牌")
@allure.title("测试批量删除售后政策-品牌接口")
def test_joyhub_after_sales_brand_delete_list_delete(self):
"""测试批量删除售后政策-品牌接口"""
if not self.policy_id:
pytest.skip("未创建测试售后政策,跳过批量删除品牌测试")
with allure.step("1. 先创建两个测试售后政策-品牌"):
timestamp = int(time.time())
resp1 = self.test_case.kw_joyhub_after_sales_brand_create_post(
brand_name=f"批量删除品牌1_{timestamp}",
after_sales_policy_id=self.policy_id,
status=2
)
resp2 = self.test_case.kw_joyhub_after_sales_brand_create_post(
brand_name=f"批量删除品牌2_{timestamp}",
after_sales_policy_id=self.policy_id,
status=2
)
brand_id1 = resp1.get("data") if resp1 and resp1.get("code") == 0 else None
brand_id2 = resp2.get("data") if resp2 and resp2.get("code") == 0 else None
if not brand_id1 or not brand_id2:
pytest.skip("创建测试品牌失败,跳过批量删除测试")
brand_ids = [brand_id1, brand_id2]
allure.attach(json.dumps({"ids": brand_ids}, ensure_ascii=False), name="待删除品牌IDs", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用批量删除接口"):
resp = self.test_case.kw_joyhub_after_sales_brand_delete_list_delete(brand_ids=brand_ids)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "批量删除售后政策-品牌失败"
logging.info("批量删除售后政策-品牌验证通过")
@allure.story("验证获得可用的品牌列表")
@allure.title("测试获得可用的品牌列表接口")
def test_joyhub_after_sales_brand_list_available_get(self):
"""测试获得可用的品牌列表接口"""
with allure.step("1. 调用接口"):
resp = self.test_case.kw_joyhub_after_sales_brand_list_available_get()
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], list), "data字段不是列表类型"
logging.info("获得可用的品牌列表验证通过")

View File

@@ -1,200 +0,0 @@
# -*- coding:utf-8 -*-
"""
blog分类管理接口测试用例
"""
import pytest
import json
import time
import logging
import allure
from dulizhan.library.BusinessKw.JoyHub.BlogCateManage import BlogCateManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - blog分类管理模块")
class TestBlogCateManage:
cate_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = BlogCateManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
import requests
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
else:
logging.error(f"登录失败: {login_response}")
pytest.skip("登录失败,跳过所有测试")
@allure.story("验证登录")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestBlogCateManage.token_set is True, "登录失败"
logging.info("登录验证通过")
@allure.story("验证获得blog分类分页")
@allure.title("测试获得blog分类分页接口")
def test_joyhub_blog_cate_page_get(self):
"""测试获得blog分类分页接口"""
with allure.step("1. 调用接口"):
resp = self.test_case.kw_joyhub_blog_cate_page_get(page_num=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], dict), "data字段不是字典类型"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
assert "total" in resp["data"], "响应中缺少total字段"
assert isinstance(resp["data"]["total"], int), "total字段不是整数类型"
logging.info("获得blog分类分页列表验证通过")
@allure.story("验证创建和删除blog分类")
@allure.title("测试创建和删除blog分类接口")
def test_joyhub_blog_cate_create_and_delete(self):
"""测试创建和删除blog分类接口"""
with allure.step("1. 准备创建请求参数"):
timestamp = int(time.time())
params = {
"name": f"测试blog分类_{timestamp}",
"status": 1,
"cover_image": "https://example.com/cover.jpg"
}
allure.attach(json.dumps(params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用创建接口"):
resp = self.test_case.kw_joyhub_blog_cate_create_post(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证创建响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], int), "data字段不是整数类型"
cate_id = resp["data"]
TestBlogCateManage.cate_id = cate_id
logging.info(f"创建blog分类成功blog分类ID: {cate_id}")
with allure.step("4. 调用删除接口"):
delete_resp = self.test_case.kw_joyhub_blog_cate_delete_delete(cate_id=cate_id)
allure.attach(json.dumps(delete_resp, ensure_ascii=False, indent=2), name="删除响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("5. 验证删除响应"):
assert delete_resp is not None, "响应为空"
assert "code" in delete_resp, "响应中缺少code字段"
assert delete_resp["code"] == 0, f"删除失败code={delete_resp.get('code')}, msg={delete_resp.get('msg')}"
assert "data" in delete_resp, "响应中缺少data字段"
assert delete_resp["data"] is True, "删除blog分类失败"
logging.info("创建并删除blog分类验证通过")
@allure.story("验证获得blog分类详情")
@allure.title("测试获得blog分类详情接口")
def test_joyhub_blog_cate_get_get(self):
"""测试获得blog分类详情接口"""
with allure.step("1. 从分页获取现有blog分类ID"):
page_resp = self.test_case.kw_joyhub_blog_cate_page_get(page_num=1, page_size=10)
if not page_resp or page_resp.get("code") != 0:
pytest.skip("获取分页失败,跳过详情测试")
data_list = page_resp.get("data", {}).get("list", [])
if not data_list:
pytest.skip("暂无blog分类数据跳过详情测试")
cate_id = data_list[0].get("id")
allure.attach(json.dumps({"id": cate_id}, ensure_ascii=False), name="blog分类ID", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用获得详情接口"):
resp = self.test_case.kw_joyhub_blog_cate_get_get(cate_id=cate_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], dict), "data字段不是字典类型"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == cate_id, "返回的ID与请求的不一致"
logging.info("获得blog分类详情验证通过")
@allure.story("验证创建和更新blog分类")
@allure.title("测试创建和更新blog分类接口")
def test_joyhub_blog_cate_create_and_update(self):
"""测试创建和更新blog分类接口"""
with allure.step("1. 创建blog分类"):
timestamp = int(time.time())
create_params = {
"name": f"测试更新blog分类_{timestamp}",
"status": 1,
"cover_image": "https://example.com/cover.jpg"
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_blog_cate_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
cate_id = create_resp["data"]
logging.info(f"创建blog分类成功blog分类ID: {cate_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"cate_id": cate_id,
"name": f"测试更新blog分类_{timestamp}",
"status": 1,
"cover_image": "https://example.com/cover_updated.jpg"
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_blog_cate_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
if update_resp["code"] == 500:
logging.warning(f"更新接口返回500错误: {update_resp}")
pytest.skip("更新接口服务端错误,跳过测试")
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新blog分类失败"
logging.info("创建并更新blog分类验证通过")
with allure.step("4. 清理测试数据"):
delete_resp = self.test_case.kw_joyhub_blog_cate_delete_delete(cate_id=cate_id)
if delete_resp and delete_resp.get("code") == 0:
logging.info("清理测试数据成功")
else:
logging.warning(f"清理测试数据失败: {delete_resp}")

View File

@@ -1,162 +0,0 @@
# -*- coding:utf-8 -*-
"""
二维码管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.DownloadQrcodeManage import DownloadQrcodeManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - 二维码管理模块")
class TestDownloadQrcodeManage:
qrcode_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = DownloadQrcodeManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestDownloadQrcodeManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得二维码分页列表")
@allure.title("测试获得二维码分页列表接口")
def test_joyhub_download_qrcode_page_get(self):
"""测试获得二维码分页列表接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_download_qrcode_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "pageResult" in resp["data"], "响应中缺少pageResult字段"
assert "list" in resp["data"]["pageResult"], "响应中缺少list字段"
assert isinstance(resp["data"]["pageResult"]["list"], list), "list字段不是列表类型"
assert "total" in resp["data"]["pageResult"], "响应中缺少total字段"
assert isinstance(resp["data"]["pageResult"]["total"], int), "total字段不是整数类型"
logging.info("获得二维码分页列表验证通过")
@allure.story("验证获得二维码详情")
@allure.title("测试获得二维码详情接口")
def test_joyhub_download_qrcode_get_get(self):
"""测试获得二维码详情接口"""
with allure.step("1. 从分页获取现有二维码ID"):
page_resp = self.test_case.kw_joyhub_download_qrcode_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("pageResult", {}).get("list"), "没有找到可用的二维码数据"
qrcode_id = page_resp["data"]["pageResult"]["list"][0].get("id")
assert qrcode_id, "二维码ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_download_qrcode_get_get(qrcode_id=qrcode_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == qrcode_id, "返回的ID与请求的ID不一致"
assert "title" in resp["data"], "响应中缺少title字段"
assert isinstance(resp["data"]["title"], str), "title字段不是字符串类型"
logging.info("获得二维码详情验证通过")
@allure.story("验证创建和更新二维码")
@allure.title("测试创建和更新二维码接口")
def test_joyhub_download_qrcode_create_and_update(self):
"""测试创建和更新二维码接口"""
created_title = None
with allure.step("1. 创建二维码"):
timestamp = int(time.time())
created_title = f"测试二维码_{timestamp}"
create_params = {
"title": created_title,
"status": 1
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_download_qrcode_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
qrcode_id = create_resp["data"]
TestDownloadQrcodeManage.qrcode_id = qrcode_id
logging.info(f"创建二维码成功ID: {qrcode_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"qrcode_id": qrcode_id,
"title": f"测试二维码_{timestamp}_updated",
"status": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_download_qrcode_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新二维码失败"
logging.info("创建并更新二维码验证通过")
@classmethod
def teardown_class(cls):
"""在整个测试类结束时清理测试数据"""
logging.info("=============================================")
logging.info("=========== 清理测试数据 ============")
logging.info("=============================================")
# 从数据库表jh_download_qrcode中删除测试数据
if cls.qrcode_id:
cls.test_case.clean_test_data_from_db(f"测试二维码_{cls.qrcode_id}")
else:
# 如果没有获取到qrcode_id尝试删除所有测试数据
cls.test_case.clean_test_data_from_db("测试二维码_")

View File

@@ -1,181 +0,0 @@
# -*- coding:utf-8 -*-
"""
FAQ数据管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.FaqManage import FaqManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - FAQ数据管理模块")
class TestFaqManage:
faq_id = None
faq_cate_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = FaqManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
# 获取FAQ分类ID供后续使用
cate_list_resp = cls.test_case.kw_joyhub_faq_cate_list_get()
if cate_list_resp.get('code') == 0 and cate_list_resp.get('data'):
cls.faq_cate_id = cate_list_resp['data'][0].get('faqCateId')
logging.info(f"获取到FAQ分类ID: {cls.faq_cate_id}")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestFaqManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得FAQ数据分页")
@allure.title("测试获得FAQ数据分页接口")
def test_joyhub_faq_page_get(self):
"""测试获得FAQ数据分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_faq_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得FAQ数据分页验证通过")
@allure.story("验证获得FAQ数据详情")
@allure.title("测试获得FAQ数据详情接口")
def test_joyhub_faq_get_get(self):
"""测试获得FAQ数据详情接口"""
with allure.step("1. 从分页获取现有FAQ数据ID"):
page_resp = self.test_case.kw_joyhub_faq_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的FAQ数据"
faq_id = page_resp["data"]["list"][0].get("id")
assert faq_id, "FAQ数据ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_faq_get_get(faq_id=faq_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == faq_id, "返回的ID与请求的ID不一致"
assert "question" in resp["data"], "响应中缺少question字段"
assert isinstance(resp["data"]["question"], str), "question字段不是字符串类型"
logging.info("获得FAQ数据详情验证通过")
@allure.story("验证创建和更新FAQ数据")
@allure.title("测试创建和更新FAQ数据接口")
def test_joyhub_faq_create_and_update(self):
"""测试创建和更新FAQ数据接口"""
if not TestFaqManage.faq_cate_id:
pytest.skip("没有可用的FAQ分类跳过测试")
with allure.step("1. 创建FAQ数据"):
timestamp = int(time.time())
create_params = {
"faq_cate_id": TestFaqManage.faq_cate_id,
"question": f"测试问题_{timestamp}",
"answer": f"测试回答内容_{timestamp}",
"rank_num": 1,
"lang": "zh_CN",
"is_hot": 0,
"status": 1
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_faq_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
faq_id = create_resp["data"]
TestFaqManage.faq_id = faq_id
logging.info(f"创建FAQ数据成功ID: {faq_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"faq_id": faq_id,
"faq_cate_id": TestFaqManage.faq_cate_id,
"question": f"测试问题_{timestamp}_updated",
"answer": f"测试回答内容_{timestamp}_updated",
"rank_num": 2,
"lang": "en",
"is_hot": 1,
"status": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_faq_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新FAQ数据失败"
logging.info("创建并更新FAQ数据验证通过")
@allure.story("验证删除FAQ数据")
@allure.title("测试删除FAQ数据接口")
def test_joyhub_faq_delete_delete(self):
"""测试删除FAQ数据接口"""
if not TestFaqManage.faq_id:
pytest.skip("没有可删除的FAQ数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_faq_delete_delete(faq_id=TestFaqManage.faq_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除FAQ数据失败"
logging.info("删除FAQ数据验证通过")

View File

@@ -1,166 +0,0 @@
# -*- coding:utf-8 -*-
"""
FAQ分类管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.FaqCateManage import FaqCateManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - FAQ分类管理模块")
class TestFaqCateManage:
faq_cate_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = FaqCateManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestFaqCateManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得FAQ分类列表")
@allure.title("测试获得FAQ分类列表接口")
def test_joyhub_faq_cate_list_get(self):
"""测试获得FAQ分类列表接口"""
with allure.step("1. 调用列表接口"):
resp = self.test_case.kw_joyhub_faq_cate_list_get()
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], list), "data字段不是列表类型"
logging.info("获得FAQ分类列表验证通过")
@allure.story("验证获得FAQ分类详情")
@allure.title("测试获得FAQ分类详情接口")
def test_joyhub_faq_cate_get_get(self):
"""测试获得FAQ分类详情接口"""
with allure.step("1. 从列表获取现有FAQ分类ID"):
list_resp = self.test_case.kw_joyhub_faq_cate_list_get()
assert list_resp.get("code") == 0, f"获取列表失败code={list_resp.get('code')}, msg={list_resp.get('msg')}"
assert list_resp.get("data"), "没有找到可用的FAQ分类数据"
faq_cate_id = list_resp["data"][0].get("id") or list_resp["data"][0].get("faqCateId")
assert faq_cate_id, "FAQ分类ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_faq_cate_get_get(faq_cate_id=faq_cate_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == faq_cate_id, "返回的ID与请求的ID不一致"
assert "title" in resp["data"], "响应中缺少title字段"
assert isinstance(resp["data"]["title"], str), "title字段不是字符串类型"
logging.info("获得FAQ分类详情验证通过")
@allure.story("验证创建和更新FAQ分类")
@allure.title("测试创建和更新FAQ分类接口")
def test_joyhub_faq_cate_create_and_update(self):
"""测试创建和更新FAQ分类接口"""
with allure.step("1. 创建FAQ分类"):
timestamp = int(time.time())
create_params = {
"title": f"测试FAQ分类_{timestamp}",
"lang": "zh_CN",
"rank_num": 1,
"pid": 0,
"status": 1
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_faq_cate_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
faq_cate_id = create_resp["data"]
TestFaqCateManage.faq_cate_id = faq_cate_id
logging.info(f"创建FAQ分类成功ID: {faq_cate_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"faq_cate_id": faq_cate_id,
"title": f"测试FAQ分类_{timestamp}_updated",
"lang": "en",
"rank_num": 2,
"pid": 0,
"status": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_faq_cate_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新FAQ分类失败"
logging.info("创建并更新FAQ分类验证通过")
@allure.story("验证删除FAQ分类")
@allure.title("测试删除FAQ分类接口")
def test_joyhub_faq_cate_delete_delete(self):
"""测试删除FAQ分类接口"""
if not TestFaqCateManage.faq_cate_id:
pytest.skip("没有可删除的FAQ分类数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_faq_cate_delete_delete(faq_cate_id=TestFaqCateManage.faq_cate_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除FAQ分类失败"
logging.info("删除FAQ分类验证通过")

View File

@@ -1,210 +0,0 @@
# -*- coding:utf-8 -*-
"""
news管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.NewsManage import NewsManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - news管理模块")
class TestNewsManage:
news_id = None
news_cate_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = NewsManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
# 获取news分类ID供后续使用
from dulizhan.library.BusinessKw.JoyHub.NewsCateManage import NewsCateManage
news_cate_manage = NewsCateManage()
news_cate_manage.set_joyhub_token(token)
cate_page_resp = news_cate_manage.kw_joyhub_news_cate_page_get(page_no=1, page_size=10)
if cate_page_resp.get('code') == 0 and cate_page_resp.get('data', {}).get('list'):
cls.news_cate_id = cate_page_resp['data']['list'][0].get('id')
logging.info(f"获取到news分类ID: {cls.news_cate_id}")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestNewsManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得news管理分页")
@allure.title("测试获得news管理分页接口")
def test_joyhub_news_page_get(self):
"""测试获得news管理分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_news_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得news管理分页验证通过")
@allure.story("验证获得news管理详情")
@allure.title("测试获得news管理详情接口")
def test_joyhub_news_get_get(self):
"""测试获得news管理详情接口"""
with allure.step("1. 从分页获取现有news管理ID"):
page_resp = self.test_case.kw_joyhub_news_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的news管理数据"
news_id = page_resp["data"]["list"][0].get("id")
assert news_id, "news管理ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_news_get_get(news_id=news_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == news_id, "返回的ID与请求的ID不一致"
assert "title" in resp["data"], "响应中缺少title字段"
assert isinstance(resp["data"]["title"], str), "title字段不是字符串类型"
logging.info("获得news管理详情验证通过")
@allure.story("验证创建和更新news管理")
@allure.title("测试创建和更新news管理接口")
def test_joyhub_news_create_and_update(self):
"""测试创建和更新news管理接口"""
with allure.step("1. 创建news管理"):
timestamp = int(time.time())
create_params = {
"title": f"测试news标题_{timestamp}",
"cover_image": {"url": "https://example.com/test.jpg", "name": "test.jpg"},
"content": f"<p>测试内容_{timestamp}</p>",
"status": 1,
"rank_num": 1
}
# 如果有可用的news分类ID添加关联
if TestNewsManage.news_cate_id:
create_params["cate_ids"] = [TestNewsManage.news_cate_id]
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_news_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
news_id = create_resp["data"]
TestNewsManage.news_id = news_id
logging.info(f"创建news管理成功ID: {news_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"news_id": news_id,
"title": f"测试news标题_{timestamp}_updated",
"cover_image": {"url": "https://example.com/test_updated.jpg", "name": "test_updated.jpg"},
"content": f"<p>测试内容_{timestamp}_updated</p>",
"status": 2,
"rank_num": 2
}
# 如果有可用的news分类ID添加关联
if TestNewsManage.news_cate_id:
update_params["cate_ids"] = [TestNewsManage.news_cate_id]
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_news_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新news管理失败"
logging.info("创建并更新news管理验证通过")
@allure.story("验证删除news管理")
@allure.title("测试删除news管理接口")
def test_joyhub_news_delete_delete(self):
"""测试删除news管理接口"""
if not TestNewsManage.news_id:
pytest.skip("没有可删除的news管理数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_news_delete_delete(news_id=TestNewsManage.news_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除news管理失败"
logging.info("删除news管理验证通过")
@allure.story("验证获得news分类关联列表")
@allure.title("测试获得news分类关联列表接口")
def test_joyhub_news_cate_relation_list_get(self):
"""测试获得news分类关联列表接口"""
with allure.step("1. 从分页获取现有news管理ID"):
page_resp = self.test_case.kw_joyhub_news_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的news管理数据"
news_id = page_resp["data"]["list"][0].get("id")
assert news_id, "news管理ID为空"
with allure.step("2. 调用获取分类关联列表接口"):
resp = self.test_case.kw_joyhub_news_cate_relation_list_get(news_id=news_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], list), "data字段不是列表类型"
logging.info("获得news分类关联列表验证通过")

View File

@@ -1,186 +0,0 @@
# -*- coding:utf-8 -*-
"""
news分类管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.NewsCateManage import NewsCateManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - news分类管理模块")
class TestNewsCateManage:
news_cate_id = None
created_names = []
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = NewsCateManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestNewsCateManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得news分类分页")
@allure.title("测试获得news分类分页接口")
def test_joyhub_news_cate_page_get(self):
"""测试获得news分类分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_news_cate_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得news分类分页验证通过")
@allure.story("验证获得news分类详情")
@allure.title("测试获得news分类详情接口")
def test_joyhub_news_cate_get_get(self):
"""测试获得news分类详情接口"""
with allure.step("1. 从分页获取现有news分类ID"):
page_resp = self.test_case.kw_joyhub_news_cate_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的news分类数据"
news_cate_id = page_resp["data"]["list"][0].get("id")
assert news_cate_id, "news分类ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_news_cate_get_get(news_cate_id=news_cate_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == news_cate_id, "返回的ID与请求的ID不一致"
assert "name" in resp["data"], "响应中缺少name字段"
assert isinstance(resp["data"]["name"], str), "name字段不是字符串类型"
logging.info("获得news分类详情验证通过")
@allure.story("验证创建和更新news分类")
@allure.title("测试创建和更新news分类接口")
def test_joyhub_news_cate_create_and_update(self):
"""测试创建和更新news分类接口"""
with allure.step("1. 创建news分类"):
timestamp = int(time.time())
created_name = f"测试news分类_{timestamp}"
TestNewsCateManage.created_names.append(created_name)
create_params = {
"name": created_name,
"status": 1,
"rank_num": 1,
"cover_image": {"url": "https://example.com/test.jpg", "name": "test.jpg"}
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_news_cate_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
news_cate_id = create_resp["data"]
TestNewsCateManage.news_cate_id = news_cate_id
logging.info(f"创建news分类成功ID: {news_cate_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
updated_name = f"测试news分类_{timestamp}_updated"
TestNewsCateManage.created_names.append(updated_name)
update_params = {
"news_cate_id": news_cate_id,
"name": updated_name,
"status": 2,
"rank_num": 2,
"cover_image": {"url": "https://example.com/test_updated.jpg", "name": "test_updated.jpg"}
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_news_cate_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新news分类失败"
logging.info("创建并更新news分类验证通过")
@allure.story("验证删除news分类")
@allure.title("测试删除news分类接口")
def test_joyhub_news_cate_delete_delete(self):
"""测试删除news分类接口"""
if not TestNewsCateManage.news_cate_id:
pytest.skip("没有可删除的news分类数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_news_cate_delete_delete(news_cate_id=TestNewsCateManage.news_cate_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除news分类失败"
logging.info("删除news分类验证通过")
@classmethod
def teardown_class(cls):
"""在整个测试类结束时清理测试数据"""
logging.info("=============================================")
logging.info("=========== 清理测试数据 ============")
logging.info("=============================================")
# 从数据库表jh_news_cate中删除测试数据
for name in cls.created_names:
cls.test_case.clean_test_data_from_db(name)
# 额外清理所有包含"测试news分类"的记录
cls.test_case.clean_test_data_from_db("测试news分类")

View File

@@ -1,490 +0,0 @@
# -*- coding:utf-8 -*-
"""
产品管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.ProductManage import ProductManage
from dulizhan.library.BusinessKw.JoyHub.ProductCateManage import ProductCateManage
from base_framework.public_tools.pgsqlhelper import PgSqlHelper
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - 产品管理模块")
class TestProductManage:
product_id = None
product_cate_id = None
shipping_template_id = None
brand_id = None
product_attr_type_id = None
product_attr_data_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = ProductManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
# 获取产品分类ID
product_cate_manage = ProductCateManage()
product_cate_manage.set_joyhub_token(token)
cate_page_resp = product_cate_manage.kw_joyhub_product_cate_page_get(page_no=1, page_size=50)
if cate_page_resp.get('code') == 0 and cate_page_resp.get('data', {}).get('list'):
for cate_item in cate_page_resp['data']['list']:
if cate_item.get('cateType') == 1:
cls.product_cate_id = cate_item.get('id')
break
if cls.product_cate_id is None:
cls.product_cate_id = cate_page_resp['data']['list'][0].get('id')
logging.info(f"获取到产品分类ID: {cls.product_cate_id}")
# 获取运费模板ID和品牌ID
try:
db_helper = PgSqlHelper()
logging.info("开始连接数据库获取运费模板ID和品牌ID")
# 从jh_shipping_template表获取运费模板ID使用joyhub数据库
shipping_sql = "SELECT id FROM jh_shipping_template WHERE deleted = 0 LIMIT 1"
logging.info(f"执行SQL: {shipping_sql}")
shipping_result = db_helper.select_one(shipping_sql, choose_db='joyhub')
logging.info(f"运费模板查询结果: {shipping_result}")
if shipping_result:
cls.shipping_template_id = shipping_result.get('id')
logging.info(f"从数据库获取到运费模板ID: {cls.shipping_template_id}")
else:
logging.warning("数据库中未找到运费模板数据")
# 从jh_after_sales_brand表获取品牌ID使用joyhub数据库
brand_sql = "SELECT id FROM jh_after_sales_brand WHERE deleted = 0 LIMIT 1"
logging.info(f"执行SQL: {brand_sql}")
brand_result = db_helper.select_one(brand_sql, choose_db='joyhub')
logging.info(f"品牌查询结果: {brand_result}")
if brand_result:
cls.brand_id = brand_result.get('id')
logging.info(f"从数据库获取到品牌ID: {cls.brand_id}")
else:
logging.warning("数据库中未找到品牌数据")
except Exception as e:
logging.error(f"从数据库获取运费模板ID和品牌ID失败: {e}")
import traceback
logging.error(traceback.format_exc())
# 获取现有产品ID用于测试
product_page_resp = cls.test_case.kw_joyhub_product_page_get(page_no=1, page_size=10)
if product_page_resp.get('code') == 0 and product_page_resp.get('data', {}).get('list'):
cls.product_id = product_page_resp['data']['list'][0].get('id')
logging.info(f"获取到现有产品ID: {cls.product_id}")
# 获取产品属性类型ID和属性值ID
from dulizhan.library.BusinessKw.JoyHub.ProductAttrManage import ProductAttrManage
product_attr_manage = ProductAttrManage()
product_attr_manage.set_joyhub_token(token)
attr_type_page_resp = product_attr_manage.kw_joyhub_product_attr_type_page_get(page_no=1, page_size=10)
if attr_type_page_resp.get('code') == 0 and attr_type_page_resp.get('data', {}).get('list'):
cls.product_attr_type_id = attr_type_page_resp['data']['list'][0].get('id')
logging.info(f"获取到产品属性类型ID: {cls.product_attr_type_id}")
# 获取该属性类型下的属性值
attr_data_page_resp = product_attr_manage.kw_joyhub_product_attr_data_page_get(
page_no=1, page_size=10, productAttrTypeId=cls.product_attr_type_id
)
if attr_data_page_resp.get('code') == 0 and attr_data_page_resp.get('data', {}).get('list'):
cls.product_attr_data_id = attr_data_page_resp['data']['list'][0].get('id')
logging.info(f"获取到产品属性值ID: {cls.product_attr_data_id}")
else:
# 如果没有属性值,创建一个
timestamp = int(time.time())
create_attr_data_resp = product_attr_manage.kw_joyhub_product_attr_data_create_post(
product_attr_type_id=cls.product_attr_type_id,
attr_value=f"测试属性值_{timestamp}"
)
if create_attr_data_resp.get('code') == 0:
cls.product_attr_data_id = create_attr_data_resp['data']
logging.info(f"创建产品属性值成功ID: {cls.product_attr_data_id}")
else:
# 如果没有产品属性类型,创建一个
timestamp = int(time.time())
create_attr_type_resp = product_attr_manage.kw_joyhub_product_attr_type_create_post(
name=f"测试产品属性_{timestamp}",
type=2,
status=1
)
if create_attr_type_resp.get('code') == 0:
cls.product_attr_type_id = create_attr_type_resp['data']
logging.info(f"创建产品属性类型成功ID: {cls.product_attr_type_id}")
# 创建属性值
create_attr_data_resp = product_attr_manage.kw_joyhub_product_attr_data_create_post(
product_attr_type_id=cls.product_attr_type_id,
attr_value=f"测试属性值_{timestamp}"
)
if create_attr_data_resp.get('code') == 0:
cls.product_attr_data_id = create_attr_data_resp['data']
logging.info(f"创建产品属性值成功ID: {cls.product_attr_data_id}")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestProductManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得产品分页")
@allure.title("测试获得产品分页接口")
def test_joyhub_product_page_get(self):
"""测试获得产品分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_product_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得产品分页验证通过")
@allure.story("验证获得产品详情")
@allure.title("测试获得产品详情接口")
def test_joyhub_product_get_get(self):
"""测试获得产品详情接口"""
with allure.step("1. 从分页获取现有产品ID"):
page_resp = self.test_case.kw_joyhub_product_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品数据"
product_id = page_resp["data"]["list"][0].get("id")
assert product_id, "产品ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_product_get_get(product_id=product_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == product_id, "返回的ID与请求的ID不一致"
assert "productName" in resp["data"], "响应中缺少productName字段"
assert isinstance(resp["data"]["productName"], str), "productName字段不是字符串类型"
logging.info("获得产品详情验证通过")
@allure.story("验证获得产品规格类型关联列表")
@allure.title("测试获得产品规格类型关联列表接口")
def test_joyhub_product_product_attr_list_by_product_id_get(self):
"""测试获得产品规格类型关联列表接口"""
with allure.step("1. 从分页获取现有产品ID"):
page_resp = self.test_case.kw_joyhub_product_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品数据"
product_id = page_resp["data"]["list"][0].get("id")
assert product_id, "产品ID为空"
with allure.step("2. 调用获取产品规格类型关联列表接口"):
resp = self.test_case.kw_joyhub_product_product_attr_list_by_product_id_get(product_id=product_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], list), "data字段不是列表类型"
logging.info("获得产品规格类型关联列表验证通过")
@allure.story("验证获得产品详情列表")
@allure.title("测试获得产品详情列表接口")
def test_joyhub_product_product_detail_list_by_product_id_get(self):
"""测试获得产品详情列表接口"""
with allure.step("1. 从分页获取现有产品ID"):
page_resp = self.test_case.kw_joyhub_product_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品数据"
product_id = page_resp["data"]["list"][0].get("id")
assert product_id, "产品ID为空"
with allure.step("2. 调用获取产品详情列表接口"):
resp = self.test_case.kw_joyhub_product_product_detail_list_by_product_id_get(product_id=product_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], list), "data字段不是列表类型"
logging.info("获得产品详情列表验证通过")
@allure.story("验证获得产品规格列表")
@allure.title("测试获得产品规格列表接口")
def test_joyhub_product_product_sku_list_by_product_id_get(self):
"""测试获得产品规格列表接口"""
with allure.step("1. 从分页获取现有产品ID"):
page_resp = self.test_case.kw_joyhub_product_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品数据"
product_id = page_resp["data"]["list"][0].get("id")
assert product_id, "产品ID为空"
with allure.step("2. 调用获取产品规格列表接口"):
resp = self.test_case.kw_joyhub_product_product_sku_list_by_product_id_get(product_id=product_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], list), "data字段不是列表类型"
logging.info("获得产品规格列表验证通过")
@allure.story("验证创建和更新产品")
@allure.title("测试创建和更新产品接口")
def test_joyhub_product_create_and_update(self):
"""测试创建和更新产品接口"""
# 检查必要的前置数据
logging.info(f"前置数据状态 - product_cate_id: {TestProductManage.product_cate_id}, "
f"shipping_template_id: {TestProductManage.shipping_template_id}, "
f"brand_id: {TestProductManage.brand_id}, "
f"product_attr_type_id: {TestProductManage.product_attr_type_id}, "
f"product_attr_data_id: {TestProductManage.product_attr_data_id}")
# 如果缺少必要数据,则跳过测试
if not TestProductManage.product_cate_id:
pytest.skip("缺少产品分类ID")
if not TestProductManage.shipping_template_id:
pytest.skip("缺少运费模板ID")
if not TestProductManage.brand_id:
pytest.skip("缺少品牌ID")
if not all([TestProductManage.product_attr_type_id, TestProductManage.product_attr_data_id]):
pytest.skip("缺少产品属性类型或属性值")
with allure.step("1. 创建产品"):
timestamp = int(time.time())
# 构建产品规格类型关联列表
product_attrs = [{
"id": 0,
"productId": 0,
"productAttrTypeId": TestProductManage.product_attr_type_id,
"productAttrDataId": TestProductManage.product_attr_data_id
}]
image_obj = {
"url": "https://img.joyhub.net/official_jub/20260413/resized_E031_1776065842307.png",
"name": None,
"alt": None
}
# 构建产品详情列表
product_details = [{
"id": 0,
"productAttrTypeId": TestProductManage.product_attr_type_id,
"productAttrDataId": TestProductManage.product_attr_data_id,
"isFeatured": 1,
"productColor": f"自动化颜色_{timestamp}",
"productColorCard": ["#b2b8bf"],
"coverImage": image_obj,
"coverProductImage": image_obj,
"categoryImage": image_obj,
"productImages": [image_obj],
"description": f"自动化产品详情_{timestamp}"
}]
# 构建产品规格列表
product_skus = [{
"id": 0,
"isFeatured": 1,
"skuNo": [f"AUTO{timestamp}"],
"productPrice": 100,
"exchangePoints": 0,
"productOriginalPrice": 120,
"stockNum": 100,
"status": 1,
"productAttrDataIds": [TestProductManage.product_attr_data_id]
}]
create_params = {
"product_name": f"测试产品_{timestamp}",
"product_cate_id": TestProductManage.product_cate_id,
"shipping_template_id": TestProductManage.shipping_template_id,
"route": f"/test/product/{timestamp}",
"intro": f"测试产品简介_{timestamp}",
"brand_id": TestProductManage.brand_id,
"product_attrs": product_attrs,
"product_skus": product_skus,
"product_details": product_details,
"status": 1
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_product_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
product_id = create_resp["data"]
TestProductManage.product_id = product_id
logging.info(f"创建产品成功ID: {product_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
# 更新产品规格类型关联列表
product_attrs = [{
"id": 0,
"productId": product_id,
"productAttrTypeId": TestProductManage.product_attr_type_id,
"productAttrDataId": TestProductManage.product_attr_data_id
}]
image_obj = {
"url": "https://img.joyhub.net/official_jub/20260413/resized_E031_1776065842307.png",
"name": None,
"alt": None
}
# 更新产品详情列表
product_details = [{
"id": 0,
"productAttrTypeId": TestProductManage.product_attr_type_id,
"productAttrDataId": TestProductManage.product_attr_data_id,
"isFeatured": 1,
"productColor": f"自动化颜色_{timestamp}_updated",
"productColorCard": ["#b2b8bf"],
"coverImage": image_obj,
"coverProductImage": image_obj,
"categoryImage": image_obj,
"productImages": [image_obj],
"description": f"自动化产品详情_{timestamp}_updated"
}]
# 更新产品规格列表
product_skus = [{
"id": 0,
"isFeatured": 1,
"skuNo": [f"AUTO{timestamp}U"],
"productPrice": 200,
"exchangePoints": 0,
"productOriginalPrice": 220,
"stockNum": 200,
"status": 1,
"productAttrDataIds": [TestProductManage.product_attr_data_id]
}]
update_params = {
"product_id": product_id,
"product_name": f"测试产品_{timestamp}_updated",
"product_cate_id": TestProductManage.product_cate_id,
"shipping_template_id": TestProductManage.shipping_template_id,
"route": f"/test/product/{timestamp}_updated",
"intro": f"测试产品简介_{timestamp}_updated",
"brand_id": TestProductManage.brand_id,
"product_attrs": product_attrs,
"product_skus": product_skus,
"product_details": product_details,
"status": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_product_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新产品失败"
logging.info("创建并更新产品验证通过")
@allure.story("验证批量上下架产品")
@allure.title("测试批量上下架产品接口")
def test_joyhub_product_change_status_put(self):
"""测试批量上下架产品接口"""
if not TestProductManage.product_id:
pytest.skip("没有可修改状态的产品数据")
with allure.step("1. 调用批量上架接口"):
resp = self.test_case.kw_joyhub_product_change_status_put(
ids=[TestProductManage.product_id],
status=1
)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证上架响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"批量上架失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "批量上架产品失败"
with allure.step("3. 调用批量下架接口"):
resp = self.test_case.kw_joyhub_product_change_status_put(
ids=[TestProductManage.product_id],
status=2
)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("4. 验证下架响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"批量下架失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "批量下架产品失败"
logging.info("批量上下架产品验证通过")
@allure.story("验证删除产品")
@allure.title("测试删除产品接口")
def test_joyhub_product_delete_delete(self):
"""测试删除产品接口"""
if not TestProductManage.product_id:
pytest.skip("没有可删除的产品数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_product_delete_delete(product_id=TestProductManage.product_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除产品失败"
logging.info("删除产品验证通过")

View File

@@ -1,320 +0,0 @@
# -*- coding:utf-8 -*-
"""
产品属性+产品属性值管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.ProductAttrManage import ProductAttrManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - 产品属性+产品属性值管理模块")
class TestProductAttrManage:
product_attr_type_id = None
product_attr_data_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = ProductAttrManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestProductAttrManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
# ============ 产品属性测试用例 ============
@allure.story("验证获得产品属性分页")
@allure.title("测试获得产品属性分页接口")
def test_joyhub_product_attr_type_page_get(self):
"""测试获得产品属性分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_product_attr_type_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得产品属性分页验证通过")
@allure.story("验证获得产品属性详情")
@allure.title("测试获得产品属性详情接口")
def test_joyhub_product_attr_type_get_get(self):
"""测试获得产品属性详情接口"""
with allure.step("1. 从分页获取现有产品属性ID"):
page_resp = self.test_case.kw_joyhub_product_attr_type_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品属性数据"
product_attr_type_id = page_resp["data"]["list"][0].get("id")
assert product_attr_type_id, "产品属性ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_product_attr_type_get_get(product_attr_type_id=product_attr_type_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == product_attr_type_id, "返回的ID与请求的ID不一致"
assert "name" in resp["data"], "响应中缺少name字段"
assert isinstance(resp["data"]["name"], str), "name字段不是字符串类型"
logging.info("获得产品属性详情验证通过")
@allure.story("验证创建和更新产品属性")
@allure.title("测试创建和更新产品属性接口")
def test_joyhub_product_attr_type_create_and_update(self):
"""测试创建和更新产品属性接口"""
with allure.step("1. 创建产品属性"):
timestamp = int(time.time())
create_params = {
"name": f"测试产品属性_{timestamp}",
"type": 2,
"status": 1,
"remark": f"测试备注_{timestamp}",
"rank_num": 1
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_product_attr_type_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
product_attr_type_id = create_resp["data"]
TestProductAttrManage.product_attr_type_id = product_attr_type_id
logging.info(f"创建产品属性成功ID: {product_attr_type_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"product_attr_type_id": product_attr_type_id,
"name": f"测试产品属性_{timestamp}_updated",
"type": 2,
"status": 2,
"remark": f"测试备注_{timestamp}_updated",
"rank_num": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_product_attr_type_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新产品属性失败"
logging.info("创建并更新产品属性验证通过")
@allure.story("验证修改产品属性状态")
@allure.title("测试修改产品属性状态接口")
def test_joyhub_product_attr_type_change_status_put(self):
"""测试修改产品属性状态接口"""
if not TestProductAttrManage.product_attr_type_id:
pytest.skip("没有可修改状态的产品属性数据")
with allure.step("1. 调用修改状态接口(启用)"):
resp = self.test_case.kw_joyhub_product_attr_type_change_status_put(
product_attr_type_id=TestProductAttrManage.product_attr_type_id,
status=1
)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"修改状态失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "修改产品属性状态失败"
logging.info("修改产品属性状态验证通过")
# ============ 产品属性值测试用例 ============
@allure.story("验证获得产品属性值分页")
@allure.title("测试获得产品属性值分页接口")
def test_joyhub_product_attr_data_page_get(self):
"""测试获得产品属性值分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_product_attr_data_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得产品属性值分页验证通过")
@allure.story("验证获得产品属性值详情")
@allure.title("测试获得产品属性值详情接口")
def test_joyhub_product_attr_data_get_get(self):
"""测试获得产品属性值详情接口"""
with allure.step("1. 从分页获取现有产品属性值ID"):
page_resp = self.test_case.kw_joyhub_product_attr_data_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品属性值数据"
product_attr_data_id = page_resp["data"]["list"][0].get("id")
assert product_attr_data_id, "产品属性值ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_product_attr_data_get_get(product_attr_data_id=product_attr_data_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == product_attr_data_id, "返回的ID与请求的ID不一致"
assert "attrValue" in resp["data"], "响应中缺少attrValue字段"
assert isinstance(resp["data"]["attrValue"], str), "attrValue字段不是字符串类型"
logging.info("获得产品属性值详情验证通过")
@allure.story("验证创建和更新产品属性值")
@allure.title("测试创建和更新产品属性值接口")
def test_joyhub_product_attr_data_create_and_update(self):
"""测试创建和更新产品属性值接口"""
# 如果没有创建的产品属性ID则使用已有产品属性ID
product_attr_type_id = TestProductAttrManage.product_attr_type_id
if not product_attr_type_id:
with allure.step("获取已有产品属性ID"):
page_resp = self.test_case.kw_joyhub_product_attr_type_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品属性数据"
product_attr_type_id = page_resp["data"]["list"][0].get("id")
with allure.step("1. 创建产品属性值"):
timestamp = int(time.time())
create_params = {
"product_attr_type_id": product_attr_type_id,
"attr_value": f"测试属性值_{timestamp}",
"color": ["#FF0000", "#00FF00"]
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_product_attr_data_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
product_attr_data_id = create_resp["data"]
TestProductAttrManage.product_attr_data_id = product_attr_data_id
logging.info(f"创建产品属性值成功ID: {product_attr_data_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"product_attr_data_id": product_attr_data_id,
"product_attr_type_id": product_attr_type_id,
"attr_value": f"测试属性值_{timestamp}_updated",
"color": ["#0000FF"]
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_product_attr_data_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新产品属性值失败"
logging.info("创建并更新产品属性值验证通过")
# ============ 删除测试用例 ============
@allure.story("验证删除产品属性值")
@allure.title("测试删除产品属性值接口")
def test_joyhub_product_attr_data_delete_delete(self):
"""测试删除产品属性值接口"""
if not TestProductAttrManage.product_attr_data_id:
pytest.skip("没有可删除的产品属性值数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_product_attr_data_delete_delete(product_attr_data_id=TestProductAttrManage.product_attr_data_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除产品属性值失败"
logging.info("删除产品属性值验证通过")
@allure.story("验证删除产品属性")
@allure.title("测试删除产品属性接口")
def test_joyhub_product_attr_type_delete_delete(self):
"""测试删除产品属性接口"""
if not TestProductAttrManage.product_attr_type_id:
pytest.skip("没有可删除的产品属性数据")
with allure.step("1. 先将产品属性状态改为停用"):
status_resp = self.test_case.kw_joyhub_product_attr_type_change_status_put(
product_attr_type_id=TestProductAttrManage.product_attr_type_id,
status=2
)
assert status_resp.get("code") == 0, f"修改状态失败code={status_resp.get('code')}, msg={status_resp.get('msg')}"
with allure.step("2. 调用删除接口"):
resp = self.test_case.kw_joyhub_product_attr_type_delete_delete(product_attr_type_id=TestProductAttrManage.product_attr_type_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除产品属性失败"
logging.info("删除产品属性验证通过")

View File

@@ -1,201 +0,0 @@
# -*- coding:utf-8 -*-
"""
产品分类管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.ProductCateManage import ProductCateManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - 产品分类管理模块")
class TestProductCateManage:
product_cate_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = ProductCateManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestProductCateManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得产品分类分页")
@allure.title("测试获得产品分类分页接口")
def test_joyhub_product_cate_page_get(self):
"""测试获得产品分类分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_product_cate_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得产品分类分页验证通过")
@allure.story("验证获得产品分类详情")
@allure.title("测试获得产品分类详情接口")
def test_joyhub_product_cate_get_get(self):
"""测试获得产品分类详情接口"""
with allure.step("1. 从分页获取现有产品分类ID"):
page_resp = self.test_case.kw_joyhub_product_cate_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的产品分类数据"
product_cate_id = page_resp["data"]["list"][0].get("id")
assert product_cate_id, "产品分类ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_product_cate_get_get(product_cate_id=product_cate_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == product_cate_id, "返回的ID与请求的ID不一致"
assert "cateName" in resp["data"], "响应中缺少cateName字段"
assert isinstance(resp["data"]["cateName"], str), "cateName字段不是字符串类型"
logging.info("获得产品分类详情验证通过")
@allure.story("验证创建和更新产品分类")
@allure.title("测试创建和更新产品分类接口")
def test_joyhub_product_cate_create_and_update(self):
"""测试创建和更新产品分类接口"""
with allure.step("1. 创建产品分类"):
timestamp = int(time.time())
create_params = {
"cate_name": f"测试产品分类_{timestamp}",
"cate_type": 1,
"status": 1,
"rank_num": 1
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_product_cate_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
product_cate_id = create_resp["data"]
TestProductCateManage.product_cate_id = product_cate_id
logging.info(f"创建产品分类成功ID: {product_cate_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"product_cate_id": product_cate_id,
"cate_name": f"测试产品分类_{timestamp}_updated",
"cate_type": 1,
"status": 2,
"rank_num": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_product_cate_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新产品分类失败"
logging.info("创建并更新产品分类验证通过")
@allure.story("验证修改产品分类状态")
@allure.title("测试修改产品分类状态接口")
def test_joyhub_product_cate_change_status_put(self):
"""测试修改产品分类状态接口"""
if not TestProductCateManage.product_cate_id:
pytest.skip("没有可修改状态的产品分类数据")
with allure.step("1. 调用修改状态接口(停用)"):
resp = self.test_case.kw_joyhub_product_cate_change_status_put(
product_cate_id=TestProductCateManage.product_cate_id,
status=2
)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证停用响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"修改状态失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "修改产品分类状态失败"
with allure.step("3. 调用修改状态接口(启用)"):
resp = self.test_case.kw_joyhub_product_cate_change_status_put(
product_cate_id=TestProductCateManage.product_cate_id,
status=1
)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("4. 验证启用响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"修改状态失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "修改产品分类状态失败"
logging.info("修改产品分类状态验证通过")
@allure.story("验证删除产品分类")
@allure.title("测试删除产品分类接口")
def test_joyhub_product_cate_delete_delete(self):
"""测试删除产品分类接口"""
if not TestProductCateManage.product_cate_id:
pytest.skip("没有可删除的产品分类数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_product_cate_delete_delete(product_cate_id=TestProductCateManage.product_cate_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除产品分类失败"
logging.info("删除产品分类验证通过")

View File

@@ -1,279 +0,0 @@
# -*- coding:utf-8 -*-
"""
支付页产品推荐接口测试用例
"""
import json
import pytest
import allure
import logging
import requests
from dulizhan.library.BusinessKw.JoyHub.ProductManage import ProductManage
from dulizhan.library.BusinessKw.JoyHub.ProductPaymentRecommendManage import ProductPaymentRecommendManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - 支付页产品推荐模块")
class TestProductPaymentRecommendManage:
product_id = None
recommend_id = None
batch_recommend_id = None
token = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = ProductPaymentRecommendManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.token = token
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
recommend_page_resp = cls.test_case.kw_joyhub_product_payment_recommend_page_get(page_no=1, page_size=999)
recommended_product_ids = set()
if recommend_page_resp.get('code') == 0 and recommend_page_resp.get('data', {}).get('list'):
recommended_product_ids = {
item.get('productId') for item in recommend_page_resp['data']['list'] if item.get('productId')
}
product_manage = ProductManage()
product_manage.set_joyhub_token(token)
product_page_resp = product_manage.kw_joyhub_product_page_get(page_no=1, page_size=50)
if product_page_resp.get('code') == 0 and product_page_resp.get('data', {}).get('list'):
for product_item in product_page_resp['data']['list']:
product_id = product_item.get('id')
if product_id and product_id not in recommended_product_ids:
cls.product_id = product_id
break
logging.info(f"获取到未推荐产品ID: {cls.product_id}")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestProductPaymentRecommendManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证管理后台获得支付页产品推荐分页")
@allure.title("测试管理后台获得支付页产品推荐分页接口")
def test_joyhub_product_payment_recommend_page_get(self):
"""测试管理后台获得支付页产品推荐分页接口"""
with allure.step("1. 准备请求参数"):
self.test_case.set_joyhub_token(TestProductPaymentRecommendManage.token)
params = {
"page_no": 1,
"page_size": 10,
"recommendStatus": 1
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用分页接口"):
resp = self.test_case.kw_joyhub_product_payment_recommend_page_get(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
if "total" in resp["data"]:
assert isinstance(resp["data"]["total"], int), "total字段不是整数类型"
logging.info("管理后台获得支付页产品推荐分页验证通过")
@allure.story("验证创建支付页产品推荐")
@allure.title("测试创建支付页产品推荐接口")
def test_joyhub_product_payment_recommend_create_post(self):
"""测试创建支付页产品推荐接口"""
if not TestProductPaymentRecommendManage.product_id:
pytest.skip("没有可用于创建支付页产品推荐的产品数据")
with allure.step("1. 准备请求参数"):
params = {
"product_ids": [TestProductPaymentRecommendManage.product_id]
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用创建接口"):
resp = self.test_case.kw_joyhub_product_payment_recommend_create_post(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"创建失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert isinstance(resp["data"], int), "data字段不是整数类型"
TestProductPaymentRecommendManage.recommend_id = resp["data"]
logging.info(f"创建支付页产品推荐成功ID: {resp['data']}")
@allure.story("验证修改支付页产品推荐排序号")
@allure.title("测试修改支付页产品推荐排序号接口")
def test_joyhub_product_payment_recommend_change_rank_num_put(self):
"""测试修改支付页产品推荐排序号接口"""
if not TestProductPaymentRecommendManage.recommend_id:
pytest.skip("没有可修改排序号的支付页产品推荐数据")
with allure.step("1. 准备请求参数"):
params = {
"recommend_id": TestProductPaymentRecommendManage.recommend_id,
"rank_num": 1
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用修改排序号接口"):
resp = self.test_case.kw_joyhub_product_payment_recommend_change_rank_num_put(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"修改排序号失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "修改支付页产品推荐排序号失败"
logging.info("修改支付页产品推荐排序号验证通过")
@allure.story("验证修改支付页产品推荐状态")
@allure.title("测试修改支付页产品推荐状态接口")
def test_joyhub_product_payment_recommend_change_status_put(self):
"""测试修改支付页产品推荐状态接口"""
if not TestProductPaymentRecommendManage.recommend_id:
pytest.skip("没有可修改状态的支付页产品推荐数据")
with allure.step("1. 准备请求参数"):
params = {
"recommend_id": TestProductPaymentRecommendManage.recommend_id,
"recommend_status": 2
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用修改状态接口"):
resp = self.test_case.kw_joyhub_product_payment_recommend_change_status_put(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"修改状态失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "修改支付页产品推荐状态失败"
logging.info("修改支付页产品推荐状态验证通过")
@allure.story("验证删除支付页产品推荐")
@allure.title("测试删除支付页产品推荐接口")
def test_joyhub_product_payment_recommend_delete_delete(self):
"""测试删除支付页产品推荐接口"""
if not TestProductPaymentRecommendManage.recommend_id:
pytest.skip("没有可删除的支付页产品推荐数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_product_payment_recommend_delete_delete(
recommend_id=TestProductPaymentRecommendManage.recommend_id
)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除支付页产品推荐失败"
TestProductPaymentRecommendManage.recommend_id = None
logging.info("删除支付页产品推荐验证通过")
@allure.story("验证批量删除支付页产品推荐")
@allure.title("测试批量删除支付页产品推荐接口")
def test_joyhub_product_payment_recommend_delete_list_delete(self):
"""测试批量删除支付页产品推荐接口"""
if not TestProductPaymentRecommendManage.product_id:
pytest.skip("没有可用于创建支付页产品推荐的产品数据")
with allure.step("1. 创建一条用于批量删除的支付页产品推荐"):
create_resp = self.test_case.kw_joyhub_product_payment_recommend_create_post(
product_ids=[TestProductPaymentRecommendManage.product_id]
)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
TestProductPaymentRecommendManage.batch_recommend_id = create_resp["data"]
with allure.step("2. 将支付页产品推荐状态改为停用"):
status_resp = self.test_case.kw_joyhub_product_payment_recommend_change_status_put(
recommend_id=TestProductPaymentRecommendManage.batch_recommend_id,
recommend_status=2
)
allure.attach(json.dumps(status_resp, ensure_ascii=False, indent=2), name="修改状态响应数据", attachment_type=allure.attachment_type.JSON)
assert status_resp is not None, "响应为空"
assert "code" in status_resp, "响应中缺少code字段"
assert status_resp["code"] == 0, f"修改状态失败code={status_resp.get('code')}, msg={status_resp.get('msg')}"
assert status_resp.get("data") is True, "修改支付页产品推荐状态失败"
with allure.step("3. 调用批量删除接口"):
params = {
"ids": [TestProductPaymentRecommendManage.batch_recommend_id]
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
resp = self.test_case.kw_joyhub_product_payment_recommend_delete_list_delete(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("4. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"批量删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "批量删除支付页产品推荐失败"
TestProductPaymentRecommendManage.batch_recommend_id = None
logging.info("批量删除支付页产品推荐验证通过")
@allure.story("验证C端获得支付页产品推荐分页")
@allure.title("测试C端获得支付页产品推荐分页接口")
def test_joyhub_web_product_payment_recommend_page_get(self):
"""测试获得支付页产品推荐分页接口"""
with allure.step("1. 准备请求参数"):
self.test_case.set_joyhub_token(None)
params = {
"page_no": 1,
"page_size": 10
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用分页接口"):
resp = self.test_case.kw_joyhub_web_product_payment_recommend_page_get(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
if "total" in resp["data"]:
assert isinstance(resp["data"]["total"], int), "total字段不是整数类型"
logging.info("获得支付页产品推荐分页验证通过")

View File

@@ -1,49 +0,0 @@
# -*- coding:utf-8 -*-
"""
JoyHub C端APP版本接口测试用例
"""
import json
import allure
import logging
from dulizhan.library.BusinessKw.JoyHubC.AppVersionManage import JoyHubCAppVersionManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("C端 - APP版本模块")
class TestJoyHubCAppVersion:
@classmethod
def setup_class(cls):
"""在整个测试类开始时初始化C端APP版本业务关键字"""
logging.info("=============================================")
logging.info("=========== 开始JoyHub C端APP版本接口测试 =========")
logging.info("=============================================")
cls.test_case = JoyHubCAppVersionManage()
@allure.story("验证C端获取APP版本列表")
@allure.title("测试C端获取APP版本列表接口")
def test_joyhub_c_web_appversion_page_get(self):
"""测试C端获取APP版本列表接口"""
with allure.step("1. 准备请求参数"):
params = {
"pageNo": 1,
"pageSize": 10
}
allure.attach(json.dumps(params, ensure_ascii=False), name="请求参数", attachment_type=allure.attachment_type.TEXT)
with allure.step("2. 调用获取APP版本列表接口"):
resp = self.test_case.kw_joyhub_c_web_appversion_page_get(**params)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
if "total" in resp["data"]:
assert isinstance(resp["data"]["total"], int), "total字段不是整数类型"
logging.info("C端获取APP版本列表接口验证通过")

Some files were not shown because too many files have changed in this diff Show More