def testAddTask(self): shotCode = "TEST SHOT (delete me) %s" % uuid1() data = { "project": { "type": "Project", "id": testProjectID }, "code": shotCode } newShotDict = self.sg.create("Shot", data, []) self.assertTrue(self.shotgun2local.connectAndRun(), "synch not successful") shot = getObject("Shot", remote_id=newShotDict["id"]) self.assertEqual(type(shot), Shot) self.assertEqual(shot.code, shotCode) self.sg.delete("Shot", newShotDict["id"]) self.assertTrue(self.shotgun2local.connectAndRun(), "synch not successful") shot = getObject("Shot", remote_id=newShotDict["id"]) self.assertEqual(shot, None)
def test_create_and_delete(self): testshot = factories.getObject("Shot", remote_id=testShotID) node = entities.Node() node.code = "testshot_" + str(uuid.uuid1())[0:8] node.sg_link = testshot node.project = self.testproject node.save() newNodeID = node.getLocalID() output = entities.Output() output.sg_link = node output.code = str(uuid.uuid1())[0:8] + "_" + "_SCR" output.sg_type = "SCR" output.project = self.testproject output.save() newOutputID = output.getLocalID() node.delete() output.delete() ret = self.local2shotgun.connectAndRun() self.assertTrue(ret, "errors while syncing ") node = factories.getObject(entities.Node._type, local_id=newNodeID) self.assertEqual(node, None, "node should not exist anymore") output = factories.getObject(entities.Output._type, local_id=newOutputID) self.assertEqual(output, None, "output should not exist anymore")
def testProjectCreation( self ): userdict = config.getUserDict() nowstr = datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S" ) projectData = { "name": "TESTPROJECTE - DELETE ME - " + str( uuid.uuid1() ), "code": "0000_" + str( uuid.uuid1() ), "updated_by": userdict, "updated_at": nowstr, "created_by": userdict, "created_at": nowstr } entityDictStr = self.serverHandler.POST( "Project", None, None, testdata = projectData ) entityDict = json.loads( entityDictStr ) self.assertTrue( entityDict["__local_id"] != None ) newObj = factories.getObject( "Project", local_id = entityDict["__local_id"] ) self.assertTrue( newObj != None ) allOk = self.eventprocessor.connectAndRun() self.assertTrue( allOk, "errors on event processing" ) newObj = factories.getObject( "Project", local_id = entityDict["__local_id"] ) self.assertTrue( newObj.getRemoteID() ) self.serverHandler.DELETE( "Project", entityDict["__local_id"], None, testdata = "dummy" ) newObj = factories.getObject( "Project", local_id = entityDict["__local_id"] ) self.assertTrue( newObj == None ) self.eventprocessor.connectAndRun()
def test_create_and_delete( self ): testshot = factories.getObject( "Shot", remote_id = testShotID ) node = entities.Node() node.code = "testshot_" + str( uuid.uuid1() )[0:8] node.sg_link = testshot node.project = self.testproject node.save() newNodeID = node.getLocalID() output = entities.Output() output.sg_link = node output.code = str( uuid.uuid1() )[0:8] + "_" + "_SCR" output.sg_type = "SCR" output.project = self.testproject output.save() newOutputID = output.getLocalID() node.delete() output.delete() ret = self.local2shotgun.connectAndRun() self.assertTrue( ret, "errors while syncing " ) node = factories.getObject( entities.Node._type, local_id = newNodeID ) self.assertEqual( node, None, "node should not exist anymore" ) output = factories.getObject( entities.Output._type, local_id = newOutputID ) self.assertEqual( output, None, "output should not exist anymore" )
def testAddTask( self ): lastevent = self.sg.find( "EventLogEntry", filters = [], fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity'], order = [{'column':'id', 'direction':'desc'}], filter_operator = 'all', limit = 1 )[0] self.lastID = lastevent["id"] data = { "project": {"type": "Project", "id": testProjectID }, "content": "TEST TASK (delete me)" } newTaskDict = self.sg.create( "Task", data, [] ) self.deleteEntities.append( newTaskDict ) newevents = self._getNewEvents() # self.assertEqual(len(newevents), 4, "not the same amount of events uppon creation of Task") self.assertEqual( newevents[0]["event_type"], "Shotgun_Task_New", "event not as expected" ) self._processEvents( newevents ) newTaskObj = factories.getObject( "Task", remote_id = newTaskDict["id"] ) self.sg.update( "Task", newTaskDict["id"], {"entity": {"type": "Shot", "id": testShotID}} ) newevents = self._getNewEvents() self.assertTrue( newevents[0]["event_type"] in ["Shotgun_Task_Change", "Shotgun_Shot_Change"] ) self.assertTrue( newevents[1]["event_type"] in ["Shotgun_Task_Change", "Shotgun_Shot_Change"] ) self._processEvents( newevents ) # check if tasks-property of Shot contains this task shotObj = factories.getObject( "Shot", remote_id = testShotID ) self.assertTrue( newTaskObj in shotObj.tasks ) self.sg.delete( "Task", newTaskDict["id"] ) newevents = self._getNewEvents() self.assertTrue( newevents[0]["event_type"] == "Shotgun_Task_Retirement" ) self.assertTrue( newevents[1]["event_type"] == "Shotgun_Task_Change" ) self._processEvents( newevents ) # check if tasks-property of Shot does not contain this task anymore shotObj = factories.getObject( "Shot", remote_id = testShotID ) self.assertFalse( newTaskObj in shotObj.tasks )
def testObjectRetrieval( self ): shotID = 1607 shot = getObject( "Shot", remote_id = shotID ) self.assertTrue( shot != None, "Shot %d does not exist?" % shotID ) shotID = 1606 shot = getObject( "Shot", remote_id = shotID ) self.assertTrue( shot == None, "Shot %d does exist?" % shotID )
def testObjectRetrieval(self): shotID = 1607 shot = getObject("Shot", remote_id=shotID) self.assertTrue(shot != None, "Shot %d does not exist?" % shotID) shotID = 1606 shot = getObject("Shot", remote_id=shotID) self.assertTrue(shot == None, "Shot %d does exist?" % shotID)
def __getattribute__(self, *args, **kwargs): name = args[0] if name == "id": name = "remote_id" if name == "sg_local_id": name = "local_id" fieldvalue = object.__getattribute__(self, name) fielddef = object.__getattribute__(self, "shotgun_fields") if fielddef.has_key(name): if fielddef[name]["data_type"]["value"] == "entity": entityObj = fieldvalue if type(entityObj) == connectors.PostgresEntityType: origvalue = factories.getObject( entityObj.type, remote_id=entityObj.remote_id, local_id=entityObj.local_id ) object.__setattr__(self, name, origvalue) return origvalue else: return entityObj elif fielddef[name]["data_type"]["value"] == "serializable": entityObj = fieldvalue if type(entityObj) in [unicode, str]: return json.loads(entityObj) else: return entityObj elif fielddef[name]["data_type"]["value"] == "multi_entity": entityObjArray = fieldvalue entityList = [] if entityObjArray == None: return [] for entityObj in entityObjArray: if type(entityObj) == connectors.PostgresEntityType: obj = factories.getObject( entityObj.type, remote_id=entityObj.remote_id, local_id=entityObj.local_id ) if obj: entityList.append(obj) else: entityList.append(entityObj) object.__setattr__(self, name, entityList) return entityList return fieldvalue
def __getattribute__( self, *args, **kwargs ): name = args[0] if name == "id": name = "remote_id" if name == "sg_local_id": name = "local_id" fieldvalue = object.__getattribute__( self, name ) fielddef = object.__getattribute__( self, "shotgun_fields" ) if fielddef.has_key( name ): if fielddef[name]["data_type"]["value"] == "entity": entityObj = fieldvalue if type( entityObj ) == connectors.PostgresEntityType: origvalue = factories.getObject( entityObj.type, remote_id = entityObj.remote_id, local_id = entityObj.local_id ) object.__setattr__( self, name, origvalue ) return origvalue else: return entityObj elif fielddef[name]["data_type"]["value"] == "serializable": entityObj = fieldvalue if type( entityObj ) in [ unicode, str ]: return json.loads( entityObj ) else: return entityObj elif fielddef[name]["data_type"]["value"] == "multi_entity": entityObjArray = fieldvalue entityList = [] if entityObjArray == None: return [] for entityObj in entityObjArray: if type( entityObj ) == connectors.PostgresEntityType: obj = factories.getObject( entityObj.type, remote_id = entityObj.remote_id, local_id = entityObj.local_id ) if obj: entityList.append( obj ) else: entityList.append( entityObj ) object.__setattr__( self, name, entityList ) return entityList return fieldvalue
def testLinkedAsset( self ): self.testasset.assets = [ self.linkedAsset ] self.testasset.save() # get connection objects from source connObj = factories.getConnectionObj( baseObj = self.testasset, linkedObj = self.linkedAsset, attribute = "assets" ) self.assertNotEqual( connObj, None ) # TODO: synch and check if not two connObj # self.assertTrue( self.local2shotgun.connectAndRun(), "synch not successful" ) connObj = factories.getConnectionObj( baseObj = self.testasset, linkedObj = self.linkedAsset, attribute = "assets" ) self.assertNotEqual( type( connObj ), list, "multiple connection objects after synch" ) # get attribute of reverse field reverseAttrName = entityNaming.getReverseAttributeName( "Asset", "assets" ) linkedAsset = factories.getObject( "Asset", local_id = self.linkedAsset.getLocalID() ) retLinks = linkedAsset.getField( reverseAttrName ) self.assertTrue( retLinks != None and self.testasset in retLinks ) # checking sync from shotgun to local self.assertTrue( self.shotgun2local.connectAndRun(), "synch not successful" ) connObj = factories.getConnectionObj( baseObj = self.testasset, linkedObj = self.linkedAsset, attribute = "assets" ) self.assertNotEqual( type( connObj ), list, "multiple connection objects after synch" ) # remove connection self.testasset.assets = [ ] self.testasset.save() connObj = factories.getConnectionObj( baseObj = self.testasset, linkedObj = self.linkedAsset, attribute = "assets" ) self.assertEqual( connObj, None ) linkedAsset = factories.getObject( "Asset", local_id = self.linkedAsset.getLocalID() ) retLinks = linkedAsset.getField( reverseAttrName ) self.assertEqual( retLinks, [] ) self.assertTrue( self.local2shotgun.connectAndRun(), "synch not successful" ) connObj = factories.getConnectionObj( baseObj = self.testasset, linkedObj = self.linkedAsset, attribute = "assets" ) self.assertEqual( connObj, None )
def setUp(self): self.testproject = getObject(Project().getType(), remote_id=testProjectID) self.eventprocessor = LocalDBEventSpooler() self.sg = shotgun.Shotgun(config.SHOTGUN_URL, config.SHOTGUN_SYNC_SKRIPT, config.SHOTGUN_SYNC_KEY) self.shotgun2local = shotgun_to_local.EventSpooler() self.testshot = factories.getObject(entities.Shot, remote_id=testShotID) self.current_cut_in = self.testshot.sg_cut_in
def setUp( self ): self.local2shotgun = local_to_shotgun.LocalDBEventSpooler() self.shotgun2local = shotgun_to_local.EventSpooler() self.testassetlibrary = factories.getObject( entities.AssetLibrary().getType(), remote_id = commanda.TEST_ASSETLIBRARY_ID ) self.task = factories.getObject( "Task", remote_id = tests_elefant.testTaskID ) self.testasset = tests_elefant.createTestAsset( self.testassetlibrary ) debug.debug( self.testasset.getLocalID() ) self.linkedAsset = tests_elefant.createTestAsset( self.testassetlibrary ) debug.debug( self.linkedAsset.getLocalID() )
def testSyncomaniaSplitsChange( self ): task = getObject( "Task", remote_id = testTaskID ) self.assertEqual( 11520, task.duration.days * 24 * 60 ) ret = self.sg.update( "Task", testTaskID, {"splits": SPLIT_NEW} ) debug.debug( ret ) self.assertTrue( self.shotgun2local.connectAndRun(), "synch not successful" ) task = getObject( "Task", remote_id = testTaskID ) self.assertEqual( 10080, task.duration.days * 24 * 60 ) self.assertEqual( len( task.splits ), 2 ) self.assertTrue( task.splits[0].has_key("start") ) self.assertTrue( task.splits[0].has_key("end") )
def testSyncomaniaSplitsChange(self): task = getObject("Task", remote_id=testTaskID) self.assertEqual(11520, task.duration.days * 24 * 60) ret = self.sg.update("Task", testTaskID, {"splits": SPLIT_NEW}) debug.debug(ret) self.assertTrue(self.shotgun2local.connectAndRun(), "synch not successful") task = getObject("Task", remote_id=testTaskID) self.assertEqual(10080, task.duration.days * 24 * 60) self.assertEqual(len(task.splits), 2) self.assertTrue(task.splits[0].has_key("start")) self.assertTrue(task.splits[0].has_key("end"))
def testDictGeneration( self ): shotID = 1607 shot = getObject( "Shot", remote_id = shotID ) datadict = shot.getShotgunDict() self.assertTrue( datadict != None ) self.assertEqual( datadict["code"], "ts020" )
def setUp( self ): self.testproject = getObject( Project().getType(), remote_id = testProjectID ) self.eventprocessor = LocalDBEventSpooler() self.sg = shotgun.Shotgun( config.SHOTGUN_URL, config.SHOTGUN_SYNC_SKRIPT, config.SHOTGUN_SYNC_KEY ) self.shotgun2local = shotgun_to_local.EventSpooler()
def setUp(self): self.local2shotgun = local_to_shotgun.LocalDBEventSpooler() self.shotgun2local = shotgun_to_local.EventSpooler() self.testassetlibrary = factories.getObject( entities.AssetLibrary().getType(), remote_id=commanda.TEST_ASSETLIBRARY_ID) self.task = factories.getObject("Task", remote_id=tests_elefant.testTaskID) self.testasset = tests_elefant.createTestAsset(self.testassetlibrary) debug.debug(self.testasset.getLocalID()) self.linkedAsset = tests_elefant.createTestAsset(self.testassetlibrary) debug.debug(self.linkedAsset.getLocalID())
def testDictGeneration(self): shotID = 1607 shot = getObject("Shot", remote_id=shotID) datadict = shot.getShotgunDict() self.assertTrue(datadict != None) self.assertEqual(datadict["code"], "ts020")
def testSyncomaniaSettingsChange( self ): lastevent = self.sg.find( "EventLogEntry", filters = [], fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity'], order = [{'column':'id', 'direction':'desc'}], filter_operator = 'all', limit = 1 )[0] debug.debug( lastevent ) lastID = lastevent["id"] ret = self.sg.update( "Task", testTaskID, {"sg_status_list": NEWVALUE} ) debug.debug( ret ) newevent = self.sg.find( "EventLogEntry", filters = [], fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity'], order = [{'column':'id', 'direction':'desc'}], filter_operator = 'all', limit = 1 )[0] debug.debug( newevent ) self.failUnlessEqual( newevent["entity"]["id"], testTaskID ) self.failUnlessEqual( newevent["meta"]["new_value"], NEWVALUE ) self.failUnlessEqual( newevent["id"], lastID + 1 ) self.assertTrue( self.shotgun2local.connectAndRun(), "synch not successful" ) task = getObject( "Task", remote_id = testTaskID ) self.assertEqual( NEWVALUE, task.sg_status_list )
def test_create(self): shot = Shot() shot.code = "delete me again - " + str(uuid.uuid1()) shot.project = self.testproject shot.save() newshotid = shot.getLocalID() self.assertTrue(newshotid != None and newshotid != shotgun_replica.UNKNOWN_SHOTGUN_ID) shot_ret = getObject("Shot", local_id=newshotid) self.assertTrue(shot_ret != None) self.assertTrue(shot_ret.getSgObj() == None) allOk = self.local2shotgun.connectAndRun() self.assertTrue(allOk, "errors while syncing ") shot_ret = getObject("Shot", local_id=newshotid) newRemoteID = shot_ret.getRemoteID() self.assertTrue( newRemoteID != None and newRemoteID != shotgun_replica.UNKNOWN_SHOTGUN_ID, "Shot with local ID %d has no remote id %s" % (newshotid, newRemoteID)) self.assertTrue(shot_ret.getSgObj() != None) entity_manipulation.deleteEntity(shot_ret) shot_ret = getObject("Shot", local_id=newshotid) self.assertTrue(shot_ret == None) newshot = self.sg.find("Shot", filters=[['id', 'is', newRemoteID]], fields=['id'], filter_operator='all', limit=100) self.assertEqual(len(newshot), 1) allOk = self.local2shotgun.connectAndRun() self.assertTrue(allOk, "errors while syncing ") newshot = self.sg.find("Shot", filters=[['id', 'is', newRemoteID]], fields=['id'], filter_operator='all', limit=100) self.assertEqual(len(newshot), 0)
def test_create( self ): shot = Shot() shot.code = "delete me again - " + str( uuid.uuid1() ) shot.project = self.testproject shot.save() newshotid = shot.getLocalID() self.assertTrue( newshotid != None and newshotid != shotgun_replica.UNKNOWN_SHOTGUN_ID ) shot_ret = getObject( "Shot", local_id = newshotid ) self.assertTrue( shot_ret != None ) self.assertTrue( shot_ret.getSgObj() == None ) allOk = self.local2shotgun.connectAndRun() self.assertTrue( allOk, "errors while syncing " ) shot_ret = getObject( "Shot", local_id = newshotid ) newRemoteID = shot_ret.getRemoteID() self.assertTrue( newRemoteID != None and newRemoteID != shotgun_replica.UNKNOWN_SHOTGUN_ID, "Shot with local ID %d has no remote id %s" % ( newshotid, newRemoteID ) ) self.assertTrue( shot_ret.getSgObj() != None ) entity_manipulation.deleteEntity( shot_ret ) shot_ret = getObject( "Shot", local_id = newshotid ) self.assertTrue( shot_ret == None ) newshot = self.sg.find( "Shot", filters = [['id', 'is', newRemoteID]], fields = ['id'], filter_operator = 'all', limit = 100 ) self.assertEqual( len( newshot ), 1 ) allOk = self.local2shotgun.connectAndRun() self.assertTrue( allOk, "errors while syncing " ) newshot = self.sg.find( "Shot", filters = [['id', 'is', newRemoteID]], fields = ['id'], filter_operator = 'all', limit = 100 ) self.assertEqual( len( newshot ), 0 )
def tearDown( self ): task = getObject( "Task", remote_id = testTaskID ) # changeEntity( task, {"sg_status_list": OLDVALUE} ) self.sg.update( "Task", testTaskID, {"sg_status_list": OLDVALUE, "splits": SPLIT_OLD, "start_date": START_DATE, "due_date": END_DATE } ) self.assertTrue( self.shotgun2local.connectAndRun(), "synch not successful" )
def test_create(self): shot = Shot() shot.code = "delete me again - " + str(uuid.uuid1()) shot.project = self.testproject shot.save() newshotid = shot.getLocalID() self.assertTrue(self.eventprocessor.connectAndRun(), "synch not successful") shot_ret = getObject("Shot", local_id=newshotid) newRemoteID = shot_ret.getRemoteID() self.assertTrue(newRemoteID != None and newRemoteID != shotgun_replica.UNKNOWN_SHOTGUN_ID) newCutIn = 1234 shot_ret.sg_cut_in = newCutIn shot_ret.save() self.assertTrue(self.eventprocessor.connectAndRun(), "synch not successful") newshot = self.sg.find("Shot", filters=[['id', 'is', newRemoteID]], fields=['id', 'sg_cut_in'], filter_operator='all', limit=100) self.assertEqual(newshot[0]['sg_cut_in'], newCutIn) shot_ret = shot_ret.delete() self.assertEqual(shot_ret, None) isShot = getObject("Shot", local_id=newshotid) self.assertEqual(isShot, None) self.assertTrue(self.eventprocessor.connectAndRun(), "synch not successful") newshot = self.sg.find("Shot", filters=[['id', 'is', newRemoteID]], fields=['id', 'sg_cut_in'], filter_operator='all', limit=100) self.assertEqual(len(newshot), 0)
def setUp(self): self.testproject = getObject(Project().getType(), remote_id=testProjectID) self.local2shotgun = LocalDBEventSpooler() self.sg = shotgun.Shotgun(config.SHOTGUN_URL, config.SHOTGUN_SYNC_SKRIPT, config.SHOTGUN_SYNC_KEY) self.shotgun2local = shotgun_to_local.EventSpooler()
def test_create( self ): shot = Shot() shot.code = "delete me again - " + str( uuid.uuid1() ) shot.project = self.testproject shot.save() newshotid = shot.getLocalID() self.assertTrue( self.eventprocessor.connectAndRun(), "synch not successful" ) shot_ret = getObject( "Shot", local_id = newshotid ) newRemoteID = shot_ret.getRemoteID() self.assertTrue( newRemoteID != None and newRemoteID != shotgun_replica.UNKNOWN_SHOTGUN_ID ) newCutIn = 1234 shot_ret.sg_cut_in = newCutIn shot_ret.save() self.assertTrue( self.eventprocessor.connectAndRun(), "synch not successful" ) newshot = self.sg.find( "Shot", filters = [['id', 'is', newRemoteID]], fields = ['id', 'sg_cut_in'], filter_operator = 'all', limit = 100 ) self.assertEqual( newshot[0]['sg_cut_in'], newCutIn ) shot_ret = shot_ret.delete() self.assertEqual( shot_ret, None ) isShot = getObject( "Shot", local_id = newshotid ) self.assertEqual( isShot, None ) self.assertTrue( self.eventprocessor.connectAndRun(), "synch not successful" ) newshot = self.sg.find( "Shot", filters = [['id', 'is', newRemoteID]], fields = ['id', 'sg_cut_in'], filter_operator = 'all', limit = 100 ) self.assertEqual( len( newshot ), 0 )
def _getEntity( self, entityType, localID, remoteID ): entityClass = connectors.getClassOfType( entityType ) if not entityClass: raise web.notfound() entity = factories.getObject( entityType, remote_id = intOrNone( remoteID ), local_id = intOrNone( localID ) ) return entity
def testVersionCreation( self ): node = factories.getObject( "Node", remote_id = testNodeID_1 ) output = factories.getObject( "Output", remote_id = testOutputID_1 ) project = factories.getObject( "Project", remote_id = testProjectID ) versionData = { "code": "001", "description": "delete me %s" % uuid.uuid1(), "entity": node.sg_link.getShortDict(), "sg_source_output": output.getShortDict(), "project": project.getShortDict(), } content = self.serverHandler.POST( "Version", None, None, versionData ) entityDict = json.loads( content ) self.assertTrue( entityDict["__local_id"] != None ) self.assertEqual( entityDict["entity"]["__local_id"], node.sg_link.getLocalID() ) content = self.serverHandler.DELETE( "Version", entityDict["__local_id"], None, testdata = "dummy" )
def test_change_Nones(self): self.testshot.sg_cut_in = None self.testshot.save() self.assertTrue(self.eventprocessor.connectAndRun(), "synch not successful") newshot = factories.getObject(entities.Shot, remote_id=testShotID) self.assertEqual(newshot.sg_cut_in, None)
def testAttributeRetrieval(self): shotID = 1607 shot = getObject("Shot", remote_id=shotID) self.assertEqual(type(shot.project), Project) self.assertEqual(type(shot.project), Project) tasks = shot.tasks self.assertTrue(len(tasks) > 0) self.assertEqual(type(tasks[0]), Task) self.assertFalse(shot == self.testtask) self.assertFalse(shot == "HANS")
def testAttributeRetrieval( self ): shotID = 1607 shot = getObject( "Shot", remote_id = shotID ) self.assertEqual( type( shot.project ), Project ) self.assertEqual( type( shot.project ), Project ) tasks = shot.tasks self.assertTrue( len( tasks ) > 0 ) self.assertEqual( type( tasks[0] ), Task ) self.assertFalse( shot == self.testtask ) self.assertFalse( shot == "HANS" )
def tearDown(self): task = getObject("Task", remote_id=testTaskID) # changeEntity( task, {"sg_status_list": OLDVALUE} ) self.sg.update( "Task", testTaskID, { "sg_status_list": OLDVALUE, "splits": SPLIT_OLD, "start_date": START_DATE, "due_date": END_DATE }) self.assertTrue(self.shotgun2local.connectAndRun(), "synch not successful")
def testAddTask( self ): shotCode = "TEST SHOT (delete me) %s" % uuid1() data = { "project": {"type": "Project", "id": testProjectID }, "code": shotCode } newShotDict = self.sg.create( "Shot", data, [] ) self.assertTrue( self.shotgun2local.connectAndRun(), "synch not successful" ) shot = getObject( "Shot", remote_id = newShotDict["id"] ) self.assertEqual( type( shot ), Shot ) self.assertEqual( shot.code, shotCode ) self.sg.delete( "Shot", newShotDict["id"] ) self.assertTrue( self.shotgun2local.connectAndRun(), "synch not successful" ) shot = getObject( "Shot", remote_id = newShotDict["id"] ) self.assertEqual( shot, None )
def _deleteEntity(self, event): """ process a delete entity event """ entity = event["corr_entity"] obj = getObject(entity.type, local_id=entity.local_id, includeRetireds=True) if obj and obj.getRemoteID() != shotgun_replica.UNKNOWN_SHOTGUN_ID: try: self.src.delete(entity) self.sg.delete(entity.type, obj.getRemoteID()) self._setProcessed(event) return True except shotgun_api3.Fault, fault: exception = "Error %s" % (str(fault)) self._setProcessed(event, exception=exception) return False
def testNodeVersionCreation( self ): versionData = { "code": "001", "sg_link": self.testnode.getShortDict(), "project": self.asset.project.getShortDict(), } content = self.serverHandler.POST( entities.NodeVersion._type, None, None, versionData ) entityDict = json.loads( content ) self.assertTrue( entityDict["sg_link"]["__local_id"] != -1 ) newObj = factories.getObject( entities.NodeVersion._type, local_id = entityDict["__local_id"] ) self.assertNotEqual( newObj.sg_link, None ) content = self.serverHandler.DELETE( entities.NodeVersion._type, entityDict["__local_id"], None, testdata = "dummy" )
def _createEntity(self, event): """ process a create entity event """ entity = event["corr_entity"] if type(entity.local_id) == type(1): try: obj = getObject(entity.type, local_id=entity.local_id, includeRetireds=True) if not obj: exception = "Error %s with local_id %d does not exist anymore" % ( entity.type, entity.local_id) self._setProcessed(event, exception=exception) return False remoteID = obj.getRemoteID() if remoteID != None and remoteID != UNKNOWN_SHOTGUN_ID: exception = ( "Error %s with local_id %d seems to be existing already.\n" + \ "This is most probably due to concurrent syncing of tests and sync-daemon? " ) % ( entity.type, entity.local_id ) self._setProcessed(event, exception=exception) return True data = obj.getShotgunDict() debug.debug(data) newdata = self.sg.create(entity.type, data) debug.debug(newdata) self.src.changeInDB(obj, "id", newdata["id"]) self._setProcessed(event) return True except AttributeError, fault: #event["type"] = "CouchdbChangeEvents" exception = "Error %s" % (str(fault)) self._setProcessed(event, exception=exception) return False except shotgun_api3.Fault, fault: #event["type"] = "CouchdbChangeEvents" exception = "Error %s" % (str(fault)) self._setProcessed(event, exception=exception) return False
def testProjectUpdate( self ): userdict = config.getUserDict() nowdt = datetime.datetime.now() nowstr = nowdt.strftime( "%Y-%m-%d %H:%M:%S" ) projectData = { "sg_status": "Active", "sg_due": "2012-08-08" } content = self.serverHandler.PUT( "Project", None, testProjectID, testdata = projectData ) entityDict = json.loads( content ) self.assertEqual( entityDict["sg_due"], "2012-08-08" ) newObj = factories.getObject( "Project", local_id = entityDict["__local_id"] ) self.assertEqual( newObj.sg_due, datetime.date( 2012, 8, 8 ) ) self.eventprocessor.connectAndRun()
def _createEntity( self, event ): """ process a create entity event """ entity = event["corr_entity"] if type( entity.local_id ) == type( 1 ): try: obj = getObject( entity.type, local_id = entity.local_id, includeRetireds = True ) if not obj: exception = "Error %s with local_id %d does not exist anymore" % ( entity.type, entity.local_id ) self._setProcessed( event, exception = exception ) return False remoteID = obj.getRemoteID() if remoteID != None and remoteID != UNKNOWN_SHOTGUN_ID: exception = ( "Error %s with local_id %d seems to be existing already.\n" + \ "This is most probably due to concurrent syncing of tests and sync-daemon? " ) % ( entity.type, entity.local_id ) self._setProcessed( event, exception = exception ) return True data = obj.getShotgunDict() debug.debug( data ) newdata = self.sg.create( entity.type, data ) debug.debug( newdata ) self.src.changeInDB( obj, "id", newdata["id"] ) self._setProcessed( event ) return True except AttributeError, fault: #event["type"] = "CouchdbChangeEvents" exception = "Error %s" % ( str( fault ) ) self._setProcessed( event, exception = exception ) return False except shotgun_api3.Fault, fault: #event["type"] = "CouchdbChangeEvents" exception = "Error %s" % ( str( fault ) ) self._setProcessed( event, exception = exception ) return False
def testSyncomaniaSettingsChange(self): lastevent = self.sg.find( "EventLogEntry", filters=[], fields=['id', 'event_type', 'attribute_name', 'meta', 'entity'], order=[{ 'column': 'id', 'direction': 'desc' }], filter_operator='all', limit=1)[0] debug.debug(lastevent) lastID = lastevent["id"] ret = self.sg.update("Task", testTaskID, {"sg_status_list": NEWVALUE}) debug.debug(ret) newevent = self.sg.find( "EventLogEntry", filters=[], fields=['id', 'event_type', 'attribute_name', 'meta', 'entity'], order=[{ 'column': 'id', 'direction': 'desc' }], filter_operator='all', limit=1)[0] debug.debug(newevent) self.failUnlessEqual(newevent["entity"]["id"], testTaskID) self.failUnlessEqual(newevent["meta"]["new_value"], NEWVALUE) self.failUnlessEqual(newevent["id"], lastID + 1) self.assertTrue(self.shotgun2local.connectAndRun(), "synch not successful") task = getObject("Task", remote_id=testTaskID) self.assertEqual(NEWVALUE, task.sg_status_list)
def testAddOutput( self ): lastevent = self.sg.find( "EventLogEntry", filters = [], fields = ['id', 'event_type', 'attribute_name', 'meta', 'entity'], order = [{'column':'id', 'direction':'desc'}], filter_operator = 'all', limit = 1 )[0] self.lastID = lastevent["id"] data = { "project": {"type": "Project", "id": testProjectID }, "code": "newoutput", "sg_link": {"type": "Task", "id": testTaskID }, } newOutputDict = self.sg.create( InOut().getType(), data, [] ) self.deleteEntities.append( newOutputDict ) newevents = self._getNewEvents() self.assertEqual( newevents[0]["event_type"], "Shotgun_CustomEntity02_New", "event not as expected" ) self.assertEqual( newevents[1]["event_type"], "Shotgun_CustomEntity02_Change", "event not as expected" ) self.assertEqual( newevents[2]["event_type"], "Shotgun_CustomEntity02_Change", "event not as expected" ) self.assertEqual( newevents[3]["event_type"], "Shotgun_CustomEntity02_Change", "event not as expected" ) self._processEvents( newevents ) newOutput = factories.getObject( "CustomEntity02", remote_id = newOutputDict["id"] ) changedData = { 'sg_sink_tasks': [ { "type": "Task", "id": testTaskID }, { "type": "Task", "id": testTaskID_2 }, ] } self.sg.update( newOutputDict["type"], newOutputDict["id"], changedData ) newevents = self._getNewEvents() self.assertEqual( len( newevents ), 5 ) self.assertEqual( newevents[0]["event_type"], "Shotgun_CustomEntity02_sg_sink_tasks_Connection_New" ) self.assertEqual( newevents[1]["event_type"], "Shotgun_CustomEntity02_sg_sink_tasks_Connection_New" ) self.assertEqual( newevents[2]["event_type"], "Shotgun_CustomEntity02_Change" ) self.assertEqual( newevents[3]["event_type"], "Shotgun_Task_Change" ) self.assertEqual( newevents[4]["event_type"], "Shotgun_Task_Change" ) self._processEvents( newevents ) # check if Connection-Entities are available filters = "custom_entity02=%s and task=ANY(%s)" taskSgObj1 = PostgresEntityType( "Task", remote_id = testTaskID ) taskSgObj2 = PostgresEntityType( "Task", remote_id = testTaskID_2 ) outputSgObj = PostgresEntityType( newOutputDict["type"], remote_id = newOutputDict["id"] ) filterValues = [ outputSgObj, [ taskSgObj1, taskSgObj2 ] ] connObjs = factories.getObjects( "CustomEntity02_sg_sink_tasks_Connection", filters, filterValues ) self.assertEqual( len( connObjs ), 2, "no conn-objs: %s" % pprint.pformat( connObjs, indent = 2 ) ) # check if return attribute of Task contains this CustomEntity02 retAttr = entityNaming.getReverseAttributeName( "CustomEntity02", "sg_sink_tasks" ) for taskID in [ testTaskID, testTaskID_2 ]: taskTmpObj = factories.getObject( "Task", remote_id = taskID ) retOutputs = taskTmpObj.__getattribute__( retAttr ) self.assertTrue( newOutput in retOutputs ) changedData["sg_sink_tasks"] = [] self.sg.update( newOutputDict["type"], newOutputDict["id"], changedData ) newevents = self._getNewEvents() # unfortunately there are two events missing: # see: https://support.shotgunsoftware.com/requests/7380 self.assertEqual( len( newevents ), 3 ) self.assertEqual( newevents[0]["event_type"], "Shotgun_CustomEntity02_Change" ) self.assertEqual( newevents[1]["event_type"], "Shotgun_Task_Change" ) self.assertEqual( newevents[2]["event_type"], "Shotgun_Task_Change" ) self._processEvents( newevents ) retAttr = entityNaming.getReverseAttributeName( "CustomEntity02", "sg_sink_tasks" ) for taskID in [ testTaskID, testTaskID_2 ]: taskTmpObj = factories.getObject( "Task", remote_id = taskID ) retOutputs = taskTmpObj.__getattribute__( retAttr ) if retOutputs: self.assertFalse( newOutput in retOutputs ) # check if Connection-Entities are deleted connObjs = factories.getObjects( "CustomEntity02_sg_sink_tasks_Connection", filters, filterValues ) self.assertEqual( len( connObjs ), 0, "conn-objs still available: %s" % pprint.pformat( connObjs, indent = 2 ) )
def changeEntity( myObj, changes ): """change entity in local database and add corresponding change-events for shotgun-sync""" # myObj.reload() src = connectors.DatabaseModificator() src.changeInDB( myObj, changes = changes ) for ( key, value ) in changes.iteritems(): if type( value ) == datetime.datetime: changes[key] = value.strftime( "%Y-%m-%d %H:%M:%S" ) if type( value ) == datetime.date: changes[key] = value.strftime( "%Y-%m-%d" ) elif type( value ) == datetime.timedelta: changes[key] = float( value.days ) * 24 + float( value.seconds ) / 3600 elif type( value ) == connectors.PostgresEntityType: changes[key] = value.getShortDict() elif isinstance( value, base_entity.ShotgunBaseEntity ): changes[key] = value.getShortDict() elif type( value ) == type( [] ): changes[key] = [] for entry in value: if isinstance( entry, base_entity.ShotgunBaseEntity ) or type( entry ) == connectors.PostgresEntityType: changes[key].append( entry.getShortDict() ) else: changes[key].append( entry ) attributeName = key fieldValues = value entityType = myObj.getType() connEntityName = entityNaming.getConnectionEntityName( entityType, attributeName ) if connEntityName != None: reverseAttribute = entityNaming.getReverseAttributeName( entityType, attributeName ) linkedEntityType = myObj.shotgun_fields[attributeName]["properties"]["valid_types"]["value"][0] baseEntityType = entityType ( baseAttrName, linkedAttrName ) = entityNaming.getConnectionEntityAttrName( baseEntityType, linkedEntityType, connEntityName ) basePgObj = myObj.getPgObj() # get connections filters = "%s=%s" % ( baseAttrName, "%s" ) filterValues = [ basePgObj ] connections = factories.getObjects( connEntityName, filters, filterValues ) # create new connection entities for linkedDict in changes[key]: linkedPostgresObj = getPgObj( linkedDict ) fieldNames = [ baseAttrName, linkedAttrName ] fieldValues = [ basePgObj, linkedPostgresObj ] # check if existing first connectionExists = False for i in range( len( connections ) ): connection = connections[i] if connection.getRawField( linkedAttrName ) == linkedPostgresObj: connections.remove( connection ) connectionExists = True break if not connectionExists: debug.debug( dict( zip( fieldNames, fieldValues ) ), prefix = "OOOOOOOOO" ) src._addToDatabase( connEntityName, fieldValues, fieldNames ) # setting reverse attribute as well linkedObj = factories.getObject( linkedDict["type"], local_id = linkedDict["__local_id"], remote_id = linkedDict["id"] ) retValues = linkedObj.getRawField( reverseAttribute ) if retValues == None: retValues = [] if basePgObj not in retValues: retValues.append( basePgObj ) src.changeInDB( linkedObj, reverseAttribute, retValues ) # delete unused connection entities for connection in connections: linkedObj = connection.getField( linkedAttrName ) retValues = linkedObj.getRawField( reverseAttribute ) retValues.remove( basePgObj ) src.changeInDB( linkedObj, reverseAttribute, retValues ) src.delete( connection ) _createChangeEvent( src, "change", corr_entity = myObj.getPgObj(), changed_values = json.dumps( changes ) ) return myObj
def testLinkedAsset(self): self.testasset.assets = [self.linkedAsset] self.testasset.save() # get connection objects from source connObj = factories.getConnectionObj(baseObj=self.testasset, linkedObj=self.linkedAsset, attribute="assets") self.assertNotEqual(connObj, None) # TODO: synch and check if not two connObj # self.assertTrue(self.local2shotgun.connectAndRun(), "synch not successful") connObj = factories.getConnectionObj(baseObj=self.testasset, linkedObj=self.linkedAsset, attribute="assets") self.assertNotEqual(type(connObj), list, "multiple connection objects after synch") # get attribute of reverse field reverseAttrName = entityNaming.getReverseAttributeName( "Asset", "assets") linkedAsset = factories.getObject( "Asset", local_id=self.linkedAsset.getLocalID()) retLinks = linkedAsset.getField(reverseAttrName) self.assertTrue(retLinks != None and self.testasset in retLinks) # checking sync from shotgun to local self.assertTrue(self.shotgun2local.connectAndRun(), "synch not successful") connObj = factories.getConnectionObj(baseObj=self.testasset, linkedObj=self.linkedAsset, attribute="assets") self.assertNotEqual(type(connObj), list, "multiple connection objects after synch") # remove connection self.testasset.assets = [] self.testasset.save() connObj = factories.getConnectionObj(baseObj=self.testasset, linkedObj=self.linkedAsset, attribute="assets") self.assertEqual(connObj, None) linkedAsset = factories.getObject( "Asset", local_id=self.linkedAsset.getLocalID()) retLinks = linkedAsset.getField(reverseAttrName) self.assertEqual(retLinks, []) self.assertTrue(self.local2shotgun.connectAndRun(), "synch not successful") connObj = factories.getConnectionObj(baseObj=self.testasset, linkedObj=self.linkedAsset, attribute="assets") self.assertEqual(connObj, None)
def _changeEntity( self, event ): """ process a change entity event """ entity = event["corr_entity"] entityObj = getObject( entity.type, remote_id = entity.remote_id, local_id = entity.local_id, includeRetireds = True ) if entityObj == None: exception = "Object not available %s local:%s remote:%s\n\n" % ( str( entity.type ), str( entity.local_id ), str( entity.remote_id ) ) self._setProcessed( event, exception = exception ) return False data = event["changed_values"] fieldDefs = connectors.getClassOfType( entity.type ).shotgun_fields hasFields = True for attribute in data.keys(): if not fieldDefs.has_key( attribute ): hasFields = False if not hasFields: exception = "some fields not available %s local:%s remote:%s" % ( str( entity.type ), str( entity.local_id ), str( entity.remote_id ) ) self._setProcessed( event, exception = exception ) return False else: for attribute in data.keys(): dataType = fieldDefs[attribute]["data_type"]["value"] value = data[attribute] if dataType == "float": data[attribute] = float( value ) elif dataType == "entity": data[attribute] = getSgObj( value ) elif dataType == "multi_entity": newvalue = [] for sgObj in value: newvalue.append( getSgObj( sgObj ) ) data[attribute] = newvalue elif dataType == "date_time": if type( value ) == type( u"" ): data[attribute] = datetime.datetime.strptime( value, "%Y-%m-%d %H:%M:%S" ) elif dataType == "date": if type( value ) == type( u"" ): data[attribute] = datetime.datetime.strptime( value, "%Y-%m-%d" ).date() elif dataType == "duration": if type( value ) == float: data[attribute] = int( value * 60 ) if fieldDefs.has_key( "sg_remotely_updated_by" ): data["sg_remotely_updated_by"] = event["updated_by"].getSgObj() try: debug.debug( data ) if entityObj.getType().endswith( "Connection" ) and entityObj.getRemoteID() == UNKNOWN_SHOTGUN_ID: remoteID = connectors.getRemoteID( entityObj.getType(), entityObj.getLocalID() ) if remoteID == None or remoteID == UNKNOWN_SHOTGUN_ID: # Connection-Entities need first the corresponding remote-id # they get that by the shotgun-event triggered by the event that causes this connection-entity to be created # so we simply have to wait and do nothing (hopefully ;) debug.info( "waiting for a connection-entitiy to appear %s" % ( str( entityObj ), ) ) return True self.sg.update( entityObj.getType(), entityObj.getRemoteID(), data ) self._setProcessed( event ) return True except shotgun_api3.Fault, fault: #event["type"] = "CouchdbChangeEvents" exception = "Error %s" % ( str( fault ) ) self._setProcessed( event, exception = exception ) return False
def testAddTask(self): lastevent = self.sg.find( "EventLogEntry", filters=[], fields=['id', 'event_type', 'attribute_name', 'meta', 'entity'], order=[{ 'column': 'id', 'direction': 'desc' }], filter_operator='all', limit=1)[0] self.lastID = lastevent["id"] data = { "project": { "type": "Project", "id": testProjectID }, "content": "TEST TASK (delete me)" } newTaskDict = self.sg.create("Task", data, []) self.deleteEntities.append(newTaskDict) newevents = self._getNewEvents() # self.assertEqual(len(newevents), 4, "not the same amount of events uppon creation of Task") self.assertEqual(newevents[0]["event_type"], "Shotgun_Task_New", "event not as expected") self._processEvents(newevents) newTaskObj = factories.getObject("Task", remote_id=newTaskDict["id"]) self.sg.update("Task", newTaskDict["id"], {"entity": { "type": "Shot", "id": testShotID }}) newevents = self._getNewEvents() self.assertTrue(newevents[0]["event_type"] in ["Shotgun_Task_Change", "Shotgun_Shot_Change"]) self.assertTrue(newevents[1]["event_type"] in ["Shotgun_Task_Change", "Shotgun_Shot_Change"]) self._processEvents(newevents) # check if tasks-property of Shot contains this task shotObj = factories.getObject("Shot", remote_id=testShotID) self.assertTrue(newTaskObj in shotObj.tasks) self.sg.delete("Task", newTaskDict["id"]) newevents = self._getNewEvents() self.assertTrue( newevents[0]["event_type"] == "Shotgun_Task_Retirement") self.assertTrue(newevents[1]["event_type"] == "Shotgun_Task_Change") self._processEvents(newevents) # check if tasks-property of Shot does not contain this task anymore shotObj = factories.getObject("Shot", remote_id=testShotID) self.assertFalse(newTaskObj in shotObj.tasks)
def setUp(self): self.testtask = getObject(Task().getType(), remote_id=testTaskID) pass
def testAddOutput(self): lastevent = self.sg.find( "EventLogEntry", filters=[], fields=['id', 'event_type', 'attribute_name', 'meta', 'entity'], order=[{ 'column': 'id', 'direction': 'desc' }], filter_operator='all', limit=1)[0] self.lastID = lastevent["id"] data = { "project": { "type": "Project", "id": testProjectID }, "code": "newoutput", "sg_link": { "type": "Task", "id": testTaskID }, } newOutputDict = self.sg.create(InOut().getType(), data, []) self.deleteEntities.append(newOutputDict) newevents = self._getNewEvents() self.assertEqual(newevents[0]["event_type"], "Shotgun_CustomEntity02_New", "event not as expected") self.assertEqual(newevents[1]["event_type"], "Shotgun_CustomEntity02_Change", "event not as expected") self.assertEqual(newevents[2]["event_type"], "Shotgun_CustomEntity02_Change", "event not as expected") self.assertEqual(newevents[3]["event_type"], "Shotgun_CustomEntity02_Change", "event not as expected") self._processEvents(newevents) newOutput = factories.getObject("CustomEntity02", remote_id=newOutputDict["id"]) changedData = { 'sg_sink_tasks': [ { "type": "Task", "id": testTaskID }, { "type": "Task", "id": testTaskID_2 }, ] } self.sg.update(newOutputDict["type"], newOutputDict["id"], changedData) newevents = self._getNewEvents() self.assertEqual(len(newevents), 5) self.assertEqual( newevents[0]["event_type"], "Shotgun_CustomEntity02_sg_sink_tasks_Connection_New") self.assertEqual( newevents[1]["event_type"], "Shotgun_CustomEntity02_sg_sink_tasks_Connection_New") self.assertEqual(newevents[2]["event_type"], "Shotgun_CustomEntity02_Change") self.assertEqual(newevents[3]["event_type"], "Shotgun_Task_Change") self.assertEqual(newevents[4]["event_type"], "Shotgun_Task_Change") self._processEvents(newevents) # check if Connection-Entities are available filters = "custom_entity02=%s and task=ANY(%s)" taskSgObj1 = PostgresEntityType("Task", remote_id=testTaskID) taskSgObj2 = PostgresEntityType("Task", remote_id=testTaskID_2) outputSgObj = PostgresEntityType(newOutputDict["type"], remote_id=newOutputDict["id"]) filterValues = [outputSgObj, [taskSgObj1, taskSgObj2]] connObjs = factories.getObjects( "CustomEntity02_sg_sink_tasks_Connection", filters, filterValues) self.assertEqual( len(connObjs), 2, "no conn-objs: %s" % pprint.pformat(connObjs, indent=2)) # check if return attribute of Task contains this CustomEntity02 retAttr = entityNaming.getReverseAttributeName("CustomEntity02", "sg_sink_tasks") for taskID in [testTaskID, testTaskID_2]: taskTmpObj = factories.getObject("Task", remote_id=taskID) retOutputs = taskTmpObj.__getattribute__(retAttr) self.assertTrue(newOutput in retOutputs) changedData["sg_sink_tasks"] = [] self.sg.update(newOutputDict["type"], newOutputDict["id"], changedData) newevents = self._getNewEvents() # unfortunately there are two events missing: # see: https://support.shotgunsoftware.com/requests/7380 self.assertEqual(len(newevents), 3) self.assertEqual(newevents[0]["event_type"], "Shotgun_CustomEntity02_Change") self.assertEqual(newevents[1]["event_type"], "Shotgun_Task_Change") self.assertEqual(newevents[2]["event_type"], "Shotgun_Task_Change") self._processEvents(newevents) retAttr = entityNaming.getReverseAttributeName("CustomEntity02", "sg_sink_tasks") for taskID in [testTaskID, testTaskID_2]: taskTmpObj = factories.getObject("Task", remote_id=taskID) retOutputs = taskTmpObj.__getattribute__(retAttr) if retOutputs: self.assertFalse(newOutput in retOutputs) # check if Connection-Entities are deleted connObjs = factories.getObjects( "CustomEntity02_sg_sink_tasks_Connection", filters, filterValues) self.assertEqual( len(connObjs), 0, "conn-objs still available: %s" % pprint.pformat(connObjs, indent=2))
def _changeEntity(self, event): """ process a change entity event """ entity = event["corr_entity"] entityObj = getObject(entity.type, remote_id=entity.remote_id, local_id=entity.local_id, includeRetireds=True) if entityObj == None: exception = "Object not available %s local:%s remote:%s\n\n" % ( str(entity.type), str(entity.local_id), str(entity.remote_id)) self._setProcessed(event, exception=exception) return False data = event["changed_values"] fieldDefs = connectors.getClassOfType(entity.type).shotgun_fields hasFields = True for attribute in data.keys(): if not fieldDefs.has_key(attribute): hasFields = False if not hasFields: exception = "some fields not available %s local:%s remote:%s" % ( str(entity.type), str(entity.local_id), str(entity.remote_id)) self._setProcessed(event, exception=exception) return False else: for attribute in data.keys(): dataType = fieldDefs[attribute]["data_type"]["value"] value = data[attribute] if value == None: continue if dataType == "float": data[attribute] = float(value) elif dataType == "entity": data[attribute] = getSgObj(value) elif dataType == "multi_entity": newvalue = [] for sgObj in value: newvalue.append(getSgObj(sgObj)) data[attribute] = newvalue elif dataType == "date_time": if type(value) == unicode or type(value) == str: data[attribute] = datetime.datetime.strptime( value, "%Y-%m-%d %H:%M:%S") if value.tzinfo == None: from pytz import timezone zurich = timezone("Europe/Zurich") value = zurich.localize(value) elif dataType == "date": if type(value) == unicode or type(value) == str: data[attribute] = datetime.datetime.strptime( value, "%Y-%m-%d").date() elif dataType == "duration": if type(value) == float: data[attribute] = int(value * 60) if fieldDefs.has_key( "sg_remotely_updated_by") and event["updated_by"] != None: data["sg_remotely_updated_by"] = event["updated_by"].getSgObj() try: debug.debug(data) if entityObj.getType().endswith( "Connection") and entityObj.getRemoteID( ) == UNKNOWN_SHOTGUN_ID: remoteID = connectors.getRemoteID(entityObj.getType(), entityObj.getLocalID()) if remoteID == None or remoteID == UNKNOWN_SHOTGUN_ID: # Connection-Entities need first the corresponding remote-id # they get that by the shotgun-event triggered by the event that causes this connection-entity to be created # so we simply have to wait and do nothing (hopefully ;) debug.info( "waiting for a connection-entitiy to appear %s" % (str(entityObj), )) return True self.sg.update(entityObj.getType(), entityObj.getRemoteID(), data) self._setProcessed(event) return True except shotgun_api3.Fault, fault: #event["type"] = "CouchdbChangeEvents" exception = "Error %s" % (str(fault)) self._setProcessed(event, exception=exception) return False
def setUp( self ): self.serverHandler = server.Handler() self.eventprocessor = LocalDBEventSpooler() self.asset = factories.getObject( "Asset", remote_id = testAssetID ) self.testnode = createTestNode( self.asset )
def setUp( self ): self.testnode = factories.getObject( entities.Node._type, remote_id = 1 )
def setUp( self ): self.testtask = getObject( Task().getType(), remote_id = testTaskID ) pass