Exemplo n.º 1
0
 def derive_transfer(
     self, conversation: Gp2gpConversation, organisation_lookup: OrganisationLookup
 ) -> Transfer:
     sla_duration = _calculate_sla(conversation, self._probe)
     requesting_practice_asid = conversation.requesting_practice_asid()
     sending_practice_asid = conversation.sending_practice_asid()
     return Transfer(
         conversation_id=conversation.conversation_id(),
         sla_duration=sla_duration,
         requesting_practice=Practice(
             asid=requesting_practice_asid,
             supplier=conversation.requesting_supplier(),
             ods_code=organisation_lookup.practice_ods_code_from_asid(requesting_practice_asid),
         ),
         sending_practice=Practice(
             asid=sending_practice_asid,
             supplier=conversation.sending_supplier(),
             ods_code=organisation_lookup.practice_ods_code_from_asid(sending_practice_asid),
         ),
         sender_error_codes=conversation.sender_error_codes(),
         final_error_codes=conversation.final_error_codes(),
         intermediate_error_codes=conversation.intermediate_error_codes(),
         outcome=TransferOutcome.from_gp2gp_conversation(conversation, sla_duration),
         date_requested=conversation.date_requested(),
         date_completed=conversation.effective_final_acknowledgement_time(),
         last_sender_message_timestamp=conversation.last_sender_message_timestamp(),
     )
Exemplo n.º 2
0
def test_returns_transfer_status_process_failure_with_reason(
        test_case, expected_reason):
    gp2gp_messages: List[Message] = test_case()
    conversation = Gp2gpConversation(
        gp2gp_messages, probe=mock_gp2gp_conversation_observability_probe)
    actual = TransferOutcome.from_gp2gp_conversation(conversation, None)

    assert actual.status == TransferStatus.PROCESS_FAILURE
    assert actual.failure_reason == expected_reason
Exemplo n.º 3
0
def test_returns_transfer_status_integrated_on_time(test_case):
    gp2gp_messages: List[Message] = test_case()
    conversation = Gp2gpConversation(
        gp2gp_messages, mock_gp2gp_conversation_observability_probe)

    actual = TransferOutcome.from_gp2gp_conversation(conversation,
                                                     timedelta(days=1))

    assert actual.status == TransferStatus.INTEGRATED_ON_TIME
    assert actual.failure_reason is None
Exemplo n.º 4
0
def test_returns_transfer_status_technical_failure_with_reason(
        test_case, expected_reason):
    gp2gp_messages: List[Message] = test_case()
    conversation = Gp2gpConversation(
        gp2gp_messages, mock_gp2gp_conversation_observability_probe)

    actual = TransferOutcome.from_gp2gp_conversation(conversation,
                                                     a_duration())

    assert actual.status == TransferStatus.TECHNICAL_FAILURE
    assert actual.failure_reason == expected_reason
Exemplo n.º 5
0
def test_returns_correct_transfer_outcome_if_fatal_sender_error_code_present(
    fatal_sender_error_code, ):
    gp2gp_messages: List[Message] = test_cases.request_acknowledged_with_error(
        error_code=fatal_sender_error_code)
    conversation = Gp2gpConversation(
        gp2gp_messages, mock_gp2gp_conversation_observability_probe)

    actual = TransferOutcome.from_gp2gp_conversation(conversation,
                                                     a_duration())

    assert actual.status == TransferStatus.TECHNICAL_FAILURE
    assert actual.failure_reason == TransferFailureReason.FATAL_SENDER_ERROR
Exemplo n.º 6
0
def test_return_process_failure_given_an_unacknowledged_ehr_with_duplicate_and_no_copc_fragments(
):
    gp2gp_messages: List[
        Message] = test_cases.acknowledged_duplicate_and_waiting_for_integration(
        )
    conversation = Gp2gpConversation(
        gp2gp_messages, mock_gp2gp_conversation_observability_probe)

    actual = TransferOutcome.from_gp2gp_conversation(conversation, None)

    assert actual.status == TransferStatus.PROCESS_FAILURE
    assert actual.failure_reason == TransferFailureReason.TRANSFERRED_NOT_INTEGRATED
Exemplo n.º 7
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
Exemplo n.º 8
0
def test_returns_correct_transfer_outcome_given_multiple_conflicting_sender_acks(
):
    a_fatal_sender_error = choice(FATAL_SENDER_ERROR_CODES)

    gp2gp_messages: List[
        Message] = test_cases.multiple_sender_acknowledgements(
            error_codes=[None, a_fatal_sender_error])
    conversation = Gp2gpConversation(
        gp2gp_messages, mock_gp2gp_conversation_observability_probe)

    actual = TransferOutcome.from_gp2gp_conversation(conversation,
                                                     a_duration())

    assert actual.status == TransferStatus.TECHNICAL_FAILURE
    assert actual.failure_reason == TransferFailureReason.FATAL_SENDER_ERROR
Exemplo n.º 9
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