def _test_online_users(self, username1, username2): """ Tests the confirm_as_online, get_online_usernames and get_online_members methods """ portal = self.portal # First clear the UAD server = utils.getConnection(self.portal) server._v_user_access_dict = {} online_users = utils.get_online_usernames(portal) self.assertEquals(online_users, []) online_members = utils.get_online_members(portal) self.assertEquals(online_members, []) self.logout() resp = json.loads(server.confirmAsOnline(None)) self.assertEquals(resp['status'], config.ERROR) self.login(name=username1) server = utils.getConnection(self.portal) resp = json.loads(server.confirmAsOnline(username1)) self.assertEquals(resp['status'], config.SUCCESS) online_users = utils.get_online_usernames(portal) self.assertEquals(online_users, [username1]) # get_online_members ignores the currently logged in user. # So, if username1 is currently logged in and also online (according to # get_online_users), get_online_members will still return an empty # list. online_members = utils.get_online_members(portal) self.assertEquals(online_members, []) self.logout() self.login(name=username2) server = utils.getConnection(self.portal) resp = json.loads(server.confirmAsOnline(username2)) self.assertEquals(resp['status'], config.SUCCESS) online_users = utils.get_online_usernames(portal) online_users.sort() self.assertEquals(online_users, [username1, username2]) # Again, the logged in username2 is ignored member1 = self.mtool.getMemberById(username1) online_members = utils.get_online_members(portal) self.assertEquals(online_members, [member1]) self.logout() # Now the logged in username1 is ignored self.login(name=username1) member2 = self.mtool.getMemberById(username2) online_members = utils.get_online_members(portal) self.assertEquals(online_members, [member2])
def get_num_online_contacts(self): """ Return one less to exclude the current user """ return len(utils.get_online_usernames(self.context))