def test_generate_custom_fields(self):
        """The data dictionary should be serialized in the predictable way.
        Allow all fields to be optional"""
        data = donor_custom_fields()

        self.assertEqual(
            payxml.generate_custom_fields(data), {
                'custom_field_1': '(1112223333)([email protected])',
                'custom_field_2': '(stttt)',
                'custom_field_3': '(ccc)(ST)(90210)',
                'custom_field_4': '(Bob Jones)',
                'custom_field_5': '(Bob)(Patty)([email protected])',
                'custom_field_6': '(Memory)(no)(Good Jorb)',
                'custom_field_7': '(111 Somewhere)'
            })
        self.assertEqual(
            payxml.generate_custom_fields({}), {
                'custom_field_1': '()()',
                'custom_field_2': '()',
                'custom_field_3': '()()()',
                'custom_field_4': '()',
                'custom_field_5': '()()()',
                'custom_field_6': '(Honor)(yes)()',
                'custom_field_7': '()'
            })
 def test_generate_custom_fields_optional(self):
     """Allow all fields to be optional"""
     self.assertEqual(payxml.generate_custom_fields({}), {
         'custom_field_1': '()()',
         'custom_field_2': '()',
         'custom_field_3': '()()()',
         'custom_field_4': '()',
         'custom_field_5': '()()()',
         'custom_field_6': '(Honor)(yes)()',
         'custom_field_7': '()'
     })
 def test_generate_custom_fields_escape_chars(self):
     """Handle escaped chars in dedication"""
     data = {'card_dedication': "Here\nis\rAn\aalert"}
     self.assertEqual(payxml.generate_custom_fields(data), {
         'custom_field_1': '()()',
         'custom_field_2': '()',
         'custom_field_3': '()()()',
         'custom_field_4': '()',
         'custom_field_5': '()()()',
         'custom_field_6': '(Honor)(yes)(Here is An alert)',
         'custom_field_7': '()'
     })
 def test_generate_custom_fields(self):
     """The data dictionary should be serialized in the predictable way."""
     data = donor_custom_fields()
     self.assertEqual(payxml.generate_custom_fields(data), {
         'custom_field_1': '(1112223333)([email protected])',
         'custom_field_2': '(stttt)',
         'custom_field_3': '(ccc)(ST)(90210)',
         'custom_field_4': '(Bob Jones)',
         'custom_field_5': '(Bob)(Patty)([email protected])',
         'custom_field_6': '(Memory)(no)(Good Jorb)',
         'custom_field_7': '(111 Somewhere)'
     })
 def test_generate_custom_fields_optional(self):
     """Allow all fields to be optional"""
     self.assertEqual(payxml.generate_custom_fields({}), {
         'custom_field_1': '()()',
         'custom_field_2': '()',
         'custom_field_3': '()()()',
         'custom_field_4': '()',
         'custom_field_5': '()()()',
         'custom_field_6': '(Honor)(yes)()',
         'custom_field_7': '()',
         'custom_field_8': 'Thank you for your gift to the Peace Corps. Your tax-deductible donation provides crucial support as we build peace and friendship in the world. We\'ll stay in touch but you can also contact us at (202)692-2170 or [email protected]. Thank you again.'
     })
 def test_generate_custom_fields_escape_chars(self):
     """Handle escaped chars in dedication"""
     data = {'card_dedication': "Here\nis\rAn\aalert"}
     self.assertEqual(payxml.generate_custom_fields(data), {
         'custom_field_1': '()()',
         'custom_field_2': '()',
         'custom_field_3': '()()()',
         'custom_field_4': '()',
         'custom_field_5': '()()()',
         'custom_field_6': '(Honor)(yes)(Here is An alert)',
         'custom_field_7': '()',
         'custom_field_8': 'Thank you for your gift to the Peace Corps. Your tax-deductible donation provides crucial support as we build peace and friendship in the world. We\'ll stay in touch but you can also contact us at (202)692-2170 or [email protected]. Thank you again.'
     })
 def test_generate_custom_fields(self):
     """The data dictionary should be serialized in the predictable way."""
     data = donor_custom_fields()
     self.assertEqual(payxml.generate_custom_fields(data), {
         'custom_field_1': '(1112223333)([email protected])',
         'custom_field_2': '(stttt)',
         'custom_field_3': '(ccc)(ST)(90210)',
         'custom_field_4': '(Bob Jones)',
         'custom_field_5': '(Bob)(Patty)([email protected])',
         'custom_field_6': '(Memory)(no)(Good Jorb)',
         'custom_field_7': '(111 Somewhere)',
         'custom_field_8': 'Thank you for your gift to the Peace Corps. Your tax-deductible donation provides crucial support as we build peace and friendship in the world. We\'ll stay in touch but you can also contact us at (202)692-2170 or [email protected]. Thank you again.'
     })
 def test_generate_custom_fields_optional(self):
     """Allow all fields to be optional"""
     self.assertEqual(
         payxml.generate_custom_fields({}), {
             'custom_field_1':
             '()()',
             'custom_field_2':
             '()',
             'custom_field_3':
             '()()()',
             'custom_field_4':
             '()',
             'custom_field_5':
             '()()()',
             'custom_field_6':
             '(Honor)(yes)()',
             'custom_field_7':
             '()',
             'custom_field_8':
             'Thank you for your gift to the Peace Corps. Your tax-deductible donation provides crucial support as we build peace and friendship in the world. We\'ll stay in touch but you can also contact us at (202)692-2170 or [email protected]. Thank you again.'
         })
 def test_generate_custom_fields_escape_chars(self):
     """Handle escaped chars in dedication"""
     data = {'card_dedication': "Here\nis\rAn\aalert"}
     self.assertEqual(
         payxml.generate_custom_fields(data), {
             'custom_field_1':
             '()()',
             'custom_field_2':
             '()',
             'custom_field_3':
             '()()()',
             'custom_field_4':
             '()',
             'custom_field_5':
             '()()()',
             'custom_field_6':
             '(Honor)(yes)(Here is An alert)',
             'custom_field_7':
             '()',
             'custom_field_8':
             'Thank you for your gift to the Peace Corps. Your tax-deductible donation provides crucial support as we build peace and friendship in the world. We\'ll stay in touch but you can also contact us at (202)692-2170 or [email protected]. Thank you again.'
         })
Exemple #10
0
 def test_generate_custom_fields(self):
     """The data dictionary should be serialized in the predictable way."""
     data = donor_custom_fields()
     self.assertEqual(
         payxml.generate_custom_fields(data), {
             'custom_field_1':
             '(1112223333)([email protected])',
             'custom_field_2':
             '(stttt)',
             'custom_field_3':
             '(ccc)(ST)(90210)',
             'custom_field_4':
             '(Bob Jones)',
             'custom_field_5':
             '(Bob)(Patty)([email protected])',
             'custom_field_6':
             '(Memory)(no)(Good Jorb)',
             'custom_field_7':
             '(111 Somewhere)',
             'custom_field_8':
             'Thank you for your gift to the Peace Corps. Your tax-deductible donation provides crucial support as we build peace and friendship in the world. We\'ll stay in touch but you can also contact us at (202)692-2170 or [email protected]. Thank you again.'
         })
    def test_xml(self):
        data = {
            'agency_tracking_id': 'PCIOCI1234',
            'agency_memo': '()(5555555)',
            'form_id': 'DONORFORM',
            'payment_amount': 2000,
            'payment_type': 'CreditCard',
            'payer_name': 'William Williams',
            'billing_address': '1 Main St',
            'billing_city': 'Anytown',
            'billing_state': 'MD',
            'billing_zip': '20852',
            'success_url': 'https://success.com',
            'failure_url': 'https://failure.com'
        }

        data.update(payxml.generate_custom_fields(donor_custom_fields()))

        collection_request = payxml.generate_collection_request(data)
        self.assertEqual('collection_request', collection_request.tag)
        protocol_versions = collection_request.findall('./protocol_version')
        self.assertEqual(len(protocol_versions), 1)

        response_message = collection_request.findall('.//response_message')[0]
        self.assertEqual(response_message.attrib['value'], 'Success')

        action = collection_request.findall('.//action')[0]
        self.assertEqual(action.attrib['value'], 'SubmitCollectionInteractive')

        success_el = collection_request.findall(
            './interactive_request/success_return_url')[0]
        self.assertEqual(success_el.attrib['value'], 'https://success.com')
        failure_el = collection_request.findall(
            './interactive_request/failure_return_url')[0]
        self.assertEqual(failure_el.attrib['value'], 'https://failure.com')

        account_data = collection_request.findall(
            './interactive_request/collection_auth/account_data')[0]
        account_xml = '<account_data><payment_type value="CreditCard" />'
        account_xml += '<payer_name value="William Williams" />'
        account_xml += '<billing_address value="1 Main St" />'
        account_xml += '<billing_city value="Anytown" />'
        account_xml += '<billing_state value="MD" />'
        account_xml += '<billing_zip value="20852" /></account_data>'

        self.assertEqual(account_xml, tostring(account_data).decode('utf-8'))

        payment_amount = collection_request.findall(
            './interactive_request/collection_auth/payment_amount')[0]
        self.assertEqual(payment_amount.attrib['value'], '20.00')

        optional_fields = collection_request.findall(
            './interactive_request/collection_auth/OptionalFieldsGroup')[0]

        optg = '<OptionalFieldsGroup>'
        optg += '<custom_field_1 value="(1112223333)([email protected])" />'
        optg += '<custom_field_2 value="(stttt)" />'
        optg += '<custom_field_3 value="(ccc)(ST)(90210)" />'
        optg += '<custom_field_4 value="(Bob Jones)" />'
        optg += '<custom_field_5 value="(Bob)(Patty)([email protected])" />'
        optg += '<custom_field_6 value="(Memory)(no)(Good Jorb)" />'
        optg += '<custom_field_7 value="(111 Somewhere)" />'
        optg += '</OptionalFieldsGroup>'

        self.assertEqual(optg, tostring(optional_fields).decode('utf-8'))