From 95ed461dba5cedeb668a70ea77ba9f4a6fa55020 Mon Sep 17 00:00:00 2001 From: Tom Scytale Date: Wed, 13 Jul 2011 10:59:11 +0100 Subject: [PATCH 1/2] make testing for test environment more consistent --- paypal/pro/helpers.py | 2 +- paypal/standard/conf.py | 4 ++-- paypal/standard/forms.py | 17 +++++++---------- paypal/standard/ipn/templates/ipn/paypal.html | 2 +- paypal/standard/pdt/models.py | 4 ++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/paypal/pro/helpers.py b/paypal/pro/helpers.py index 4942bf2..b62f95e 100644 --- a/paypal/pro/helpers.py +++ b/paypal/pro/helpers.py @@ -16,7 +16,7 @@ from paypal.pro.models import PayPalNVP, L from paypal.pro.exceptions import PayPalFailure -TEST = settings.PAYPAL_TEST +TEST = getattr(settings, "PAYPAL_TEST", True) USER = settings.PAYPAL_WPP_USER PASSWORD = settings.PAYPAL_WPP_PASSWORD SIGNATURE = settings.PAYPAL_WPP_SIGNATURE diff --git a/paypal/standard/conf.py b/paypal/standard/conf.py index 5c5fd45..16b7121 100644 --- a/paypal/standard/conf.py +++ b/paypal/standard/conf.py @@ -2,9 +2,9 @@ class PayPalSettingsError(Exception): """Raised when settings be bad.""" - -TEST = getattr(settings, "PAYPAL_TEST", True) + +TEST = getattr(settings, "PAYPAL_TEST", settings.DEBUG) RECEIVER_EMAIL = settings.PAYPAL_RECEIVER_EMAIL diff --git a/paypal/standard/forms.py b/paypal/standard/forms.py index 38e33d9..045f9d8 100644 --- a/paypal/standard/forms.py +++ b/paypal/standard/forms.py @@ -5,8 +5,8 @@ from django.utils.safestring import mark_safe from paypal.standard.conf import * from paypal.standard.widgets import ValueHiddenInput, ReservedValueHiddenInput -from paypal.standard.conf import (POSTBACK_ENDPOINT, SANDBOX_POSTBACK_ENDPOINT, - RECEIVER_EMAIL) +from paypal.standard.conf import (POSTBACK_ENDPOINT, SANDBOX_POSTBACK_ENDPOINT, + RECEIVER_EMAIL, TEST) # 20:18:05 Jan 30, 2009 PST - PST timezone support is not included out of the box. @@ -100,17 +100,14 @@ def __init__(self, button_type="buy", *args, **kwargs): self.button_type = button_type def render(self): + if TEST: + postback_endpoint = SANDBOX_POSTBACK_ENDPOINT + else: + postback_endpoint = POSTBACK_ENDPOINT return mark_safe(u"""
%s -
""" % (POSTBACK_ENDPOINT, self.as_p(), self.get_image())) - - - def sandbox(self): - return mark_safe(u"""
- %s - -
""" % (SANDBOX_POSTBACK_ENDPOINT, self.as_p(), self.get_image())) +""" % (postback_endpoint, self.as_p(), self.get_image())) def get_image(self): return { diff --git a/paypal/standard/ipn/templates/ipn/paypal.html b/paypal/standard/ipn/templates/ipn/paypal.html index 695b241..3e40e53 100644 --- a/paypal/standard/ipn/templates/ipn/paypal.html +++ b/paypal/standard/ipn/templates/ipn/paypal.html @@ -6,7 +6,7 @@ -{{ form.sandbox }} +{{ form.render }} diff --git a/paypal/standard/pdt/models.py b/paypal/standard/pdt/models.py index 72e7d7d..33e85fc 100644 --- a/paypal/standard/pdt/models.py +++ b/paypal/standard/pdt/models.py @@ -7,7 +7,7 @@ from django.http import QueryDict from django.utils.http import urlencode from paypal.standard.models import PayPalStandardBase -from paypal.standard.conf import POSTBACK_ENDPOINT, SANDBOX_POSTBACK_ENDPOINT +from paypal.standard.conf import POSTBACK_ENDPOINT, SANDBOX_POSTBACK_ENDPOINT, TEST from paypal.standard.pdt.signals import pdt_successful, pdt_failed # ### Todo: Move this logic to conf.py: @@ -48,7 +48,7 @@ def _postback(self): def get_endpoint(self): """Use the sandbox when in DEBUG mode as we don't have a test_ipn variable in pdt.""" - if getattr(settings, 'PAYPAL_DEBUG', settings.DEBUG): + if TEST: return SANDBOX_POSTBACK_ENDPOINT else: return POSTBACK_ENDPOINT From fc03899d9c4016b315ee974102d655f3b630aca8 Mon Sep 17 00:00:00 2001 From: Tom Scytale Date: Wed, 13 Jul 2011 11:09:59 +0100 Subject: [PATCH 2/2] make pro/helpers.py use same convention for looking up TEST settings as rest of code --- paypal/pro/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paypal/pro/helpers.py b/paypal/pro/helpers.py index b62f95e..e1ec3df 100644 --- a/paypal/pro/helpers.py +++ b/paypal/pro/helpers.py @@ -16,8 +16,8 @@ from paypal.pro.models import PayPalNVP, L from paypal.pro.exceptions import PayPalFailure -TEST = getattr(settings, "PAYPAL_TEST", True) -USER = settings.PAYPAL_WPP_USER +TEST = getattr(settings, "PAYPAL_TEST", settings.DEBUG) +USER = settings.PAYPAL_WPP_USER PASSWORD = settings.PAYPAL_WPP_PASSWORD SIGNATURE = settings.PAYPAL_WPP_SIGNATURE VERSION = 54.0