def test_session_cache(self):
        """
        Makes sure that the user enabled sessions are stored properly.
        """

        # Make sure we stored the session token.
        host = "https://host.shotgunstudio.com"
        session_cache.cache_session_data(
            host,
            "bob",
            "bob_session_token",
            "bob_session_metadata"
        )
        self.assertEqual(
            session_cache.get_session_data(host, "bob")["session_token"], "bob_session_token"
        )
        self.assertEqual(
            session_cache.get_session_data(host, "bob")["session_metadata"], "bob_session_metadata"
        )

        # Make sure we can store a second one.
        session_cache.cache_session_data(
            host,
            "alice",
            "alice_session_token",
            "alice_session_metadata"
        )
        # We can see the old one
        self.assertEqual(
            session_cache.get_session_data(host, "bob")["session_token"], "bob_session_token"
        )
        self.assertEqual(
            session_cache.get_session_data(host, "bob")["session_metadata"], "bob_session_metadata"
        )
        # check for the new one
        self.assertEqual(
            session_cache.get_session_data(host, "alice")["session_token"], "alice_session_token"
        )
        self.assertEqual(
            session_cache.get_session_data(host, "alice")["session_metadata"], "alice_session_metadata"
        )

        session_cache.delete_session_data(host, "bob")

        self.assertEqual(session_cache.get_session_data(host, "bob"), None)
        self.assertEqual(
            session_cache.get_session_data(host, "alice")["session_token"], "alice_session_token"
        )
        self.assertEqual(
            session_cache.get_session_data(host, "alice")["session_metadata"], "alice_session_metadata"
        )
    def test_host_case_insensitivity(self):
        """
        Make sure that the host name case doesn't impact the cache.
        """
        lowercase_host = "https://host.shotgunstudio.com"
        uppercase_host = lowercase_host.upper()

        user = "bob"
        session_token = "123"
        session_data = {
            "login": user,
            "session_token": session_token
        }

        # Store using lower case
        session_cache.cache_session_data(
            lowercase_host,
            user,
            session_token
        )

        # Same inputs should resolve the token.
        self.assertEqual(
            session_cache.get_session_data(lowercase_host, user),
            session_data
        )

        # upper case user should still recover the session token.
        self.assertEqual(
            session_cache.get_session_data(uppercase_host, user),
            session_data
        )

        # Deleting with the upper case user should also work.
        session_cache.delete_session_data(uppercase_host, user)

        # Should not be able to resolve the user, with any case
        self.assertIsNone(
            session_cache.get_session_data(uppercase_host, user)
        )
        self.assertIsNone(
            session_cache.get_session_data(lowercase_host, user),
        )
    def test_login_case_insensitivity(self):
        """
        Make sure that the login name comparison in the session cache is case insensitive.
        """
        host = "https://case_insensitive.shotgunstudio.com"
        lowercase_bob = "bob"
        uppercase_bob = "BOB"
        session_token = "123"
        session_data = {
            "login": lowercase_bob,
            "session_token": session_token
        }

        # Store using lower
        session_cache.cache_session_data(
            host,
            lowercase_bob,
            session_token
        )

        # Same inputs should resolve the token.
        self.assertEqual(
            session_cache.get_session_data(host, lowercase_bob),
            session_data
        )

        # upper case user should still recover the session token.
        self.assertEqual(
            session_cache.get_session_data(host, uppercase_bob),
            session_data
        )

        # Deleting with the upper case user should also work.
        session_cache.delete_session_data(host, uppercase_bob)

        # Should not be able to resolve the user, with any case
        self.assertIsNone(
            session_cache.get_session_data(host, uppercase_bob)
        )
        self.assertIsNone(
            session_cache.get_session_data(host, lowercase_bob),
        )