Commit fc04cb1b authored by Lucas Carvalho's avatar Lucas Carvalho

Big clean up and more testing will be added soon for Anonymous navigation.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29048 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 25f1f864
...@@ -32,6 +32,7 @@ from AccessControl.SecurityManagement import newSecurityManager ...@@ -32,6 +32,7 @@ from AccessControl.SecurityManagement import newSecurityManager
from zLOG import LOG from zLOG import LOG
import transaction import transaction
import urllib import urllib
import string
SESSION_ID = "12345678" SESSION_ID = "12345678"
LANGUAGE_LIST = ('en', 'fr', 'de', 'bg',) LANGUAGE_LIST = ('en', 'fr', 'de', 'bg',)
...@@ -68,7 +69,6 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -68,7 +69,6 @@ class TestCommerce(ERP5TypeTestCase):
> SaleOrder_finalizeShopping doesnt check if the payment is successful or not > SaleOrder_finalizeShopping doesnt check if the payment is successful or not
> Fix proxy for SaleOrder_finalizeShopping anonym and normal user cant use it > Fix proxy for SaleOrder_finalizeShopping anonym and normal user cant use it
> SaleOrder_getAvailableShippingResourceList have hardcoded > SaleOrder_getAvailableShippingResourceList have hardcoded
> SaleOrder_getSelectedShippingResource want a shipping_method but there is not
> SaleOrder_getShoppingCartCustomer need to be refactor for fit clustering > SaleOrder_getShoppingCartCustomer need to be refactor for fit clustering
> SaleOrder_getShoppingCartDefaultCurrency should depend of site configuration > SaleOrder_getShoppingCartDefaultCurrency should depend of site configuration
> SaleOrder_isConsistent the usage must be more generic or rename it > SaleOrder_isConsistent the usage must be more generic or rename it
...@@ -76,9 +76,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -76,9 +76,7 @@ class TestCommerce(ERP5TypeTestCase):
Not tested : Not tested :
Person_getApplicableDiscountList Person_getApplicableDiscountList
Person_getApplicableTaxList
SaleOrder_externalPaymentHandler SaleOrder_externalPaymentHandler
SaleOrder_getSelectedShippingResource
SaleOrder_isShippingRequired SaleOrder_isShippingRequired
WebSection_checkPaypalIdentification WebSection_checkPaypalIdentification
WebSection_checkoutProcedure WebSection_checkoutProcedure
...@@ -101,6 +99,17 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -101,6 +99,17 @@ class TestCommerce(ERP5TypeTestCase):
def getTitle(self): def getTitle(self):
return "E-Commerce System" return "E-Commerce System"
def getBusinessTemplateList(self):
"""
Return the list of required business templates.
"""
return ('erp5_base',
'erp5_web',
'erp5_trade',
'erp5_pdm',
'erp5_commerce',)
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
portal = self.getPortal() portal = self.getPortal()
...@@ -111,38 +120,50 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -111,38 +120,50 @@ class TestCommerce(ERP5TypeTestCase):
currency.setReference('EUR') currency.setReference('EUR')
currency.setShortTitle('€') currency.setShortTitle('€')
currency.setBaseUnitQuantity(0.01) currency.setBaseUnitQuantity(0.01)
currency.validate()
currency.publish()
# create product, set price & currency # create product, set price & currency
product = portal.product_module.newContent(portal_type='Product', id='1') product = portal.product_module.newContent(portal_type='Product', id='1')
product.setSupplyLinePriceCurrency(currency.getRelativeUrl()) product.setSupplyLinePriceCurrency(currency.getRelativeUrl())
product.setBasePrice(10.0) product.setBasePrice(10.0)
product.validate()
product.publish()
# create second product, set price & currency # create second product, set price & currency
product = portal.product_module.newContent(portal_type='Product', id='2') product = portal.product_module.newContent(portal_type='Product', id='2')
product.setSupplyLinePriceCurrency(currency.getRelativeUrl()) product.setSupplyLinePriceCurrency(currency.getRelativeUrl())
product.setBasePrice(20.0) product.setBasePrice(20.0)
product.validate()
product.publish()
# create shipping which is actually a product # create shipping which is actually a product
shipping = portal.product_module.newContent(portal_type='Product', shipping = portal.product_module.newContent(portal_type='Product',
id='3') id='3')
shipping.setSupplyLinePriceCurrency(currency.getRelativeUrl()) shipping.setSupplyLinePriceCurrency(currency.getRelativeUrl())
shipping.setBasePrice(10.0) shipping.setBasePrice(10.0)
shipping.setProductLine('shipping') shipping.setProductLine('shipping')
shipping.validate()
shipping.publish()
# validate default order rule # validate default order rule
default_order_rule = portal.portal_rules.default_order_rule default_order_rule = portal.portal_rules.default_order_rule
if default_order_rule.getValidationState() != 'validated': if default_order_rule.getValidationState() != 'validated':
portal.portal_rules.default_order_rule.validate() portal.portal_rules.default_order_rule.validate()
self.web_site = self.setupWebSite()
self.app.REQUEST.set('session_id', SESSION_ID)
self.changeUser('ivan')
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()
self.tic() self.tic()
def beforeTearDown(self): def beforeTearDown(self):
self.clearModule(self.portal.web_site_module)
self.clearModule(self.portal.product_module) self.clearModule(self.portal.product_module)
self.clearModule(self.portal.sale_order_module) self.clearModule(self.portal.sale_order_module)
self.clearModule(self.portal.currency_module) self.clearModule(self.portal.currency_module)
...@@ -154,12 +175,10 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -154,12 +175,10 @@ class TestCommerce(ERP5TypeTestCase):
""" """
self.organisation_module = self.portal.getDefaultModule('Organisation') self.organisation_module = self.portal.getDefaultModule('Organisation')
if 'seller' not in self.organisation_module.objectIds(): if 'seller' not in self.organisation_module.objectIds():
self.nexedi = self.organisation_module.newContent( self.nexedi = self.organisation_module.newContent(title="Seller",
title="Seller",
group='seller', group='seller',
role='internal', role='internal',
id='seller', id='seller')
)
def createTestUser(self, first_name, last_name, reference, group, def createTestUser(self, first_name, last_name, reference, group,
destination_project=None, id=None): destination_project=None, id=None):
...@@ -198,13 +217,6 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -198,13 +217,6 @@ class TestCommerce(ERP5TypeTestCase):
user = uf.getUserById('ivan').__of__(uf) user = uf.getUserById('ivan').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def getBusinessTemplateList(self):
"""
Return the list of required business templates.
"""
return ('erp5_base', 'erp5_web',
'erp5_trade', 'erp5_pdm', 'erp5_commerce',)
def getDefaultProduct(self, id='1'): def getDefaultProduct(self, id='1'):
""" """
Get default product. Get default product.
...@@ -212,15 +224,8 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -212,15 +224,8 @@ class TestCommerce(ERP5TypeTestCase):
return self.getPortal().product_module[id] return self.getPortal().product_module[id]
def initialiseSupplyLine(self): def initialiseSupplyLine(self):
portal = self.getPortal()
euro = portal.currency_module.newContent(portal_type='Currency',
id='euro',
reference='EUR')
euro.setBaseUnitQuantity(1.00)
euro.validate()
category_list = [] category_list = []
portal_categories = portal.portal_categories portal_categories = self.portal.portal_categories
if hasattr(portal_categories.product_line, 'ldlc'): if hasattr(portal_categories.product_line, 'ldlc'):
portal_categories.product_line.manage_delObjects(['ldlc']) portal_categories.product_line.manage_delObjects(['ldlc'])
ldlc = portal_categories.product_line.newContent(portal_type='Category', ldlc = portal_categories.product_line.newContent(portal_type='Category',
...@@ -250,7 +255,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -250,7 +255,7 @@ class TestCommerce(ERP5TypeTestCase):
for i in range(3): for i in range(3):
title = '%s %s' % (category.getTitle(), i) title = '%s %s' % (category.getTitle(), i)
reference = '%s_%s' % (category.getId(), i) reference = '%s_%s' % (category.getId(), i)
product = portal.product_module.newContent(portal_type="Product", product = self. portal.product_module.newContent(portal_type="Product",
title=title, title=title,
reference=reference) reference=reference)
product_line = category.getRelativeUrl().replace('product_line/', '') product_line = category.getRelativeUrl().replace('product_line/', '')
...@@ -266,10 +271,10 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -266,10 +271,10 @@ class TestCommerce(ERP5TypeTestCase):
for product in product_list: for product in product_list:
product.validate() product.validate()
product.publish()
ups = portal.product_module.newContent(portal_type='Product', ups = self.portal.product_module.newContent(portal_type='Product',
title='UPS Shipping : 24h') title='UPS Shipping : 24h')
ups.validate()
ups.setQuantityUnit('unit/piece') ups.setQuantityUnit('unit/piece')
supply_line = ups.setProductLine('shipping/UPS24h') supply_line = ups.setProductLine('shipping/UPS24h')
supply_line = ups.newContent(id='default_supply_line', supply_line = ups.newContent(id='default_supply_line',
...@@ -278,13 +283,17 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -278,13 +283,17 @@ class TestCommerce(ERP5TypeTestCase):
supply_line.setPricedQuantity(1) supply_line.setPricedQuantity(1)
supply_line.setDefaultResourceValue(product) supply_line.setDefaultResourceValue(product)
supply_line.setPriceCurrency('currency_module/EUR') supply_line.setPriceCurrency('currency_module/EUR')
ups.validate()
ups.publish()
transaction.commit()
self.tic()
def createUser(self, name, role_list): def createUser(self, name, role_list):
user_folder = self.getPortal().acl_users user_folder = self.portal.acl_users
user_folder._doAddUser(name, 'password', role_list, []) user_folder._doAddUser(name, 'password', role_list, [])
def changeUser(self, user_id): def changeUser(self, user_id):
user_folder = self.getPortal().acl_users user_folder = self.portal.acl_users
user = user_folder.getUserById(user_id).__of__(user_folder) user = user_folder.getUserById(user_id).__of__(user_folder)
newSecurityManager(None, user) newSecurityManager(None, user)
...@@ -292,18 +301,15 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -292,18 +301,15 @@ class TestCommerce(ERP5TypeTestCase):
""" """
Setup Web Site Setup Web Site
""" """
portal = self.getPortal()
request = self.app.REQUEST
# add supported languages for Localizer # add supported languages for Localizer
localizer = portal.Localizer localizer = self.portal.Localizer
for language in LANGUAGE_LIST: for language in LANGUAGE_LIST:
localizer.manage_addLanguage(language=language) localizer.manage_addLanguage(language=language)
# create website # create website
web_site = getattr(portal.web_site_module, 'web_site', None) web_site = getattr(self.portal.web_site_module, 'web_site', None)
if web_site is None: if web_site is None:
web_site = portal.web_site_module.newContent(portal_type='Web Site', web_site = self.portal.web_site_module.newContent(portal_type='Web Site',
id='web_site', id='web_site',
**kw) **kw)
transaction.commit() transaction.commit()
...@@ -311,7 +317,6 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -311,7 +317,6 @@ class TestCommerce(ERP5TypeTestCase):
web_site.WebSite_setupECommerceWebSite() web_site.WebSite_setupECommerceWebSite()
self.initialiseSupplyLine() self.initialiseSupplyLine()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -323,157 +328,143 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -323,157 +328,143 @@ class TestCommerce(ERP5TypeTestCase):
return web_site return web_site
def test_01_AddResourceToShoppingCart(self, quiet=0, run=run_all_test): def createShoppingCartWithProductListAndShipping(self):
"""
This method must create a Shopping Cart and add
some Products and select one Shipping.
"""
default_product = self.getDefaultProduct()
self.portal.Resource_addToShoppingCart(resource=default_product,
quantity=1)
shopping_cart = self.portal.SaleOrder_getShoppingCart()
shipping_list = self.portal.SaleOrder_getAvailableShippingResourceList()
order_line = getattr(shopping_cart, 'shipping_method', None)
if order_line is None:
order_line = shopping_cart.newContent(id='shipping_method',
portal_type='Sale Order Line')
order_line.setResource(shipping_list[0].getRelativeUrl())
order_line.setQuantity(1)
transaction.commit()
self.tic()
def test_01_AddResourceToShoppingCart(self):
""" """
Test adding an arbitrary resources to shopping cart. Test adding an arbitrary resources to shopping cart.
""" """
if not run:
return
if not quiet:
message = '\nCheck adding product to shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
# set 'session_id' to simulate browser (cookie) environment # set 'session_id' to simulate browser (cookie) environment
request.set('session_id', SESSION_ID) self.app.REQUEST.set('session_id', SESSION_ID)
self.assertEquals(SESSION_ID, portal.SaleOrder_getShoppingCartId()) self.assertEquals(SESSION_ID, self.portal.SaleOrder_getShoppingCartId())
# check if the shopping cart is empty
self.assertTrue(self.portal.SaleOrder_isShoppingCartEmpty())
# add product to shopping cart # add product to shopping cart
self.assertTrue(portal.SaleOrder_isShoppingCartEmpty()) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1)
shoppping_cart_items = portal.SaleOrder_getShoppingCartItemList() shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList()
self.assertEquals(1, len(shoppping_cart_items)) self.assertEquals(1, len(shoppping_cart_item_list))
self.assertEquals(1, shoppping_cart_items[0].getQuantity()) self.assertEquals(1, shoppping_cart_item_list[0].getQuantity())
self.assertEquals(shoppping_cart_items[0].getResource(), \ self.assertEquals(shoppping_cart_item_list[0].getResource(), \
default_product.getRelativeUrl()) default_product.getRelativeUrl())
self.assertFalse(portal.SaleOrder_isShoppingCartEmpty()) self.assertFalse(self.portal.SaleOrder_isShoppingCartEmpty())
def test_02_AddSameResourceToShoppingCart(self, quiet=0, run=run_all_test): def test_02_AddSameResourceToShoppingCart(self):
""" """
Test adding same resource to shopping cart. Test adding same resource to shopping cart.
""" """
if not run:
return
if not quiet:
message = '\nCheck adding same product to shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID)
# add in two steps same product and check that we do not create # add in two steps same product and check that we do not create
# new Sale Order Line but just increase quantity on existing one # new Sale Order Line but just increase quantity on existing one
portal.Resource_addToShoppingCart(default_product, 1) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1) self.portal.Resource_addToShoppingCart(default_product, 1)
shoppping_cart_items = portal.SaleOrder_getShoppingCartItemList()
self.assertEquals(1, len(shoppping_cart_items)) shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList()
self.assertEquals(2, shoppping_cart_items[0].getQuantity())
self.assertEquals(shoppping_cart_items[0].getResource(), \ self.assertEquals(1, len(shoppping_cart_item_list))
self.assertEquals(2, shoppping_cart_item_list[0].getQuantity())
self.assertEquals(shoppping_cart_item_list[0].getResource(), \
default_product.getRelativeUrl()) default_product.getRelativeUrl())
def test_03_AddDifferentResourceToShoppingCart(self, quiet=0, run=run_all_test): def test_03_AddDifferentResourceToShoppingCart(self):
""" """
Test adding different resource to shopping cart. Test adding different resource to shopping cart.
""" """
if not run:
return
if not quiet:
message = '\nCheck adding different product to shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
another_product = self.getDefaultProduct(id = '2') another_product = self.getDefaultProduct(id='2')
request.set('session_id', SESSION_ID)
# add second diff product and check that we create new Sale Order Line # add second diff product and check that we create new Sale Order Line
portal.Resource_addToShoppingCart(default_product, 1) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(another_product, 1) self.portal.Resource_addToShoppingCart(another_product, 1)
shoppping_cart_items = portal.SaleOrder_getShoppingCartItemList() shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList()
self.assertEquals(2, len(shoppping_cart_items)) self.assertEquals(2, len(shoppping_cart_item_list))
self.assertEquals(2, shoppping_cart_items[0].getQuantity()) self.assertEquals(2, shoppping_cart_item_list[0].getQuantity())
self.assertEquals(1, shoppping_cart_items[1].getQuantity()) self.assertEquals(1, shoppping_cart_item_list[1].getQuantity())
self.assertEquals(shoppping_cart_items[0].getResource(), \ self.assertEquals(shoppping_cart_item_list[0].getResource(), \
default_product.getRelativeUrl()) default_product.getRelativeUrl())
self.assertEquals(shoppping_cart_items[1].getResource(), \ self.assertEquals(shoppping_cart_item_list[1].getResource(), \
another_product.getRelativeUrl()) another_product.getRelativeUrl())
def test_04_CalculateTotaShoppingCartPrice(self, quiet=0, run=run_all_test): def test_04_CalculateTotaShoppingCartPrice(self):
""" """
Test calculation shopping cart's total price. Test calculation shopping cart's total price.
""" """
if not run:
return
if not quiet:
message = '\nTest calculation shopping cart total price'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
another_product = self.getDefaultProduct(id='2') another_product = self.getDefaultProduct(id='2')
request.set('session_id', SESSION_ID) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1) self.portal.Resource_addToShoppingCart(another_product, 1)
portal.Resource_addToShoppingCart(another_product, 1)
shopping_cart = portal.SaleOrder_getShoppingCart() shopping_cart = self.portal.SaleOrder_getShoppingCart()
self.assertEquals(40.0, \ self.assertEquals(40.0, \
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice())) float(shopping_cart.SaleOrder_getShoppingCartTotalPrice()))
# include taxes (by default it's 20%) # include taxes (by default it's 20%)
self.assertEquals(40.0*1.20, \ self.assertEquals(40.0*1.20, \
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(include_shipping=True, float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(
include_shipping=True,
include_taxes=True))) include_taxes=True)))
# no shipping selected yet so price should be the same # no shipping selected yet so price should be the same
self.assertEquals(40.0, \ self.assertEquals(40.0, \
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(include_shipping=True))) float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(
include_shipping=True)))
# add shipping # add shipping
shipping = self.getDefaultProduct('3') shipping = self.getDefaultProduct('3')
portal.SaleOrder_editShoppingCart(field_my_shipping_method=shipping.getRelativeUrl()) self.portal.SaleOrder_editShoppingCart(
field_my_shipping_method=shipping.getRelativeUrl())
# test price calculation only with shipping # test price calculation only with shipping
self.assertEquals(40.0 + 10.0, \ self.assertEquals(40.0 + 10.0, \
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(include_shipping=True))) float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(
include_shipping=True)))
# test price calculation shipping and taxes # test price calculation shipping and taxes
self.assertEquals((40.0 + 10.0)*1.20, \ self.assertEquals((40.0 + 10.0)*1.20, \
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(include_shipping=True, float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(
include_shipping=True,
include_taxes=True))) include_taxes=True)))
def test_05_TestUpdateShoppingCart(self, quiet=0, run=run_all_test): def test_05_TestUpdateShoppingCart(self):
""" """
Test update of shopping cart. Test update of shopping cart.
""" """
if not run:
return
if not quiet:
message = '\nTest update of shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
another_product = self.getDefaultProduct(id='2') another_product = self.getDefaultProduct(id='2')
shipping = self.getDefaultProduct('3') shipping = self.getDefaultProduct('3')
request.set('session_id', SESSION_ID)
portal.Resource_addToShoppingCart(default_product, quantity=1)
portal.Resource_addToShoppingCart(another_product, quantity=1)
shopping_cart = portal.SaleOrder_getShoppingCart() self.portal.Resource_addToShoppingCart(default_product, quantity=1)
self.portal.Resource_addToShoppingCart(another_product, quantity=1)
shopping_cart = self.portal.SaleOrder_getShoppingCart()
shipping_url = shipping.getRelativeUrl() shipping_url = shipping.getRelativeUrl()
# increase shopping item number and set shipping # increase shopping item number and set shipping
portal.SaleOrder_editShoppingCart(field_my_buy_quantity=(2, 1,), self.portal.SaleOrder_editShoppingCart(field_my_buy_quantity=(2, 1,),
field_my_shipping_method=shipping_url) field_my_shipping_method=shipping_url)
# test price calculation without shipping and without taxes # test price calculation without shipping and without taxes
...@@ -490,53 +481,33 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -490,53 +481,33 @@ class TestCommerce(ERP5TypeTestCase):
include_taxes=True))) include_taxes=True)))
# delete shopping item # delete shopping item
portal.SaleOrder_deleteShoppingCartItem('1') self.portal.SaleOrder_deleteShoppingCartItem('1')
self.assertEquals(1, \ self.assertEquals(1, \
len(portal.SaleOrder_getShoppingCartItemList())) len(self.portal.SaleOrder_getShoppingCartItemList()))
portal.SaleOrder_deleteShoppingCartItem('2') self.portal.SaleOrder_deleteShoppingCartItem('2')
self.assertEquals(0, \ self.assertEquals(0, \
len(portal.SaleOrder_getShoppingCartItemList())) len(self.portal.SaleOrder_getShoppingCartItemList()))
self.assertEquals(0.0, \ self.assertEquals(0.0, \
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice())) float(shopping_cart.SaleOrder_getShoppingCartTotalPrice()))
def test_06_TestClearShoppingCart(self, quiet=0, run=run_all_test): def test_06_TestClearShoppingCart(self):
""" """
Test clear of shopping cart. Test clear of shopping cart.
""" """
if not run:
return
if not quiet:
message = '\nTest clear shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID) self.createShoppingCartWithProductListAndShipping()
another_product = self.getDefaultProduct(id = '2')
portal.Resource_addToShoppingCart(default_product, quantity=1)
portal.Resource_addToShoppingCart(another_product, quantity=1)
self.tic()
transaction.commit() transaction.commit()
self.tic()
shopping_cart = portal.SaleOrder_getShoppingCart(action='reset') shopping_cart = self.portal.SaleOrder_getShoppingCart(action='reset')
self.assertEquals(0, len(portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(0, len(self.portal.SaleOrder_getShoppingCartItemList()))
def test_07_SessionIDGeneration(self, quiet=0, run=run_all_test): def test_07_SessionIDGeneration(self):
""" """
Test the generation of session id Test the generation of session id.
""" """
if not run:
return
if not quiet:
message = '\nTest session id generation'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
import string
id_string = self.getPortal().Base_generateSessionID() id_string = self.getPortal().Base_generateSessionID()
self.assertEquals(10, len(id_string)) self.assertEquals(10, len(id_string))
for caracter in id_string: for caracter in id_string:
...@@ -549,283 +520,162 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -549,283 +520,162 @@ class TestCommerce(ERP5TypeTestCase):
id_string = self.getPortal().Base_generateSessionID(max_long=0) id_string = self.getPortal().Base_generateSessionID(max_long=0)
self.assertEquals(0, len(id_string)) self.assertEquals(0, len(id_string))
def test_08_getApplicableDiscountList(self, quiet=0, run=run_all_test): def test_09_getApplicableTaxList(self):
"""
Test the Person_getApplicableDiscountList script
"""
if not run:
return
if not quiet:
message = '\nTest the discount list'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
# XXX : actually the script is only in squeleton mode, only return None
self.assertEquals(None, self.getPortal().Person_getApplicableDiscountList())
def test_09_getApplicableTaxList(self, quiet=0, run=run_all_test):
""" """
Test the Person_getApplicableTaxList script Test the Person_getApplicableTaxList script
""" """
if not run:
return
if not quiet:
message = '\nTest the applicable tax list'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
# XXX : actually the script is only in squeleton mode, only return a tax of 20% # XXX : actually the script is only in squeleton mode, only return a tax of 20%
self.assertEquals({'VAT':20.0}, self.getPortal().Person_getApplicableTaxList()) self.assertEquals({'VAT': 20.0}, self.getPortal().Person_getApplicableTaxList())
def test_10_paymentRedirect(self, quiet=0, run=run_all_test): def test_10_paymentRedirect(self):
""" """
Test the SaleOrder_paymentRedirect script Test the SaleOrder_paymentRedirect script
""" """
if not run:
return
if not quiet:
message = '\nTest the confirmation of shopping and payment redirect'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID) self.portal.Resource_addToShoppingCart(default_product, quantity=1)
portal.Resource_addToShoppingCart(default_product, quantity=1)
self.tic()
transaction.commit() transaction.commit()
self.tic()
# the confirmation should not be possible if the user is not logged # the confirmation should not be possible if the user is not logged
self.logout() self.logout()
self.assertEquals(1, len(portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(1, len(self.portal.SaleOrder_getShoppingCartItemList()))
self.portal.SaleOrder_paymentRedirect() self.portal.SaleOrder_paymentRedirect()
self.assertTrue(urllib.quote("You need to create an account to " \ self.assertTrue(urllib.quote("You need to create an account to " \
"continue. If you already have please login.") in "continue. If you already have please login.") in
request.RESPONSE.getHeader('location')) self.app.REQUEST.RESPONSE.getHeader('location'))
# but it should work if the user is authenticated # but it should work if the user is authenticated
self.changeUser('customer') self.changeUser('customer')
self.portal.SaleOrder_paymentRedirect() self.portal.SaleOrder_paymentRedirect()
self.assertTrue(urllib.quote("SaleOrder_viewConfirmAsWeb") in self.assertTrue(urllib.quote("SaleOrder_viewConfirmAsWeb") in
request.RESPONSE.getHeader('location')) self.app.REQUEST.RESPONSE.getHeader('location'))
def test_11_deleteShoppingCartItem(self, quiet=0, run=run_all_test): def test_11_deleteShoppingCartItem(self):
""" """
Test the SaleOrder_deleteShoppingCartItem script Test the SaleOrder_deleteShoppingCartItem script
""" """
if not run:
return
if not quiet:
message = '\nTest the deletion of cart item'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID) self.portal.Resource_addToShoppingCart(default_product, quantity=1)
self.assertEquals(1, len(self.portal.SaleOrder_getShoppingCartItemList()))
portal.Resource_addToShoppingCart(default_product, quantity=1) # Trying to remove
self.tic()
transaction.commit()
self.assertEquals(1, len(portal.SaleOrder_getShoppingCartItemList()))
self.portal.SaleOrder_deleteShoppingCartItem() self.portal.SaleOrder_deleteShoppingCartItem()
self.assertTrue(urllib.quote("Please select an item.") in self.assertTrue(urllib.quote("Please select an item.") in
request.RESPONSE.getHeader('location')) self.app.REQUEST.RESPONSE.getHeader('location'))
self.assertEquals(1, len(portal.SaleOrder_getShoppingCartItemList()))
self.portal.SaleOrder_deleteShoppingCartItem(field_my_order_line_id=default_product.getId())
self.assertTrue(urllib.quote("Successfully removed from shopping cart.") in
request.RESPONSE.getHeader('location'))
self.assertEquals(0, len(portal.SaleOrder_getShoppingCartItemList()))
def test_12_externalPaymentHandler(self, quiet=0, run=run_all_test): # Check if the item still into the Shopping Cart
""" self.assertEquals(1, len(self.portal.SaleOrder_getShoppingCartItemList()))
Test the SaleOrder_externalPaymentHandler script
""" # Remove the product from the Shopping Cart
if not run: product_id = default_product.getId()
return self.portal.SaleOrder_deleteShoppingCartItem(
if not quiet: field_my_order_line_id=product_id)
message = '\nTest the External online payment system handler'
ZopeTestCase._print(message) # Check if the Product have been removed sucessfully
LOG('Testing... ', 0, message) self.assertTrue(
portal = self.getPortal() urllib.quote("Successfully removed from shopping cart.") in
request = self.app.REQUEST self.app.REQUEST.RESPONSE.getHeader('location'))
default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID)
# XXX : no test possible, script empty # Check if the Shopping Cart is empty
self.assertEquals(0, len(self.portal.SaleOrder_getShoppingCartItemList()))
def test_13_finalizeShopping(self, quiet=0, run=run_all_test): def test_13_finalizeShopping(self):
""" """
Test the SaleOrder_finalizeShopping script Test the SaleOrder_finalizeShopping script
""" """
if not run:
return
if not quiet:
message = '\nTest the finalisation of the shopping procedure'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
self.setupWebSite()
self.changeUser('webmaster') self.changeUser('webmaster')
self.portal.Resource_addToShoppingCart(self.getDefaultProduct(),
portal = self.getPortal() quantity=1)
request = self.app.REQUEST self.portal.Resource_addToShoppingCart(self.getDefaultProduct('2'),
request.set('session_id', SESSION_ID) quantity=1)
portal.Resource_addToShoppingCart(self.getDefaultProduct(), quantity=1)
portal.Resource_addToShoppingCart(self.getDefaultProduct('2'), quantity=1)
transaction.commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(2, len(portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(2, len(self.portal.SaleOrder_getShoppingCartItemList()))
self.assertEquals(0, len(portal.sale_order_module.contentValues())) self.assertEquals(0, len(self.portal.sale_order_module.contentValues()))
portal.SaleOrder_finalizeShopping() self.portal.SaleOrder_finalizeShopping()
transaction.commit() transaction.commit()
self.tic() self.tic()
sale_order_object_list = portal.sale_order_module.contentValues()
sale_order_object_list = self.portal.sale_order_module.contentValues()
self.assertEquals(1, len(sale_order_object_list)) self.assertEquals(1, len(sale_order_object_list))
self.assertEquals(2, len(sale_order_object_list[0].contentValues())) self.assertEquals(2, len(sale_order_object_list[0].contentValues()))
self.assertEquals(0, len(self.portal.SaleOrder_getShoppingCartItemList()))
self.assertEquals(0, len(portal.SaleOrder_getShoppingCartItemList())) def test_14_getAvailableShippingResourceList(self):
self.changeUser('ivan')
def test_14_getAvailableShippingResourceList(self, quiet=0, run=run_all_test):
""" """
Test the SaleOrder_getAvailableShippingResourceList script Test the SaleOrder_getAvailableShippingResourceList script
""" """
if not run:
return
if not quiet:
message = '\nTest to get the available shipping resource list'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID) product_line = self.portal.portal_categories.product_line
shipping_url = product_line.shipping.getRelativeUrl()
shipping = portal.portal_categories.product_line.shipping.getRelativeUrl() self.portal.product_module.newContent(portal_type='Product',
portal.product_module.newContent(portal_type='Product',
title='shipping', title='shipping',
product_line=shipping) product_line=shipping_url)
transaction.commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(2, self.assertEquals(2,
len(portal.SaleOrder_getAvailableShippingResourceList())) len(self.portal.SaleOrder_getAvailableShippingResourceList()))
def test_15_getFormatedData(self):
def test_15_getFormatedData(self, quiet=0, run=run_all_test):
""" """
Test the datas formating scripts Test the datas formating scripts
""" """
if not run: sale_order = self.portal.sale_order_module.newContent(
return portal_type="Sale Order")
if not quiet:
message = '\nTest to get the datas formating scripts'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
sale_order = portal.sale_order_module.newContent(portal_type="Sale Order",)
sale_order_line = sale_order.newContent(portal_type="Sale Order Line", sale_order_line = sale_order.newContent(portal_type="Sale Order Line",
quantity="2", quantity="2",
price="10") price="10")
formated_date = sale_order.SaleOrder_getFormattedCreationDate() self.assertEqual(
formated_price = sale_order.SaleOrder_getFormattedTotalPrice() sale_order.getCreationDate().strftime('%a, %d %b %Y %H:%M %p'),
self.assertEqual(sale_order.getCreationDate().strftime('%a, %d %b %Y %H:%M %p'), formated_date) sale_order.SaleOrder_getFormattedCreationDate())
self.assertEqual('%s %s' %('20.0', sale_order.getPriceCurrencyTitle()), formated_price) self.assertEqual('%s %s' %('20.0', sale_order.getPriceCurrencyTitle()),
sale_order.SaleOrder_getFormattedTotalPrice())
def test_16_getSelectedShippingResource(self, quiet=0, run=run_all_test): def test_16_getSelectedShippingResource(self):
""" """
Test the SaleOrder_getSelectedShippingResource script Test the SaleOrder_getSelectedShippingResource script
""" """
if not run:
return
if not quiet:
message = '\nTest to get selected shipping method from shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
request.set('session_id', SESSION_ID)
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1) shopping_cart = self.portal.SaleOrder_getShoppingCart()
shopping_cart = portal.SaleOrder_getShoppingCart() shipping_list = self.portal.SaleOrder_getAvailableShippingResourceList()
shipping_resource_list = portal.SaleOrder_getAvailableShippingResourceList()
order_line = getattr(shopping_cart, 'shipping_method', None) order_line = getattr(shopping_cart, 'shipping_method', None)
if order_line is None: if order_line is None:
order_line = shopping_cart.newContent(id='shipping_method', portal_type='Sale Order Line') order_line = shopping_cart.newContent(id='shipping_method',
order_line.setResource(shipping_resource_list[0].getRelativeUrl()) portal_type='Sale Order Line')
order_line.setResource(shipping_list[0].getRelativeUrl())
order_line.setQuantity(1) order_line.setQuantity(1)
self.assertEquals(shipping_resource_list[0].getRelativeUrl(), self.assertEquals(shipping_list[0].getRelativeUrl(),
portal.SaleOrder_getSelectedShippingResource()) self.portal.SaleOrder_getSelectedShippingResource())
def test_17_getShoppingCartDefaultCurrency(self, quiet=0, run=run_all_test): def test_17_getShoppingCartDefaultCurrency(self):
""" """
Testing the scripts: Testing the scripts:
- SaleOrder_getShoppingCartDefaultCurrency - SaleOrder_getShoppingCartDefaultCurrency
- SaleOrder_getShoppingCartDefaultCurrencyCode - SaleOrder_getShoppingCartDefaultCurrencyCode
- SaleOrder_getShoppingCartDefaultCurrencySymbol - SaleOrder_getShoppingCartDefaultCurrencySymbol
""" """
if not run: currency = self.portal.restrictedTraverse('currency_module/EUR')
return
if not quiet:
message = '\nTest to get the default currency of a shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
currency = portal.restrictedTraverse('currency_module/EUR')
self.assertEquals(currency, self.assertEquals(currency,
portal.SaleOrder_getShoppingCartDefaultCurrency()) self.portal.SaleOrder_getShoppingCartDefaultCurrency())
currency_code = currency.getReference() self.assertEquals(currency.getReference(),
self.assertEquals(currency_code, self.portal.SaleOrder_getShoppingCartDefaultCurrencyCode())
portal.SaleOrder_getShoppingCartDefaultCurrencyCode())
currency_symbol = currency.getShortTitle()
self.assertEquals(currency_symbol,
portal.SaleOrder_getShoppingCartDefaultCurrencySymbol())
def test_18_webSiteInitialisation(self, quiet=0, run=run_all_test):
"""
Test the SaleOrder_getShoppingCartDefaultCurrency script
"""
if not run:
return
if not quiet:
message = '\nTest to get the default currency of a shopping cart'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal() self.assertEquals(currency.getShortTitle(),
self.portal.SaleOrder_getShoppingCartDefaultCurrencySymbol())
def test_19_simulatePaypalPayment(self, quiet=0, run=run_all_test): def test_19_simulatePaypalPayment(self):
""" """
Test all the scripts related to paypal Test all the scripts related to paypal
""" """
if not run:
return
if not quiet:
message = '\nTest to simulate paypal payment.'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
# create new python script to replace the external method # create new python script to replace the external method
custom_skin = self.getPortal().portal_skins.custom custom_skin = self.portal.portal_skins.custom
method_id = 'WebSection_submitPaypalNVPRequest' method_id = 'WebSection_submitPaypalNVPRequest'
if method_id in custom_skin.objectIds(): if method_id in custom_skin.objectIds():
custom_skin.manage_delObjects([method_id]) custom_skin.manage_delObjects([method_id])
...@@ -833,13 +683,12 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -833,13 +683,12 @@ class TestCommerce(ERP5TypeTestCase):
.manage_addPythonScript(id = method_id) .manage_addPythonScript(id = method_id)
script = custom_skin[method_id] script = custom_skin[method_id]
script.ZPythonScript_edit('parameter_dict, nvp_url', SIMULATE_PAYPAL_SERVER) script.ZPythonScript_edit('parameter_dict, nvp_url', SIMULATE_PAYPAL_SERVER)
self.getPortal().changeSkin('View') self.portal.changeSkin('View')
#1 initialise a website #1 initialise a website
web_site = self.setupWebSite() self.web_site.setProperty('ecommerce_paypal_username', 'user')
web_site.setProperty('ecommerce_paypal_username', 'user') self.web_site.setProperty('ecommerce_paypal_password', 'pass')
web_site.setProperty('ecommerce_paypal_password', 'pass') self.web_site.setProperty('ecommerce_paypal_signature', 'signature')
web_site.setProperty('ecommerce_paypal_signature', 'signature')
#2 login and activate a cart #2 login and activate a cart
self.changeUser('webmaster') self.changeUser('webmaster')
...@@ -847,161 +696,140 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -847,161 +696,140 @@ class TestCommerce(ERP5TypeTestCase):
request.set('session_id', SESSION_ID) request.set('session_id', SESSION_ID)
#3 add a product in the cart #3 add a product in the cart
default_product = self.getDefaultProduct() self.createShoppingCartWithProductListAndShipping()
portal.Resource_addToShoppingCart(resource=default_product, quantity=1)
transaction.commit()
self.tic()
#4 chose a shipping for the cart
shopping_cart = portal.SaleOrder_getShoppingCart()
shipping_resource_list = portal.SaleOrder_getAvailableShippingResourceList()
order_line = getattr(shopping_cart, 'shipping_method', None)
if order_line is None:
order_line = shopping_cart.newContent(id='shipping_method',
portal_type='Sale Order Line')
order_line.setResource(shipping_resource_list[0].getRelativeUrl())
order_line.setQuantity(1)
self.assertEquals(shipping_resource_list[0].getRelativeUrl(),
portal.SaleOrder_getSelectedShippingResource())
#5 : paypal step 1 : get a new token #4 : paypal step 1 : get a new token
token = web_site.checkout.WebSection_getNewPaypalToken() token = self.web_site.checkout.WebSection_getNewPaypalToken()
self.assertNotEquals(token, None) self.assertNotEquals(token, None)
#6 : paypal step 2 : go to paypal and confirm this token #5 : paypal step 2 : go to paypal and confirm this token
# PayerID is normaly set in the request when paypal redirect to the instance # PayerID is normaly set in the request when paypal redirect to the instance
request.set('PayerID', 'THEPAYERID') request.set('PayerID', 'THEPAYERID')
#7 : paypal step 3 : check if this token is confirmed by paypal #6 : paypal step 3 : check if this token is confirmed by paypal
error = web_site.WebSection_checkPaypalIdentification() error = self.web_site.WebSection_checkPaypalIdentification()
self.assertEquals(error, None) self.assertEquals(error, None)
self.assertTrue('/checkout' in request.RESPONSE.getHeader('location')) self.assertTrue('/checkout' in request.RESPONSE.getHeader('location'))
#8 : paypal step 4 : validate the payment #7 : paypal step 4 : validate the payment
self.assertEquals(1, len(portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(1, len(self.portal.SaleOrder_getShoppingCartItemList()))
self.assertEquals(0, len(portal.sale_order_module.contentValues())) self.assertEquals(0, len(self.portal.sale_order_module.contentValues()))
web_site.WebSection_doPaypalPayment(token=token) self.web_site.WebSection_doPaypalPayment(token=token)
transaction.commit() transaction.commit()
self.tic() self.tic()
#9 check if sale order created #8 check if sale order created
self.assertEquals(0, len(portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(0, len(self.portal.SaleOrder_getShoppingCartItemList()))
self.assertEquals(1, len(portal.sale_order_module.contentValues())) self.assertEquals(1, len(self.portal.sale_order_module.contentValues()))
custom_skin.manage_delObjects([method_id]) custom_skin.manage_delObjects([method_id])
self.changeUser('ivan')
def test_20_getProductListFromWebSection(self, quiet=0, run=run_all_test): def test_20_getProductListFromWebSection(self):
""" """
Test the WebSection_getProductList script. Test the WebSection_getProductList script.
""" """
if not run:
return
if not quiet:
message = '\nTest the script WebSection_getProductList.'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
web_site = self.setupWebSite()
laptop_product = self.getDefaultProduct(id='1') laptop_product = self.getDefaultProduct(id='1')
laptop_product.setProductLine('ldlc/laptop') laptop_product.setProductLine('ldlc/laptop')
netbook_product = self.getDefaultProduct(id='2') netbook_product = self.getDefaultProduct(id='2')
netbook_product.setProductLine('ldlc/laptop') netbook_product.setProductLine('ldlc/laptop')
self.web_site.WebSection_generateSectionFromCategory(
web_site.WebSection_generateSectionFromCategory(category='product_line/ldlc', category='product_line/ldlc',
section_id='products', section_id='products',
depth=2) depth=2)
transaction.commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(12, len(web_site.products.WebSection_getProductList())) self.assertEquals(14, len(self.web_site.products.WebSection_getProductList()))
def test_21_editShoppingCardWithABlankShippingMethod(self, def test_21_editShoppingCardWithABlankShippingMethod(self):
quiet=0,
run=run_all_test):
""" """
This test must make sure that you can edit the shopping cart selecting a This test must make sure that you can edit the shopping cart selecting a
blank shipping method and it will not break. blank shipping method and it will not break.
""" """
if not run:
return
if not quiet:
message = '\nTest edit the Shopping Cart with blank shipping method.'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1)
shopping_cart = portal.SaleOrder_getShoppingCart()
shopping_cart = self.portal.SaleOrder_getShoppingCart()
self.assertFalse(hasattr(shopping_cart, 'shipping_method')) self.assertFalse(hasattr(shopping_cart, 'shipping_method'))
portal.SaleOrder_editShoppingCart(field_my_shipping_method='') self.portal.SaleOrder_editShoppingCart(field_my_shipping_method='')
portal.SaleOrder_editShoppingCart(field_my_shipping_method=None) self.portal.SaleOrder_editShoppingCart(field_my_shipping_method=None)
# add shipping # add shipping
shipping = self.getDefaultProduct('3') shipping = self.getDefaultProduct('3')
portal.SaleOrder_editShoppingCart(field_my_shipping_method=shipping.getRelativeUrl()) self.portal.SaleOrder_editShoppingCart(
field_my_shipping_method=shipping.getRelativeUrl())
self.assertTrue(hasattr(shopping_cart, 'shipping_method')) self.assertTrue(hasattr(shopping_cart, 'shipping_method'))
def test_22_editShoppingCardWithShippingMethodWithoutPrice(self):
def test_22_editShoppingCardWithShippingMethodWithoutPrice(self,
quiet=0,
run=run_all_test):
""" """
This test must make sure that you can not edit the shopping cart This test must make sure that you can not edit the shopping cart
selecting a shipping method without price. selecting a shipping method without price.
""" """
if not run:
return
if not quiet:
message = '\nTest edit the Cart with shipping method without price.'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
request = self.app.REQUEST
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
request.set('session_id', SESSION_ID) self.portal.Resource_addToShoppingCart(default_product, 1)
portal.Resource_addToShoppingCart(default_product, 1) shopping_cart = self.portal.SaleOrder_getShoppingCart()
shopping_cart = portal.SaleOrder_getShoppingCart()
# add shipping # add shipping
shipping = self.getDefaultProduct('3') shipping = self.getDefaultProduct('3')
shipping.setBasePrice(None) shipping.setBasePrice(None)
portal.SaleOrder_editShoppingCart(field_my_shipping_method=shipping.getRelativeUrl()) self.portal.SaleOrder_editShoppingCart(
self.assertEquals(10.0, \ field_my_shipping_method=shipping.getRelativeUrl())
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(include_shipping=True)))
shipping.setBasePrice(10.0)
self.assertEquals(10.0, \
float(shopping_cart.SaleOrder_getShoppingCartTotalPrice(
include_shipping=True)))
def test_23_getProductListFromWebSite(self, quiet=0, run=run_all_test): def test_23_getProductListFromWebSite(self):
""" """
Test the WebSite_getProductList script. Test the WebSite_getProductList script.
""" """
if not run: self.assertEquals(5, len(self.web_site.WebSite_getProductList()))
return self.assertEquals(16,
if not quiet: len(self.web_site.WebSite_getProductList(limit=1000)))
message = '\nTest the script WebSite_getProductList.'
ZopeTestCase._print(message)
LOG('Testing... ', 0, message)
portal = self.getPortal()
web_site = self.setupWebSite() def test_24_AddResourceToShoppingCartWithAnonymousUser(self):
"""
Test adding an arbitrary resources to shopping cart with Anonymous user.
"""
# anonymous user
self.logout()
self.createShoppingCartWithProductListAndShipping()
shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList()
self.assertEquals(1, len(shoppping_cart_item_list))
def test_25_createShoppingCartWithAnonymousAndLogin(self):
"""
Test adding an arbitrary resources to shopping cart with Anonymous user
then create a new user, login and check if the Shopping Cart still the
same.
"""
# anonymous user
self.logout()
self.createShoppingCartWithProductListAndShipping()
shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList()
self.assertEquals(1, len(shoppping_cart_item_list))
kw = dict(reference='toto',
first_name='Toto',
last_name='Test',
default_email_text='test@test.com',
password='secret',
password_confirm='secret')
for key, item in kw.items():
self.app.REQUEST.set('field_your_%s' %key, item)
self.web_site.WebSite_createWebSiteAccount('WebSite_viewRegistrationDialog')
transaction.commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(5, len(web_site.WebSite_getProductList())) self.changeUser('toto')
self.assertEquals(13, len(web_site.WebSite_getProductList(limit=1000))) self.portal.SaleOrder_paymentRedirect()
self.assertTrue(urllib.quote("SaleOrder_viewConfirmAsWeb") in
self.app.REQUEST.RESPONSE.getHeader('location'))
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