From 2c557347941aa7e67cb86d4fcd4845b3fe227878 Mon Sep 17 00:00:00 2001
From: Ivan Tyagov <ivan@nexedi.com>
Date: Mon, 18 Jul 2011 16:14:04 +0300
Subject: [PATCH] Test calculation of early password expiration warning.

---
 .../ERP5/tests/testAuthenticationPolicy.py    | 25 +++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/tests/testAuthenticationPolicy.py b/product/ERP5/tests/testAuthenticationPolicy.py
index a1b15b4477..f3fbfd9e3b 100644
--- a/product/ERP5/tests/testAuthenticationPolicy.py
+++ b/product/ERP5/tests/testAuthenticationPolicy.py
@@ -376,6 +376,8 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
       Test password expire.
     """
     portal = self.getPortal()
+    request = self.app.REQUEST
+    
     self.assertTrue(portal.ERP5Site_isAuthenticationPolicyEnabled())
     
     person = portal.portal_catalog.getResultValue(portal_type = 'Person', 
@@ -387,6 +389,7 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
     self.stepTic()
     self._clearCache()
     self.assertFalse(person.isPasswordExpired())
+    self.assertFalse(request['is_user_account_password_expired'])
     
     # set older last password modification date just for test
     now = DateTime()
@@ -394,12 +397,30 @@ class TestAuthenticationPolicy(ERP5TypeTestCase):
     self.stepTic()
     self._clearCache()
     self.assertTrue(person.isPasswordExpired())
+    self.assertTrue(request['is_user_account_password_expired'])    
     
     # set longer password validity interval
-    preference.setPreferredMaxPasswordLifetimeDuration(4*24)
+    person.setLastPasswordModificationDate(now)
+    preference.setPreferredMaxPasswordLifetimeDuration(4*24) # password expire in 4 days
+    self.stepTic()
+    self._clearCache()
+    self.assertFalse(person.isPasswordExpired())
+    self.assertFalse(request['is_user_account_password_expired'])
+    
+    # test early warning password expire notification is detected
+    preference.setPreferredPasswordLifetimeExpireWarningDuration(4*24) # password expire notification appear immediately
     self.stepTic()
     self._clearCache()
-    self.assertFalse(person.isPasswordExpired())    
+    self.assertFalse(person.isPasswordExpired())
+    self.assertTrue(request['is_user_account_password_expired_warning_on'])
+    
+    # test early warning password expire notification is detected
+    preference.setPreferredPasswordLifetimeExpireWarningDuration(4*24-24) # password expire notification appear 3 days befor time
+    self.stepTic()
+    self._clearCache()
+    self.assertFalse(person.isPasswordExpired())
+    #import pdb; pdb.set_trace()
+    self.assertFalse(request['is_user_account_password_expired_warning_on']) 
             
     
 def test_suite():
-- 
2.30.9