def test_basic_execution(self): """ Test basic execution and return value structure """ cc = self.mockgun.create( "PipelineConfiguration", dict( code="Primary", project=self._project, users=[], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor= "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, ), ) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) expected_fields = [ "descriptor_source_uri", "name", "project", "descriptor", "type", "id", ] self.assertEqual(len(configs), 1) config = configs[0] self.assertEqual(sorted(expected_fields), sorted(config.keys())) self.assertEqual(config["id"], cc["id"]) self.assertEqual(config["type"], "PipelineConfiguration") self.assertEqual(config["name"], "Primary") self.assertEqual(config["project"], self._project) self.assertEqual( config["descriptor"].get_uri(), "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", ) self.assertEqual( config["descriptor_source_uri"], "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", ) # with a different plugin id we won't get anything mgr.plugin_id = "something.else" configs = mgr.get_pipeline_configurations(self._project) self.assertEqual(len(configs), 0)
def test_override_logic(self): """ Tests that paths override descriptors """ self.mockgun.create( "PipelineConfiguration", dict( code="Primary", project=self._project, users=[], windows_path="/path", mac_path="/path", linux_path="/path", plugin_ids="basic.*", descriptor= "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, )) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) config = configs[0] self.assertEqual( config["descriptor"].get_uri(), "sgtk:descriptor:path?linux_path=/path&mac_path=/path&windows_path=\\path" ) self.assertEqual(config["descriptor_source_uri"], None)
def test_latest_tracking_descriptor(self, _): """ Test descriptors tracking latest """ self.mockgun.create( "PipelineConfiguration", dict( code="Primary", project=self._project, users=[], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor="sgtk:descriptor:app_store?name=tk-config-basic", uploaded_config=None, )) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) config = configs[0] self.assertTrue(isinstance(config["descriptor"], Mock)) self.assertEqual(config["descriptor_source_uri"], "sgtk:descriptor:app_store?name=tk-config-basic")
def test_override_logic(self): """ Tests that paths override descriptors """ self.mockgun.create( "PipelineConfiguration", dict( code="Primary", project=self._project, users=[], windows_path="/path", mac_path="/path", linux_path="/path", plugin_ids="basic.*", descriptor="sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, ) ) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) config = configs[0] self.assertEqual( config["descriptor"].get_uri(), "sgtk:descriptor:path?linux_path=/path&mac_path=/path&windows_path=%5Cpath" ) self.assertEqual(config["descriptor_source_uri"], None)
def test_latest_tracking_descriptor(self, _): """ Test descriptors tracking latest """ self.mockgun.create( "PipelineConfiguration", dict( code="Primary", project=self._project, users=[], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor="sgtk:descriptor:app_store?name=tk-config-basic", uploaded_config=None, ) ) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) config = configs[0] self.assertTrue(isinstance(config["descriptor"], Mock)) self.assertEqual(config["descriptor_source_uri"], "sgtk:descriptor:app_store?name=tk-config-basic")
def test_basic_execution(self): """ Test basic execution and return value structure """ cc = self.mockgun.create( "PipelineConfiguration", dict( code="Primary", project=self._project, users=[], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor="sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, ) ) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) expected_fields = [ "descriptor_source_uri", "name", "project", "descriptor", "type", "id" ] self.assertEqual(len(configs), 1) config = configs[0] self.assertEqual(sorted(expected_fields), sorted(config.keys())) self.assertEqual(config["id"], cc["id"]) self.assertEqual(config["type"], "PipelineConfiguration") self.assertEqual(config["name"], "Primary") self.assertEqual(config["project"], self._project) self.assertEqual(config["descriptor"].get_uri(), "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3") self.assertEqual(config["descriptor_source_uri"], "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3") # with a different plugin id we won't get anything mgr.plugin_id = "something.else" configs = mgr.get_pipeline_configurations(self._project) self.assertEqual(len(configs), 0)
def test_serialization(self, _): """ Ensures we're serializing the manager properly. """ # Make sure nobody has added new parameters that need to be serialized. class_attrs = set(dir(ToolkitManager)) instance_attrs = set(dir(ToolkitManager())) unserializable_attrs = set([ "_sg_connection", "_sg_user", "_pre_engine_start_callback", "_progress_cb" ]) # Through this operation, we're taking all the symbols that are defined from an instance, # we then remove everything that is defined also in the class, which means we're left # with what was added during __init__, and then we remove the parameters we know can't # be serialized. We're left with a small list of values that can be serialized. instance_data_members = instance_attrs - class_attrs - unserializable_attrs self.assertEqual(len(instance_data_members), 7) # Create a manager that hasn't been updated yet. clean_mgr = ToolkitManager() clean_settings = clean_mgr.extract_settings() # Now create one where we modify everything. modified_mgr = ToolkitManager() modified_mgr.bundle_cache_fallback_paths = ["/a/b/c"] modified_mgr.caching_policy = ToolkitManager.CACHE_FULL modified_mgr.pipeline_configuration = "Primary" modified_mgr.base_configuration = ( "sgtk:descriptor:app_store?" "version=v0.18.91&name=tk-config-basic") modified_mgr.do_shotgun_config_lookup = False modified_mgr.plugin_id = "basic.default" modified_mgr.allow_config_overrides = False # Extract settings and make sure the implementation still stores dictionaries. modified_settings = modified_mgr.extract_settings() self.assertIsInstance(modified_settings, dict) # Make sure the unit test properly changes all the settings from their default values. for k, v in modified_settings.items(): self.assertNotEqual(v, clean_settings[k]) # Restore the settings from the manager. restored_mgr = ToolkitManager() restored_mgr.restore_settings(modified_settings) # Extract the settings back from the restored manager to make sure everything was written # back correctly. self.assertEqual(restored_mgr.extract_settings(), modified_settings)
def test_serialization(self, _): """ Ensures we're serializing the manager properly. """ # Make sure nobody has added new parameters that need to be serialized. class_attrs = set(dir(ToolkitManager)) instance_attrs = set(dir(ToolkitManager())) unserializable_attrs = set( ["_sg_connection", "_sg_user", "_pre_engine_start_callback", "_progress_cb"] ) # Through this operation, we're taking all the symbols that are defined from an instance, # we then remove everything that is defined also in the class, which means we're left # with what was added during __init__, and then we remove the parameters we know can't # be serialized. We're left with a small list of values that can be serialized. instance_data_members = instance_attrs - class_attrs - unserializable_attrs self.assertEqual(len(instance_data_members), 7) # Create a manager that hasn't been updated yet. clean_mgr = ToolkitManager() clean_settings = clean_mgr.extract_settings() # Now create one where we modify everything. modified_mgr = ToolkitManager() modified_mgr.bundle_cache_fallback_paths = ["/a/b/c"] modified_mgr.caching_policy = ToolkitManager.CACHE_FULL modified_mgr.pipeline_configuration = "Primary" modified_mgr.base_configuration = "sgtk:descriptor:app_store?"\ "version=v0.18.91&name=tk-config-basic" modified_mgr.do_shotgun_config_lookup = False modified_mgr.plugin_id = "basic.default" modified_mgr.allow_config_overrides = False # Extract settings and make sure the implementation still stores dictionaries. modified_settings = modified_mgr.extract_settings() self.assertIsInstance(modified_settings, dict) # Make sure the unit test properly changes all the settings from their default values. for k, v in modified_settings.iteritems(): self.assertNotEqual(v, clean_settings[k]) # Restore the settings from the manager. restored_mgr = ToolkitManager() restored_mgr.restore_settings(modified_settings) # Extract the settings back from the restored manager to make sure everything was written # back correctly. self.assertEqual(restored_mgr.extract_settings(), modified_settings)
def test_user_filters(self): """ Test user based sandboxes """ self.mockgun.create( "PipelineConfiguration", dict( code="Doe Dev", project=self._project, users=[self._john_doe], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor= "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, ), ) self.mockgun.create( "PipelineConfiguration", dict( code="Smith Dev", project=self._project, users=[self._john_smith], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor= "sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, ), ) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) self.assertEqual(len(configs), 1) config = configs[0] self.assertEqual(config["name"], "Doe Dev")
def test_user_filters(self): """ Test user based sandboxes """ self.mockgun.create( "PipelineConfiguration", dict( code="Doe Dev", project=self._project, users=[self._john_doe], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor="sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, ) ) self.mockgun.create( "PipelineConfiguration", dict( code="Smith Dev", project=self._project, users=[self._john_smith], windows_path=None, mac_path=None, linux_path=None, plugin_ids="basic.*", descriptor="sgtk:descriptor:app_store?name=tk-config-basic&version=v1.2.3", uploaded_config=None, ) ) mgr = ToolkitManager(self._mocked_sg_user) mgr.plugin_id = "basic.test" configs = mgr.get_pipeline_configurations(self._project) self.assertEqual(len(configs), 1) config = configs[0] self.assertEqual(config["name"], "Doe Dev")