From 578791764f90ffcbabdb4131c14168c39b6aa7f9 Mon Sep 17 00:00:00 2001
From: Rafael Monnerat <rafael@nexedi.com>
Date: Fri, 25 May 2012 02:52:05 -0300
Subject: [PATCH] Update setUp/TearDown for Product Tutorial Funcional Test

It creates and drop currency for the Functional Test related to the
tutorial: user-Howto.Create.and.Manage.Products-HTML5

It defines append preference variation "variation" if it is not present
already at the default system preference. If this test runs after
the Configurator this change is ignored.
---
 .../Zuite_getHowToInfo.xml                    |  2 ++
 .../Zuite_setUpProductTest.xml                | 26 +++++++++++++++++--
 .../Zuite_tearDownProductTest.xml             |  9 +++++++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_getHowToInfo.xml b/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_getHowToInfo.xml
index b95c4400cb..2d1950c3bb 100644
--- a/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_getHowToInfo.xml
+++ b/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_getHowToInfo.xml
@@ -85,6 +85,8 @@ return {\'now\': DateTime(),\n
         \'link_howto_organisation2_title\': \'ZUITE-TEST-LINK-ORGANISATION-002\',\n
         \'product_howto_product_title\': \'ZUITE-TEST-PRODUCT-PRODUCT-001\',\n
         \'product_howto_organisation_title\': \'ZUITE-TEST-PRODUCT-ORGANISATION-001\',\n
+        \'product_howto_currency_title\': \'Euro\',\n
+        \'product_howto_currency_tag\': \'EUR\',\n
         \'sale_howto_product_title\': \'ZUITE-TEST-SALEORDER-PRODUCT-001\',\n
         \'sale_howto_organisation_title\': \'ZUITE-TEST-SALEORDER-ORGANISATION-001\',\n
         \'sale_howto_organisation2_title\': \'ZUITE-TEST-SALEORDER-ORGANISATION-002\',\n
diff --git a/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_setUpProductTest.xml b/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_setUpProductTest.xml
index 3e00a11704..9ef26ccf7c 100644
--- a/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_setUpProductTest.xml
+++ b/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_setUpProductTest.xml
@@ -53,12 +53,34 @@
             <value> <string>if clean:\n
   context.Zuite_tearDownProductTest()\n
 \n
+howto_dict = context.Zuite_getHowToInfo()\n
 portal = context.getPortalObject()\n
+isTransitionPossible = portal.portal_workflow.isTransitionPossible\n
+\n
+system_preference = portal.portal_preferences.getActiveSystemPreference()\n
+base_category_list = system_preference.getPreferredProductIndividualVariationBaseCategoryList()\n
+if \'variation\' not in base_category_list:\n
+  base_category_list.append(\'variation\')\n
+  system_preference.setPreferredProductIndividualVariationBaseCategoryList(base_category_list)\n
+\n
+# check if there is already the euro curency on the instance\n
+currency = context.portal_catalog.getResultValue(portal_type=\'Currency\',\n
+                                                 title=howto_dict[\'product_howto_currency_title\'])\n
+if currency is None:\n
+  currency = portal.currency_module.newContent(portal_type=\'Currency\',\n
+                                               title=howto_dict[\'product_howto_currency_title\'],\n
+                                               reference=howto_dict[\'product_howto_currency_tag\'],\n
+                                               id=howto_dict[\'product_howto_currency_tag\'],\n
+                                               base_unit_quantity=0.01)\n
+\n
+if isTransitionPossible(currency, \'validate\'):\n
+  currency.validate()\n
+\n
 \n
 organisation = portal.organisation_module.newContent(\n
                  portal_type=\'Organisation\',\n
-                 title=context.Zuite_getHowToInfo()[\'product_howto_organisation_title\'],\n
-                 corporate_name=context.Zuite_getHowToInfo()[\'product_howto_organisation_title\'])\n
+                 title=howto_dict[\'product_howto_organisation_title\'],\n
+                 corporate_name=howto_dict[\'product_howto_organisation_title\'])\n
 organisation.validate()\n
 \n
 portal.portal_caches.clearAllCache()\n
diff --git a/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_tearDownProductTest.xml b/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_tearDownProductTest.xml
index 3915779d1f..917b25fc32 100644
--- a/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_tearDownProductTest.xml
+++ b/bt5/erp5_user_tutorial_ui_test/SkinTemplateItem/portal_skins/erp5_user_tutorial_ui_test/Zuite_tearDownProductTest.xml
@@ -52,6 +52,15 @@
             <key> <string>_body</string> </key>
             <value> <string>portal = context.getPortalObject()\n
 \n
+howto_dict = context.Zuite_getHowToInfo()\n
+\n
+# remove the currency if it was created by us before\n
+currency = context.portal_catalog.getResultValue(portal_type=\'Currency\',\n
+                                                 title=howto_dict[\'product_howto_currency_title\'],\n
+                                                 local_roles = \'Owner\')\n
+if currency is not None:\n
+  context.currency_module.deleteContent(currency.getId())\n
+\n
 # remove the product of the test if existing\n
 product_list = context.Zuite_checkPortalCatalog(portal_type=\'Product\', max_count=1,\n
                                                 title=context.Zuite_getHowToInfo()[\'product_howto_product_title\'])\n
-- 
2.30.9