Beispiel #1
0
    def test_from_xml(self):
        from r2.lib.authorize.api import SimpleXMLObject
        from BeautifulSoup import BeautifulStoneSoup

        class TestXML(SimpleXMLObject):
            _keys = ["color", "breed"]

        parsed = BeautifulStoneSoup(
            "<dog>" + "<color>black</color>" + "<breed>mixed</breed>" + "<something>else</something>" + "</dog>"
        )
        constructed = TestXML.fromXML(parsed)
        expected = SimpleXMLObject(color="black", breed="mixed")
        self.assertEqual(constructed.toXML(), expected.toXML(), "Constructed does not match expected")
Beispiel #2
0
 def test_simple_tag(self):
     from r2.lib.authorize.api import SimpleXMLObject
     xml_output = SimpleXMLObject.simple_tag("cat", "Jini", breed="calico",
                                                            demenor="evil",
                                                            )
     self.assertEqual(xml_output,
                      '<cat breed="calico" demenor="evil">Jini</cat>')
Beispiel #3
0
 def test_simple_tag(self):
     from r2.lib.authorize.api import SimpleXMLObject
     xml_output = SimpleXMLObject.simple_tag("cat", "Jini", breed="calico",
                                                            demenor="evil",
                                                            )
     self.assertEqual(xml_output,
                      '<cat breed="calico" demenor="evil">Jini</cat>')
Beispiel #4
0
    def test_from_xml(self):
        from r2.lib.authorize.api import SimpleXMLObject
        from BeautifulSoup import BeautifulStoneSoup

        class TestXML(SimpleXMLObject):
            _keys = ["color", "breed"]

        parsed = BeautifulStoneSoup("<dog>" + "<color>black</color>" +
                                    "<breed>mixed</breed>" +
                                    "<something>else</something>" + "</dog>")
        constructed = TestXML.fromXML(parsed)
        expected = SimpleXMLObject(
            color="black",
            breed="mixed",
        )
        self.assertEqual(constructed.toXML(), expected.toXML(),
                         "Constructed does not match expected")
Beispiel #5
0
 def setUp(self):
     from r2.lib.authorize.api import SimpleXMLObject
     self.basic_object = SimpleXMLObject(name="Test",
                                        test="123",
                                        )
Beispiel #6
0
class SimpleXMLObjectTest(RedditTestCase):

    def setUp(self):
        from r2.lib.authorize.api import SimpleXMLObject
        self.basic_object = SimpleXMLObject(name="Test",
                                           test="123",
                                           )

    def test_to_xml(self):
        self.assertEqual(self.basic_object.toXML(),
                         "<test>123</test><name>Test</name>",
                         "Unexpected XML produced")

    def test_simple_tag(self):
        from r2.lib.authorize.api import SimpleXMLObject
        xml_output = SimpleXMLObject.simple_tag("cat", "Jini", breed="calico",
                                                               demenor="evil",
                                                               )
        self.assertEqual(xml_output,
                         '<cat breed="calico" demenor="evil">Jini</cat>')

    def test_from_xml(self):
        from r2.lib.authorize.api import SimpleXMLObject
        from BeautifulSoup import BeautifulStoneSoup
        class TestXML(SimpleXMLObject):
            _keys = ["color", "breed"]

        parsed = BeautifulStoneSoup("<dog>" +
                                    "<color>black</color>" +
                                    "<breed>mixed</breed>" +
                                    "<something>else</something>" +
                                    "</dog>")
        constructed = TestXML.fromXML(parsed)
        expected = SimpleXMLObject(color="black",
                                   breed="mixed",
                                   )
        self.assertEqual(constructed.toXML(), expected.toXML(), 
                         "Constructed does not match expected")

    def test_address(self):
        from r2.lib.authorize import Address
        address = Address(firstName="Bob",
                          lastName="Smith",
                          company="Reddit Inc.",
                          address="123 Main St.",
                          city="San Francisco",
                          state="California",
                          zip="12345",
                          country="USA",
                          phoneNumber="415-555-1234",
                          faxNumber="415-555-4321",
                          customerPaymentProfileId="1234567890",
                          customerAddressId="2233",
                          )
        expected = ("<firstName>Bob</firstName>" +
                   "<lastName>Smith</lastName>" +
                   "<company>Reddit Inc.</company>" +
                   "<address>123 Main St.</address>" +
                   "<city>San Francisco</city>" +
                   "<state>California</state>" +
                   "<zip>12345</zip>" +
                   "<country>USA</country>" +
                   "<phoneNumber>415-555-1234</phoneNumber>" +
                   "<faxNumber>415-555-4321</faxNumber>" +
                   "<customerPaymentProfileId>1234567890</customerPaymentProfileId>" +
                   "<customerAddressId>2233</customerAddressId>")

        self.assertEqual(address.toXML(), expected)

    def test_credit_card(self):
        from r2.lib.authorize import CreditCard
        card = CreditCard(cardNumber="1111222233334444",
                          expirationDate="11/22/33",
                          cardCode="123"
                          )
        expected = ("<cardNumber>1111222233334444</cardNumber>" +
                    "<expirationDate>11/22/33</expirationDate>" +
                    "<cardCode>123</cardCode>")
        self.assertEqual(card.toXML(), expected)

    def test_payment_profile(self):
        from r2.lib.authorize.api import PaymentProfile
        profile = PaymentProfile(billTo="Joe",
                                 paymentId="222",
                                 card="1111222233334444",
                                 validationMode="42",
                                 )
        expected = ("<billTo>Joe</billTo>" +
                    "<payment>" +
                        "<creditCard>1111222233334444</creditCard>" +
                    "</payment>" +
                    "<customerPaymentProfileId>222</customerPaymentProfileId>" +
                    "<validationMode>42</validationMode>")
        self.assertEqual(profile.toXML(), expected)

    def test_transation(self):
        from r2.lib.authorize.api import Transaction
        transaction = Transaction(amount="42.42",
                                  profile_id="112233",
                                  pay_id="1111",
                                  trans_id="2222", 
                                  order="42",
                                  )
     
        expected = ("<transaction>" +
                        "<amount>42.42</amount>" +
                        "<customerProfileId>112233</customerProfileId>" +
                        "<customerPaymentProfileId>1111</customerPaymentProfileId>" +
                        "<transId>2222</transId>" +
                        "<order>42</order>" +
                    "</transaction>")
        self.assertEqual(transaction.toXML(), expected)
Beispiel #7
0
 def setUp(self):
     from r2.lib.authorize.api import SimpleXMLObject
     self.basic_object = SimpleXMLObject(
         name="Test",
         test="123",
     )
Beispiel #8
0
class SimpleXMLObjectTest(RedditTestCase):
    def setUp(self):
        from r2.lib.authorize.api import SimpleXMLObject
        self.basic_object = SimpleXMLObject(
            name="Test",
            test="123",
        )

    def test_to_xml(self):
        self.assertEqual(self.basic_object.toXML(),
                         "<test>123</test><name>Test</name>",
                         "Unexpected XML produced")

    def test_simple_tag(self):
        from r2.lib.authorize.api import SimpleXMLObject
        xml_output = SimpleXMLObject.simple_tag(
            "cat",
            "Jini",
            breed="calico",
            demenor="evil",
        )
        self.assertEqual(xml_output,
                         '<cat breed="calico" demenor="evil">Jini</cat>')

    def test_from_xml(self):
        from r2.lib.authorize.api import SimpleXMLObject
        from BeautifulSoup import BeautifulStoneSoup

        class TestXML(SimpleXMLObject):
            _keys = ["color", "breed"]

        parsed = BeautifulStoneSoup("<dog>" + "<color>black</color>" +
                                    "<breed>mixed</breed>" +
                                    "<something>else</something>" + "</dog>")
        constructed = TestXML.fromXML(parsed)
        expected = SimpleXMLObject(
            color="black",
            breed="mixed",
        )
        self.assertEqual(constructed.toXML(), expected.toXML(),
                         "Constructed does not match expected")

    def test_address(self):
        from r2.lib.authorize import Address
        address = Address(
            firstName="Bob",
            lastName="Smith",
            company="Reddit Inc.",
            address="123 Main St.",
            city="San Francisco",
            state="California",
            zip="12345",
            country="USA",
            phoneNumber="415-555-1234",
            faxNumber="415-555-4321",
            customerPaymentProfileId="1234567890",
            customerAddressId="2233",
        )
        expected = (
            "<firstName>Bob</firstName>" + "<lastName>Smith</lastName>" +
            "<company>Reddit Inc.</company>" +
            "<address>123 Main St.</address>" + "<city>San Francisco</city>" +
            "<state>California</state>" + "<zip>12345</zip>" +
            "<country>USA</country>" +
            "<phoneNumber>415-555-1234</phoneNumber>" +
            "<faxNumber>415-555-4321</faxNumber>" +
            "<customerPaymentProfileId>1234567890</customerPaymentProfileId>" +
            "<customerAddressId>2233</customerAddressId>")

        self.assertEqual(address.toXML(), expected)

    def test_credit_card(self):
        from r2.lib.authorize import CreditCard
        card = CreditCard(cardNumber="1111222233334444",
                          expirationDate="11/22/33",
                          cardCode="123")
        expected = ("<cardNumber>1111222233334444</cardNumber>" +
                    "<expirationDate>11/22/33</expirationDate>" +
                    "<cardCode>123</cardCode>")
        self.assertEqual(card.toXML(), expected)

    def test_payment_profile(self):
        from r2.lib.authorize.api import PaymentProfile
        profile = PaymentProfile(
            billTo="Joe",
            paymentId="222",
            card="1111222233334444",
            validationMode="42",
        )
        expected = (
            "<billTo>Joe</billTo>" + "<payment>" +
            "<creditCard>1111222233334444</creditCard>" + "</payment>" +
            "<customerPaymentProfileId>222</customerPaymentProfileId>" +
            "<validationMode>42</validationMode>")
        self.assertEqual(profile.toXML(), expected)

    def test_transation(self):
        from r2.lib.authorize.api import Transaction
        transaction = Transaction(
            amount="42.42",
            profile_id="112233",
            pay_id="1111",
            trans_id="2222",
            order="42",
        )

        expected = (
            "<transaction>" + "<amount>42.42</amount>" +
            "<customerProfileId>112233</customerProfileId>" +
            "<customerPaymentProfileId>1111</customerPaymentProfileId>" +
            "<transId>2222</transId>" + "<order>42</order>" + "</transaction>")
        self.assertEqual(transaction.toXML(), expected)