def tearDown(self): """ Clear cached appstore connection """ tank.util.shotgun.g_sg_cached_connection = None tank.util.shotgun.g_app_store_connection = None tank.set_authenticated_user(None)
def setUp(self): """ Clear cached appstore connection """ tank.util.shotgun.connection._g_sg_cached_connections = threading.local( ) tank.set_authenticated_user(None) # Prevents from connecting to Shotgun. self._server_caps_mock = patch( "tank_vendor.shotgun_api3.Shotgun.server_caps") self._server_caps_mock.start() self.addCleanup(self._server_caps_mock.stop) # Avoids crash because we're not in a pipeline configuration. self._get_api_core_config_location_mock = patch( "tank.util.shotgun.connection.__get_api_core_config_location", return_value="unused_path_location") self._get_api_core_config_location_mock.start() self.addCleanup(self._get_api_core_config_location_mock.stop) # Mocks app store script user credentials retrieval self._get_app_store_key_from_shotgun_mock = patch( "tank.descriptor.io_descriptor.appstore.IODescriptorAppStore." "_IODescriptorAppStore__get_app_store_key_from_shotgun", return_value=("abc", "123")) self._get_app_store_key_from_shotgun_mock.start() self.addCleanup(self._get_app_store_key_from_shotgun_mock.stop)
def tearDown(self): """ Clear cached appstore connection """ tank.util.shotgun.connection._g_sg_cached_connections = threading.local( ) tank.set_authenticated_user(None)
def setUp(self): """ Clear cached appstore connection """ tank.util.shotgun.connection._g_sg_cached_connections = threading.local() tank.set_authenticated_user(None) # Prevents from connecting to Shotgun. self._server_caps_mock = patch("tank_vendor.shotgun_api3.Shotgun.server_caps") self._server_caps_mock.start() self.addCleanup(self._server_caps_mock.stop) # Avoids crash because we're not in a pipeline configuration. self._get_api_core_config_location_mock = patch( "tank.util.shotgun.connection.__get_api_core_config_location", return_value="unused_path_location" ) self._get_api_core_config_location_mock.start() self.addCleanup(self._get_api_core_config_location_mock.stop) # Mocks app store script user credentials retrieval self._get_app_store_key_from_shotgun_mock = patch( "tank.descriptor.io_descriptor.appstore.IODescriptorAppStore." "_IODescriptorAppStore__get_app_store_key_from_shotgun", return_value=("abc", "123") ) self._get_app_store_key_from_shotgun_mock.start() self.addCleanup(self._get_app_store_key_from_shotgun_mock.stop)
def test_serialize_with_user(self): """ Make sure the user is serialized and restored. """ tank.set_authenticated_user(self._user) ctx = context.Context(**self.kws) ctx_str = tank.Context.serialize(ctx) # Reset the current user to later check if it is restored. tank.set_authenticated_user(None) # Unserializing should restore the user. tank.Context.deserialize(ctx_str) self._assert_same_user(tank.get_authenticated_user(), self._user)
def test_serialize_without_user(self): """ Make sure the user is not serialized and not restored. """ tank.set_authenticated_user(self._user) ctx = context.Context(**self.kws) ctx_str = tank.Context.serialize(ctx) # Change the current user to make sure that the deserialize operation doesn't # change it back to the original user. other_user = ShotgunAuthenticator().create_script_user( "script_user", "script_key", "https://abc.shotgunstudio.com") tank.set_authenticated_user(other_user) # The unserialized context shouldn't have changed the current user. tank.Context.deserialize(ctx_str) self._assert_same_user(tank.get_authenticated_user(), other_user)
def test_serialize_without_user(self): """ Make sure the user is not serialized and not restored. """ tank.set_authenticated_user(self._user) ctx = context.Context(**self.kws) ctx_str = tank.Context.serialize(ctx) # Change the current user to make sure that the deserialize operation doesn't # change it back to the original user. other_user = ShotgunAuthenticator().create_script_user( "script_user", "script_key", "https://abc.shotgunstudio.com" ) tank.set_authenticated_user(other_user) # The unserialized context shouldn't have changed the current user. tank.Context.deserialize(ctx_str) self._assert_same_user(tank.get_authenticated_user(), other_user)
def _run_test( self, site, source_proxy=None, source_store_proxy=ConnectionSettingsTestCases.FOLLOW_HTTP_PROXY_SETTING, expected_store_proxy=None, ): """ Mock information coming from the Shotgun user and shotgun.yml for authentication. """ with patch("tank.util.shotgun.connection.__get_sg_config_data") as mock: # Mocks shotgun.yml content mock.return_value = { # We're supposed to read only the proxy settings for the appstore "host": "https://this_should_not_be_read.shotgunstudio.com", "api_script": "1234", "api_key": "1234", "http_proxy": "123.234.345.456:7890", } # Adds the app store proxy setting in the mock shotgun.yml settings if one should be present. if ( source_store_proxy != ConnectionSettingsTestCases.FOLLOW_HTTP_PROXY_SETTING ): mock.return_value["app_store_http_proxy"] = source_store_proxy # Mocks a user being authenticated. user = ShotgunUser( SessionUser( login="******", session_token="abc1234", host=site, http_proxy=source_proxy, ) ) tank.set_authenticated_user(user) ConnectionSettingsTestCases.Impl._run_test( self, site=site, source_proxy=source_proxy, source_store_proxy=source_store_proxy, expected_store_proxy=expected_store_proxy, )
def _setup_shotgun(self, server_caps): # Override what's in TestTantBase with 'older' server caps self.mockgun.server_caps = server_caps self.setup_fixtures() self._create_context() self._shotgun = tank.util.shotgun tank.util.shotgun.connection._g_sg_cached_connections = threading.local( ) # Clear cached appstore connection tank.set_authenticated_user(None) # Prevents an actual connection to a Shotgun site. self._server_caps_mock = patch( "tank_vendor.shotgun_api3.Shotgun.server_caps") self._server_caps_mock.start() self.addCleanup(self._server_caps_mock.stop) # Avoids crash because we're not in a pipeline configuration. self._get_api_core_config_location_mock = patch( "tank.util.shotgun.connection.__get_api_core_config_location", return_value="unused_path_location") self._get_api_core_config_location_mock.start() self.addCleanup(self._get_api_core_config_location_mock.stop) # Mocks app store script user credentials retrieval self._get_app_store_key_from_shotgun_mock = patch( "tank.descriptor.io_descriptor.appstore.IODescriptorAppStore._IODescriptorAppStore__get_app_store_key_from_shotgun", return_value=("abc", "123")) self._get_app_store_key_from_shotgun_mock.start() self.addCleanup(self._get_app_store_key_from_shotgun_mock.stop) self._authenticate() self._create_engine() # Patch & Mock the `urlopen` method self._urlopen_mock = patch("urllib2.urlopen") self._mocked_method = self._urlopen_mock.start()
def _run_test( self, site, source_proxy=None, source_store_proxy=ConnectionSettingsTestCases.FOLLOW_HTTP_PROXY_SETTING, expected_store_proxy=None ): """ Mock information coming from the Shotgun user and shotgun.yml for authentication. """ with patch("tank.util.shotgun.connection.__get_sg_config_data") as mock: # Mocks shotgun.yml content mock.return_value = { # We're supposed to read only the proxy settings for the appstore "host": "https://this_should_not_be_read.shotgunstudio.com", "api_script": "1234", "api_key": "1234", "http_proxy": "123.234.345.456:7890" } # Adds the app store proxy setting in the mock shotgun.yml settings if one should be present. if source_store_proxy != ConnectionSettingsTestCases.FOLLOW_HTTP_PROXY_SETTING: mock.return_value["app_store_http_proxy"] = source_store_proxy # Mocks a user being authenticated. user = ShotgunUser( SessionUser( login="******", session_token="abc1234", host=site, http_proxy=source_proxy ) ) tank.set_authenticated_user(user) ConnectionSettingsTestCases.Impl._run_test( self, site=site, source_proxy=source_proxy, source_store_proxy=source_store_proxy, expected_store_proxy=expected_store_proxy )
def _de_authenticate(self): tank.util.shotgun.connection._g_sg_cached_connections = threading.local( ) tank.set_authenticated_user(None)
def tearDown(self): """ Clear cached appstore connection """ tank.util.shotgun.connection._g_sg_cached_connections = threading.local() tank.set_authenticated_user(None)
def _de_authenticate(self): tank.set_authenticated_user(None)
def _authenticate(self): # Need to set authenticated user prior to MetricDispatcher.start below user = ShotgunAuthenticator().create_script_user( "script_user", "script_key", "https://abc.shotgunstudio.com") tank.set_authenticated_user(user)
QtCore.QCoreApplication.processEvents() # check for open file change global g_current_file cur_file = tde4.getProjectPath() if g_current_file != cur_file: if cur_file: engine = tank.platform.current_engine() context = engine.context new_context = engine.tank.context_from_path(cur_file, context) if new_context != context: tank.platform.change_context(new_context) g_current_file = cur_file if __name__ == '__main__': engine = tank.platform.current_engine() if not engine: from tank_vendor.shotgun_authentication import ShotgunAuthenticator user = ShotgunAuthenticator(tank.util.CoreDefaultsManager()).get_user() tank.set_authenticated_user(user) context = tank.context.deserialize(os.environ.get("TANK_CONTEXT")) engine = tank.platform.start_engine('tk-3de4', context.tank, context) # Qt if not QtCore.QCoreApplication.instance(): QtGui.QApplication([]) global g_current_file g_current_file = tde4.getProjectPath() tde4.setTimerCallbackFunction("_timer", 50) engine.post_qt_init()