保存今天的修改

This commit is contained in:
songxinnuo
2026-11-02 17:51:10 +08:00
parent 04f94ad665
commit eebaba8084
44 changed files with 2831 additions and 154 deletions
+17
View File
@@ -14,6 +14,7 @@ from unittest.mock import patch
import requests
from logistics_chat import create_app, db
from staff_fixture import login_staff
class ModelResponse:
@@ -45,6 +46,7 @@ class ApiTests(unittest.TestCase):
self.root = Path(self.directory.name)
self.app = self.application(self.root)
self.client = self.app.test_client()
login_staff(self.app, self.client)
self.client.post('/api/visitor/session', json={'key':'1'*64})
self.app.extensions['rate_hits'].clear()
from logistics_chat.order_data import import_records
@@ -313,6 +315,21 @@ class ApiTests(unittest.TestCase):
self.assertEqual(self.client.get('/api/human/active').json, [])
self.assertEqual(self.client.get(f'/api/human/poll?sid={sid}').json['status'], 'closed')
def test_human_queue_marks_items_over_five_minutes_using_server_clock(self):
from datetime import datetime, timezone, timedelta
with patch('logistics_chat.human_service.datetime') as clock:
clock.now.return_value = datetime(2026, 10, 29, 12, 0, tzinfo=timezone(timedelta(hours=8)))
sid = self.client.post('/api/human/request',json={'conv_id':self.conversation()}).json['session_id']
before = self.client.get('/api/human/queue').json[0]
self.assertEqual((before['waiting_minutes'],before['overdue']), (0,False))
clock.now.return_value = datetime(2026, 10, 29, 12, 5, tzinfo=timezone(timedelta(hours=8)))
boundary = self.client.get('/api/human/queue').json[0]
self.assertFalse(boundary['overdue'])
clock.now.return_value = datetime(2026, 10, 29, 12, 5, 1, tzinfo=timezone(timedelta(hours=8)))
after = self.client.get('/api/human/queue').json[0]
self.assertEqual(after['id'], sid)
self.assertEqual((after['waiting_minutes'],after['overdue'],after['overdue_minutes']), (5,True,1))
def test_application_state_is_not_shared_between_factories(self):
self.app.extensions['human_typing']['1'] = 123
self.app.extensions['rate_hits']['127.0.0.1'].append(123)