Permalink
Browse files

Having to do paypal.sdk.PayPalInterface is kind of long-handed, when …

…paypal.PayPalInterface is shorter. Nothing was under paypal's root module, so it was just needless depth. Re-org the codebase into paypal. Also did a bunch of fixing up of the unit tests. See the README file in the new tests directory for details.
  • Loading branch information...
Greg Taylor authored and patcoll committed Aug 5, 2010
1 parent 4c9321a commit b59358d93611a1ae595d370ec4c64dd67763b66a
View
@@ -1,4 +1,5 @@
*.pyc
.project
.pydevproject
-.settings
+.settings
+api_details.py
View
@@ -1 +1,4 @@
# coding=utf-8
+from interface import PayPalInterface
+from settings import PayPalConfig
+from exceptions import ApiError
File renamed without changes.
@@ -21,14 +21,22 @@ class PayPalInterface(object):
queries, configuration, etc, all go through here. See the __init__ method
for config related details.
"""
- def __init__(self , **kwargs):
+ def __init__(self , config=None, **kwargs):
"""
Constructor, which passes all config directives to the config class
via kwargs. For example:
paypal = PayPalInterface(API_USERNAME='somevalue')
+
+ Optionally, you may pass a 'config' kwarg to provide your own
+ PayPalConfig object.
"""
- self.config = PayPalConfig(**kwargs)
+ if config:
+ # User provided their own PayPalConfig object.
+ self.config = config
+ else:
+ # Take the kwargs and stuff them in a new PayPalConfig object.
+ self.config = PayPalConfig(**kwargs)
def _encode_utf8(self, **kwargs):
"""
File renamed without changes.
View
@@ -1,3 +0,0 @@
-#coding=utf-8
-
-from interface import PayPalInterface
File renamed without changes.
View
@@ -0,0 +1,8 @@
+In order to run these tests, you must copy the included api_details_blank.py
+file to api_details.py and substitute the API credential placeholders with your
+own PayPal test account credentials. All tests will fail unless you do this.
+
+Once your credentials are in place, you'll want to run the tests through
+the runner.py module:
+
+ python runnery.py
View
No changes.
View
@@ -0,0 +1,29 @@
+"""
+This file contains your PayPal test account credentials. If you are just
+getting started, you'll want to copy api_details_blank.py to api_details.py,
+and substitute the placeholders below with your PayPal test account details.
+"""
+from paypal import PayPalConfig
+
+# Enter your test account's API details here. You'll need the 3-token
+# credentials, not the certificate stuff.
+CONFIG = PayPalConfig(API_USERNAME = "xxx_xxx_apix.xxx.com",
+ API_PASSWORD = "xxxxxxxxxx",
+ API_SIGNATURE = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
+ DEBUG_LEVEL=0)
+
+"""
+The following values may be found by visiting https://developer.paypal.com/,
+clicking on the 'Test Accounts' navbar link in the sandbox, and looking at
+the accounts listed there. You'll need a business and a personal account
+created to run these tests.
+"""
+# The email address of your personal test account. This is typically the
+# customer for these tests.
+EMAIL_PERSONAL = 'custX_xxxxxxxxxx_per@xxxxxxxx.com'
+# If you view the details of your personal account, you'll see credit card
+# details. Enter the credit card number from there.
+VISA_ACCOUNT_NO = 'xxxxxxxxxxxxxxxx'
+# And the expiration date in the form of MMYYYY. Note that there are no slashes,
+# and single-digit month numbers have a leading 0 (IE: 03 for march).
+VISA_EXPIRATION = 'mmyyyy'
View
@@ -0,0 +1,26 @@
+import sys
+import os
+
+project_root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+if not project_root_dir in sys.path:
+ sys.path.insert(0, project_root_dir)
+
+import paypal
+
+try:
+ import api_details
+except ImportError:
+ print """
+ ERROR: No api_details.py file exists in your paypal/tests directory. Please
+ copy api_details_blank.py to api_details.py and modify the values to your
+ own API developer _test_ credentials.
+
+ If you don't already have test credentials, please visit:
+
+ https://developer.paypal.com
+
+ """
+ sys.exit(1)
+
+def get_interface_obj():
+ return paypal.PayPalInterface(config=api_details.CONFIG)
View
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+"""
+Execute this module to run all of the unit tests for paypal-python. If you
+haven't already, read README and act accordingly or all of these tests
+will fail.
+"""
+import os
+import sys
+# Prepare the path to use the included paypal module instead of the system
+# one (if applicable).
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+import unittest
+import t_direct_payment
+import t_express_checkout
+
+# A list of the modules under the tests package that should be ran.
+test_modules = [t_direct_payment, t_express_checkout]
+
+# Fire off all of the tests.
+for mod in test_modules:
+ suite = unittest.TestLoader().loadTestsFromModule(mod)
+ unittest.TextTestRunner(verbosity=1).run(suite)
@@ -1,26 +1,18 @@
# coding=utf-8
-import sdk
import unittest
+import interface_factory
+import api_details
-interface= sdk.Interface(
- API_USERNAME = "#####",
- API_PASSWORD = "#####",
- API_SIGNATURE = "#####",
-)
-
-email_per= '#####'
-email_biz= '#####'
-visa_acct= '#####'
-visa_expr= '#####'
+interface = interface_factory.get_interface_obj()
class TestDirectPayment(unittest.TestCase):
def setUp(self):
self.credit_card = {
'amt': '10.00',
'creditcardtype': 'Visa',
- 'acct': visa_acct,
- 'expdate': visa_expr,
+ 'acct': api_details.VISA_ACCOUNT_NO,
+ 'expdate': api_details.VISA_EXPIRATION,
'cvv2': '123',
'firstname': 'John',
'lastname': 'Doe',
@@ -32,9 +24,6 @@ def setUp(self):
'currencycode': 'USD',
}
- # def test_address_verify(self):
- # print(address_verify(email_biz, "1 Main St", "95131"))
-
def test_sale(self):
sale = interface.do_direct_payment('Sale', **self.credit_card)
self.assertTrue(sale.success)
@@ -82,53 +71,5 @@ def test_authorize_and_void(self):
self.assertTrue(details.success)
self.assertEqual(details.PAYMENTSTATUS.upper(), 'VOIDED')
-# TODO: implement the paypal account log-in as web-based? somehow implement with a bare-bones python web client so it's programmable?
-class TestExpressCheckout(unittest.TestCase):
- def setUp(self):
- self.returnurl = 'http://www.paypal.com'
- self.cancelurl = 'http://www.ebay.com'
-
- def test_sale(self):
- pass
-
- def test_authorize_and_delayed_capture(self):
- """
- Tests a four-step checkout process involving the following flow::
-
- One or more calls to `SetExpressCheckout`.
- --- User goes to PayPal, logs in, and confirms shipping, taxes,
- and total amount. ---
- A call to `GetExpressCheckoutDetails`.
- A call to `DoExpressCheckoutPayment`.
- A call to `DoAuthorization`.
- A call to `DoCapture`.
- """
- setexp = interface.set_express_checkout(amt='10.00', returnurl=self.returnurl, \
- cancelurl=self.cancelurl, paymentaction='Order', \
- email=email_per)
- self.assertTrue(setexp.success)
- # print(setexp)
- # getexp = get_express_checkout_details(token=setexp.token)
- # print(getexp)
-
- def test_authorize_and_void(self):
- """
- Tests a four-step checkout process involving the following flow::
-
- One or more calls to `SetExpressCheckout`.
- --- User goes to PayPal, logs in, and confirms shipping, taxes,
- and total amount. ---
- A call to `GetExpressCheckoutDetails`.
- A call to `DoExpressCheckoutPayment`.
- A call to `DoAuthorization`.
- A call to `DoVoid`.
- """
- pass
-
-if __name__ == "__main__":
- cases = [
- TestDirectPayment,
- TestExpressCheckout,
- ]
- suite = unittest.TestSuite(map(unittest.TestLoader().loadTestsFromTestCase, cases))
- unittest.TextTestRunner(verbosity=2).run(suite)
+if __name__ == '__main__':
+ unittest.main()
@@ -0,0 +1,53 @@
+# coding=utf-8
+
+import unittest
+import interface_factory
+import api_details
+
+interface = interface_factory.get_interface_obj()
+
+# TODO: implement the paypal account log-in as web-based? somehow implement with a bare-bones python web client so it's programmable?
+class TestExpressCheckout(unittest.TestCase):
+ def setUp(self):
+ self.returnurl = 'http://www.paypal.com'
+ self.cancelurl = 'http://www.ebay.com'
+
+ def test_sale(self):
+ pass
+
+ def test_authorize_and_delayed_capture(self):
+ """
+ Tests a four-step checkout process involving the following flow::
+
+ One or more calls to `SetExpressCheckout`.
+ --- User goes to PayPal, logs in, and confirms shipping, taxes,
+ and total amount. ---
+ A call to `GetExpressCheckoutDetails`.
+ A call to `DoExpressCheckoutPayment`.
+ A call to `DoAuthorization`.
+ A call to `DoCapture`.
+ """
+ setexp = interface.set_express_checkout(amt='10.00', returnurl=self.returnurl, \
+ cancelurl=self.cancelurl, paymentaction='Order', \
+ email=api_details.EMAIL_PERSONAL)
+ self.assertTrue(setexp.success)
+ # print(setexp)
+ # getexp = get_express_checkout_details(token=setexp.token)
+ # print(getexp)
+
+ def test_authorize_and_void(self):
+ """
+ Tests a four-step checkout process involving the following flow::
+
+ One or more calls to `SetExpressCheckout`.
+ --- User goes to PayPal, logs in, and confirms shipping, taxes,
+ and total amount. ---
+ A call to `GetExpressCheckoutDetails`.
+ A call to `DoExpressCheckoutPayment`.
+ A call to `DoAuthorization`.
+ A call to `DoVoid`.
+ """
+ pass
+
+if __name__ == '__main__':
+ unittest.main()

0 comments on commit b59358d

Please sign in to comment.