def test_get_errors_user(errorsdb_session, test_user): all_errors = messages.get_messages(errorsdb_session, test_user, statuses=["ERROR"], since=days_ago(730)) # Test user should see error messages from TEST_SENDING_FACILITY_1 assert {error.id for error in all_errors} == {1}
def test_get_errors_superuser(errorsdb_session, superuser): all_msgs = messages.get_messages(errorsdb_session, superuser, statuses=["ERROR"], since=days_ago(730)) # Superuser should see all error messages assert {error.id for error in all_msgs} == {1, 2}
def error_messages( facility: Optional[str] = None, since: Optional[datetime.datetime] = None, until: Optional[datetime.datetime] = None, status: Optional[list[str]] = QueryParam(None), ni: Optional[list[str]] = QueryParam([]), user: UKRDCUser = Security(auth.get_user()), errorsdb: Session = Depends(get_errorsdb), sorter: SQLASorter = Depends(ERROR_SORTER), audit: Auditer = Depends(get_auditer), ): """ Retreive a list of error messages, optionally filtered by NI, facility, or date. By default returns message created within the last 365 days. """ audit.add_event(Resource.MESSAGES, None, MessageOperation.READ) return paginate( sorter.sort( get_messages( errorsdb, user, statuses=status, nis=ni, facility=facility, since=since, until=until, )))
def test_get_errors_facility(errorsdb_session, superuser): all_errors = messages.get_messages( errorsdb_session, superuser, since=days_ago(730), facility="TEST_SENDING_FACILITY_2", ) assert {error.id for error in all_errors} == {2}
def test_get_errors_until(errorsdb_session, superuser): all_errors = messages.get_messages( errorsdb_session, superuser, since=days_ago(730), until=days_ago(2), ) assert {error.id for error in all_errors} == {2}
def workitem_messages( workitem_id: int, facility: Optional[str] = None, since: Optional[datetime.datetime] = None, until: Optional[datetime.datetime] = None, status: Optional[list[str]] = QueryParam(None), user: UKRDCUser = Security(auth.get_user()), jtrace: Session = Depends(get_jtrace), errorsdb: Session = Depends(get_errorsdb), audit: Auditer = Depends(get_auditer), ): """Retreive a list of other work items related to a particular work item""" workitem = get_extended_workitem(jtrace, workitem_id, user) workitem_nis: list[str] = [ record.nationalid for record in workitem.incoming.master_records ] if workitem.master_record: workitem_nis.append(workitem.master_record.nationalid) audit.add_event( Resource.MESSAGES, None, AuditOperation.READ, parent=audit.add_event(Resource.WORKITEM, workitem_id, AuditOperation.READ), ) return paginate( get_messages( errorsdb, user, statuses=status, nis=workitem_nis, facility=facility, since=since, until=until, ))
def test_get_messages_nis(errorsdb_session, superuser): all_msgs = messages.get_messages(errorsdb_session, superuser, since=days_ago(730), nis=["999999999"]) assert {error.id for error in all_msgs} == {1, 3}