更新
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Any
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QDate, Signal
|
||||
from PySide6.QtCore import QDate, QEvent, Signal
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QDialog,
|
||||
@@ -19,7 +19,7 @@ from PySide6.QtWidgets import (
|
||||
QWidget,
|
||||
)
|
||||
|
||||
from doctor_workstation.core import PermissionSet
|
||||
from doctor_workstation.core import PermissionSet, UserProfile
|
||||
from doctor_workstation.ui.dialogs import diagnosis as diagnosis_module
|
||||
from doctor_workstation.ui.pages import consultations as consultations_module
|
||||
from doctor_workstation.ui.pages.consultations import (
|
||||
@@ -669,7 +669,7 @@ def test_switching_rows_invalidates_prescription_worker_and_clears_busy(
|
||||
application.processEvents()
|
||||
|
||||
|
||||
def test_native_call_does_not_reuse_video_qr_permission(
|
||||
def test_list_video_entry_uses_watch_permission_not_video_qr_permission(
|
||||
application: QApplication,
|
||||
) -> None:
|
||||
class VideoRepository:
|
||||
@@ -686,13 +686,17 @@ def test_native_call_does_not_reuse_video_qr_permission(
|
||||
pass
|
||||
|
||||
live_row = _row(
|
||||
assistant_id=66,
|
||||
video_call_hint={
|
||||
"state": "live",
|
||||
"label": "视频通话进行中",
|
||||
"start_time": 1787102100,
|
||||
}
|
||||
)
|
||||
page = ConsultationsPage(VideoRepository(), permissions=PermissionSet([]))
|
||||
page = ConsultationsPage(
|
||||
VideoRepository(), permissions=PermissionSet(["tcm.diagnosis/watchCall"]),
|
||||
current_user={"id": 66, "role_id": 2},
|
||||
)
|
||||
emitted: list[dict[str, Any]] = []
|
||||
page.video_requested.connect(emitted.append)
|
||||
page.table.set_rows([live_row])
|
||||
@@ -738,10 +742,13 @@ def test_video_join_action_is_hidden_until_doctor_session_is_live(
|
||||
def end_call(self, diagnosis_id: int) -> None:
|
||||
pass
|
||||
|
||||
page = ConsultationsPage(VideoRepository(), permissions=PermissionSet([]))
|
||||
page = ConsultationsPage(
|
||||
VideoRepository(), permissions=PermissionSet(["tcm.diagnosis/watchCall"]),
|
||||
current_user={"id": 66, "role_id": 2},
|
||||
)
|
||||
emitted: list[dict[str, Any]] = []
|
||||
page.video_requested.connect(emitted.append)
|
||||
page.table.set_rows([_row(video_call_hint=hint)])
|
||||
page.table.set_rows([_row(assistant_id=66, video_call_hint=hint)])
|
||||
page.table.selectRow(0)
|
||||
application.processEvents()
|
||||
|
||||
@@ -752,6 +759,92 @@ def test_video_join_action_is_hidden_until_doctor_session_is_live(
|
||||
assert emitted == []
|
||||
page.close()
|
||||
application.processEvents()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("user", [
|
||||
{"id": 66, "role_id": 1},
|
||||
{"id": 66, "role_id": "1"},
|
||||
{"id": 66, "role_ids": [1, 2]},
|
||||
{"id": 66, "role_id": "1,2"},
|
||||
{"id": 66, "roles": [{"id": 1}]},
|
||||
{"id": 66, "role_id": 1, "root": True},
|
||||
UserProfile.from_dict({"id": 66, "role_id": [1, 2]}),
|
||||
])
|
||||
@pytest.mark.parametrize("state,status", [
|
||||
("live", "通话中"), ("pending_room", "接通中"), ("none", "—"),
|
||||
])
|
||||
def test_doctor_video_column_is_readonly_even_with_full_permission(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
user: Any,
|
||||
state: str,
|
||||
status: str,
|
||||
) -> None:
|
||||
from doctor_workstation.services import DemoDoctorRepository
|
||||
|
||||
monkeypatch.setattr(consultations_module, "run_async", lambda *_a, **_kw: None)
|
||||
# Even a mixed-role doctor assigned to this row must not get the receiver entry.
|
||||
row = _row(assistant_id=66, video_call_hint={"state": state})
|
||||
page = ConsultationsPage(DemoDoctorRepository(), PermissionSet(["*"]), current_user=user)
|
||||
emitted = []
|
||||
page.video_requested.connect(emitted.append)
|
||||
try:
|
||||
page.table_host.set_rows([row])
|
||||
page.table.selectRow(0)
|
||||
page._selection_changed()
|
||||
cell = page.table_host.fixed.indexWidget(page.table_host.model.index(0, 10))
|
||||
assert cell.findChildren(QToolButton) == []
|
||||
assert status in [label.text() for label in cell.findChildren(QLabel)]
|
||||
assert page.call_toolbar_button.isHidden()
|
||||
assert not page.video_button.isEnabled()
|
||||
page._row_video(row)
|
||||
page.video_button.setEnabled(True)
|
||||
page.video_button.click()
|
||||
assert emitted == []
|
||||
finally:
|
||||
page.close()
|
||||
page.deleteLater()
|
||||
application.sendPostedEvents(None, QEvent.Type.DeferredDelete)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("user,permissions,assistant_id,allowed", [
|
||||
({"id": 66, "role_id": 2}, ["tcm.diagnosis/watchCall"], 66, True),
|
||||
({"id": 66, "role_id": 2}, ["tcm.diagnosis/videoQr"], 66, False),
|
||||
({"id": 66, "role_id": 2}, [], 66, False),
|
||||
({"id": 66, "role_id": 2}, ["*"], 77, False),
|
||||
({"id": 66, "role_id": 0, "root": True}, ["*"], 77, False),
|
||||
({"id": 66, "role_id": 0, "root": True}, ["*"], 66, True),
|
||||
({"id": 0, "role_id": 2}, ["*"], 0, False),
|
||||
(None, ["*"], 66, False),
|
||||
])
|
||||
def test_list_video_entry_requires_the_assigned_user_and_watch_permission(
|
||||
application: QApplication,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
user: Any,
|
||||
permissions: list[str],
|
||||
assistant_id: int,
|
||||
allowed: bool,
|
||||
) -> None:
|
||||
from doctor_workstation.services import DemoDoctorRepository
|
||||
|
||||
monkeypatch.setattr(consultations_module, "run_async", lambda *_a, **_kw: None)
|
||||
row = _row(assistant_id=assistant_id, video_call_hint={"state": "live"})
|
||||
page = ConsultationsPage(DemoDoctorRepository(), PermissionSet(permissions), current_user=user)
|
||||
emitted = []
|
||||
page.video_requested.connect(emitted.append)
|
||||
try:
|
||||
page.table_host.set_rows([row])
|
||||
page.table.selectRow(0)
|
||||
page._selection_changed()
|
||||
cell = page.table_host.fixed.indexWidget(page.table_host.model.index(0, 10))
|
||||
assert bool(cell.findChildren(QToolButton)) is allowed
|
||||
assert page.video_button.isEnabled() is allowed
|
||||
page._request_video()
|
||||
assert bool(emitted) is allowed
|
||||
finally:
|
||||
page.close()
|
||||
page.deleteLater()
|
||||
application.sendPostedEvents(None, QEvent.Type.DeferredDelete)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user