def test_current_user(self): """ Makes sure the current user is saved appropriately for a given host. """ host = "https://host.shotgunstudio.com" # Use mixed case to make sure we are case preserving user = "******" # Write the current user for a host and makes sure we get it back. session_cache.set_current_user(host, user) self.assertEqual(session_cache.get_current_user(host), user) # Write the current user for a second host and make sure we get it # back. Also make sure we are not updating the other host for some # reason. other_host = "https://other_host.shotgunstudio.com" other_user = "******" session_cache.set_current_user(other_host, other_user) self.assertEqual(session_cache.get_current_user(other_host), other_user) self.assertEqual(session_cache.get_current_user(host), user)
def test_recent_users(self): """ Makes sure the recent hosts list is keep up to date. """ HOST = "https://host.shotgunstudio.com" LOGIN_A = "login_a" LOGIN_B = "login_b" self._clear_site_yml(HOST) # Make sure the recent hosts is initially empty. self.assertEqual(session_cache.get_recent_users(HOST), []) # Set HOST_A as the current host. session_cache.set_current_user(HOST, LOGIN_A) self.assertEqual(session_cache.get_recent_users(HOST), [LOGIN_A]) self.assertEqual(session_cache.get_current_user(HOST), LOGIN_A) # Then set HOST_B as the new current host. session_cache.set_current_user(HOST, LOGIN_B) self.assertEqual(session_cache.get_recent_users(HOST), [LOGIN_B, LOGIN_A]) self.assertEqual(session_cache.get_current_user(HOST), LOGIN_B) # Now set back HOST_A as the current host. It should now be the most recent. session_cache.set_current_user(HOST, LOGIN_A) self.assertEqual(session_cache.get_recent_users(HOST), [LOGIN_A, LOGIN_B]) self.assertEqual(session_cache.get_current_user(HOST), LOGIN_A) # Update the cache 10 times. n_users = ["login-%d" % i for i in range(10)] for user in n_users: session_cache.set_current_user(HOST, user) # We should now have users 9 down to 2 in the most recent list. most_recents = ["login-%d" % i for i in range(9, 1, -1)] self.assertEqual(session_cache.get_recent_users(HOST), most_recents)