コード例 #1
0
 def __init__(self, url):
     Calendar.__init__(self, url)
     self.url = url
     self.GHelper = GlobalHelper()
     self.reqBuilder = SysUtils.getRequestBuilder()
コード例 #2
0
	def __init__(self,url):
		Calendar.__init__(self, url)
		self.url = url
		self.GHelper = GlobalHelper()
		self.reqBuilder = SysUtils.getRequestBuilder()
コード例 #3
0
class CalendarLib(Calendar):
    def __init__(self, url):
        Calendar.__init__(self, url)
        self.url = url
        self.GHelper = GlobalHelper()
        self.reqBuilder = SysUtils.getRequestBuilder()

    def get_calendar_param_by_key(self, **kargs):
        '''
		kargs['res'] -> {
			"id" : "http://*****:*****@openwave.com/webtop_14bc54f58a9",
			"name" : "create test2",
			"color" : null,
			"visible" : true,
			"primary" : false,
			"personal" : true,
			"readOnly" : false,
			"sharingUrl" : "http://*****:*****@openwave.com/webtop_14bc54f58a9"
		  }
		kargs['key'] -> eg. "name" means check by name
		kargs['exp_value'] -> expect a value of key, eg. "new cal" means calendar name
		kargs['get'] -> the param expect to get, eg. "id" means to get calendar id
		'''
        calendar = eval(kargs['res'])
        if calendar[kargs['key']] == kargs['exp_value']:
            return calendar[kargs['get']]
        else:
            raise Exception('Failed to get %s by %s' %
                            (kargs['get'], kargs['key']))

    def get_calendar_id_by_name(self, **kargs):
        res = self.list_calendar()
        result_id = utils.getIdListByName(name=kargs['name'], res=str(res))
        if kargs.has_key('one_string'):
            return result_id[0]
        if kargs.has_key('index'):
            index = int(kargs['index'])
            return result_id[index]
        return result_id

    def del_all_calendars(self):
        res = self.list_calendar()
        cal_list = eval(res)
        print type(cal_list)
        for cal in cal_list:
            if 'main calendar' not in cal['name']:
                kargs = {'params.id': cal['id']}
                self.del_calendar(**kargs)

    def get_oringinal_event_ids(self, **kargs):
        '''	kargs['res'] -> report event response
			return ids list, if there's a recurrent event, just return the oringinal one '''
        eventRes = eval(kargs['res'])['events']['results']
        ids = []
        for event in eventRes:
            if event.has_key('recurrence') and event.has_key('recurrenceOf'):
                pass
            elif event['@type'] == 'Event':
                ids.append(event['uid'])
        if kargs.has_key('index'):
            index = int(kargs['index'])
            return ids[index]
        return ids

    def get_recurrence_master_event_ids(self, **kargs):
        '''	kargs['res'] -> report event response
			return ids list, only for a recurrent event, just return the oringinal ones '''
        eventRes = eval(kargs['res'])['events']['results']
        ids = []
        for event in eventRes:
            if not event.has_key('recurrenceOf') and event.has_key(
                    'recurrence') and event['@type'] == 'Event':
                ids.append(event['uid'])
        return ids

    def get_recurrence_sub_event_ids(self, **kargs):
        '''	kargs['res'] -> report event response
			kargs['masterId'] -> only one master event Id
			kargs['index'] -> from 0 to .., index of sub-event Id
			return ids list, only for a recurrent event, just return the sub ones which match the 'masterId' '''
        eventRes = eval(kargs['res'])['events']['results']
        index = int(kargs['index'])
        ids = []
        for event in eventRes:
            if event.has_key('recurrenceOf'
                             ) and event['recurrenceOf'] == kargs['masterId']:
                ids.append(event['uid'])
        return ids[index]

    def del_events(self, **kargs):
        '''kargs -> either 'params.calendarId' and 'ids', means delete all ids from 'ids' list
					or 'params.calendarId' and 'params.eventId'
		'''
        if kargs.has_key('ids'):
            ids = kargs['ids']
            del kargs['ids']
            for id in ids:
                kargs['params.eventId'] = id
                self.del_event(**kargs)
        else:
            print 'del a event'
            self.del_event(**kargs)

    def empty_event(self, **kargs):
        '''kargs['name'], params.startTime, params.endTime  '''
        get_id_h = {'name': kargs['name']}
        cal_ids = self.get_calendar_id_by_name(**get_id_h)

        report_event_h = {
            'params.calendarIds': cal_ids,
            'params.startTime': kargs['params.startTime'],
            'params.endTime': kargs['params.endTime']
        }
        events_res = self.report_event(**report_event_h)

        original_ids_h = {'res': events_res}
        event_ids = self.get_oringinal_event_ids(**original_ids_h)

        del_events_h = {'params.calendarId': cal_ids[0], 'ids': event_ids}
        self.del_events(**del_events_h)

        return 'Empty events done'

    def birthday_startTime(self, **kargs):
        '''
			i.e. 
			(refer to ${birth day}	makeContactField	label=birthday	type=lzPersonal	value=19860608	primary=false)
			${birthday_startTime}	birthday_startTime	birthday=${birth day}
		'''
        return str(kargs['birthday']['value']) + 'T000000'

    def empty_tasklist(self, **kargs):
        list_tasklist_params = {'params.calendarId': kargs['calendarId']}
        list_tasklist_res = self.list_tasklist(**list_tasklist_params)

        GHelper_params = {'res': list_tasklist_res, 'all': 'true'}
        tasklist_id_list = self.GHelper.get_id_list_by_name(**GHelper_params)

        for id in tasklist_id_list:
            del_tasklist_params = {
                'params.calendarId': kargs['calendarId'],
                'params.taskListId': id
            }
            self.del_tasklist(**del_tasklist_params)
        return 'All tasklist are deleted'

    def empty_todos(self, **kargs):
        ''' kargs['name'] = ${common_from}${common_domain}'s main calendar'''
        calid = self.get_calendar_id_by_name(**kargs)
        list_task_h = {'params.calendarId': calid}
        list_task_res = self.list_task(**list_task_h)
        todo_list = eval(list_task_res)['toDos']['results']
        uid_k = {'res': todo_list, 'all': True}
        uid_list = self.GHelper.get_id_list_by_name(**uid_k)

        del_task_k = {'params.calendarId': calid}
        # del_task	params.calendarId=${cal ids}	params.toDoId=${created_uid}
        for uid in uid_list:
            del_task_k['params.toDoId'] = uid
            self.del_task(**del_task_k)
            print 'del ' + str(uid)
        return 'empty_todos done for the calendar'

    # ---------------------------------------old func----------------------------------------------
    def get_cal_id_by_name(self, **kargs):
        res = self.list_calendar()
        result_list = utils.getCalendarIDListByName(kargs['name'], res)
        if len(result_list) == 0:
            raise Exception('Can not find calendar(name : %s) !' %
                            kargs['name'])
        return result_list[0]

    def create_max_calendar(self, **kargs):
        if not kargs.has_key('calendarMax'):
            raise Exception('Missing calendarMax in parameters!')
        exceedNumber = int(kargs['calendarMax']) + 1
        for i in range(exceedNumber):
            try:
                kargs['name'] = 'testmax' + str(i)
                self.create_calendar(**kargs)
                print 'create number ' + str(i)
            except Exception, ex:
                if (i == int(kargs['calendarMax'])
                    ):  #to do:need to assert the error msg
                    return 'One more than Max raise exception, case pass!'
                else:
                    print 'number ' + str(i) + ' failed'
                    raise ex
        raise Exception(
            'Exceed the nested layer limitation %s! No error found in response.'
            % str(exceedNumber))
コード例 #4
0
class CalendarLib(Calendar):
	def __init__(self,url):
		Calendar.__init__(self, url)
		self.url = url
		self.GHelper = GlobalHelper()
		self.reqBuilder = SysUtils.getRequestBuilder()
		
	def get_calendar_param_by_key(self, **kargs):
		'''
		kargs['res'] -> {
			"id" : "http://*****:*****@openwave.com/webtop_14bc54f58a9",
			"name" : "create test2",
			"color" : null,
			"visible" : true,
			"primary" : false,
			"personal" : true,
			"readOnly" : false,
			"sharingUrl" : "http://*****:*****@openwave.com/webtop_14bc54f58a9"
		  }
		kargs['key'] -> eg. "name" means check by name
		kargs['exp_value'] -> expect a value of key, eg. "new cal" means calendar name
		kargs['get'] -> the param expect to get, eg. "id" means to get calendar id
		'''
		calendar = eval(kargs['res'])
		if calendar[kargs['key']] == kargs['exp_value']:
			return calendar[kargs['get']]
		else:
			raise Exception('Failed to get %s by %s'%(kargs['get'],kargs['key'] ))
	
	def get_calendar_id_by_name(self, **kargs):
		res = self.list_calendar()
		result_id = utils.getIdListByName(name=kargs['name'], res=str(res))
		if kargs.has_key('one_string'):
			return result_id[0]
		if kargs.has_key('index'):
			index = int(kargs['index'])
			return result_id[index]
		return result_id
		
	
	def del_all_calendars(self):
		res = self.list_calendar()
		cal_list = eval(res)
		print type(cal_list)
		for cal in cal_list:
			if 'main calendar' not in cal['name']:
				kargs = {'params.id': cal['id']}
				self.del_calendar(**kargs)
	
	def get_oringinal_event_ids(self, **kargs):
		'''	kargs['res'] -> report event response
			return ids list, if there's a recurrent event, just return the oringinal one '''
		eventRes = eval(kargs['res'])['events']['results']
		ids = []
		for event in eventRes:
			if event.has_key('recurrence') and event.has_key('recurrenceOf'):
				pass
			elif event['@type'] == 'Event':
				ids.append(event['uid'])
		if kargs.has_key('index'):
			index = int(kargs['index'])
			return ids[index]
		return ids
		
	def get_recurrence_master_event_ids(self, **kargs):
		'''	kargs['res'] -> report event response
			return ids list, only for a recurrent event, just return the oringinal ones '''
		eventRes = eval(kargs['res'])['events']['results']
		ids = []
		for event in eventRes:
			if not event.has_key('recurrenceOf') and event.has_key('recurrence') and event['@type'] == 'Event':
				ids.append(event['uid'])
		return ids
	
	def get_recurrence_sub_event_ids(self, **kargs):
		'''	kargs['res'] -> report event response
			kargs['masterId'] -> only one master event Id
			kargs['index'] -> from 0 to .., index of sub-event Id
			return ids list, only for a recurrent event, just return the sub ones which match the 'masterId' '''
		eventRes = eval(kargs['res'])['events']['results']
		index = int(kargs['index'])
		ids = []
		for event in eventRes:
			if event.has_key('recurrenceOf') and event['recurrenceOf'] == kargs['masterId']:
				ids.append(event['uid'])
		return ids[index]
		
		
	def del_events(self, **kargs):
		'''kargs -> either 'params.calendarId' and 'ids', means delete all ids from 'ids' list
					or 'params.calendarId' and 'params.eventId'
		'''
		if kargs.has_key('ids'):
			ids = kargs['ids']
			del kargs['ids']
			for id in ids:
				kargs['params.eventId'] = id
				self.del_event(**kargs)
		else:
			print 'del a event'
			self.del_event(**kargs)
		
	def empty_event(self, **kargs):
		'''kargs['name'], params.startTime, params.endTime  '''
		get_id_h = {'name': kargs['name']}
		cal_ids = self.get_calendar_id_by_name(**get_id_h)
		
		report_event_h = {'params.calendarIds':cal_ids,'params.startTime': kargs['params.startTime'], 'params.endTime': kargs['params.endTime']}
		events_res = self.report_event(**report_event_h)
		
		original_ids_h = {'res': events_res}
		event_ids = self.get_oringinal_event_ids(**original_ids_h)
		
		del_events_h = {'params.calendarId':cal_ids[0], 'ids': event_ids}
		self.del_events(**del_events_h)
		
		return 'Empty events done'
	
	def birthday_startTime(self, **kargs):
		'''
			i.e. 
			(refer to ${birth day}	makeContactField	label=birthday	type=lzPersonal	value=19860608	primary=false)
			${birthday_startTime}	birthday_startTime	birthday=${birth day}
		'''
		return str(kargs['birthday']['value'])+'T000000'
	
	
	def empty_tasklist(self, **kargs):
		list_tasklist_params = {'params.calendarId':kargs['calendarId']}
		list_tasklist_res = self.list_tasklist(**list_tasklist_params)
		
		GHelper_params = {'res':list_tasklist_res, 'all':'true'}
		tasklist_id_list = self.GHelper.get_id_list_by_name(**GHelper_params)
		
		for id in tasklist_id_list:
			del_tasklist_params = {'params.calendarId':kargs['calendarId'], 'params.taskListId':id}
			self.del_tasklist(**del_tasklist_params)
		return 'All tasklist are deleted'
	
	def empty_todos(self, **kargs):
		''' kargs['name'] = ${common_from}${common_domain}'s main calendar'''
		calid = self.get_calendar_id_by_name(**kargs)
		list_task_h = {'params.calendarId': calid}
		list_task_res = self.list_task(**list_task_h)
		todo_list = eval(list_task_res)['toDos']['results']
		uid_k = {'res':todo_list, 'all':True}
		uid_list = self.GHelper.get_id_list_by_name(**uid_k)
		
		del_task_k = {'params.calendarId': calid}
		# del_task	params.calendarId=${cal ids}	params.toDoId=${created_uid}
		for uid in uid_list:
			del_task_k['params.toDoId'] = uid
			self.del_task(**del_task_k)
			print 'del '+str(uid)
		return 'empty_todos done for the calendar'
		


		
	
	# ---------------------------------------old func----------------------------------------------
	def get_cal_id_by_name(self, **kargs):
		res = self.list_calendar()
		result_list = utils.getCalendarIDListByName(kargs['name'], res)
		if len(result_list) == 0:
			raise Exception('Can not find calendar(name : %s) !'%kargs['name'])
		return result_list[0]

	
	def create_max_calendar(self,**kargs):
		if not kargs.has_key('calendarMax'):
			raise Exception('Missing calendarMax in parameters!')
		exceedNumber = int(kargs['calendarMax']) + 1
		for i in range(exceedNumber):
			try:
				kargs['name'] = 'testmax' + str(i)
				self.create_calendar(**kargs)
				print 'create number '+str(i)
			except Exception,ex:
				if (i == int(kargs['calendarMax'])): #to do:need to assert the error msg
					return 'One more than Max raise exception, case pass!'
				else:
					print 'number '+str(i)+' failed'
					raise ex
		raise Exception('Exceed the nested layer limitation %s! No error found in response.'%str(exceedNumber))