def test_produces_sla_of_successful_conversation():
    conversation = build_mock_gp2gp_conversation(
        request_completed_time=a_datetime(year=2020,
                                          month=6,
                                          day=1,
                                          hour=12,
                                          minute=42,
                                          second=0),
        final_acknowledgement_time=a_datetime(year=2020,
                                              month=6,
                                              day=1,
                                              hour=13,
                                              minute=52,
                                              second=0),
    )
    mock_lookup = Mock()

    transfer_service = TransferService(
        message_stream=[],
        cutoff=timedelta(days=14),
        observability_probe=mock_transfer_observability_probe,
    )

    actual = transfer_service.derive_transfer(conversation, mock_lookup)

    expected_sla_duration = timedelta(hours=1, minutes=10)

    assert actual.sla_duration == expected_sla_duration
Beispiel #2
0
def test_returns_unclassified_given_unacknowledged_ehr_with_duplicate_and_copc_fragments(
):
    conversation = build_mock_gp2gp_conversation()

    conversation.is_integrated.return_value = False
    conversation.has_concluded_with_failure.return_value = False
    conversation.contains_unacknowledged_duplicate_ehr_and_copc_fragments.return_value = True

    actual = TransferOutcome.from_gp2gp_conversation(conversation, None)

    assert actual.status == TransferStatus.UNCLASSIFIED_FAILURE
    assert actual.failure_reason == TransferFailureReason.AMBIGUOUS_COPCS
def test_extracts_conversation_id():
    conversation = build_mock_gp2gp_conversation(conversation_id="1234")
    mock_lookup = Mock()

    transfer_service = TransferService(
        message_stream=[],
        cutoff=timedelta(days=14),
        observability_probe=mock_transfer_observability_probe,
    )

    actual = transfer_service.derive_transfer(conversation, mock_lookup)
    expected_conversation_id = "1234"

    assert actual.conversation_id == expected_conversation_id
Beispiel #4
0
def test_returns_transferred_not_integrated_with_error_given_stalled_with_copc_error(
):
    conversation = build_mock_gp2gp_conversation()

    conversation.is_integrated.return_value = False
    conversation.has_concluded_with_failure.return_value = False
    conversation.contains_copc_fragments.return_value = True
    conversation.contains_unacknowledged_duplicate_ehr_and_copc_fragments.return_value = False
    conversation.contains_copc_error.return_value = True
    conversation.is_missing_copc_ack.return_value = False

    actual = TransferOutcome.from_gp2gp_conversation(conversation, None)

    assert actual.status == TransferStatus.UNCLASSIFIED_FAILURE
    assert actual.failure_reason == TransferFailureReason.TRANSFERRED_NOT_INTEGRATED_WITH_ERROR
def test_produces_sending_ods_code_using_organisation_lookup():
    conversation = build_mock_gp2gp_conversation(sending_practice_asid="100")
    mock_lookup = Mock()
    mock_lookup.practice_ods_code_from_asid.return_value = "AB123"

    transfer_service = TransferService(
        message_stream=[],
        cutoff=timedelta(days=14),
        observability_probe=mock_transfer_observability_probe,
    )

    actual = transfer_service.derive_transfer(conversation, mock_lookup)
    expected_sending_ods_code = "AB123"

    assert actual.sending_practice.ods_code == expected_sending_ods_code
    mock_lookup.practice_ods_code_from_asid.assert_any_call("100")
def test_logs_negative_sla_warning():
    conversation_id = a_string()
    mock_probe = Mock()
    conversation = build_mock_gp2gp_conversation(
        conversation_id=conversation_id,
        final_acknowledgement_time=a_datetime(year=2021, month=12, day=1),
        request_completed_time=a_datetime(year=2021, month=12, day=2),
    )
    mock_lookup = Mock()

    transfer_service = TransferService(message_stream=[],
                                       cutoff=timedelta(days=14),
                                       observability_probe=mock_probe)

    transfer_service.derive_transfer(conversation, mock_lookup)

    mock_probe.record_negative_sla.assert_called_once_with(conversation)
def test_produces_no_sla_given_no_request_completed_time():
    conversation = build_mock_gp2gp_conversation(
        request_completed_time=None,
        final_acknowledgement_time=None,
    )
    mock_lookup = Mock()

    transfer_service = TransferService(
        message_stream=[],
        cutoff=timedelta(days=14),
        observability_probe=mock_transfer_observability_probe,
    )

    actual = transfer_service.derive_transfer(conversation, mock_lookup)

    expected_sla_duration = None

    assert actual.sla_duration == expected_sla_duration
def test_negative_sla_duration_clamped_to_zero():
    conversation = build_mock_gp2gp_conversation(
        request_completed_time=a_datetime(year=2021, month=1, day=5),
        final_acknowledgement_time=a_datetime(year=2021, month=1, day=4),
    )

    expected_sla_duration = timedelta(0)
    mock_lookup = Mock()

    transfer_service = TransferService(
        message_stream=[],
        cutoff=timedelta(days=14),
        observability_probe=mock_transfer_observability_probe,
    )

    actual = transfer_service.derive_transfer(conversation, mock_lookup)

    assert actual.sla_duration == expected_sla_duration
def test_produces_no_ods_code_using_organisation_lookup_when_no_ods_mapping_exists(
):
    conversation = build_mock_gp2gp_conversation()
    mock_lookup = Mock()
    mock_lookup.practice_ods_code_from_asid.return_value = None

    transfer_service = TransferService(
        message_stream=[],
        cutoff=timedelta(days=14),
        observability_probe=mock_transfer_observability_probe,
    )

    actual = transfer_service.derive_transfer(conversation, mock_lookup)
    expected_requesting_ods_code = None
    expected_sending_ods_code = None

    assert actual.requesting_practice.ods_code == expected_requesting_ods_code
    assert actual.sending_practice.ods_code == expected_sending_ods_code
def test_probe_should_log_warning_given_negative_sla():
    conversation_id = a_string()
    final_acknowledgement_time = a_datetime(year=2021, month=11)
    request_completed_time = a_datetime(year=2021, month=12)
    conversation = build_mock_gp2gp_conversation(
        conversation_id=conversation_id,
        final_acknowledgement_time=final_acknowledgement_time,
        request_completed_time=request_completed_time,
    )
    mock_logger = Mock()

    probe = TransferObservabilityProbe(logger=mock_logger)
    probe.record_negative_sla(conversation)

    mock_logger.warning.assert_called_once_with(
        f":Negative SLA duration for conversation: {conversation_id}",
        extra={
            "event": "NEGATIVE_SLA_DETECTED",
            "conversation_id": conversation_id,
            "final_acknowledgement_time": final_acknowledgement_time,
            "request_completed_time": request_completed_time,
        },
    )