Browse Source

HUE-112. Correctly register 'last access time'. Add test for 'last access time'.

vinithra 15 years ago
parent
commit
e70732efbf
2 changed files with 25 additions and 3 deletions
  1. 4 3
      desktop/core/src/desktop/log/access.py
  2. 21 0
      desktop/core/src/desktop/tests.py

+ 4 - 3
desktop/core/src/desktop/log/access.py

@@ -101,9 +101,6 @@ class AccessInfo(dict):
         app_dict = { }
         app_dict = { }
         _per_user_lk[user] = threading.Lock()
         _per_user_lk[user] = threading.Lock()
         recent_access_map[user] = app_dict
         recent_access_map[user] = app_dict
-        # Update the IP address and last access time of the user
-        last_access_map[user] = {'ip':self['remote_ip'],
-                                 'time':self['time']}
       finally:
       finally:
         _recent_access_map_lk.release()
         _recent_access_map_lk.release()
 
 
@@ -128,6 +125,10 @@ class AccessInfo(dict):
       view_access_list.insert(0, self)
       view_access_list.insert(0, self)
       if len(view_access_list) > _USER_ACCESS_HISTORY_SIZE:
       if len(view_access_list) > _USER_ACCESS_HISTORY_SIZE:
         view_access_list.pop()
         view_access_list.pop()
+
+      # Update the IP address and last access time of the user
+      last_access_map[user] = {'ip':self['remote_ip'],
+                               'time':self['time']}
     finally:
     finally:
       user_lk.release()
       user_lk.release()
 
 

+ 21 - 0
desktop/core/src/desktop/tests.py

@@ -26,6 +26,7 @@ import desktop
 import desktop.urls
 import desktop.urls
 import desktop.conf
 import desktop.conf
 import logging
 import logging
+import time
 from desktop.lib.django_util import TruncatingModel
 from desktop.lib.django_util import TruncatingModel
 import desktop.views as views
 import desktop.views as views
 
 
@@ -301,3 +302,23 @@ def test_config_check():
   finally:
   finally:
     for old_conf in reset:
     for old_conf in reset:
       old_conf()
       old_conf()
+
+
+def test_last_access_time():
+  c = make_logged_in_client(username="access_test")
+  c.post('/accounts/login_ajax')
+  login = desktop.auth.views.get_current_users()
+  before_access_time = time.time()
+  response = c.post('/status_bar')
+  after_access_time = time.time()
+  access = desktop.auth.views.get_current_users()
+
+  user = response.context['user']
+  login_time = login[user]['time']
+  access_time = access[user]['time']
+
+  # Check that 'last_access_time' is later than login time
+  assert_true(login_time < access_time)
+  # Check that 'last_access_time' is in between the timestamps before and after the last access path
+  assert_true(before_access_time < access_time)
+  assert_true(access_time < after_access_time)