Пример #1
0
    def test_login_value(self):
        session_user = user.ShotgunUser(user_impl.SessionUser(
            host="https://tank.shotgunstudio.com",
            login="******",
            session_token="session_token",
            http_proxy="http_proxy"
        ))
        self.assertEqual(session_user.login, "session_user")

        script_user = user.ShotgunUser(user_impl.ScriptUser(
            host="host",
            api_script="api_script",
            api_key="api_key",
            http_proxy="http_proxy"
        ))
        self.assertIsNone(script_user.login)

        class CustomUser(user_impl.ShotgunUserImpl):

            def __init__(self):
                super(CustomUser, self).__init__("https://test.shotgunstudio.com", None)

            def get_login(self):
                return "custom_user"

        custom_user = user.ShotgunUser(CustomUser())

        self.assertEqual(custom_user.login, "custom_user")
Пример #2
0
 def _create_test_user(self):
     return user.ShotgunUser(user_impl.SessionUser(
         host="https://tank.shotgunstudio.com",
         login="******",
         session_token="session_token",
         http_proxy="http_proxy"
     ))
Пример #3
0
    def test_serialize_deserialize(self):
        """
        Makes sure serialization and deserialization works for users
        """
        # First start with a non-SAML user.
        su = self._create_test_user()
        self.assertNotIsInstance(su, user.ShotgunSamlUser)
        self.assertFalse("session_metadata" in su.impl.to_dict())
        su_2 = user.deserialize_user(user.serialize_user(su))
        self.assertNotIsInstance(su_2, user.ShotgunSamlUser)
        self.assertEqual(su.host, su_2.host)
        self.assertEqual(su.http_proxy, su_2.http_proxy)
        self.assertEqual(su.login, su_2.login)
        self.assertEqual(su.impl.get_session_token(),
                         su_2.impl.get_session_token())

        # Then, with a SAML user.
        su = self._create_test_saml_user()
        self.assertIsInstance(su, user.ShotgunSamlUser)
        self.assertTrue("session_metadata" in su.impl.to_dict())
        su_2 = user.deserialize_user(user.serialize_user(su))
        self.assertIsInstance(su_2, user.ShotgunSamlUser)
        self.assertEqual(su.host, su_2.host)
        self.assertEqual(su.http_proxy, su_2.http_proxy)
        self.assertEqual(su.login, su_2.login)
        self.assertEqual(su.impl.get_session_token(),
                         su_2.impl.get_session_token())

        su = user.ShotgunUser(
            user_impl.ScriptUser(host="host",
                                 api_script="api_script",
                                 api_key="api_key",
                                 http_proxy="http_proxy"))

        su_2 = user.deserialize_user(user.serialize_user(su))
        self.assertEqual(su.host, su_2.host)
        self.assertEqual(su.http_proxy, su_2.http_proxy)
        self.assertEqual(su.login, su_2.login)
        self.assertEqual(su.impl.get_key(), su_2.impl.get_key())
        self.assertEqual(su.impl.get_script(), su_2.impl.get_script())

        # Make sure we can unserialize a user with data that is not completely understood.
        user_with_unknown_data = {
            "host": "https://test.shotgunstudio.com",
            "login": "******",
            "session_token": "token",
            "http_proxy": "127.0.0.1",
            "unexpected": "stuff"
        }

        user_impl.SessionUser.from_dict(user_with_unknown_data)

        script_user_with_unknown_data = {
            "host": "https://test.shotgunstudio.com",
            "api_script": "x123",
            "api_key": "x12333",
            "http_proxy": "127.0.0.1",
            "unexpected": "stuff"
        }
        user_impl.ScriptUser.from_dict(script_user_with_unknown_data)
Пример #4
0
 def _create_script_user(self):
     return user.ShotgunUser(
         user_impl.ScriptUser(
             host="host",
             api_script="api_script",
             api_key="api_key",
             http_proxy="http_proxy",
         ))
Пример #5
0
    def test_serialize_deserialize(self):
        """
        Makes sure serialization and deserialization works for users
        """
        su = self._create_test_user()
        su_2 = user.deserialize_user(user.serialize_user(su))
        self.assertEquals(su.host, su_2.host)
        self.assertEquals(su.http_proxy, su_2.http_proxy)
        self.assertEquals(su.login, su_2.login)
        self.assertEquals(su.impl.get_session_token(),
                          su_2.impl.get_session_token())

        su = user.ShotgunUser(
            user_impl.ScriptUser(host="host",
                                 api_script="api_script",
                                 api_key="api_key",
                                 http_proxy="http_proxy"))

        su_2 = user.deserialize_user(user.serialize_user(su))
        self.assertEquals(su.host, su_2.host)
        self.assertEquals(su.http_proxy, su_2.http_proxy)
        self.assertEquals(su.login, su_2.login)
        self.assertEquals(su.impl.get_key(), su_2.impl.get_key())
        self.assertEquals(su.impl.get_script(), su_2.impl.get_script())