From 62f832b45de0dbe6710d17b44e82af56c768c9ff Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Wed, 2 Sep 2020 12:26:36 +0900
Subject: [PATCH] ZODB Components: erp5_authentication_policy: Migrate Unit
 Test.

---
 .../test.erp5.testAuthenticationPolicy.py     |   9 +-
 .../test.erp5.testAuthenticationPolicy.xml    | 110 ++++++++++++++++++
 .../bt/template_test_id_list                  |   1 +
 .../bt/test_dependency_list                   |   5 +
 4 files changed, 118 insertions(+), 7 deletions(-)
 rename product/ERP5/tests/testAuthenticationPolicy.py => bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.py (99%)
 create mode 100644 bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.xml
 create mode 100644 bt5/erp5_authentication_policy/bt/template_test_id_list
 create mode 100644 bt5/erp5_authentication_policy/bt/test_dependency_list

diff --git a/product/ERP5/tests/testAuthenticationPolicy.py b/bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.py
similarity index 99%
rename from product/ERP5/tests/testAuthenticationPolicy.py
rename to bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.py
index f4cdac8494..c740e5c8ae 100644
--- a/product/ERP5/tests/testAuthenticationPolicy.py
+++ b/bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.py
@@ -35,7 +35,6 @@ from StringIO import StringIO
 import time
 import httplib
 from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
-from Products.Formulator.Errors import ValidationError
 from Products.ERP5Type.Document import newTempBase
 
 class TestAuthenticationPolicy(ERP5TypeTestCase):
@@ -125,7 +124,6 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
     """
     if person_kw is None:
       person_kw = {}
-    self.createUser
     person = self.portal.person_module.newContent(
         portal_type='Person', **person_kw)
     login = person.newContent(portal_type='ERP5 Login',
@@ -284,7 +282,6 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
       Test validity of a password.
     """
     portal = self.getPortal()
-    request = self.app.REQUEST
 
     regular_expression_list = ['([a-z]+)', # english lowercase
                                '([A-Z]+)', # english uppercase
@@ -607,7 +604,6 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
       Test automatic system recover password
     """
     portal = self.portal
-    request = self.app.REQUEST
 
     self.assertTrue(portal.portal_preferences.isAuthenticationPolicyEnabled())
     preference = portal.portal_catalog.getResultValue(portal_type = 'System Preference',
@@ -635,7 +631,7 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
     )
     # User cannot login
     # fire 5 requests, only 1 credential recovery should be created
-    for i in range(5):
+    for _ in range(5):
       response = publish()
       self.assertTrue(response.getHeader("Location").endswith("login_form"))
     self.tic()
@@ -663,7 +659,6 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
       Check HTTP responses
     """
     portal = self.getPortal()
-    request = self.app.REQUEST
 
     preference = portal.portal_catalog.getResultValue(portal_type = 'System Preference',
                                                       title = 'Authentication',)
@@ -786,7 +781,7 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
       password='current',
       person_kw={'first_name': 'Alice'})
     person.newContent(portal_type = 'Assignment').open()
-    login = person.objectValues(portal_type='ERP5 Login')[0]
+    self.assertEqual(len(person.objectValues(portal_type='ERP5 Login')), 1)
     preference = self.portal.portal_catalog.getResultValue(
       portal_type='System Preference',
       title='Authentication',)
diff --git a/bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.xml b/bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.xml
new file mode 100644
index 0000000000..c85e4084e7
--- /dev/null
+++ b/bt5/erp5_authentication_policy/TestTemplateItem/portal_components/test.erp5.testAuthenticationPolicy.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="Test Component" module="erp5.portal_type"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>default_reference</string> </key>
+            <value> <string>testAuthenticationPolicy</string> </value>
+        </item>
+        <item>
+            <key> <string>default_source_reference</string> </key>
+            <value> <string>Products.ERP5.tests.testAuthenticationPolicy</string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>test.erp5.testAuthenticationPolicy</string> </value>
+        </item>
+        <item>
+            <key> <string>portal_type</string> </key>
+            <value> <string>Test Component</string> </value>
+        </item>
+        <item>
+            <key> <string>sid</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>text_content_error_message</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>text_content_warning_message</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>version</string> </key>
+            <value> <string>erp5</string> </value>
+        </item>
+        <item>
+            <key> <string>workflow_history</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <global name="PersistentMapping" module="Persistence.mapping"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>data</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>component_validation_workflow</string> </key>
+                    <value>
+                      <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
+                    </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="3" aka="AAAAAAAAAAM=">
+    <pickle>
+      <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_log</string> </key>
+            <value>
+              <list>
+                <dictionary>
+                  <item>
+                      <key> <string>action</string> </key>
+                      <value> <string>validate</string> </value>
+                  </item>
+                  <item>
+                      <key> <string>validation_state</string> </key>
+                      <value> <string>validated</string> </value>
+                  </item>
+                </dictionary>
+              </list>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_authentication_policy/bt/template_test_id_list b/bt5/erp5_authentication_policy/bt/template_test_id_list
new file mode 100644
index 0000000000..71c78466ed
--- /dev/null
+++ b/bt5/erp5_authentication_policy/bt/template_test_id_list
@@ -0,0 +1 @@
+test.erp5.testAuthenticationPolicy
\ No newline at end of file
diff --git a/bt5/erp5_authentication_policy/bt/test_dependency_list b/bt5/erp5_authentication_policy/bt/test_dependency_list
new file mode 100644
index 0000000000..46a775cadf
--- /dev/null
+++ b/bt5/erp5_authentication_policy/bt/test_dependency_list
@@ -0,0 +1,5 @@
+erp5_full_text_mroonga_catalog
+erp5_core_proxy_field_legacy
+erp5_base
+erp5_web
+erp5_crm
\ No newline at end of file
-- 
2.30.9