Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
harness PayPalInterface._call with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mamachanko committed Oct 21, 2014
1 parent b6ad54d commit 29e19d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nose
requests
mock
requests
33 changes: 33 additions & 0 deletions tests/test_express_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import unittest
import warnings

from mock import patch, Mock

from . import interface_factory
from . import api_details
from paypal.exceptions import PayPalAPIResponseError
from paypal.interface import PayPalInterface
from paypal.response import PayPalResponse

interface = interface_factory.get_interface_obj()

Expand Down Expand Up @@ -175,3 +179,32 @@ def test_returns_certificate_call_params(self):
'timeout': interface.config.HTTP_TIMEOUT,
'verify': interface.config.API_CA_CERTS}
self.assertEqual(expected_call_params, call_params)


class CallTest(unittest.TestCase):

def test_posts_params(self):
with patch('paypal.interface.requests.post') as post_mock:
post_mock.return_value = Mock(text='ACK=SUCCESS')
paypal_response = interface._call('some_method',
param_a='a1',
param_b='b2')
expected_data = {'PARAM_A': 'a1',
'PARAM_B': 'b2',
'USER': interface.config.API_USERNAME,
'PWD': interface.config.API_PASSWORD,
'SIGNATURE': interface.config.API_SIGNATURE,
'METHOD': 'some_method',
'VERSION': interface.config.API_VERSION}
post_mock.assert_called_once_with(interface.config.API_ENDPOINT,
timeout=interface.config.HTTP_TIMEOUT,
verify=interface.config.API_CA_CERTS,
data=expected_data)
self.assertIsInstance(paypal_response, PayPalResponse)
self.assertTrue(paypal_response.success)

def test_raises_configerror_on_error_response(self):
with patch('paypal.interface.requests.post') as post_mock:
post_mock.return_value = Mock(text='ACK=NO_SUCCESS')
with self.assertRaises(PayPalAPIResponseError):
interface._call('some_method', param='a')

0 comments on commit 29e19d5

Please sign in to comment.