Commit 2dd436a4 authored by Lucas Carvalho's avatar Lucas Carvalho

fixed the test, use web site object as context instead of portal object.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29619 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2f89a180
...@@ -344,9 +344,9 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -344,9 +344,9 @@ class TestCommerce(ERP5TypeTestCase):
some Products and select one Shipping. some Products and select one Shipping.
""" """
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
self.portal.Resource_addToShoppingCart(resource=default_product, self.web_site.Resource_addToShoppingCart(resource=default_product,
quantity=1) quantity=1)
shopping_cart = self.portal.SaleOrder_getShoppingCart() shopping_cart = self.portal.SaleOrder_getShoppingCart()
shipping_list = self.portal.SaleOrder_getAvailableShippingResourceList() shipping_list = self.portal.SaleOrder_getAvailableShippingResourceList()
order_line = getattr(shopping_cart, 'shipping_method', None) order_line = getattr(shopping_cart, 'shipping_method', None)
...@@ -366,20 +366,20 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -366,20 +366,20 @@ class TestCommerce(ERP5TypeTestCase):
# set 'session_id' to simulate browser (cookie) environment # set 'session_id' to simulate browser (cookie) environment
self.app.REQUEST.set('session_id', SESSION_ID) self.app.REQUEST.set('session_id', SESSION_ID)
self.assertEquals(SESSION_ID, self.portal.SaleOrder_getShoppingCartId()) self.assertEquals(SESSION_ID, self.web_site.SaleOrder_getShoppingCartId())
# check if the shopping cart is empty # check if the shopping cart is empty
self.assertTrue(self.portal.SaleOrder_isShoppingCartEmpty()) self.assertTrue(self.web_site.SaleOrder_isShoppingCartEmpty())
# add product to shopping cart # add product to shopping cart
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList() shoppping_cart_item_list = self.web_site.SaleOrder_getShoppingCartItemList()
self.assertEquals(1, len(shoppping_cart_item_list)) self.assertEquals(1, len(shoppping_cart_item_list))
self.assertEquals(1, shoppping_cart_item_list[0].getQuantity()) self.assertEquals(1, shoppping_cart_item_list[0].getQuantity())
self.assertEquals(shoppping_cart_item_list[0].getResource(), \ self.assertEquals(shoppping_cart_item_list[0].getResource(), \
default_product.getRelativeUrl()) default_product.getRelativeUrl())
self.assertFalse(self.portal.SaleOrder_isShoppingCartEmpty()) self.assertFalse(self.web_site.SaleOrder_isShoppingCartEmpty())
def test_02_AddSameResourceToShoppingCart(self): def test_02_AddSameResourceToShoppingCart(self):
""" """
...@@ -389,10 +389,10 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -389,10 +389,10 @@ class TestCommerce(ERP5TypeTestCase):
# 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
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList() shoppping_cart_item_list = self.web_site.SaleOrder_getShoppingCartItemList()
self.assertEquals(1, len(shoppping_cart_item_list)) self.assertEquals(1, len(shoppping_cart_item_list))
self.assertEquals(2, shoppping_cart_item_list[0].getQuantity()) self.assertEquals(2, shoppping_cart_item_list[0].getQuantity())
...@@ -407,10 +407,10 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -407,10 +407,10 @@ class TestCommerce(ERP5TypeTestCase):
another_product = self.getDefaultProduct(id='2') another_product = self.getDefaultProduct(id='2')
# 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
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
self.portal.Resource_addToShoppingCart(another_product, 1) self.web_site.Resource_addToShoppingCart(another_product, 1)
shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList() shoppping_cart_item_list = self.web_site.SaleOrder_getShoppingCartItemList()
self.assertEquals(2, len(shoppping_cart_item_list)) self.assertEquals(2, len(shoppping_cart_item_list))
self.assertEquals(2, shoppping_cart_item_list[0].getQuantity()) self.assertEquals(2, shoppping_cart_item_list[0].getQuantity())
self.assertEquals(1, shoppping_cart_item_list[1].getQuantity()) self.assertEquals(1, shoppping_cart_item_list[1].getQuantity())
...@@ -426,9 +426,9 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -426,9 +426,9 @@ class TestCommerce(ERP5TypeTestCase):
""" """
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
another_product = self.getDefaultProduct(id='2') another_product = self.getDefaultProduct(id='2')
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
self.portal.Resource_addToShoppingCart(another_product, 1) self.web_site.Resource_addToShoppingCart(another_product, 1)
shopping_cart = self.portal.SaleOrder_getShoppingCart() shopping_cart = self.portal.SaleOrder_getShoppingCart()
self.assertEquals(40.0, \ self.assertEquals(40.0, \
...@@ -467,8 +467,8 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -467,8 +467,8 @@ class TestCommerce(ERP5TypeTestCase):
another_product = self.getDefaultProduct(id='2') another_product = self.getDefaultProduct(id='2')
shipping = self.getDefaultProduct('3') shipping = self.getDefaultProduct('3')
self.portal.Resource_addToShoppingCart(default_product, quantity=1) self.web_site.Resource_addToShoppingCart(default_product, quantity=1)
self.portal.Resource_addToShoppingCart(another_product, quantity=1) self.web_site.Resource_addToShoppingCart(another_product, quantity=1)
shopping_cart = self.portal.SaleOrder_getShoppingCart() shopping_cart = self.portal.SaleOrder_getShoppingCart()
shipping_url = shipping.getRelativeUrl() shipping_url = shipping.getRelativeUrl()
...@@ -514,8 +514,8 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -514,8 +514,8 @@ class TestCommerce(ERP5TypeTestCase):
transaction.commit() transaction.commit()
self.tic() self.tic()
shopping_cart = self.portal.SaleOrder_getShoppingCart(action='reset') shopping_cart = self.web_site.SaleOrder_getShoppingCart(action='reset')
self.assertEquals(0, len(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(0, len(self.web_site.SaleOrder_getShoppingCartItemList()))
def test_07_SessionIDGeneration(self): def test_07_SessionIDGeneration(self):
...@@ -546,13 +546,13 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -546,13 +546,13 @@ class TestCommerce(ERP5TypeTestCase):
Test the SaleOrder_paymentRedirect script Test the SaleOrder_paymentRedirect script
""" """
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
self.portal.Resource_addToShoppingCart(default_product, quantity=1) self.web_site.Resource_addToShoppingCart(default_product, quantity=1)
transaction.commit() transaction.commit()
self.tic() 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(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(1, len(self.web_site.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
...@@ -569,8 +569,8 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -569,8 +569,8 @@ class TestCommerce(ERP5TypeTestCase):
Test the SaleOrder_deleteShoppingCartItem script Test the SaleOrder_deleteShoppingCartItem script
""" """
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
self.portal.Resource_addToShoppingCart(default_product, quantity=1) self.web_site.Resource_addToShoppingCart(default_product, quantity=1)
self.assertEquals(1, len(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(1, len(self.web_site.SaleOrder_getShoppingCartItemList()))
# Trying to remove # Trying to remove
self.portal.SaleOrder_deleteShoppingCartItem() self.portal.SaleOrder_deleteShoppingCartItem()
...@@ -578,7 +578,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -578,7 +578,7 @@ class TestCommerce(ERP5TypeTestCase):
self.app.REQUEST.RESPONSE.getHeader('location')) self.app.REQUEST.RESPONSE.getHeader('location'))
# Check if the item still into the Shopping Cart # Check if the item still into the Shopping Cart
self.assertEquals(1, len(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(1, len(self.web_site.SaleOrder_getShoppingCartItemList()))
# Remove the product from the Shopping Cart # Remove the product from the Shopping Cart
product_id = default_product.getId() product_id = default_product.getId()
...@@ -591,21 +591,21 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -591,21 +591,21 @@ class TestCommerce(ERP5TypeTestCase):
self.app.REQUEST.RESPONSE.getHeader('location')) self.app.REQUEST.RESPONSE.getHeader('location'))
# Check if the Shopping Cart is empty # Check if the Shopping Cart is empty
self.assertEquals(0, len(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(0, len(self.web_site.SaleOrder_getShoppingCartItemList()))
def test_11_finalizeShopping(self): def test_11_finalizeShopping(self):
""" """
Test the SaleOrder_finalizeShopping script Test the SaleOrder_finalizeShopping script
""" """
self.changeUser('webmaster') self.changeUser('webmaster')
self.portal.Resource_addToShoppingCart(self.getDefaultProduct(), self.web_site.Resource_addToShoppingCart(self.getDefaultProduct(),
quantity=1) quantity=1)
self.portal.Resource_addToShoppingCart(self.getDefaultProduct('2'), self.web_site.Resource_addToShoppingCart(self.getDefaultProduct('2'),
quantity=1) quantity=1)
transaction.commit() transaction.commit()
self.tic() self.tic()
self.assertEquals(2, len(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(2, len(self.web_site.SaleOrder_getShoppingCartItemList()))
self.assertEquals(0, len(self.portal.sale_order_module.contentValues())) self.assertEquals(0, len(self.portal.sale_order_module.contentValues()))
self.web_site.SaleOrder_finalizeShopping() self.web_site.SaleOrder_finalizeShopping()
...@@ -615,7 +615,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -615,7 +615,7 @@ class TestCommerce(ERP5TypeTestCase):
sale_order_object_list = self.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(self.web_site.SaleOrder_getShoppingCartItemList()))
def test_12_getAvailableShippingResourceList(self): def test_12_getAvailableShippingResourceList(self):
""" """
...@@ -653,7 +653,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -653,7 +653,7 @@ class TestCommerce(ERP5TypeTestCase):
Test the SaleOrder_getSelectedShippingResource script Test the SaleOrder_getSelectedShippingResource script
""" """
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
shopping_cart = self.portal.SaleOrder_getShoppingCart() shopping_cart = self.portal.SaleOrder_getShoppingCart()
shipping_list = self.portal.SaleOrder_getAvailableShippingResourceList() shipping_list = self.portal.SaleOrder_getAvailableShippingResourceList()
...@@ -696,7 +696,9 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -696,7 +696,9 @@ class TestCommerce(ERP5TypeTestCase):
custom_skin.manage_addProduct['PythonScripts']\ custom_skin.manage_addProduct['PythonScripts']\
.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.portal.changeSkin('View') self.portal.changeSkin('View')
#1 initialise a website #1 initialise a website
...@@ -717,7 +719,8 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -717,7 +719,8 @@ class TestCommerce(ERP5TypeTestCase):
self.assertNotEquals(token, None) self.assertNotEquals(token, None)
#5 : 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')
#6 : paypal step 3 : check if this token is confirmed by paypal #6 : paypal step 3 : check if this token is confirmed by paypal
...@@ -726,7 +729,8 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -726,7 +729,8 @@ class TestCommerce(ERP5TypeTestCase):
self.assertTrue('/checkout' in request.RESPONSE.getHeader('location')) self.assertTrue('/checkout' in request.RESPONSE.getHeader('location'))
#7 : paypal step 4 : validate the payment #7 : paypal step 4 : validate the payment
self.assertEquals(1, len(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(1,
len(self.web_site.SaleOrder_getShoppingCartItemList()))
self.assertEquals(0, len(self.portal.sale_order_module.contentValues())) self.assertEquals(0, len(self.portal.sale_order_module.contentValues()))
self.web_site.WebSection_doPaypalPayment(token=token) self.web_site.WebSection_doPaypalPayment(token=token)
...@@ -734,7 +738,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -734,7 +738,7 @@ class TestCommerce(ERP5TypeTestCase):
self.tic() self.tic()
#8 check if sale order created #8 check if sale order created
self.assertEquals(0, len(self.portal.SaleOrder_getShoppingCartItemList())) self.assertEquals(0, len(self.web_site.SaleOrder_getShoppingCartItemList()))
self.assertEquals(1, len(self.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])
...@@ -769,7 +773,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -769,7 +773,7 @@ class TestCommerce(ERP5TypeTestCase):
blank shipping method and it will not break. blank shipping method and it will not break.
""" """
default_product = self.getDefaultProduct() default_product = self.getDefaultProduct()
self.portal.Resource_addToShoppingCart(default_product, 1) self.web_site.Resource_addToShoppingCart(default_product, 1)
shopping_cart = self.web_site.SaleOrder_getShoppingCart() shopping_cart = self.web_site.SaleOrder_getShoppingCart()
self.assertFalse(hasattr(shopping_cart, 'shipping_method')) self.assertFalse(hasattr(shopping_cart, 'shipping_method'))
...@@ -790,8 +794,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -790,8 +794,7 @@ class TestCommerce(ERP5TypeTestCase):
selecting a shipping method without price. selecting a shipping method without price.
""" """
default_product = self.getDefaultProduct(id='1') default_product = self.getDefaultProduct(id='1')
product = getattr(self.portal.product_module, default_product.getId()) self.web_site.Resource_addToShoppingCart(default_product, 1)
product.Resource_addToShoppingCart(default_product, 1)
shopping_cart = self.web_site.SaleOrder_getShoppingCart() shopping_cart = self.web_site.SaleOrder_getShoppingCart()
# add shipping # add shipping
...@@ -819,7 +822,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -819,7 +822,7 @@ class TestCommerce(ERP5TypeTestCase):
# anonymous user # anonymous user
self.logout() self.logout()
self.createShoppingCartWithProductListAndShipping() self.createShoppingCartWithProductListAndShipping()
shoppping_cart_item_list = self.portal.SaleOrder_getShoppingCartItemList() shoppping_cart_item_list = self.web_site.SaleOrder_getShoppingCartItemList()
self.assertEquals(1, len(shoppping_cart_item_list)) self.assertEquals(1, len(shoppping_cart_item_list))
def test_22_createShoppingCartWithAnonymousAndLogin(self): def test_22_createShoppingCartWithAnonymousAndLogin(self):
...@@ -923,7 +926,7 @@ class TestCommerce(ERP5TypeTestCase): ...@@ -923,7 +926,7 @@ class TestCommerce(ERP5TypeTestCase):
""" """
self.changeUser('webmaster') self.changeUser('webmaster')
comment = 'TESTING COMMENT' comment = 'TESTING COMMENT'
self.portal.Resource_addToShoppingCart(self.getDefaultProduct(), self.web_site.Resource_addToShoppingCart(self.getDefaultProduct(),
quantity=1) quantity=1)
self.web_site.SaleOrder_paymentRedirect(field_my_comment=comment) self.web_site.SaleOrder_paymentRedirect(field_my_comment=comment)
......
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