Commit c51b3bc6 authored by Vincent Desmares's avatar Vincent Desmares

Creation of a script to replace the external method who should contact paypal

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28195 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent aaf58f81
...@@ -36,6 +36,28 @@ import transaction ...@@ -36,6 +36,28 @@ import transaction
import urllib import urllib
SESSION_ID = "12345678" SESSION_ID = "12345678"
LANGUAGE_LIST = ('en', 'fr', 'de', 'bg',)
SIMULATE_PAYPAL_SERVER = """
# this script simulate the reponse of paypal
if not 'METHOD' in parameter_dict:
return {'ACK':'Failure'}
# Step 1 : get a token
if parameter_dict['METHOD'] == 'SetExpressCheckout':
return {'ACK':'Success',
'TOKEN':'FOOTOKEN'}
# Step 2 : check if token is good
if parameter_dict['METHOD'] == 'GetExpressCheckoutDetails':
return {'ACK':'Success',
'PAYERID':'THEPAYERID'}
# Step 3 : pay
if parameter_dict['METHOD'] == 'DoExpressCheckoutPayment':
return {'ACK':'Success',
'PAYERID':'THEPAYERID'}
return {'ACK':'Failure'}
"""
class TestCommerce(ERP5TypeTestCase): class TestCommerce(ERP5TypeTestCase):
""" """
...@@ -111,6 +133,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -111,6 +133,7 @@ class TestCommerce(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
def clearModule(self, module): def clearModule(self, module):
module.manage_delObjects(list(module.objectIds())) module.manage_delObjects(list(module.objectIds()))
transaction.commit() transaction.commit()
...@@ -148,7 +171,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -148,7 +171,7 @@ class TestCommerce(ERP5TypeTestCase):
""" """
return self.getPortal().product_module[id] return self.getPortal().product_module[id]
def InitialiseShippingLine(self): def initialiseSupplyLine(self):
portal = self.getPortal() portal = self.getPortal()
euro = portal.currency_module.newContent(portal_type='Currency', euro = portal.currency_module.newContent(portal_type='Currency',
id='euro', id='euro',
...@@ -193,6 +216,30 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -193,6 +216,30 @@ class TestCommerce(ERP5TypeTestCase):
supply_line.setDefaultResourceValue(product) supply_line.setDefaultResourceValue(product)
supply_line.setPriceCurrency('currency_module/1') supply_line.setPriceCurrency('currency_module/1')
def setupWebSite(self, **kw):
"""
Setup Web Site
"""
portal = self.getPortal()
request = self.app.REQUEST
# add supported languages for Localizer
localizer = portal.Localizer
for language in LANGUAGE_LIST:
localizer.manage_addLanguage(language = language)
# create website
if hasattr(portal.web_site_module, 'web_site'):
portal.web_site_module.manage_delObjects('web_site')
web_site = portal.web_site_module.newContent(portal_type = 'Web Site',
id = 'web_site',
**kw)
transaction.commit()
self.tic()
web_site.WebSite_setupECommerceWebSite()
self.initialiseSupplyLine()
return web_site
def test_01_AddResourceToShoppingCart(self, quiet=0, run=run_all_test): def test_01_AddResourceToShoppingCart(self, quiet=0, run=run_all_test):
""" """
Test adding an arbitrary resources to shopping cart. Test adding an arbitrary resources to shopping cart.
...@@ -645,8 +692,46 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -645,8 +692,46 @@ class TestCommerce(ERP5TypeTestCase):
message = '\nTest to simulate paypal payment.' message = '\nTest to simulate paypal payment.'
ZopeTestCase._print(message) ZopeTestCase._print(message)
LOG('Testing... ', 0, message) LOG('Testing... ', 0, message)
portal = self.getPortal() portal = self.getPortal()
# create new python script to replace the external method
custom_skin = self.getPortal().portal_skins.custom
method_id = 'ERP5Base_submitPaypalNVPRequest'
if method_id in custom_skin.objectIds():
custom_skin.manage_delObjects([method_id])
custom_skin.manage_addProduct['PythonScripts']\
.manage_addPythonScript(id = method_id)
script = custom_skin[method_id]
script.ZPythonScript_edit('parameter_dict, nvp_url', SIMULATE_PAYPAL_SERVER)
self.getPortal().changeSkin('View')
#1 initialise a website
web_site = self.setupWebSite()
#2 login
#3 add a product in the cart
#4 chose a shipping for the cart
#5 : paypal step 1 : get a new token
#token = web_site.WebSite_getNewPaypalToken()
#self.assertNotEquals(token, None)
#6 : paypal step 2 : go to paypal and confirm this token
#7 : paypal step 3 : check if this token is confirmed by paypal
# use WebSection_checkPaypalIdentification
#8 : paypal step 4 : validate the payment
# use WebSection_doPaypalPayment
#9 check if sale order created
#10 check sale order price and status
#11 clean
custom_skin.manage_delObjects([method_id])
import unittest import unittest
def test_suite(): def test_suite():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment