def test_recent_hosts(self):
        """
        Makes sure the recent hosts list is keep up to date.
        """
        HOST_A = "https://host-a.shotgunstudio.com"
        HOST_B = "https://host-b.shotgunstudio.com"

        # Make sure the recent hosts is initially empty.
        self.assertEqual(session_cache.get_recent_hosts(), [])

        # Set HOST_A as the current host.
        session_cache.set_current_host(HOST_A)
        self.assertEqual(session_cache.get_recent_hosts(), [HOST_A])
        self.assertEqual(session_cache.get_current_host(), HOST_A)

        # Then set HOST_B as the new current host.
        session_cache.set_current_host(HOST_B)
        self.assertEqual(session_cache.get_recent_hosts(), [HOST_B, HOST_A])
        self.assertEqual(session_cache.get_current_host(), HOST_B)

        # Now set back HOST_A as the current host. It should now be the most recent.
        session_cache.set_current_host(HOST_A)
        self.assertEqual(session_cache.get_recent_hosts(), [HOST_A, HOST_B])
        self.assertEqual(session_cache.get_current_host(), HOST_A)

        # Update the cache 10 times.
        n_hosts = ["https://host-%d.shotgunstudio.com" % i for i in range(10)]
        for host in n_hosts:
            session_cache.set_current_host(host)

        # We should now have hosts 9 down to 2 in the most recent list.
        most_recents = ["https://host-%d.shotgunstudio.com" % i for i in range(9, 1, -1)]

        self.assertEqual(session_cache.get_recent_hosts(), most_recents)
    def test_recent_hosts_upgrade(self):
        """
        Ensures that if we've just upgraded to the latest core that the current
        host is part of the recent hosts.
        """
        # The recent_users array is not present in the authentication.yml
        # file, so make sure that the session cache reports the user as the
        # most recent.
        self._write_global_yml(
            {"current_host": "https://host.shotgunstudio.com"})

        self.assertEqual(session_cache.get_recent_hosts(),
                         ["https://host.shotgunstudio.com"])
    def test_recent_hosts(self):
        """
        Makes sure the recent hosts list is keep up to date.
        """
        HOST_A = "https://host-a.shotgunstudio.com"
        HOST_B = "https://host-b.shotgunstudio.com"

        # Make sure the recent hosts is initially empty.
        self.assertEqual(session_cache.get_recent_hosts(), [])

        # Set HOST_A as the current host.
        session_cache.set_current_host(HOST_A)
        self.assertEqual(session_cache.get_recent_hosts(), [HOST_A])
        self.assertEqual(session_cache.get_current_host(), HOST_A)

        # Then set HOST_B as the new current host.
        session_cache.set_current_host(HOST_B)
        self.assertEqual(session_cache.get_recent_hosts(), [HOST_B, HOST_A])
        self.assertEqual(session_cache.get_current_host(), HOST_B)

        # Now set back HOST_A as the current host. It should now be the most recent.
        session_cache.set_current_host(HOST_A)
        self.assertEqual(session_cache.get_recent_hosts(), [HOST_A, HOST_B])
        self.assertEqual(session_cache.get_current_host(), HOST_A)

        # Update the cache 10 times.
        n_hosts = ["https://host-%d.shotgunstudio.com" % i for i in range(10)]
        for host in n_hosts:
            session_cache.set_current_host(host)

        # We should now have hosts 9 down to 2 in the most recent list.
        most_recents = [
            "https://host-%d.shotgunstudio.com" % i for i in range(9, 1, -1)
        ]

        self.assertEqual(session_cache.get_recent_hosts(), most_recents)
    def test_recent_hosts_upgrade(self):
        """
        Ensures that if we've just upgraded to the latest core that the current
        host is part of the recent hosts.
        """
        # The recent_users array is not present in the authentication.yml
        # file, so make sure that the session cache reports the user as the
        # most recent.
        self._write_global_yml(
            {"current_host": "https://host.shotgunstudio.com"}
        )

        self.assertEqual(
            session_cache.get_recent_hosts(),
            ["https://host.shotgunstudio.com"]
        )
    def test_recent_hosts_downgrade(self):
        """
        Ensures that if an older core updated the authentication file, which means
        recent_hosts has not been kept up to date, that the recent hosts list
        has the current_host at the front.
        """
        self._write_global_yml(
            {"current_host": "https://current.shotgunstudio.com",
             "recent_hosts": ["https://older.shotgunstudio.com", "https://current.shotgunstudio.com"]}
        )

        self.assertEqual(
            session_cache.get_recent_hosts(), [
                "https://current.shotgunstudio.com",
                "https://older.shotgunstudio.com"
            ]
        )
    def test_recent_hosts_downgrade(self):
        """
        Ensures that if an older core updated the authentication file, which means
        recent_hosts has not been kept up to date, that the recent hosts list
        has the current_host at the front.
        """
        self._write_global_yml({
            "current_host":
            "https://current.shotgunstudio.com",
            "recent_hosts": [
                "https://older.shotgunstudio.com",
                "https://current.shotgunstudio.com"
            ]
        })

        self.assertEqual(session_cache.get_recent_hosts(), [
            "https://current.shotgunstudio.com",
            "https://older.shotgunstudio.com"
        ])