def testCreateAndDelete(self): name = 'test_saved_search_' + str(int(time.time())) string = '| search foo' #namespace = 'samples' #namespace = 'debug' #samples app no longer included in build, see SPL-18783 namespace = 'search' #apparently debug isn't either... just do it in the search app. search = Entity('saved/searches', name, namespace=namespace, owner=self.owner) search['search'] = string setEntity(search) challenge = getEntity('saved/searches', name, namespace=namespace, owner=self.owner) self.assertEqual(challenge.name, name) self.assertEqual(challenge.namespace, namespace) self.assertEqual(challenge['search'], string) deleteEntity('saved/searches', name, namespace=namespace, owner=self.owner) self.assert_(not rest.checkResourceExists( buildEndpoint('/saved/searches/', name, namespace=namespace)))
def testCreateAndDelete(self): name = 'test_saved_search_' + str(int(time.time())) string = '| search foo' #namespace = 'samples' #namespace = 'debug' #samples app no longer included in build, see SPL-18783 namespace = 'search' #apparently debug isn't either... just do it in the search app. search = Entity('saved/searches', name, namespace=namespace, owner=self.owner) search['search'] = string setEntity(search) challenge = getEntity('saved/searches', name, namespace=namespace, owner=self.owner) self.assertEqual(challenge.name, name) self.assertEqual(challenge.namespace, namespace) self.assertEqual(challenge['search'], string) deleteEntity('saved/searches', name, namespace=namespace, owner=self.owner) self.assert_(not rest.checkResourceExists(buildEndpoint('/saved/searches/', name, namespace=namespace)))
def setEntity(entity, sessionKey=None, uri=None, msgObj=None): ''' Commits the properties of a generic entity object ''' if not entity: raise Exception, 'Cannot set entity; no entity provided' if not entity.path: raise Exception, 'Entity does not have path defined' if not entity.name: raise Exception, 'Entity does not have name defined' if not entity.namespace: raise Exception, 'Cannot set entity without a namespace; %s' % entity.name # if editing entities that were owned by the system name, then convert to # to current user if not entity.owner: entity.owner = auth.getCurrentUser()['name'] if not uri: # This is where we determine edit / create behavior. WoNkY! if len(entity.links) > 0: for action, link in entity.links: if action == 'edit': uri = link if uri == None: uri = entity.getFullPath() postargs = entity.getCommitProperties() """ logger.debug("*" * 25) logger.debug("entity: %s." % entity) logger.debug("uri: %s." % uri) logger.debug("postargs: %s." % postargs) logger.debug("*" * 25) """ if not postargs: logger.warn('setEntity - tried to commit empty entity') raise Exception, 'setEntity - tried to commit empty entity' # if exists, then update by POST to own endpoint if rest.checkResourceExists(uri, sessionKey=sessionKey): # EAI sets entity.name to new for the new template... # so it will exist and not fall into the else case # do any of the endpoints used by Entity post back to # a nonexistent name for the create action? # EAI posts to the basePath. if entity.name == '_new': logger.debug("setting properties to create a new guy.") uri = entity.getBasePath() createName = entity.properties['name'] logger.debug("creating %s on %s." % (createName, uri)) entity.name = createName serverResponse, serverContent = rest.simpleRequest( uri, sessionKey=sessionKey, postargs=postargs, raiseAllErrors=True) if (serverResponse.status == 201): if msgObj: msgObj['messages'] = serverResponse.messages if serverResponse.status not in [200, 201]: logger.warn("Server did not return status 200 or 201.") else: try: atomFeed = rest.format.parseFeedDocument(serverContent) entity.id = atomFeed[0].id except Exception, e: pass return True
def setEntity(entity, sessionKey=None, uri=None, msgObj=None, strictCreate=False, filterArguments=None): ''' Commits the properties of a generic entity object ''' logger.debug("entity.setEntity() is deprecated") if not entity: raise Exception, 'Cannot set entity; no entity provided' if not entity.path: raise Exception, 'Entity does not have path defined' if not entity.name: raise Exception, 'Entity does not have name defined' if not entity.namespace: raise Exception, 'Cannot set entity without a namespace; %s' % entity.name # if editing entities that were owned by the system name, then convert to # to current user if not entity.owner: entity.owner = auth.getCurrentUser()['name'] #check if we should filter arguments based on optional/required/wildcardFields #only enabled for datamodel and data/ui/views for now if filterArguments is None: filterArguments = False if entity.path.startswith("data/models") or re.match( "^\/?data\/ui\/views(\/|$)", entity.path) or re.match( "^\/?saved\/searches(\/|$)", entity.path): filterArguments = True tmpEntity = None if not uri: # This is where we determine edit / create behavior. WoNkY! if len(entity.links) > 0: for action, link in entity.links: if action == 'edit': uri = link if uri == None: uri = entity.getFullPath() if filterArguments: tmpEntity = getEntity(entity.path, None, uri=uri + "/_new", sessionKey=sessionKey) if filterArguments and tmpEntity == None: tmpEntity = getEntity(entity.path, entity.name, uri=uri, sessionKey=sessionKey) if filterArguments: postargs = entity.getCommitProperties( optionalFields=tmpEntity.optionalFields, requiredFields=tmpEntity.requiredFields, wildcardFields=tmpEntity.wildcardFields, isACL=uri.endswith('/acl'), filterArguments=filterArguments) else: postargs = entity.getCommitProperties() """ logger.debug("*" * 25) logger.debug("entity: %s." % entity) logger.debug("uri: %s." % uri) logger.debug("postargs: %s." % postargs) logger.debug("*" * 25) """ if not postargs: logger.warn('setEntity - tried to commit empty entity') raise Exception, 'setEntity - tried to commit empty entity' # if exists, then update by POST to own endpoint if rest.checkResourceExists(uri, sessionKey=sessionKey) and not strictCreate: # EAI sets entity.name to new for the new template... # so it will exist and not fall into the else case # do any of the endpoints used by Entity post back to # a nonexistent name for the create action? # EAI posts to the basePath. if entity.name == '_new': logger.debug("setting properties to create a new guy.") uri = entity.getBasePath() createName = entity.properties['name'] logger.debug("creating %s on %s." % (createName, uri)) entity.name = createName serverResponse, serverContent = rest.simpleRequest( uri, sessionKey=sessionKey, postargs=postargs, raiseAllErrors=True) if (serverResponse.status == 201): if msgObj: msgObj['messages'] = serverResponse.messages if serverResponse.status not in [200, 201]: logger.warn("Server did not return status 200 or 201.") else: try: atomFeed = rest.format.parseFeedDocument(serverContent) entity.id = atomFeed[0].id except Exception, e: pass return True
def setEntity(entity, sessionKey=None, uri=None, msgObj=None, strictCreate=False, filterArguments=None): ''' Commits the properties of a generic entity object ''' logger.debug("entity.setEntity() is deprecated") if not entity: raise Exception, 'Cannot set entity; no entity provided' if not entity.path: raise Exception, 'Entity does not have path defined' if not entity.name: raise Exception, 'Entity does not have name defined' if not entity.namespace: raise Exception, 'Cannot set entity without a namespace; %s' % entity.name # if editing entities that were owned by the system name, then convert to # to current user if not entity.owner: entity.owner = auth.getCurrentUser()['name'] #check if we should filter arguments based on optional/required/wildcardFields #only enabled for datamodel and data/ui/views for now if filterArguments is None: filterArguments = False if entity.path.startswith("data/models") or re.match("^\/?data\/ui\/views(\/|$)", entity.path) or re.match("^\/?saved\/searches(\/|$)", entity.path): filterArguments = True tmpEntity = None if not uri: # This is where we determine edit / create behavior. WoNkY! if len(entity.links) > 0: for action, link in entity.links: if action == 'edit': uri = link if uri == None: uri = entity.getFullPath() if filterArguments: tmpEntity = getEntity(entity.path, None, uri=uri + "/_new", sessionKey=sessionKey) if filterArguments and tmpEntity == None: tmpEntity = getEntity(entity.path, entity.name, uri=uri, sessionKey=sessionKey) if filterArguments: postargs = entity.getCommitProperties(optionalFields=tmpEntity.optionalFields, requiredFields=tmpEntity.requiredFields, wildcardFields=tmpEntity.wildcardFields, isACL=uri.endswith('/acl'), filterArguments=filterArguments) else: postargs = entity.getCommitProperties() """ logger.debug("*" * 25) logger.debug("entity: %s." % entity) logger.debug("uri: %s." % uri) logger.debug("postargs: %s." % postargs) logger.debug("*" * 25) """ if not postargs: logger.warn('setEntity - tried to commit empty entity') raise Exception, 'setEntity - tried to commit empty entity' # if exists, then update by POST to own endpoint if rest.checkResourceExists(uri, sessionKey=sessionKey) and not strictCreate: # EAI sets entity.name to new for the new template... # so it will exist and not fall into the else case # do any of the endpoints used by Entity post back to # a nonexistent name for the create action? # EAI posts to the basePath. if entity.name == '_new': logger.debug("setting properties to create a new guy.") uri = entity.getBasePath() createName = entity.properties['name'] logger.debug("creating %s on %s." % (createName,uri)) entity.name = createName serverResponse, serverContent = rest.simpleRequest(uri, sessionKey=sessionKey, postargs=postargs, raiseAllErrors=True) if (serverResponse.status == 201): if msgObj: msgObj['messages'] = serverResponse.messages if serverResponse.status not in [200, 201]: logger.warn("Server did not return status 200 or 201.") else: try: atomFeed = rest.format.parseFeedDocument(serverContent) entity.id = atomFeed[0].id except Exception, e: pass return True
def setEntity(entity, sessionKey=None, uri=None, msgObj=None): ''' Commits the properties of a generic entity object ''' if not entity: raise Exception, 'Cannot set entity; no entity provided' if not entity.path: raise Exception, 'Entity does not have path defined' if not entity.name: raise Exception, 'Entity does not have name defined' if not entity.namespace: raise Exception, 'Cannot set entity without a namespace; %s' % entity.name # if editing entities that were owned by the system name, then convert to # to current user if not entity.owner: entity.owner = auth.getCurrentUser()['name'] if not uri: # This is where we determine edit / create behavior. WoNkY! if len(entity.links) > 0: for action, link in entity.links: if action == 'edit': uri = link if uri == None: uri = entity.getFullPath() postargs = entity.getCommitProperties() """ logger.debug("*" * 25) logger.debug("entity: %s." % entity) logger.debug("uri: %s." % uri) logger.debug("postargs: %s." % postargs) logger.debug("*" * 25) """ if not postargs: logger.warn('setEntity - tried to commit empty entity') raise Exception, 'setEntity - tried to commit empty entity' # if exists, then update by POST to own endpoint if rest.checkResourceExists(uri, sessionKey=sessionKey): # EAI sets entity.name to new for the new template... # so it will exist and not fall into the else case # do any of the endpoints used by Entity post back to # a nonexistent name for the create action? # EAI posts to the basePath. if entity.name == '_new': logger.debug("setting properties to create a new guy.") uri = entity.getBasePath() createName = entity.properties['name'] logger.debug("creating %s on %s." % (createName,uri)) entity.name = createName serverResponse, serverContent = rest.simpleRequest(uri, sessionKey=sessionKey, postargs=postargs, raiseAllErrors=True) if (serverResponse.status == 201): if msgObj: msgObj['messages'] = serverResponse.messages if serverResponse.status not in [200, 201]: logger.warn("Server did not return status 200 or 201.") else: try: atomFeed = rest.format.parseFeedDocument(serverContent) entity.id = atomFeed[0].id except Exception, e: pass return True