From 25dbcfe920a911952dc8ede385b03704e0eca678 Mon Sep 17 00:00:00 2001
From: Sankar Ramalingam <sramling@redhat.com>
Date: Tue, 3 Jan 2017 19:28:13 +0530
Subject: [PATCH] Ticket 48050 - CI test - acctpolicy_plugin

Bug Description: Account policy plugin tests

Fix Description: pytest.raises-for-CONSTRAINT-VIOLATION and Fixed-docstrings

https://fedorahosted.org/389/ticket/48050

Reviewed by: ?
---
 .../tests/suites/acctpolicy_plugin/accpol_test.py  | 53 ++++++++++------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/dirsrvtests/tests/suites/acctpolicy_plugin/accpol_test.py b/dirsrvtests/tests/suites/acctpolicy_plugin/accpol_test.py
index bef6914..700e276 100644
--- a/dirsrvtests/tests/suites/acctpolicy_plugin/accpol_test.py
+++ b/dirsrvtests/tests/suites/acctpolicy_plugin/accpol_test.py
@@ -38,10 +38,10 @@ def accpolicy_local(topology_st):
         topology_st.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'specattrname', 'acctPolicySubentry')])
         topology_st.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'limitattrname', 'accountInactivityLimit')])
     except ldap.LDAPError as e:
-        log.error("Failed to modify account policy plugin attrs")
+        log.error('Failed to modify account policy plugin attrs')
         raise
 
-    log.info("Adding Local account policy plugin configuration entries")
+    log.info('Adding Local account policy plugin configuration entries')
     try:
         topology_st.standalone.add_s(Entry((LOCAL_CONFIG, {
             'objectclass': ['top', 'ldapsubentry', 'extensibleObject', 'accountpolicy'],
@@ -110,12 +110,9 @@ def account_status(topology_st, suffix, subtre, userid, nousrs, ulimit, tochck):
                 log.error('User {} is inactivated, expected 0 : error {}'.format(userdn, e.message['desc']))
                 raise
         elif(tochck == "Disabled"):
-            try:
+            with pytest.raises(ldap.CONSTRAINT_VIOLATION):
                 topology_st.standalone.simple_bind_s(userdn, USER_PW)
-            except ldap.LDAPError as e:
-                log.info('User {} is successfully inactivated : error {}'.format(userdn, e.message['desc']))
-            else:
-                raise Exception('User {} is not inactivated, expected error 19'.format(userdn))
+                log.error('User {} is not inactivated, expected error 19'.format(userdn))
         nousrs = nousrs - 1
 
 
@@ -128,11 +125,11 @@ def test_actNinact_local(topology_st, accpolicy_local):
             accountInactivityLimit set to 15, Inactivate account by Account policy plugin
 
     :Steps: 1. Configure account policy plugin with accpol_local for ou=people subtree
-	    2. Set accountInactivityLimit to 15
-	    3. Add few users to ou=people subtre in the default suffix
-	    4. Wait for 14 secs and run ldapsearch as normal user to check if its not inactivated, expected 0.
-	    5. Wait for 2 secs or till accountInactivityLimit is exceeded
-	    6. Run ldapsearch as normal user and check if its inactivated, expected error 19.
+            2. Set accountInactivityLimit to 15
+            3. Add few users to ou=people subtre in the default suffix
+            4. Wait for 14 secs and run ldapsearch as normal user to check if its not inactivated, expected 0.
+            5. Wait for 2 secs or till accountInactivityLimit is exceeded
+            6. Run ldapsearch as normal user and check if its inactivated, expected error 19.
             7. Sleep for +14 secs to check if accounts accessed at step4 are inactivated now
 
     :Assert: Should return error code 19
@@ -143,13 +140,13 @@ def test_actNinact_local(topology_st, accpolicy_local):
     userid = "inactusr"
     userpw = USER_PW
     nousrs = 3
-    log.info("AccountInactivityLimit set to 15. Account will be inactivated if not accessed in 15 secs")
+    log.info('AccountInactivityLimit set to 15. Account will be inactivated if not accessed in 15 secs')
     add_users(topology_st, suffix, subtre, userid, nousrs)
-    log.info("Sleeping for 14 secs to check account is not inactivated, expected value 0")
+    log.info('Sleeping for 14 secs to check account is not inactivated, expected value 0')
     time.sleep(14)
-    log.info("Account should not be inactivated since AccountInactivityLimit not exceeded")
+    log.info('Account should not be inactivated since AccountInactivityLimit not exceeded')
     account_status(topology_st, suffix, subtre, userid, 3, 2, "Enabled")
-    log.info("Sleeping for 2 more secs to check if account is inactivated")
+    log.info('Sleeping for 2 more secs to check if account is inactivated')
     time.sleep(2)
     account_status(topology_st, suffix, subtre, userid, 2, 0, "Disabled")
     log.info('Sleeping +14 secs to check if account {}3 is inactivated'.format(userid))
@@ -167,7 +164,7 @@ def test_noinact_local(topology_st, accpolicy_local):
             accountInactivityLimit set to 15, Inactivate account by Account policy plugin
 
     :Steps: 1. Add few users to ou=groups subtre in the default suffix, plugin configured to ou=people subtree only.
-	    2. Wait for 16 secs and run ldapsearch as normal user to check account is active, expected 0.
+            2. Wait for 16 secs and run ldapsearch as normal user to check account is active, expected 0.
             3. Move users from ou=groups to ou=people subtree
             4. Sleep for 16 secs and check if entries are inactivated
 
@@ -179,20 +176,20 @@ def test_noinact_local(topology_st, accpolicy_local):
     userid = "nolockusr"
     userpw = USER_PW
     nousrs = 1
-    log.info("Account should not be inactivated since the subtree is not configured")
+    log.info('Account should not be inactivated since the subtree is not configured')
     add_users(topology_st, suffix, subtre, userid, nousrs)
-    log.info("Sleeping for 16 secs to check if account is not inactivated, expected value 0")
+    log.info('Sleeping for 16 secs to check if account is not inactivated, expected value 0')
     time.sleep(16)
     account_status(topology_st, suffix, subtre, userid, nousrs, 0, "Enabled")
-    log.info("Moving users from ou=groups to ou=people subtree")
+    log.info('Moving users from ou=groups to ou=people subtree')
     try:
         topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
         topology_st.standalone.rename_s('uid=nolockusr1,ou=groups,dc=example,dc=com', 'uid=nolockusr1', 'ou=people,dc=example,dc=com')
     except ldap.LDAPError as e:
-        log.error("Failed to move user uid=nolockusr1 from ou=groups to ou=people")
+        log.error('Failed to move user uid=nolockusr1 from ou=groups to ou=people')
         raise
     subtre="ou=people"
-    log.info("Then wait for 16 and check if entries are inactivated")
+    log.info('Then wait for 16 secs and check if entries are inactivated')
     time.sleep(16)
     account_status(topology_st, suffix, subtre, userid, nousrs, 0, "Disabled")
     del_users(topology_st, suffix, subtre, userid, nousrs)
@@ -207,7 +204,7 @@ def test_inact_local(topology_st, accpolicy_local):
             accountInactivityLimit set to 15, Inactivate account by Account policy plugin
 
     :Steps: 1. Add few users to ou=people subtre in the default suffix
-	    2. Wait for 14 secs and run ldapsearch as normal user to check if its not inactivated, expected 0.
+            2. Wait for 14 secs and run ldapsearch as normal user to check if its not inactivated, expected 0.
             3. Move users from ou=people to ou=groups subtree
             4. Sleep for +2 secs and check if users are inactivated in ou=people subtree
             5. Check if users are not inactivated in ou=groups subtree
@@ -220,19 +217,19 @@ def test_inact_local(topology_st, accpolicy_local):
     userid = "lockusr"
     userpw = USER_PW
     nousrs = 1
-    log.info("Account should be inactivated since the subtree is configured")
+    log.info('Account should be inactivated since the subtree is configured')
     add_users(topology_st, suffix, subtre, userid, nousrs)
-    log.info("Sleeping for 16 secs to check if account is inactivated, expected value 19")
+    log.info('Sleeping for 16 secs to check if account is inactivated, expected value 19')
     time.sleep(14)
     account_status(topology_st, suffix, subtre, userid, nousrs, 0, "Enabled")
-    log.info("Moving users from ou=people to ou=groups subtree")
+    log.info('Moving users from ou=people to ou=groups subtree')
     try:
         topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
         topology_st.standalone.rename_s('uid=lockusr1,ou=people,dc=example,dc=com', 'uid=lockusr1', 'ou=groups,dc=example,dc=com')
     except ldap.LDAPError as e:
-        log.error("Failed to move user uid=lockusr1 from ou=groups to ou=people")
+        log.error('Failed to move user uid=lockusr1 from ou=groups to ou=people')
         raise
-    log.info("Sleep for +2 secs and check users from both ou=people and ou=groups subtree")
+    log.info('Sleep for +2 secs and check users from both ou=people and ou=groups subtree')
     time.sleep(2)
     subtre="ou=groups"
     account_status(topology_st, suffix, subtre, userid, 1, 0, "Enabled")
-- 
2.7.4

