From 7fda8a0c57c5e23fff9f1dca4ac90855599e82d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 25 Jan 2008 17:47:49 +0000
Subject: [PATCH] update test for the new workflow

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18867 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/tests/testAccounting.py | 51 ++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 3 deletions(-)

diff --git a/product/ERP5/tests/testAccounting.py b/product/ERP5/tests/testAccounting.py
index 15ed042073..c9ed142f31 100644
--- a/product/ERP5/tests/testAccounting.py
+++ b/product/ERP5/tests/testAccounting.py
@@ -31,12 +31,16 @@
 """
 
 import unittest
+
+from Testing import ZopeTestCase
+from DateTime import DateTime
+from Products.CMFCore.utils import _checkPermission
+
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
 from Products.ERP5Type.tests.utils import reindex
 from Products.DCWorkflow.DCWorkflow import ValidationFailed
 from AccessControl.SecurityManagement import newSecurityManager
 from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
-from DateTime import DateTime
 
 SOURCE = 'source'
 DESTINATION = 'destination'
@@ -105,7 +109,7 @@ class AccountingTestCase(ERP5TypeTestCase):
   rather than modifying default documents. 
   """
   
-  username = 'username'
+  username = ZopeTestCase.user_name
 
   @reindex
   def _makeOne(self, portal_type='Accounting Transaction', lines=None,
@@ -143,7 +147,7 @@ class AccountingTestCase(ERP5TypeTestCase):
     return tr
 
 
-  def login(self):
+  def login(self, name=username):
     """login with Assignee, Assignor & Author roles."""
     uf = self.getPortal().acl_users
     uf._doAddUser(self.username, '', ['Assignee', 'Assignor', 'Author'], [])
@@ -461,6 +465,47 @@ class TestTransactionValidation(AccountingTestCase):
     self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
 
 
+  def test_AccountingWorkflow(self):
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               destination_section_value=self.organisation_module.client_1,
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           source_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           source_credit=500)))
+    
+    doActionFor = self.portal.portal_workflow.doActionFor
+    self.assertEquals('draft', transaction.getSimulationState())
+    self.assertTrue(_checkPermission('Modify portal content', transaction))
+                    
+    doActionFor(transaction, 'plan_action')
+    self.assertEquals('planned', transaction.getSimulationState())
+    self.assertTrue(_checkPermission('Modify portal content', transaction))
+
+    doActionFor(transaction, 'confirm_action')
+    self.assertEquals('confirmed', transaction.getSimulationState())
+    self.assertTrue(_checkPermission('Modify portal content', transaction))
+
+    doActionFor(transaction, 'stop_action')
+    self.assertEquals('stopped', transaction.getSimulationState())
+    self.assertFalse(_checkPermission('Modify portal content', transaction))
+    
+    doActionFor(transaction, 'restart_action')
+    self.assertEquals('started', transaction.getSimulationState())
+    self.assertTrue(_checkPermission('Modify portal content', transaction))
+
+    doActionFor(transaction, 'stop_action')
+    self.assertEquals('stopped', transaction.getSimulationState())
+    self.assertFalse(_checkPermission('Modify portal content', transaction))
+
+    doActionFor(transaction, 'deliver_action')
+    self.assertEquals('delivered', transaction.getSimulationState())
+    self.assertFalse(_checkPermission('Modify portal content', transaction))
+
+
 class TestClosingPeriod(AccountingTestCase):
   """Various tests for closing the period.
   """
-- 
2.30.9