115 lines
4.0 KiB
Python
115 lines
4.0 KiB
Python
from apps.solutions.models import Solution, TicketSolutionLink
|
|
from apps.tickets.models import Ticket
|
|
|
|
|
|
def test_create_and_list_solution(admin_client, db):
|
|
response = admin_client.post(
|
|
"/api/solutions",
|
|
data={
|
|
"title": "Restart callback worker",
|
|
"problem_signature": "HTTP 500 from callback",
|
|
"root_cause": "Worker connection pool stale",
|
|
"solution": "Restart callback worker and verify queue depth.",
|
|
"status": "published",
|
|
},
|
|
content_type="application/json",
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
solution_id = response.json()["id"]
|
|
|
|
response = admin_client.get("/api/solutions")
|
|
assert response.status_code == 200
|
|
assert response.json()[0]["id"] == solution_id
|
|
|
|
|
|
def test_link_solution_to_ticket_increments_usage(admin_client, db):
|
|
ticket = Ticket.objects.create(ticket_no="TK202606300020", title="A", description="A")
|
|
solution = admin_client.post(
|
|
"/api/solutions",
|
|
data={"title": "S", "problem_signature": "P", "root_cause": "R", "solution": "Do S"},
|
|
content_type="application/json",
|
|
).json()
|
|
|
|
response = admin_client.post(
|
|
f"/api/solutions/{solution['id']}/link-ticket",
|
|
data={"ticket_id": ticket.id, "link_type": "adopted"},
|
|
content_type="application/json",
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
assert response.json()["link_type"] == "adopted"
|
|
assert response.json()["solution_usage_count"] == 1
|
|
|
|
|
|
def test_list_ticket_solutions_returns_linked_solution_details(admin_client, db):
|
|
ticket = Ticket.objects.create(ticket_no="TK202607020001", title="A", description="A")
|
|
solution = admin_client.post(
|
|
"/api/solutions",
|
|
data={
|
|
"title": "Restart callback worker",
|
|
"problem_signature": "Callback timeout",
|
|
"root_cause": "Worker queue blocked",
|
|
"solution": "Restart worker and verify queue depth.",
|
|
"status": "published",
|
|
},
|
|
content_type="application/json",
|
|
).json()
|
|
admin_client.post(
|
|
f"/api/solutions/{solution['id']}/link-ticket",
|
|
data={"ticket_id": ticket.id, "link_type": "adopted"},
|
|
content_type="application/json",
|
|
)
|
|
|
|
response = admin_client.get(f"/api/solutions/tickets/{ticket.id}")
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload[0]["link_type"] == "adopted"
|
|
assert payload[0]["solution"]["title"] == "Restart callback worker"
|
|
|
|
|
|
def test_adopt_solution_closes_ticket_and_records_resolution(admin_client, db):
|
|
ticket = Ticket.objects.create(
|
|
ticket_no="TK202607030300",
|
|
title="查询采集进度",
|
|
description="客户需要确认采集进度",
|
|
status="pending",
|
|
)
|
|
solution = Solution.objects.create(
|
|
title="查询采集进度处理方案",
|
|
problem_signature="采集进度查询",
|
|
root_cause="税局采集链路不稳定",
|
|
solution="查询 Python 日志,确认税局不稳定,仍在采集中。",
|
|
status="published",
|
|
)
|
|
|
|
response = admin_client.post(
|
|
f"/api/solutions/{solution.id}/adopt-ticket",
|
|
data={
|
|
"ticket_id": ticket.id,
|
|
"replied_to_customer": True,
|
|
"remark": "采纳方案并回复客户",
|
|
},
|
|
content_type="application/json",
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload["link_type"] == "adopted"
|
|
assert payload["solution_usage_count"] == 1
|
|
|
|
ticket.refresh_from_db()
|
|
assert ticket.status == "closed"
|
|
assert ticket.resolution_summary == solution.solution
|
|
assert ticket.is_resolved is True
|
|
assert ticket.replied_to_customer is True
|
|
assert ticket.resolved_at is not None
|
|
assert ticket.closed_at is not None
|
|
assert TicketSolutionLink.objects.filter(
|
|
ticket=ticket,
|
|
solution=solution,
|
|
link_type="adopted",
|
|
).exists()
|
|
assert ticket.events.filter(event_type="solution_adopted").exists()
|