feat(收尾): 附录A#10联系人CRUD补齐(serializer可写FK+前端dialog+test_contact_crud) / D2真机重跑全绿 / 后端512+PG4

This commit is contained in:
seagull
2026-09-14 02:01:59 +08:00
parent e0e1430e8d
commit 2973776dc3
4 changed files with 245 additions and 1 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ class ContactSerializer(AsyncModelSerializer):
model = Contact
fields = [
"id", "name", "phone", "email", "title", "is_primary",
"customer_code", "supplier_code",
"customer", "supplier", "customer_code", "supplier_code",
"is_deleted", "created_at", "updated_at",
]
read_only_fields = ["id", "created_at", "updated_at"]
+27
View File
@@ -89,3 +89,30 @@ def test_anon_cannot_access(anon, tenant):
anon.credentials(HTTP_X_TENANT_ID=tenant.code)
resp = anon.get("/api/v1/partner/customers/")
assert resp.status_code == 401
@pytest.mark.django_db
def test_contact_crud(auth_client, tenant):
# 新建(无挂靠)
resp = auth_client.post(
"/api/v1/partner/contacts/",
{"name": "张三", "phone": "13800138000", "title": "采购"},
format="json",
)
assert resp.status_code == 201, resp.content
cid = resp.json()["id"]
# 编辑
resp = auth_client.patch(
f"/api/v1/partner/contacts/{cid}/",
{"title": "采购经理"},
format="json",
)
assert resp.status_code == 200, resp.content
assert resp.json()["title"] == "采购经理"
# 列表可见
resp = auth_client.get("/api/v1/partner/contacts/")
assert resp.status_code == 200
assert resp.json()["count"] == 1
# 删除
resp = auth_client.delete(f"/api/v1/partner/contacts/{cid}/")
assert resp.status_code in (200, 202, 204), resp.content