def __init__(self): import maya.standalone maya.standalone.initialize(name='python') import maya.cmds, maya.mel from tactic_client_lib.application.maya import Maya self.app = Maya()
def test_all(self): from tactic_client_lib.application.common import TacticNodeUtil self.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya self.app = Maya() self._test_nodes() self._test_attributes() self._test_file()
def __init__(self): import maya.standalone maya.standalone.initialize( name='python' ) import maya.cmds, maya.mel from tactic_client_lib.application.maya import Maya self.app = Maya()
def test_all(my): from tactic_client_lib.application.common import TacticNodeUtil my.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya my.app = Maya() my._test_nodes() my._test_attributes() my._test_file()
def test_all(self): print "Running Client Application API Test" from tactic_client_lib import TacticServerStub # set the server to test... assume it is run on the server server = "localhost" url = "http://%s/tactic/default/Api/" % server self.server = TacticServerStub.get() project_code = "unittest" self.server.set_project(project_code) self.server.start("Client API Unittest") from tactic_client_lib.application.common import TacticNodeUtil self.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya self.app = Maya() try: data = {'code': 'joe'} self.person = self.server.insert("unittest/person", data) data = {'code': 'mary'} self.person2 = self.server.insert("unittest/person", data) self._test_load_template() self._test_checkin() self._test_load() self._test_introspect() except Exception: self.server.abort() raise else: self.server.abort()
def test_all(self): print "Running Client Application API Test" from tactic_client_lib import TacticServerStub # set the server to test... assume it is run on the server server = "localhost" url = "http://%s/tactic/default/Api/" % server self.server = TacticServerStub.get() project_code = "unittest" self.server.set_project(project_code) self.server.start("Client API Unittest") from tactic_client_lib.application.common import TacticNodeUtil self.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya self.app = Maya() try: data = { 'code': 'joe' } self.person = self.server.insert("unittest/person", data) data = { 'code': 'mary' } self.person2 = self.server.insert("unittest/person", data) self._test_load_template() self._test_checkin() self._test_load() self._test_introspect() except Exception: self.server.abort() raise else: self.server.abort()
def get(cls): if not cls.app: from tactic_client_lib.application.maya import Maya cls.app = Maya() return cls.app
class ApplicationApiTest(unittest.TestCase): def setUp(self): pass def test_all(self): print "Running Client Application API Test" from tactic_client_lib import TacticServerStub # set the server to test... assume it is run on the server server = "localhost" url = "http://%s/tactic/default/Api/" % server self.server = TacticServerStub.get() project_code = "unittest" self.server.set_project(project_code) self.server.start("Client API Unittest") from tactic_client_lib.application.common import TacticNodeUtil self.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya self.app = Maya() try: data = {'code': 'joe'} self.person = self.server.insert("unittest/person", data) data = {'code': 'mary'} self.person2 = self.server.insert("unittest/person", data) self._test_load_template() self._test_checkin() self._test_load() self._test_introspect() except Exception: self.server.abort() raise else: self.server.abort() def _test_load_template(self): '''load in asset (one with no snapshots)''' search_key = self.person.get("__search_key__") code = self.person.get("code") context = 'model' # create a new default entity node_name = code tactic_node = self.util.create_default_node(node_name, search_key, context) self.assertEquals("tactic_joe", tactic_node) # check that it exists in Maya exists = self.app.mel("ls %s" % tactic_node) self.assertEquals(True, exists != None) # create a second one search_key = self.person2.get("__search_key__") code = self.person2.get("code") context = 'model' # create a new default entity node_name = code tactic_node = self.util.create_default_node(node_name, search_key, context) self.assertEquals("tactic_mary", tactic_node) # now that it is created, find all of the tactic nodes tactic_nodes = self.util.get_all_tactic_nodes() self.assertEquals(2, len(tactic_nodes)) def _test_checkin(self): # checkin a tactic node tactic_node = 'tactic_joe' # get the entity to check into (assume same as last one) search_key = self.util.get_search_key(tactic_node) self.assertEquals("unittest/person?project=unittest&code=joe", search_key) context = self.util.get_context(tactic_node) self.assertEquals("model", context) # create a new snapshot snapshot = self.server.create_snapshot(search_key, context=context) # add the snapshot to the node self.util.add_snapshot_to_node(tactic_node, snapshot) # save the file and check it in path = "blah.ma" path = self.app.save(path) # check in the file snapshot_code = snapshot.get('code') snapshot = self.server.add_file(snapshot_code, file_path=path, mode='upload') # extract the path path = self.server.get_path_from_snapshot(snapshot.get('code')) exists = os.path.exists(path) self.assertEquals(True, exists) # get the path from the latest snapshot context = 'model' snapshot = self.server.get_snapshot(search_key, context) snapshot_code = snapshot.get('code') path = self.server.get_path_from_snapshot(snapshot_code) self.app.load(path) # get all of the tactic nodes tactic_nodes = self.util.get_all_tactic_nodes() self.assertEquals(['tactic_joe', 'tactic_mary'], tactic_nodes) def _test_load(self): '''a more realistic loading example''' return # find all of the Tactic nodes search_type = self.person.get('__search_type__') code = self.person.get('code') search_key = self.server.build_search_key(search_type, code) # first checkin in a dummy model file path = "whatever_model.ma" file = open(path, 'w') file.write("whatever_model.ma") file.close() self.server.upload_file(path) model_snapshot = self.server.simple_checkin(search_key, file_path=path, context="model") # then checkin a dummy rig file with a reference to the model snapshot path = "whatever_rig.ma" file = open(path, 'w') file.write("whatever_rig.ma") file.close() self.server.upload_file(path) rig_snapshot = self.server.simple_checkin(search_key, file_path=path, context="rig") rig_snapshot = self.server.add_dependency_by_code( rig_snapshot.get('code'), model_snapshot.get('code')) # the the latest full snapshot context = "rig" snapshot = self.server.get_snapshot(search_key, context) snapshot_type = snapshot.get("snapshot_type") snapshot_code = snapshot.get('code') snapshot_xml = self.server.get_full_snapshot_xml(snapshot_code) # we know based on the snapshot type that there is a rig and a # reference to a model print snapshot_xml def _test_introspect(self): # introspect the session from tactic_client_lib.application.common import Session session = Session() xml = session.introspect() # commit this session to the database session.commit() # get snapshots from the session snapshots = session.get_snapshots() # only one tactic node has a checkin self.assertEquals(1, len(snapshots)) # get the last session session.get_last() # get snapshots from the session snapshots = session.get_snapshots() self.assertEquals(1, len(snapshots)) def test_explorer(self): pass def main(): #sys.path.insert(0, "C:/Program Files/Southpaw/Tactic1.9/src/client") sys.path.insert(0, "..") try: unittest.main() except SystemExit: pass main = staticmethod(main)
class TacticNodeUtil(object): '''This class encapsulates functionality needed interact with information to communicate with any application.''' def __init__(self): import maya.standalone maya.standalone.initialize( name='python' ) import maya.cmds, maya.mel from tactic_client_lib.application.maya import Maya self.app = Maya() def is_tactic_node(self, node_name): '''Determines whether a particular node is a tactic node''' pass def get_all_tactic_nodes(self): '''Gets all of the Tactic nodes in the session @return a list of all tactic node names ''' tactic_nodes = [] nodes = self.app.get_nodes_by_name("tactic_*") # go through each node an make sure that the attribute # exists for node in nodes: if self.is_tactic_node(node): tactic_nodes.append(node) return tactic_nodes def is_tactic_node(self, node_name): '''determines whether the given node is a tactic node ''' attribute = "tacticNodeData" exists = self.mel("attributeExists %s %s" % (attribute, node_name)) if not exists: return False else: return True # # action functions # def create_default_node(self, node_name, search_key=None, context=None): '''Creates a default template structure when loading a context that has no snapshots associated with it @params node_name: the name of the node to be created search_key: a search_key representing the sobject that this node belongs to @return the name of the tactic node created ''' # create the node type = "transform" node_name = self.app.add_node(node_name, type) # create the tactic node tactic_type = "transform" tactic_node_name = "tactic_%s" % node_name tactic_node_name = self.app.add_node(tactic_node_name, tactic_type) # add the tacticNodeData attribute and record the search type node_data = NodeData(tactic_node_name) if search_key: node_data.set_attr("ref", "search_key", search_key) if context: node_data.set_attr("ref", "context", context) node_data.commit() # attache the tactic node to the node self.mel("parent %s %s" % (tactic_node_name, node_name) ) return tactic_node_name def add_snapshot_to_node(self, tactic_node_name, snapshot): snapshot_code = snapshot.get('code') search_type = snapshot.get('search_type') search_id = snapshot.get('search_id') context = snapshot.get('context') version = snapshot.get('version') revision = snapshot.get('revision') node_data = NodeData(tactic_node_name) node_data.set_attr("ref", "snapshot_code", snapshot_code) node_data.set_attr("ref", "search_type", search_type) node_data.set_attr("ref", "search_id", search_id) node_data.set_attr("ref", "context", context) node_data.set_attr("ref", "version", version) node_data.set_attr("ref", "revision", revision) node_data.commit() def get_search_key(self, tactic_node_name): '''gets the snapshot data on a particular tactic node <node> <ref context='model' version='3' search_type='prod/asset?project=bar' search_id='4'/> </node> ''' node_data = NodeData(tactic_node_name) search_type = node_data.get_attr("ref", "search_key") return search_type def get_context(self, tactic_node_name): '''gets the snapshot data on a particular tactic node <node> <ref context='model' version='3' search_type='prod/asset?project=bar' search_id='4'/> </node> ''' node_data = NodeData(tactic_node_name) search_type = node_data.get_attr("ref", "context") return search_type def mel(self, cmd, verbose=None): '''Excecute a mel command (TEMPORARY - use maya specific)''' return maya.mel.eval(cmd)
class MayaTest(unittest.TestCase): '''Test the basic level interaction to Maya''' def test_all(self): from tactic_client_lib.application.common import TacticNodeUtil self.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya self.app = Maya() self._test_nodes() self._test_attributes() self._test_file() def _test_nodes(self): # create a test node node_name = "test_node" created_name = self.app.add_node(node_name) self.assertEquals(node_name, created_name) # test to see whether it exists exists = self.app.node_exists(created_name) self.assertEquals(True, exists) # create a node of the same name created_name2 = self.app.add_node(node_name) self.assertEquals("test_node1", created_name2) # create a node that should be unique created_name3 = self.app.add_node(node_name, unique=True) self.assertEquals("test_node", created_name3) # get the nodes by name pattern pattern = "test_*" nodes = self.app.get_nodes_by_name(pattern) self.assertEquals(['test_node', 'test_node1'], nodes) def _test_attributes(self): '''tests various attribute functionality''' def _test_file(self): if os.name == "nt": dir = "C:/sthpw/temp" else: dir = "/tmp/sthpw/temp" if not os.path.exists(dir): os.makedirs(dir) path = '%s/test' % dir if os.path.exists(path): os.unlink(path) path = self.app.save(path) self.assertEquals(True, os.path.exists(path)) # remove the file if os.path.exists(path): os.unlink(path) def main(): import sys sys.path.insert(0, "C:/Program Files/Southpaw/Tactic1.9/src/client") try: unittest.main() except SystemExit: pass main = staticmethod(main)
class TacticNodeUtil(object): '''This class encapsulates functionality needed interact with information to communicate with any application.''' def __init__(self): import maya.standalone maya.standalone.initialize(name='python') import maya.cmds, maya.mel from tactic_client_lib.application.maya import Maya self.app = Maya() def is_tactic_node(self, node_name): '''Determines whether a particular node is a tactic node''' pass def get_all_tactic_nodes(self): '''Gets all of the Tactic nodes in the session @return a list of all tactic node names ''' tactic_nodes = [] nodes = self.app.get_nodes_by_name("tactic_*") # go through each node an make sure that the attribute # exists for node in nodes: if self.is_tactic_node(node): tactic_nodes.append(node) return tactic_nodes def is_tactic_node(self, node_name): '''determines whether the given node is a tactic node ''' attribute = "tacticNodeData" exists = self.mel("attributeExists %s %s" % (attribute, node_name)) if not exists: return False else: return True # # action functions # def create_default_node(self, node_name, search_key=None, context=None): '''Creates a default template structure when loading a context that has no snapshots associated with it @params node_name: the name of the node to be created search_key: a search_key representing the sobject that this node belongs to @return the name of the tactic node created ''' # create the node type = "transform" node_name = self.app.add_node(node_name, type) # create the tactic node tactic_type = "transform" tactic_node_name = "tactic_%s" % node_name tactic_node_name = self.app.add_node(tactic_node_name, tactic_type) # add the tacticNodeData attribute and record the search type node_data = NodeData(tactic_node_name) if search_key: node_data.set_attr("ref", "search_key", search_key) if context: node_data.set_attr("ref", "context", context) node_data.commit() # attache the tactic node to the node self.mel("parent %s %s" % (tactic_node_name, node_name)) return tactic_node_name def add_snapshot_to_node(self, tactic_node_name, snapshot): snapshot_code = snapshot.get('code') search_type = snapshot.get('search_type') search_id = snapshot.get('search_id') context = snapshot.get('context') version = snapshot.get('version') revision = snapshot.get('revision') node_data = NodeData(tactic_node_name) node_data.set_attr("ref", "snapshot_code", snapshot_code) node_data.set_attr("ref", "search_type", search_type) node_data.set_attr("ref", "search_id", search_id) node_data.set_attr("ref", "context", context) node_data.set_attr("ref", "version", version) node_data.set_attr("ref", "revision", revision) node_data.commit() def get_search_key(self, tactic_node_name): '''gets the snapshot data on a particular tactic node <node> <ref context='model' version='3' search_type='prod/asset?project=bar' search_id='4'/> </node> ''' node_data = NodeData(tactic_node_name) search_type = node_data.get_attr("ref", "search_key") return search_type def get_context(self, tactic_node_name): '''gets the snapshot data on a particular tactic node <node> <ref context='model' version='3' search_type='prod/asset?project=bar' search_id='4'/> </node> ''' node_data = NodeData(tactic_node_name) search_type = node_data.get_attr("ref", "context") return search_type def mel(self, cmd, verbose=None): '''Excecute a mel command (TEMPORARY - use maya specific)''' return maya.mel.eval(cmd)
class ApplicationApiTest(unittest.TestCase): def setUp(self): pass def test_all(self): print "Running Client Application API Test" from tactic_client_lib import TacticServerStub # set the server to test... assume it is run on the server server = "localhost" url = "http://%s/tactic/default/Api/" % server self.server = TacticServerStub.get() project_code = "unittest" self.server.set_project(project_code) self.server.start("Client API Unittest") from tactic_client_lib.application.common import TacticNodeUtil self.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya self.app = Maya() try: data = { 'code': 'joe' } self.person = self.server.insert("unittest/person", data) data = { 'code': 'mary' } self.person2 = self.server.insert("unittest/person", data) self._test_load_template() self._test_checkin() self._test_load() self._test_introspect() except Exception: self.server.abort() raise else: self.server.abort() def _test_load_template(self): '''load in asset (one with no snapshots)''' search_key = self.person.get("__search_key__") code = self.person.get("code") context = 'model' # create a new default entity node_name = code tactic_node = self.util.create_default_node(node_name, search_key, context) self.assertEquals( "tactic_joe", tactic_node) # check that it exists in Maya exists = self.app.mel("ls %s" % tactic_node) self.assertEquals( True, exists != None ) # create a second one search_key = self.person2.get("__search_key__") code = self.person2.get("code") context = 'model' # create a new default entity node_name = code tactic_node = self.util.create_default_node(node_name, search_key, context) self.assertEquals( "tactic_mary", tactic_node) # now that it is created, find all of the tactic nodes tactic_nodes = self.util.get_all_tactic_nodes() self.assertEquals( 2, len(tactic_nodes) ) def _test_checkin(self): # checkin a tactic node tactic_node = 'tactic_joe' # get the entity to check into (assume same as last one) search_key = self.util.get_search_key(tactic_node) self.assertEquals("unittest/person?project=unittest&code=joe", search_key) context = self.util.get_context(tactic_node) self.assertEquals("model", context) # create a new snapshot snapshot = self.server.create_snapshot(search_key, context=context) # add the snapshot to the node self.util.add_snapshot_to_node(tactic_node, snapshot) # save the file and check it in path = "blah.ma" path = self.app.save(path) # check in the file snapshot_code = snapshot.get('code') snapshot = self.server.add_file(snapshot_code, file_path=path, mode='upload') # extract the path path = self.server.get_path_from_snapshot(snapshot.get('code')) exists = os.path.exists(path) self.assertEquals(True, exists) # get the path from the latest snapshot context = 'model' snapshot = self.server.get_snapshot(search_key, context) snapshot_code = snapshot.get('code') path = self.server.get_path_from_snapshot(snapshot_code) self.app.load(path) # get all of the tactic nodes tactic_nodes = self.util.get_all_tactic_nodes() self.assertEquals(['tactic_joe', 'tactic_mary'], tactic_nodes) def _test_load(self): '''a more realistic loading example''' return # find all of the Tactic nodes search_type = self.person.get('__search_type__') code = self.person.get('code') search_key = self.server.build_search_key(search_type, code) # first checkin in a dummy model file path = "whatever_model.ma" file = open(path, 'w') file.write("whatever_model.ma") file.close() self.server.upload_file(path) model_snapshot = self.server.simple_checkin(search_key, file_path=path, context="model") # then checkin a dummy rig file with a reference to the model snapshot path = "whatever_rig.ma" file = open(path, 'w') file.write("whatever_rig.ma") file.close() self.server.upload_file(path) rig_snapshot = self.server.simple_checkin(search_key, file_path=path, context="rig") rig_snapshot = self.server.add_dependency_by_code( rig_snapshot.get('code'), model_snapshot.get('code') ) # the the latest full snapshot context = "rig" snapshot = self.server.get_snapshot(search_key, context) snapshot_type = snapshot.get("snapshot_type") snapshot_code = snapshot.get('code') snapshot_xml = self.server.get_full_snapshot_xml(snapshot_code) # we know based on the snapshot type that there is a rig and a # reference to a model print snapshot_xml def _test_introspect(self): # introspect the session from tactic_client_lib.application.common import Session session = Session() xml = session.introspect() # commit this session to the database session.commit() # get snapshots from the session snapshots = session.get_snapshots() # only one tactic node has a checkin self.assertEquals( 1, len(snapshots) ) # get the last session session.get_last() # get snapshots from the session snapshots = session.get_snapshots() self.assertEquals( 1, len(snapshots) ) def test_explorer(self): pass def main(): #sys.path.insert(0, "C:/Program Files/Southpaw/Tactic1.9/src/client") sys.path.insert(0, "..") try: unittest.main() except SystemExit: pass main = staticmethod(main)
class MayaTest(unittest.TestCase): '''Test the basic level interaction to Maya''' def test_all(self): from tactic_client_lib.application.common import TacticNodeUtil self.util = TacticNodeUtil() from tactic_client_lib.application.maya import Maya self.app = Maya() self._test_nodes() self._test_attributes() self._test_file() def _test_nodes(self): # create a test node node_name = "test_node" created_name = self.app.add_node(node_name) self.assertEquals(node_name, created_name) # test to see whether it exists exists = self.app.node_exists(created_name) self.assertEquals(True, exists) # create a node of the same name created_name2 = self.app.add_node(node_name) self.assertEquals("test_node1", created_name2) # create a node that should be unique created_name3 = self.app.add_node(node_name, unique=True) self.assertEquals("test_node", created_name3) # get the nodes by name pattern pattern = "test_*" nodes = self.app.get_nodes_by_name(pattern) self.assertEquals(['test_node','test_node1'], nodes) def _test_attributes(self): '''tests various attribute functionality''' def _test_file(self): if os.name == "nt": dir = "C:/sthpw/temp" else: dir = "/tmp/sthpw/temp" if not os.path.exists(dir): os.makedirs(dir) path = '%s/test' % dir if os.path.exists(path): os.unlink(path) path = self.app.save(path) self.assertEquals(True, os.path.exists(path)) # remove the file if os.path.exists(path): os.unlink(path) def main(): import sys sys.path.insert(0, "C:/Program Files/Southpaw/Tactic1.9/src/client") try: unittest.main() except SystemExit: pass main = staticmethod(main)