forked from dcramer/django-paypal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed crasher with Python 3 and IPN postbacks
- Loading branch information
1 parent
c5371c9
commit 536415a
Showing
3 changed files
with
39 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,17 +50,13 @@ | |
} | ||
|
||
|
||
class IPNTest(TestCase): | ||
class IPNTestBase(TestCase): | ||
urls = 'paypal.standard.ipn.tests.test_urls' | ||
|
||
def setUp(self): | ||
self.old_debug = settings.DEBUG | ||
settings.DEBUG = True | ||
|
||
# Monkey patch over PayPalIPN to make it get a VERFIED response. | ||
self.old_postback = PayPalIPN._postback | ||
PayPalIPN._postback = lambda self: "VERIFIED" | ||
|
||
self.payment_was_successful_receivers = payment_was_successful.receivers | ||
self.payment_was_flagged_receivers = payment_was_flagged.receivers | ||
self.payment_was_refunded_receivers = payment_was_refunded.receivers | ||
|
@@ -81,10 +77,8 @@ def setUp(self): | |
recurring_payment.receivers = [] | ||
recurring_cancel.receivers = [] | ||
|
||
|
||
def tearDown(self): | ||
settings.DEBUG = self.old_debug | ||
PayPalIPN._postback = self.old_postback | ||
|
||
payment_was_successful.receivers = self.payment_was_successful_receivers | ||
payment_was_flagged.receivers = self.payment_was_flagged_receivers | ||
|
@@ -126,13 +120,34 @@ def handle_signal(sender, **kwargs): | |
self.assertEqual(self.signal_obj, ipn_obj) | ||
return ipn_obj | ||
|
||
def assertFlagged(self, updates, flag_info): | ||
params = IPN_POST_PARAMS.copy() | ||
params.update(updates) | ||
response = self.paypal_post(params) | ||
self.assertEqual(response.status_code, 200) | ||
ipn_obj = PayPalIPN.objects.all()[0] | ||
self.assertEqual(ipn_obj.flag, True) | ||
self.assertEqual(ipn_obj.flag_info, flag_info) | ||
return ipn_obj | ||
|
||
|
||
class IPNTest(IPNTestBase): | ||
|
||
def setUp(self): | ||
# Monkey patch over PayPalIPN to make it get a VERFIED response. | ||
self.old_postback = PayPalIPN._postback | ||
PayPalIPN._postback = lambda self: b("VERIFIED") | ||
|
||
def tearDown(self): | ||
PayPalIPN._postback = self.old_postback | ||
|
||
def test_correct_ipn(self): | ||
ipn_obj = self.assertGotSignal(payment_was_successful, False) | ||
# Check some encoding issues: | ||
self.assertEqual(ipn_obj.first_name, u"J\u00f6rg") | ||
|
||
def test_failed_ipn(self): | ||
PayPalIPN._postback = lambda self: "INVALID" | ||
PayPalIPN._postback = lambda self: b("INVALID") | ||
self.assertGotSignal(payment_was_flagged, True) | ||
|
||
def test_refunded_ipn(self): | ||
|
@@ -163,15 +178,6 @@ def test_reversed_ipn(self): | |
|
||
self.assertGotSignal(payment_was_reversed, False, params) | ||
|
||
def assertFlagged(self, updates, flag_info): | ||
params = IPN_POST_PARAMS.copy() | ||
params.update(updates) | ||
response = self.paypal_post(params) | ||
self.assertEqual(response.status_code, 200) | ||
ipn_obj = PayPalIPN.objects.all()[0] | ||
self.assertEqual(ipn_obj.flag, True) | ||
self.assertEqual(ipn_obj.flag_info, flag_info) | ||
|
||
def test_incorrect_receiver_email(self): | ||
update = {"receiver_email": "[email protected]"} | ||
flag_info = "Invalid receiver_email. ([email protected])" | ||
|
@@ -271,3 +277,12 @@ def handle_signal(sender, **kwargs): | |
ipns = PayPalIPN.objects.all() | ||
self.assertEqual(len(ipns), 1) | ||
self.assertFalse(self.got_signal) | ||
|
||
|
||
class IPNPostbackTest(IPNTestBase): | ||
""" | ||
Tests an actual postback to PayPal server. | ||
""" | ||
def test_postback(self): | ||
# Incorrect signature means we will always get failure | ||
self.assertFlagged({}, u'Invalid postback. (INVALID)') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters