feat(server): ingest v2事件级归属+session_resume+stay区间并集重算+响应明细契约
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,11 @@ def _body(n=1, sid="s1", vid="v1"):
|
||||
def test_collect_ok_creates_events(db, client):
|
||||
Site.objects.create(name="s", domains=["www.a.com"], site_id="site_x")
|
||||
r = _post(client, _body(2))
|
||||
assert r.status_code == 200 and r.json() == {"code": 200, "data": {"accepted": 2, "duplicated": 0}, "message": "ok"}
|
||||
assert r.status_code == 200
|
||||
body = r.json() # 包含式断言:v2 响应新增 rejected/request_id/server_time 字段
|
||||
assert body["code"] == 200 and body["message"] == "ok"
|
||||
assert body["data"]["accepted"] == 2 and body["data"]["duplicated"] == 0
|
||||
assert body["data"]["rejected"] == [] and body["data"]["request_id"]
|
||||
assert r["Access-Control-Allow-Origin"] == "https://www.a.com"
|
||||
|
||||
def test_origin_not_whitelisted_rejected(db, client):
|
||||
@@ -97,3 +101,27 @@ def test_malformed_content_length_400_not_500(db, client):
|
||||
Site.objects.create(name="s", domains=["www.a.com"], site_id="site_x")
|
||||
r = _post(client, _body(1), extra={"CONTENT_LENGTH": "abc"})
|
||||
assert r.status_code == 400 and r.json()["message"] == "payload_too_large"
|
||||
|
||||
|
||||
# ---- 响应契约(阶段A Task3)----
|
||||
|
||||
def test_response_contract_rejected_details(db, client):
|
||||
"""部分拒绝批:rejected 明细(index/event_id/reason)回传——HTTP 200 不再隐含全量成功。"""
|
||||
Site.objects.create(name="s", domains=["www.a.com"], site_id="site_x")
|
||||
b = _body(2)
|
||||
b["events"][0]["event_name"] = "bad_name"
|
||||
r = _post(client, b)
|
||||
assert r.status_code == 200
|
||||
data = r.json()["data"]
|
||||
assert data["accepted"] == 1 and data["duplicated"] == 0
|
||||
assert data["rejected"] == [{"index": 0, "event_id": "e0",
|
||||
"reason": "event_name_not_allowed"}]
|
||||
|
||||
def test_request_id_in_response_and_raw_batch(db, client):
|
||||
"""request_id(uuid4 hex 32)随响应回传,且与 RawBatch.request_id 同值落库(对账)。"""
|
||||
from tracker.models import RawBatch
|
||||
Site.objects.create(name="s", domains=["www.a.com"], site_id="site_x")
|
||||
r = _post(client, _body(1))
|
||||
rid = r.json()["data"]["request_id"]
|
||||
assert isinstance(rid, str) and len(rid) == 32
|
||||
assert RawBatch.objects.get().request_id == rid
|
||||
|
||||
Reference in New Issue
Block a user