""" 公司管理测试 —— /api/companies 覆盖: 公司列表 / 当前公司详情 / 更新公司信息 / 权限 """ import pytest from httpx import AsyncClient from tests.conftest import COMPANY_ID class TestCompanyList: """GET /api/companies""" async def test_list_companies(self, client: AsyncClient, admin_headers): """管理员获取公司列表 → 200""" resp = await client.get("/api/companies", headers=admin_headers) assert resp.status_code == 200 data = resp.json()["data"] assert "companies" in data assert len(data["companies"]) >= 1 assert data["companies"][0]["code"] == "TEST-CO" class TestCurrentCompany: """GET /api/companies/current""" async def test_get_current_company(self, client: AsyncClient, admin_headers): """获取当前公司详情 → 200""" resp = await client.get("/api/companies/current", headers=admin_headers) assert resp.status_code == 200 data = resp.json()["data"] assert data["name"] == "测试润滑油有限公司" class TestUpdateCompany: """PUT /api/companies/current""" async def test_admin_update_company(self, client: AsyncClient, admin_headers): """管理员更新公司信息 → 200""" resp = await client.put("/api/companies/current", headers=admin_headers, json={ "full_info": {"full_name": "天津测试润滑油有限公司-改", "tax_id": "91120000XXXX"} }) assert resp.status_code == 200 async def test_sales_update_company_forbidden(self, client: AsyncClient, sales_headers): """普通销售更新公司 → 403""" resp = await client.put("/api/companies/current", headers=sales_headers, json={ "full_info": {"full_name": "hack"} }) assert resp.status_code == 403