示例#1
0
    def test_fail_reinstantiating(self):
        """
        Ensure the configuration will recover if the user can't be serialized/unserialized.
        """
        configuration = Configuration(None, None)

        default_user = self._create_session_user("default_user")

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=default_user
        ):
            # Python 2.6 doesn't support multi-expression with statement, so nest the calls instead.
            with patch(
                "tank_vendor.shotgun_authentication.deserialize_user",
                wraps=tank_vendor.shotgun_authentication.deserialize_user
            ) as deserialize_wrapper:
                current_user = self._create_session_user("current_user")
                configuration._set_authenticated_user(current_user, current_user.login, "invalid")

                deserialize_wrapper.assert_called_once_with("invalid")

                # Because we couldn't unserialize, we should just get the same login...
                self.assertEqual(sgtk.get_authenticated_user().login, current_user.login)
                # ... and the original ShotgunUser back.
                self.assertEqual(id(sgtk.get_authenticated_user()), id(current_user))
示例#2
0
    def test_script_to_noscript_authentication(self):
        """
        Ensure that bootstrapping with a script into a project without a script user in its
        configuration will pick the bootstrap user.
        """
        configuration = Configuration(None, None)

        user_for_bootstrap = self._create_script_user("api_script_for_bootstrap")
        user_for_project = self._create_session_user("project_user")

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=user_for_project
        ):
            configuration._set_authenticated_user(
                user_for_bootstrap,
                user_for_bootstrap.login,
                sgtk.authentication.serialize_user(user_for_bootstrap)
            )

            # we should be using the same login...
            auth_user = sgtk.get_authenticated_user()
            self.assertIsNone(auth_user.login)
            self.assertEqual(auth_user.login, user_for_bootstrap.login)
            self.assertEqual(auth_user.impl.get_script(), user_for_bootstrap.impl.get_script())
            # ... but we shouldn't be using the name ShotgunUser instance. It should
            # have been serialized and deserialized.
            self.assertNotEqual(id(auth_user), id(user_for_bootstrap))
示例#3
0
    def test_login_to_login_authentication(self):
        """
        Ensure the configuration will always pick the user passed in when there is no script user
        in the project configuration.
        """
        default_user = self._create_session_user("default_user")

        configuration = Configuration(None, None)

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=default_user
        ):
            current_user = self._create_session_user("current_user")
            configuration._set_authenticated_user(
                current_user,
                current_user.login,
                sgtk.authentication.serialize_user(current_user)
            )

            # we should be using the same login...
            self.assertEqual(sgtk.get_authenticated_user().login, current_user.login)
            # ... but we shouldn't be using the name ShotgunUser instance. It should
            # have been serialized and deserialized.
            self.assertNotEqual(id(sgtk.get_authenticated_user()), id(current_user))
示例#4
0
    def test_fail_reinstantiating(self):
        """
        Ensure the configuration will recover if the user can't be serialized/unserialized.
        """
        configuration = Configuration(None, None)

        default_user = self._create_session_user("default_user")

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=default_user
        ):
            # Python 2.6 doesn't support multi-expression with statement, so nest the calls instead.
            with patch(
                "tank_vendor.shotgun_authentication.deserialize_user",
                wraps=tank_vendor.shotgun_authentication.deserialize_user
            ) as deserialize_wrapper:
                current_user = self._create_session_user("current_user")
                configuration._set_authenticated_user(current_user, current_user.login, "invalid")

                deserialize_wrapper.assert_called_once_with("invalid")

                # Because we couldn't unserialize, we should just get the same login...
                self.assertEqual(sgtk.get_authenticated_user().login, current_user.login)
                # ... and the original ShotgunUser back.
                self.assertEqual(id(sgtk.get_authenticated_user()), id(current_user))
示例#5
0
    def test_login_to_login_authentication(self):
        """
        Ensure the configuration will always pick the user passed in when there is no script user
        in the project configuration.
        """
        default_user = self._create_session_user("default_user")

        configuration = Configuration(None, None)

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=default_user
        ):
            current_user = self._create_session_user("current_user")
            configuration._set_authenticated_user(
                current_user,
                current_user.login,
                sgtk.authentication.serialize_user(current_user)
            )

            # we should be using the same login...
            self.assertEqual(sgtk.get_authenticated_user().login, current_user.login)
            # ... but we shouldn't be using the name ShotgunUser instance. It should
            # have been serialized and deserialized.
            self.assertNotEqual(id(sgtk.get_authenticated_user()), id(current_user))
示例#6
0
    def test_script_to_noscript_authentication(self):
        """
        Ensure that bootstrapping with a script into a project without a script user in its
        configuration will pick the bootstrap user.
        """
        configuration = Configuration(None, None)

        user_for_bootstrap = self._create_script_user("api_script_for_bootstrap")
        user_for_project = self._create_session_user("project_user")

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=user_for_project
        ):
            configuration._set_authenticated_user(
                user_for_bootstrap,
                user_for_bootstrap.login,
                sgtk.authentication.serialize_user(user_for_bootstrap)
            )

            # we should be using the same login...
            auth_user = sgtk.get_authenticated_user()
            self.assertIsNone(auth_user.login)
            self.assertEqual(auth_user.login, user_for_bootstrap.login)
            self.assertEqual(auth_user.impl.get_script(), user_for_bootstrap.impl.get_script())
            # ... but we shouldn't be using the name ShotgunUser instance. It should
            # have been serialized and deserialized.
            self.assertNotEqual(id(auth_user), id(user_for_bootstrap))
示例#7
0
    def test_script_to_script_authentication(self):
        """
        Ensure a project configuration overrides a script user used for bootstrapping.
        """
        configuration = Configuration(None, None)

        script_user_for_bootstrap = self._create_script_user("api_script_for_bootstrap")
        script_user_for_project = self._create_script_user("api_script_for_project")

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=script_user_for_project,
        ):
            configuration._set_authenticated_user(
                script_user_for_bootstrap,
                script_user_for_bootstrap.login,
                sgtk.authentication.serialize_user(script_user_for_bootstrap),
            )

            # The ShotgunUser instance from get_authenticated_user was retrieved
            # through get_default_user, so we simply need to compare the object ids.
            self.assertEqual(
                id(sgtk.get_authenticated_user()), id(script_user_for_project)
            )
示例#8
0
    def test_login_based_authentication(self):
        """
        Ensure the configuration will always pick the user passed in when there is no script user.
        """
        configuration = Configuration(None, None)

        self._mock_default_user.login = "******"

        user = MagicMock(login="******")
        configuration._set_authenticated_user(user)

        self.assertEqual(sgtk.get_authenticated_user(), user)
示例#9
0
    def test_login_based_authentication(self):
        """
        Ensure the configuration will always pick the user passed in when there is no script user.
        """
        configuration = Configuration(None, None)

        self._mock_default_user.login = "******"

        user = MagicMock(login="******")
        configuration._set_authenticated_user(user)

        self.assertEqual(sgtk.get_authenticated_user(), user)
示例#10
0
    def test_endpoint_url_swap(self):
        """
        Make sure that if the endpoint changes after the bootstrap that we're using the new endpoint.
        """
        configuration = Configuration(None, None)
        bootstrap_user = self._create_session_user("default_user")
        project_user = self._create_session_user(
            "default_user", "https://test-2.shotgunstudio.com")

        with patch("tank.authentication.ShotgunAuthenticator.get_default_user",
                   return_value=project_user):
            configuration._set_authenticated_user(
                bootstrap_user, bootstrap_user.login,
                sgtk.authentication.serialize_user(bootstrap_user))

        self.assertEqual(sgtk.get_authenticated_user().host,
                         "https://test-2.shotgunstudio.com")
示例#11
0
    def test_endpoint_url_swap(self):
        """
        Make sure that if the endpoint changes after the bootstrap that we're using the new endpoint.
        """
        configuration = Configuration(None, None)
        bootstrap_user = self._create_session_user("default_user")
        project_user = self._create_session_user("default_user", "https://test-2.shotgunstudio.com")

        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=project_user
        ):
            configuration._set_authenticated_user(
                bootstrap_user,
                bootstrap_user.login,
                sgtk.authentication.serialize_user(bootstrap_user)
            )

        self.assertEqual(sgtk.get_authenticated_user().host, "https://test-2.shotgunstudio.com")
示例#12
0
    def test_login_to_script_authentication(self):
        """
        Ensure the configuration will always pick the script user when project configuration has
        one.
        """
        configuration = Configuration(None, None)

        script_user = self._create_script_user("api_script")

        # Create a default user.
        with patch("tank.authentication.ShotgunAuthenticator.get_default_user",
                   return_value=script_user):
            current_user = self._create_session_user("current_user")
            configuration._set_authenticated_user(
                current_user, current_user.login,
                sgtk.authentication.serialize_user(current_user))

            # The ShotgunUser instance from get_authenticated_user was retrieved
            # through get_default_user, so we simply need to compare the object ids.
            self.assertEqual(id(sgtk.get_authenticated_user()),
                             id(script_user))
示例#13
0
    def test_script_to_script_authentication(self):
        """
        Ensure a project configuration overrides a script user used for bootstrapping.
        """
        configuration = Configuration(None, None)

        script_user_for_bootstrap = self._create_script_user("api_script_for_bootstrap")
        script_user_for_project = self._create_script_user("api_script_for_project")

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=script_user_for_project
        ):
            configuration._set_authenticated_user(
                script_user_for_bootstrap,
                script_user_for_bootstrap.login,
                sgtk.authentication.serialize_user(script_user_for_bootstrap)
            )

            # The ShotgunUser instance from get_authenticated_user was retrieved
            # through get_default_user, so we simply need to compare the object ids.
            self.assertEqual(id(sgtk.get_authenticated_user()), id(script_user_for_project))
示例#14
0
    def test_login_to_script_authentication(self):
        """
        Ensure the configuration will always pick the script user when project configuration has
        one.
        """
        configuration = Configuration(None, None)

        script_user = self._create_script_user("api_script")

        # Create a default user.
        with patch(
            "tank.authentication.ShotgunAuthenticator.get_default_user",
            return_value=script_user
        ):
            current_user = self._create_session_user("current_user")
            configuration._set_authenticated_user(
                current_user,
                current_user.login,
                sgtk.authentication.serialize_user(current_user)
            )

            # The ShotgunUser instance from get_authenticated_user was retrieved
            # through get_default_user, so we simply need to compare the object ids.
            self.assertEqual(id(sgtk.get_authenticated_user()), id(script_user))