예제 #1
0
    def test_url_cleanup(self):

        # Make sure that if a file has the url saved incorrectly...
        with patch("sgtk.util.shotgun.connection.sanitize_url", wraps=lambda x: x):
            session_cache.set_current_host("https://host.cleaned.up.on.read/")
            # ... then sure we indeed disabled cleanup and that the malformed value was written to disk...
            self.assertEquals("https://host.cleaned.up.on.read/", session_cache.get_current_host())

        # ... and finaly that the value is filtered when being read back from disk.
        self.assertEquals("https://host.cleaned.up.on.read", session_cache.get_current_host())

        # Make sure we're cleaning up the hostname when saving it.
        session_cache.set_current_host("https://host.cleaned.up.on.write/")

        with open(
            os.path.join(
                LocalFileStorageManager.get_global_root(
                    LocalFileStorageManager.CACHE
                ),
                "authentication.yml"
            ),
            "r"
        ) as fh:
            # Let's read the file directly to see if the data was cleaned up.
            data = yaml.load(fh)
            self.assertEqual(
                data["current_host"],
                "https://host.cleaned.up.on.write"
            )
예제 #2
0
    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_url_cleanup(self):

        # Make sure that if a file has the url saved incorrectly...
        with patch("sgtk.util.shotgun.connection.sanitize_url",
                   wraps=lambda x: x):
            session_cache.set_current_host("https://host.cleaned.up.on.read/")
            # ... then sure we indeed disabled cleanup and that the malformed value was written to disk...
            self.assertEquals("https://host.cleaned.up.on.read/",
                              session_cache.get_current_host())

        # ... and finaly that the value is filtered when being read back from disk.
        self.assertEquals("https://host.cleaned.up.on.read",
                          session_cache.get_current_host())

        # Make sure we're cleaning up the hostname when saving it.
        session_cache.set_current_host("https://host.cleaned.up.on.write/")

        with open(
                os.path.join(
                    LocalFileStorageManager.get_global_root(
                        LocalFileStorageManager.CACHE), "authentication.yml"),
                "r") as fh:
            # Let's read the file directly to see if the data was cleaned up.
            data = yaml.load(fh)
            self.assertEqual(data["current_host"],
                             "https://host.cleaned.up.on.write")
예제 #4
0
    def test_current_host(self):
        """
        Makes sure current host is saved appropriately.
        """
        # Write the host and make sure we read it back.
        # Use mixed case to make sure we are case preserving
        host = "https://hOsT.shotgunstudio.com"
        session_cache.set_current_host(host)
        self.assertEqual(session_cache.get_current_host(), host)

        # Update the host and make sure we read it back.
        other_host = "https://other_host.shotgunstudio.com"
        session_cache.set_current_host(other_host)
        self.assertEqual(session_cache.get_current_host(), other_host)
예제 #5
0
    def test_current_host(self):
        """
        Makes sure current host is saved appropriately.
        """
        # Write the host and make sure we read it back.
        # Use mixed case to make sure we are case preserving
        host = "https://hOsT.shotgunstudio.com"
        session_cache.set_current_host(host)
        self.assertEqual(session_cache.get_current_host(), host)

        # Update the host and make sure we read it back.
        other_host = "https://other_host.shotgunstudio.com"
        session_cache.set_current_host(other_host)
        self.assertEqual(session_cache.get_current_host(), other_host)
예제 #6
0
    def test_current_host(self):
        """
        Makes sure current host is saved appropriately.
        """
        # Write the host and make sure we read it back.
        #
        # Use mixed case to make sure we are not case preserving. If we did,
        # as we used to, we would run into problems with some site url
        # comparisons incorrectly determining that hOsT.shotgunstudio.com
        # isn't the same site as host.shotgunstudio.com.
        host = "https://hOsT.shotgunstudio.com"
        session_cache.set_current_host(host)
        self.assertEqual(session_cache.get_current_host(), host.lower())

        # Update the host and make sure we read it back.
        other_host = "https://other_host.shotgunstudio.com"
        session_cache.set_current_host(other_host)
        self.assertEqual(session_cache.get_current_host(), other_host)
    def test_current_host(self):
        """
        Makes sure current host is saved appropriately.
        """
        # Write the host and make sure we read it back.
        #
        # Use mixed case to make sure we are not case preserving. If we did,
        # as we used to, we would run into problems with some site url
        # comparisons incorrectly determining that hOsT.shotgunstudio.com
        # isn't the same site as host.shotgunstudio.com.
        host = "https://hOsT.shotgunstudio.com"
        session_cache.set_current_host(host)
        self.assertEqual(session_cache.get_current_host(), host.lower())

        # Update the host and make sure we read it back.
        other_host = "https://other_host.shotgunstudio.com"
        session_cache.set_current_host(other_host)
        self.assertEqual(session_cache.get_current_host(), other_host)
    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)