From 37f7b8e6d3434669cc371dd136839072cfc8ba19 Mon Sep 17 00:00:00 2001
From: Yusei Tahara <yusei@nexedi.com>
Date: Fri, 16 Jan 2009 04:32:31 +0000
Subject: [PATCH] Added a test with negative price order line.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25141 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/tests/testOrder.py | 56 ++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/product/ERP5/tests/testOrder.py b/product/ERP5/tests/testOrder.py
index 4a90d17d27..c8eaf836d0 100644
--- a/product/ERP5/tests/testOrder.py
+++ b/product/ERP5/tests/testOrder.py
@@ -42,6 +42,7 @@ class TestOrderMixin:
 
   default_quantity = 99
   default_price = 555
+  default_negative_price = -5550
   resource_portal_type = 'Apparel Model'
   order_portal_type = 'Sale Order'
   order_line_portal_type = 'Sale Order Line'
@@ -103,7 +104,7 @@ class TestOrderMixin:
                                                  portal_type='Category',
                                                  id=category_id)
 
-    product_line_category_list = ['apparel', ]
+    product_line_category_list = ['apparel', 'cancel']
     if len(category_tool.product_line.contentValues()) == 0:
       for category_id in product_line_category_list:
         o = category_tool.product_line.newContent(
@@ -132,6 +133,23 @@ class TestOrderMixin:
     resource_list.append(resource)
     sequence.edit( resource_list = resource_list )
 
+  def stepCreateNotVariatedResourceForNegativePriceOrderLine(self, sequence=None, sequence_list=None, **kw):
+    """
+      Create a resource with no variation for negative price order line.
+    """
+    portal = self.getPortal()
+    resource_module = portal.getDefaultModule(self.resource_portal_type)
+    resource = resource_module.newContent(portal_type=self.resource_portal_type)
+    resource.edit(
+      title = "NotVariatedResourceForNegativePriceOrderLine%s" % resource.getId(),
+      product_line = 'cancel'
+    )
+
+    sequence.edit( resource = resource )
+    resource_list = sequence.get('resource_list',default=[])
+    resource_list.append(resource)
+    sequence.edit( resource_list = resource_list )
+
   def stepCreateVariatedResource(self, sequence=None, sequence_list=None, \
                                  **kw):
     """
@@ -435,6 +453,15 @@ class TestOrderMixin:
     order_line.edit(quantity=self.default_quantity,
                     price=self.default_price)
 
+  def stepSetOrderLineDefaultNegativePriceValue(self, sequence=None, \
+                                           sequence_list=None, **kw):
+    """
+      Set the default negative price and 1 to quantity on the order line.
+    """
+    order_line = sequence.get('order_line')
+    order_line.edit(quantity=1,
+                    price=self.default_negative_price)
+
   def stepCheckOrderLineDefaultValues(self, sequence=None, \
                                     sequence_list=None, **kw):
     """
@@ -1390,6 +1417,33 @@ class TestOrder(TestOrderMixin, ERP5TypeTestCase):
     sequence_list.addSequenceString(sequence_string)
     sequence_list.play(self)
 
+  def test_09b_Order_testTotalPriceWithNegativePriceOrderLine(self, quiet=0, run=run_all_test):
+    """
+      Test method getTotalPrice on a order
+    """
+    if not run: return
+    sequence_list = SequenceList()
+    # Test with positive price order line and negative price order line.
+    sequence_string = '\
+                      stepCreateOrder \
+                      stepCheckOrderTotalQuantity \
+                      stepCreateNotVariatedResource \
+                      stepCreateOrderLine \
+                      stepTic \
+                      stepSetOrderLineResource \
+                      stepSetOrderLineDefaultValues \
+                      stepTic \
+                      stepCreateNotVariatedResourceForNegativePriceOrderLine \
+                      stepCreateOrderLine \
+                      stepTic \
+                      stepSetOrderLineResource \
+                      stepSetOrderLineDefaultNegativePriceValue \
+                      stepTic \
+                      stepCheckOrderTotalPrice \
+                      '
+    sequence_list.addSequenceString(sequence_string)
+    sequence_list.play(self)
+
   def test_10_Order_testSimulationState(self, quiet=0, run=run_all_test):
     """
       Test simulation state acquisition on Order
-- 
2.30.9