Do not need to check if user has existing session 83/53283/1
authorthuva4 <tharma.thuva@gmail.com>
Thu, 8 Mar 2018 08:26:20 +0000 (13:56 +0530)
committerthuva4 <tharma.thuva@gmail.com>
Thu, 8 Mar 2018 08:26:20 +0000 (13:56 +0530)
We are currently checking no matter user has a session
or not.Fix it.
Current implemetation don't allow user to use existing
session. Fix it.

Change-Id: I5c1bf2bf9b3475f4723d7e136a60effd4287199d
Signed-off-by: thuva4 <tharma.thuva@gmail.com>
testapi/testapi-client/testapiclient/identity.py

index 03b3ac5..f38d8e1 100644 (file)
@@ -17,19 +17,21 @@ def _authenticate(username, password):
         'form_id': 'user_login'
     }
     response = session.post(hostname, data)
-    user.User.session = session
+    if "login" not in response.text:
+        user.User.session = session
     return response
 
 
 def authenticate(xstep):
     @functools.wraps(xstep)
     def wrapper(self, parsed_args):
-        username = parsed_args.u
-        password = parsed_args.p
-        if(username and password):
-            response = _authenticate(username, password)
-            if "login" in response.text:
-                print "Authentication has failed."
-            else:
-                xstep(self, parsed_args)
+        if(user.User.session is None):
+            username = parsed_args.u
+            password = parsed_args.p
+            if(username and password):
+                response = _authenticate(username, password)
+                if "login" in response.text:
+                    print "Authentication has failed."
+                    return
+        xstep(self, parsed_args)
     return wrapper