def test_create_session_user(self, get_global_root, generate_session_token_mock, server_caps_mock): """ Makes sure that create_session_user does correct input validation. :param generate_session_token_mock: Mocked so we can skip communicating with the Shotgun server. """ generate_session_token_mock.return_value = "session_token" get_global_root.return_value = os.path.join(self.tank_temp, "session_cache") # No login should throw with self.assertRaises(IncompleteCredentials): ShotgunAuthenticator(CustomDefaultManager()).create_session_user("", "session_token") # No password or session token should throw with self.assertRaises(IncompleteCredentials): ShotgunAuthenticator(CustomDefaultManager()).create_session_user("login") # Passing a password should generate a session token session_user = ShotgunAuthenticator(CustomDefaultManager()).create_session_user( "login", password="******", host="https://host.shotgunstudio.com" ) self.assertIsInstance(session_user, user.ShotgunUser) self.assertNotIsInstance(session_user, user.ShotgunSamlUser) self.assertEquals(generate_session_token_mock.call_count, 1) self.assertEquals(session_user.impl.get_session_token(), "session_token") connection = session_user.create_sg_connection() self.assertEqual(connection.config.session_token, "session_token") # Passing invalid session_metadata will result in a regular ShotgunUser session_user = ShotgunAuthenticator(CustomDefaultManager())._create_session_user( "login", password="******", host="https://host.shotgunstudio.com", session_metadata="invalid session_metadata" ) self.assertIsInstance(session_user, user.ShotgunUser) self.assertNotIsInstance(session_user, user.ShotgunSamlUser) self.assertEquals(generate_session_token_mock.call_count, 2) self.assertEquals(session_user.impl.get_session_token(), "session_token") connection = session_user.create_sg_connection() self.assertEqual(connection.config.session_token, "session_token") # Passing valid session_metadata will result in a ShotgunSamlUser session_user = ShotgunAuthenticator(CustomDefaultManager())._create_session_user( "login", password="******", host="https://host.shotgunstudio.com", session_metadata=valid_session_metadata ) self.assertIsInstance(session_user, user.ShotgunSamlUser) self.assertEquals(generate_session_token_mock.call_count, 3) self.assertEquals(session_user.impl.get_session_token(), "session_token") connection = session_user.create_sg_connection() self.assertEqual(connection.config.session_token, "session_token")
def test_create_script_user(self, server_caps_mock): """ Makes sure that create_script_user does correct input validation. """ # No script name should throw with self.assertRaises(IncompleteCredentials): ShotgunAuthenticator(TestDefaultManager()).create_script_user("", "api_key") # No script key should throw with self.assertRaises(IncompleteCredentials): ShotgunAuthenticator(TestDefaultManager()).create_script_user("api_script", "") # With valid values it should work user = ShotgunAuthenticator(TestDefaultManager()).create_script_user( "api_script", "api_key", "https://host.shotgunstudio.com", None ) connection = user.create_sg_connection() self.assertEqual(connection.config.script_name, "api_script") self.assertEqual(connection.config.api_key, "api_key")
def test_create_script_user(self, server_caps_mock): """ Makes sure that create_script_user does correct input validation. """ # No script name should throw with self.assertRaises(IncompleteCredentials): ShotgunAuthenticator(TestDefaultManager()).create_script_user( "", "api_key") # No script key should throw with self.assertRaises(IncompleteCredentials): ShotgunAuthenticator(TestDefaultManager()).create_script_user( "api_script", "") # With valid values it should work user = ShotgunAuthenticator(TestDefaultManager()).create_script_user( "api_script", "api_key", "https://host.shotgunstudio.com", None) connection = user.create_sg_connection() self.assertEqual(connection.config.script_name, "api_script") self.assertEqual(connection.config.api_key, "api_key")