Пример #1
0
class TestAddGateway(unittest.TestCase):
    def setUp(self):
        self.environment = Environment("key", "secret")

    @patch('spreedly.environment.ssl_requester.raw_ssl_request')
    def test_successful_add_gateway(self, test_patch):
        request_mock = test_patch.return_value
        request_mock.status_code = 200
        request_mock.text = successful_add_test_gateway_response

        gateway = self.environment.add_gateway('test')

        self.assertEqual("4dFb93AiRDEJ18MS9xDGMyu22uO", gateway.token)
        self.assertEqual("test", gateway.gateway_type)
        self.assertEqual("retained", gateway.state)
        self.assertEqual("Test", gateway.name)
        self.assertEqual({'login': '******'}, gateway.credentials)

    def test_request_body_params(self):
        body = self.environment.add_gateway_body(
            'wirecard', {
                'username': '******',
                'password': '******',
                'business_case_signature': 'TheSig'
            })

        gateway = body.xpath('/gateway')[0]
        self.assertEqual(gateway.xpath('./gateway_type')[0].text, 'wirecard')
        self.assertEqual(gateway.xpath('./username')[0].text, 'TheUsername')
        self.assertEqual(gateway.xpath('./password')[0].text, 'ThePassword')
        self.assertEqual(
            gateway.xpath('./business_case_signature')[0].text, 'TheSig')
Пример #2
0
class TestAddGateway(unittest.TestCase):
    def setUp(self):
        self.environment = Environment("key", "secret")

    @patch("spreedly.environment.ssl_requester.raw_ssl_request")
    def test_successful_add_gateway(self, test_patch):
        request_mock = test_patch.return_value
        request_mock.status_code = 200
        request_mock.text = successful_add_test_gateway_response

        gateway = self.environment.add_gateway("test")

        self.assertEqual("4dFb93AiRDEJ18MS9xDGMyu22uO", gateway.token)
        self.assertEqual("test", gateway.gateway_type)
        self.assertEqual("retained", gateway.state)
        self.assertEqual("Test", gateway.name)
        self.assertEqual({"login": "******"}, gateway.credentials)

    def test_request_body_params(self):
        body = self.environment.add_gateway_body(
            "wirecard", {"username": "******", "password": "******", "business_case_signature": "TheSig"}
        )

        gateway = body.xpath("/gateway")[0]
        self.assertEqual(gateway.xpath("./gateway_type")[0].text, "wirecard")
        self.assertEqual(gateway.xpath("./username")[0].text, "TheUsername")
        self.assertEqual(gateway.xpath("./password")[0].text, "ThePassword")
        self.assertEqual(gateway.xpath("./business_case_signature")[0].text, "TheSig")
class TestRedactPaymentMethod(unittest.TestCase):
    def setUp(self):
        self.environment = Environment("key", "secret")

    @patch('spreedly.environment.ssl_requester.raw_ssl_request')
    def test_successful_redact(self, test_patch):
        request_mock = test_patch.return_value
        request_mock.status_code = 200
        request_mock.text = successful_redact_response

        transaction = self.environment.redact_payment_method(
            "TransactionToken", {'remove_from_gateway': 'ThePassedGatewayToken'})
        self.assertIsInstance(transaction, RedactPaymentMethod)

        self.assertEqual(transaction.token, '2BSe5T6FHpypph3ensF7m3Nb3qk')
        self.assertEqual(transaction.created_at.year, 2013)
        self.assertEqual(transaction.created_at.month, 8)
        self.assertEqual(transaction.created_at.day, 05)
        self.assertEqual(transaction.message, 'Succeeded!')
        self.assertEqual(transaction.state, 'succeeded')
        self.assertEqual(transaction.payment_method.storage_state, 'redacted')
        self.assertEqual(transaction.payment_method.token, 'RvsxKgbAZBmiZHEPhhTcOQzJeC2')

    def test_redact_payment_method_body(self):
        body = self.environment.redact_payment_method_body({'remove_from_gateway': 'ThePassedGatewayToken'})
        print etree.tostring(body)

        transaction = body.xpath('.')[0]
        self.assertEqual(transaction.xpath('./remove_from_gateway')[0].text, 'ThePassedGatewayToken')
Пример #4
0
class TestAddCreditCard(unittest.TestCase):
    def setUp(self):
        self.environment = Environment("key", "secret")

    @patch('spreedly.environment.ssl_requester.raw_ssl_request')
    def test_successful_add_credit_card(self, test_patch):
        request_mock = test_patch.return_value
        request_mock.status_code = 200
        request_mock.text = successful_add_credit_card_response

        transaction = self.environment.add_credit_card(full_card_details)

        self.assertEqual('6wxjN6HcDik8e3mAhBaaoVGSImH', transaction.token)
        self.assertFalse(transaction.retained)
        self.assertTrue(transaction.succeeded)

        self.assertEqual(transaction.created_at.year, 2013)
        self.assertEqual(transaction.created_at.month, 8)
        self.assertEqual(transaction.created_at.day, 2)

        self.assertEqual(transaction.payment_method.token, 'AXaBXfVUqhaGMg8ytf8isiMAAL9')
        self.assertEqual(transaction.payment_method.full_name, 'Eland Venture')
        self.assertEqual(transaction.payment_method.data,
                         "Don't test everything here, since find_payment_method tests it all.")

    def test_auth_purchase_body(self):
        from lxml import etree

        body = self.environment.credit_card_body(full_card_details).xpath('/payment_method')[0]

        self.assertEqual(body.xpath('./data')[0].text, 'talent: Late')
        self.assertEqual(body.xpath('./email')[0].text, '*****@*****.**')
        self.assertEqual(body.xpath('./retained')[0].text, 'true')

        card = body.xpath('./credit_card')[0]

        self.assertEqual(card.xpath('./first_name')[0].text, 'Leavenworth')
        self.assertEqual(card.xpath('./last_name')[0].text, 'Smedry')
        self.assertEqual(card.xpath('./number')[0].text, '9555555555554444')
        self.assertEqual(card.xpath('./month')[0].text, '3')
        self.assertEqual(card.xpath('./year')[0].text, '2021')
        self.assertEqual(card.xpath('./address1')[0].text, '10 Dragon Lane')
        self.assertEqual(card.xpath('./address2')[0].text, 'Suite 9')
        self.assertEqual(card.xpath('./city')[0].text, 'Tuki Tuki')
        self.assertEqual(card.xpath('./state')[0].text, 'Mokia')
        self.assertEqual(card.xpath('./zip')[0].text, '1122')
        self.assertEqual(card.xpath('./country')[0].text, 'Free Kingdoms')
        self.assertEqual(card.xpath('./phone_number')[0].text, '81Ab')
Пример #5
0
class TestPurchase(unittest.TestCase):
    def setUp(self):
        self.environment = Environment("key", "secret")

    @patch('spreedly.environment.ssl_requester.raw_ssl_request')
    def test_successful_purchase_on_gateway(self, test_patch):
        request_mock = test_patch.return_value
        request_mock.status_code = 200
        request_mock.text = successful_purchase_response

        transaction = self.environment.purchase_on_gateway("TheGatewayToken", "TheCardToken", 2001, all_possible_options)
        self.assertIsInstance(transaction, Purchase)

        self.assertEqual(transaction.amount, 144)
        self.assertEqual(transaction.token, 'Btcyks35m4JLSNOs9ymJoNQLjeX')
        self.assertEqual(transaction.created_at.year, 2013)
        self.assertEqual(transaction.created_at.month, 7)
        self.assertEqual(transaction.created_at.day, 31)
        self.assertEqual(transaction.response.error_detail, 'The eagle lives!')
        self.assertEqual(transaction.response.message, 'Successful purchase')

    @patch('spreedly.environment.ssl_requester.raw_ssl_request')
    def test_failed_purchase_on_gateway(self, test_patch):
        request_mock = test_patch.return_value
        request_mock.status_code = 200
        request_mock.text = failed_purchase_transaction

        transaction = self.environment.purchase_on_gateway("TheGatewayToken", "TheCardToken", 2001, all_possible_options)
        self.assertIsInstance(transaction, Purchase)

        self.assertEqual(transaction.amount, 5148)
        self.assertEqual(transaction.token, 'RxkxK78ZlvDiXRQRnyuJM5ee0Ww')
        self.assertEqual(transaction.created_at.year, 2013)
        self.assertEqual(transaction.created_at.month, 7)
        self.assertEqual(transaction.created_at.day, 31)
        self.assertFalse(transaction.success)
        self.assertEqual(transaction.state, 'gateway_processing_failed')
        self.assertEqual(transaction.response.error_detail, 'The eagle is dead Jim.')

    def test_auth_purchase_body(self):
        body = self.environment.auth_purchase_body(100, "TheCardToken", all_possible_options)

        self.assertEqual(int(body.xpath('./amount')[0].text), 100)
        self.assertEqual(body.xpath('./currency_code')[0].text, 'EUR')
        self.assertEqual(body.xpath('./retain_on_success')[0].text, 'true')
Пример #6
0
class TestRedactGateway(unittest.TestCase):
    def setUp(self):
        self.environment = Environment("key", "secret")

    @patch('spreedly.environment.ssl_requester.raw_ssl_request')
    def test_successful_redact(self, test_patch):
        request_mock = test_patch.return_value
        request_mock.status_code = 200
        request_mock.text = successful_redact_gateway_response

        transaction = self.environment.redact_gateway("TransactionToken")
        self.assertIsInstance(transaction, RedactGateway)

        self.assertEqual(transaction.token, 'NXKt1iNkIJhzF5QCDt1qSsuFbcN')
        self.assertEqual(transaction.created_at.year, 2013)
        self.assertEqual(transaction.created_at.month, 8)
        self.assertEqual(transaction.created_at.day, 19)
        self.assertTrue(transaction.succeeded)
        self.assertEqual(transaction.gateway.token, '8zy49qcEUigjYbpPKCjlhDzUqJ')
        self.assertEqual(transaction.message, 'Succeeded!')
        self.assertEqual(transaction.gateway.name, 'Spreedly Test')
        self.assertEqual(transaction.gateway.state, 'redacted')
Пример #7
0
 def setUp(self):
     self.environment = Environment("key", "secret")