Example #1
0
    def fake_get_agreement(key, doc_type, match_tag=True):
        content = TestPartnerBase.agreement_json
        agreement = jsonserializer.deserialize(content,
                                               doc_type,
                                               match_tag)
        if key == "A01":
            agr_01 = copy.deepcopy(agreement)
            agr_01.id = "A01"
            agr_01.outbound_agreement.is_auth = False
            agr_01.outbound_agreement.is_proxy = False
            agr_01.profiler_enabled = False
            agr_01.outbound_agreement.customer_http_headers = None
            return agr_01
        if key == "A02":
            agr_02 = copy.deepcopy(agreement)
            agr_02.id = "A02"
            agr_02.outbound_agreement.authentication_scheme = "basic"
            return agr_02
        if key == "A03":
            agr_03 = copy.deepcopy(agreement)
            agr_03.id = "A03"
            agr_03.outbound_agreement.authentication_scheme = "digest"
            return agr_03

        return None
Example #2
0
    def fake_find_agreement(condition, doc_type, match_tag=True):
        agreement = None
        if condition['LocalIdentity'] == 'as2_01' \
                and condition['TradingIdentity'] == 'Newegg' \
                and condition['IsPrimary']:
            content = TestPartnerBase.agreement_json
            agr_01 = jsonserializer.deserialize(content,
                                                doc_type,
                                                match_tag)

            agreement = copy.deepcopy(agr_01)
            agreement.id = "A01"
            agreement.inbound_agreement.is_signed = False
            agreement.inbound_agreement.is_compressed = False
            agreement.inbound_agreement.is_encrypted = False

        if agreement is not None:
            result = CloudStoreQueryResult()
            result.page_size = 1
            result.page_index = 1
            result.total_count = 1
            result.succeeded = True
            result.records = [agreement]
            return result

        return agreement
Example #3
0
 def test_send_async_mdn_ok(self):
     headers = TestPartnerBase.mdn_headers
     body = TestPartnerBase.mdn_content
     pm = PartnerManager(headers, body)
     message = jsonserializer.deserialize(TestPartnerMdnMessage.message_json,
                                          AS2Message)
     pm.send_async_mdn(message)
Example #4
0
 def test_save_async_mdn_exception_when_msg_not_found(self):
     self.mock_cloud_data_find.side_effect = Exception('msg not found')
     headers = {'Content-Type': 'application/json', }
     body = None
     pm = PartnerManager(headers, body)
     message = jsonserializer.deserialize(TestPartnerMdnMessage.async_mdn_message_json,
                                          AsyncMdnReceive)
     pm.save_mdn_event_message(message)
Example #5
0
 def test_save_async_mdn_ok(self):
     headers = {'Content-Type': 'application/json', }
     body = None
     pm = PartnerManager(headers, body)
     message = jsonserializer.deserialize(TestPartnerMdnMessage.async_mdn_message_json,
                                          AsyncMdnReceive)
     msg = pm.save_mdn_event_message(message)
     assert_not_equal(None, msg)
     assert_not_equal(None, msg.message_mdn)
Example #6
0
    def fake_get_certificate(key, doc_type, match_tag=True):
        content = None
        if key == "PB01":
            content = TestPartnerBase.certificate_json_pb_01
        if key == "PR01":
            content = TestPartnerBase.certificate_json_pr_01

        return jsonserializer.deserialize(content,
                                          doc_type,
                                          match_tag)
Example #7
0
def get_request_entity(req_type):
    body = get_request_body()
    content_type = request.content_type
    match_tag = strtobool(request.query.get('match_tag', 'true'))

    try:
        if 'application/xml' == content_type:
            return xmlserializer.deserialize(body,
                                             entity_type=req_type,
                                             match_tag=match_tag)

        return jsonserializer.deserialize(body,
                                          entity_type=req_type,
                                          match_tag=match_tag)
    except:
        abort(400)
Example #8
0
    def retry(file_full_name):
        with open(file_full_name, 'r') as fp:
            content = fp.read()
            retry = jsonserializer.deserialize(content, MessageRetry)

        headers = None
        if retry.message_queue_headers is not None:
            headers = {}
            for item in retry.message_queue_headers:
                headers[item['name']] = item['value']

        rst = MessageQueueHelper().send_message_json(
            retry.message,
            retry.message_queue_name,
            retry.message_queue_password,
            additional_headers=headers,
            serialization_match_tag=retry.match_tag)

        if rst.succeeded:
            os.remove(file_full_name)
        else:
            logger.error('failed retry {0} , due to {1}'.format(
                file_full_name, rst.message))