class SchemaTestCase(unittest.TestCase): """Reset the schema API between unit tests""" def setUp(self): self.rv = NullRepositoryView(verify=True) def tearDown(self): self.failUnless(self.rv.check(), "check() failed")
def setUp(self): # This setup is needed because we'd like to be able to use # --locale on the command line to test a given locale. So, # basically the code below is copy-and-pasted out of Utility.py # to make sure that everything gets initialized in the right # order. needInit = (self.view is None) # We always store a list of all failures, so that we can report them # all rather than fail on the first. self.failures = [] if needInit: Utility.initLogging(Globals.options) type(self).view = NullRepositoryView() parcelPath = Utility.initParcelEnv(Globals.options, Globals.chandlerDirectory) pluginEnv, pluginEggs = Utility.initPluginEnv( Globals.options, Globals.options.pluginPath) Utility.initI18n(Globals.options) Utility.initParcels(Globals.options, self.view, parcelPath) Utility.initPlugins(Globals.options, self.view, pluginEnv, pluginEggs) # We don't want to import these globally, because they will # trigger parcel loading, and that will cause i18n to be set # up before the above call to initI18n, which will mean --locale # won't work on the command line. So, instead, we stash these # in instance variables. self.Menu = schema.importString('osaf.framework.blocks.Menu') self.MenuItem = schema.importString('osaf.framework.blocks.MenuItem')
def createItems(paramDict): if bool(wx.GetApp()): view = QAUITestAppLib.App_ns.itsView else: # when running unit tests there is no app view = NullRepositoryView(verify=True) tzinfo = view.tzinfo.getDefault() totalItems = int(paramDict['textCtrlTotalItems']) #get titles to use TITLES = getDataFromFile(paramDict['textCtrlTitleSourceFile']) #create collections to use collectionNames = addRandomWithoutDups( getDataFromFile(paramDict['textCtrlCollectionFileName']), int(paramDict['textCtrlCollectionCount'])) sidebarCollections = createCollections(collectionNames, view) #determine how many collections each item should participate in collectionMembershipIndex = createMembershipIndex( paramDict['textCtrlCollectionMembership'], range(totalItems)) collectionMembershipDict = {} ##fill collectionMembershipDict with correct number of collections for each item index for i in range(totalItems): collectionMembershipDict[i] = addRandomWithoutDups( sidebarCollections, collectionMembershipIndex[i]) #get locations to use LOCATIONS = getDataFromFile(paramDict['textCtrlLocationSourceFilePath']) #get note field text NOTES = getDataFromFile(paramDict['textCtrlNoteSourceFilePath'], note=True) itemTypes = percentsToCount( totalItems, { 'mail': int(paramDict['choicePercentMail']), 'task': int(paramDict['choicePercentTask']), 'event': int(paramDict['choicePercentEvent']) }) triageStatus = percentsToCount( totalItems, { 'unassigned': int(paramDict['choicePercentUnassignedStatus']), 'now': int(paramDict['choicePercentNow']), 'later': int(paramDict['choicePercentLater']), 'done': int(paramDict['choicePercentDone']) }, randomize=True) triageStatusAssignments = percentsToAssignments(triageStatus) #convert the string triage value to the triageEnum that can be used to set it triageEnums = { 'now': pim.TriageEnum.now, 'later': pim.TriageEnum.later, 'done': pim.TriageEnum.done } triageStatusUnassigned = [] for index, status in triageStatusAssignments.iteritems(): if status == 'unassigned': triageStatusUnassigned.append(index) else: triageStatusAssignments[index] = triageEnums[status] recurTypes = percentsToCount( itemTypes['event'], { 'non': int(paramDict['choicePercentNonRecurring']), 'daily': int(paramDict['choicePercentDaily']), 'weekly': int(paramDict['choicePercentWeekly']), 'biweekly': int(paramDict['choicePercentBiWeekly']), 'monthly': int(paramDict['choicePercentMonthly']), 'yearly': int(paramDict['choicePercentYearly']) }, randomize=True) durationTypes = percentsToCount( itemTypes['event'], { 'allDay': int(paramDict['choicePercentAllDay']), 'atTime': int(paramDict['choicePercentAtTime']), 'anyTime': int(paramDict['choicePercentAnyTime']), 'duration': int(paramDict['choicePercentDuration']) }, randomize=True) eventStatus = percentsToCount( durationTypes['duration'], { 'confirmed': int(paramDict['choicePercentConfirmed']), 'FYI': int(paramDict['choicePercentFYI']), 'tentative': int(paramDict['choicePercentTentative']) }, randomize=True) eventStatusAssignment = percentsToAssignments(eventStatus) global startTimes startTimes = createStartTimeRange(paramDict['textCtrlTimeOfDay'], itemTypes['event']) startDateText = paramDict['textCtrlStartDate'] if startDateText: y, m, d = startDateText.split(',') startDate = datetime(int(y), int(m), int(d)) y, m, d = paramDict['textCtrlEndDate'].split(',') endDate = datetime(int(y), int(m), int(d)) global dates dates = createDateRange(startDate, endDate) durationsTimed = createDurationIndex(paramDict['textCtrlDuration'], durationTypes['duration']) itemsWithDuration = durationsTimed.keys() relativeReminders, absoluteReminders = createAlarmIndex( paramDict['textCtrlAlarmSpec'], itemTypes['event'], totalItems, tzinfo) allRecurring = recurTypes['daily'] + recurTypes['weekly'] + recurTypes[ 'biweekly'] + recurTypes['monthly'] + recurTypes['yearly'] recurenceEndDate = createEndDateIndex( paramDict['textCtrlRecurrenceEndDates'], allRecurring) # email stuff emailAddresses = [] for firstName in firstNames: for lastName in lastNames: for domain in domainList: emailAddresses.append(firstName + lastName + '@' + domain) # get address sources if paramDict['textCtrlToFile'] == '': toAddresses = emailAddresses else: toAddresses = getDataFromFile(paramDict['textCtrlToFile']) if paramDict['textCtrlCCFileName'] == '': ccAddresses = emailAddresses else: ccAddresses = getDataFromFile(paramDict['textCtrlCCFileName']) if paramDict['textCtrlBCCFileName'] == '': bccAddresses = emailAddresses else: bccAddresses = getDataFromFile(paramDict['textCtrlBCCFileName']) # make email indexes from specs toIndex = createAddressIndex(itemTypes['mail'], paramDict['textCtrlToSpec'], toAddresses) ccIndex = createAddressIndex(itemTypes['mail'], paramDict['textCtrlCCSpec'], ccAddresses) bccIndex = createAddressIndex(itemTypes['mail'], paramDict['textCtrlBCCSpec'], bccAddresses) created = [] for i in range(totalItems): created.append(pim.notes.Note(itsView=view)) item = created[i] item.displayName = random.choice(TITLES) item.body = random.choice(NOTES) if i not in triageStatusUnassigned: item.setTriageStatus(triageStatusAssignments[i]) if i in absoluteReminders.keys(): item.setUserReminderTime( datetime.combine(date.today(), absoluteReminders[i])) if i in itemTypes['mail']: mailStampedItem = pim.MailStamp(item) mailStampedItem.add() if i in toIndex.keys(): for address in toIndex[i]: mailStampedItem.toAddress.append( Mail.EmailAddress.getEmailAddress(view, address)) if i in ccIndex.keys(): for address in ccIndex[i]: mailStampedItem.ccAddress.append( Mail.EmailAddress.getEmailAddress(view, address)) if i in bccIndex.keys(): for address in bccIndex[i]: mailStampedItem.bccAddress.append( Mail.EmailAddress.getEmailAddress(view, address)) if i in itemTypes['task']: pim.TaskStamp(item).add() if i in itemTypes['event']: eventStampedItem = pim.EventStamp(item) eventStampedItem.add() if i in itemsWithDuration: #if its an event with duration then assign status eventStampedItem.transparency = eventStatusAssignment[i].lower( ) eventStampedItem.location = Calendar.Location.getLocation( view, random.choice(LOCATIONS)) eventStampedItem.anyTime = i in durationTypes['anyTime'] eventStampedItem.allDay = i in durationTypes['allDay'] eventStampedItem.startTime = createStartTime(i, tzinfo) if i in durationTypes['atTime']: eventStampedItem.duration = timedelta(0) else: if i in itemsWithDuration: eventStampedItem.duration = durationsTimed[i] if i in relativeReminders.keys(): eventStampedItem.setUserReminderInterval(relativeReminders[i]) if i in allRecurring: ruleItem = RecurrenceRule(None, itsView=view) ruleSetItem = RecurrenceRuleSet(None, itsView=view) recurFreq = rangeName(i, recurTypes) #specail case biweekly if recurFreq == 'biweekly': ruleItem.freq = 'weekly' ruleItem.interval = 2 else: ruleItem.freq = recurFreq #add end date if i in recurenceEndDate and recurenceEndDate[ i]: # zero means don't use an end date endDateDate = calcEndDate(eventStampedItem.startTime, recurenceEndDate[i], recurFreq) ruleItem.until = endDateDate ruleSetItem.addRule(ruleItem) eventStampedItem.rruleset = ruleSetItem for collection in collectionMembershipDict[i]: collection.add(item) return created #return value used for testing in TestCreateItems.py:TestItemCreation
def setUp(self): self.rv = NullRepositoryView(verify=True)
def setUp(self): self.view = NullRepositoryView(verify=True) self.tzinfo = self.view.tzinfo.getInstance("US/Pacific")
def validate(self): """Attempts to check that all settings in dialog are valid.""" if bool(wx.GetApp()): view = QAUITestAppLib.App_ns.itsView else: # when running unit tests there is no app view = NullRepositoryView(verify=True) tzinfo = view.tzinfo.getDefault() self.output = True def _markValid(isValid, label): """mark control as 'Valid' or 'Error'""" if isValid: label.ForegroundColour = 'black' label.SetLabel('Valid') else: label.ForegroundColour = 'red' label.SetLabel('Error') self.output = False # test total items result = self.isNumericAndNonZero(self.textCtrlTotalItems) _markValid(result, self.labelNumOfItemsValid) # mark stamp percentages valid (all possible input is valid) _markValid(True, self.labelStampsValid) # test title source result = self.isValidPath(self.textCtrlTitleSourceFile.GetValue()) _markValid(result, self.labelTitleSourceValid) # test note source result = self.isValidPath(self.textCtrlNoteSourceFilePath.GetValue()) _markValid(result, self.labelNoteSourceValid) # test collection source result = self.isValidPath(self.textCtrlCollectionFileName.GetValue()) _markValid(result, self.labelCollectionSourceValid) # test number of collections result = self.isNumericAndNonZero(self.textCtrlCollectionCount) _markValid(result, self.labelCollectionCountValid) # test collection membership membershipSpec = self.textCtrlCollectionMembership.GetValue() totalCollectionCount = int(self.textCtrlCollectionCount.GetValue()) result = self.tryToProcess(createItems.createMembershipIndex, membershipSpec, totalCollectionCount) \ and \ self.collectionCountNotExceeded(membershipSpec, totalCollectionCount) _markValid(result, self.labelCollectionMembershipValid) # test location source result = self.isValidPath( self.textCtrlLocationSourceFilePath.GetValue()) _markValid(result, self.labelLocationSourceValid) # test triage percentaqes result = self.sumValueIs100(self.choicePercentUnassignedStatus, self.choicePercentNow, self.choicePercentLater, self.choicePercentDone) _markValid(result, self.labelTriageValid) # test start/ end dates result = self.datesCorrect(self.textCtrlStartDate.GetValue(), self.textCtrlEndDate.GetValue()) _markValid(result, self.labelDateRangeValid) # test time of day spec result = self.tryToProcess(createItems.createStartTimeRange, self.textCtrlTimeOfDay.GetValue(), [1, 2, 3]) _markValid(result, self.labelTimeOfDaySpecValid) # test duration spec result = self.tryToProcess(createItems.createDurationIndex, self.textCtrlDuration.GetValue(), [1, 2, 3]) _markValid(result, self.labelDurationSpecValid) # test duration type percentages result = self.sumValueIs100(self.choicePercentAllDay, self.choicePercentAtTime, self.choicePercentAnyTime, self.choicePercentDuration) _markValid(result, self.labelDurationTypesValid) # test status percentages result = self.sumValueIs100(self.choicePercentConfirmed, self.choicePercentTentative, self.choicePercentFYI) _markValid(result, self.labelStatusValid) # test recurrence percentages result = self.sumValueIs100(self.choicePercentNonRecurring, self.choicePercentDaily, self.choicePercentWeekly, self.choicePercentBiWeekly, self.choicePercentMonthly, self.choicePercentYearly) _markValid(result, self.labelRecurrenceValid) # test recurrence end date spec result = self.tryToProcess(createItems.createEndDateIndex, self.textCtrlRecurrenceEndDates.GetValue(), [1, 2, 3]) _markValid(result, self.labelRecurrenceEndDateValid) # test alarm spec result = self.tryToProcess(createItems.createAlarmIndex, self.textCtrlAlarmSpec.GetValue(), [1, 2, 3], [1, 2, 3, 4], tzinfo) _markValid(result, self.labelAlarmTypeValid) # test To source file result = self.isValidPath(self.textCtrlToFile.GetValue()) _markValid(result, self.labelToSourceValid) # test To spec result = self.tryToProcess(createItems.createAddressIndex, [1, 2, 3], self.textCtrlToSpec.GetValue(), [1, 2, 3]) _markValid(result, self.labelToSpecValid) # test CC source file result = self.isValidPath(self.textCtrlCCFileName.GetValue()) _markValid(result, self.labelCCSourceValid) # test CC spec result = self.tryToProcess(createItems.createAddressIndex, [1, 2, 3], self.textCtrlCCSpec.GetValue(), [1, 2, 3]) _markValid(result, self.labelCCSpecValid) # test BCC source file result = self.isValidPath(self.textCtrlBCCFileName.GetValue()) _markValid(result, self.labelBCCSourceValid) # test To spec result = self.tryToProcess(createItems.createAddressIndex, [1, 2, 3], self.textCtrlBCCSpec.GetValue(), [1, 2, 3]) _markValid(result, self.labelBCCSpecValid) return self.output
# limitations under the License. from osaf.mail.message import kindToMessageText from osaf.pim import MailStamp, EventStamp, TaskStamp, notes from osaf.pim.mail import EmailAddress from i18n.tests import uw from datetime import datetime, timedelta import random from osaf.pim.calendar import Calendar from osaf import pim from osaf.pim.calendar.Recurrence import RecurrenceRule, RecurrenceRuleSet from util.easyprof import QuickProfile from chandlerdb.persistence.RepositoryView import NullRepositoryView import sys view = NullRepositoryView() ARG_LOOKUP = { "": "Mail", "M": "Mail", "E": "Event", "T": "Task", "R": "RecurringEvent", } def getOpts(): try: return sys.argv[1] except: return ""
def setUp(self): Globals.options = Utility.initOptions() Utility.initLogging(Globals.options) self.view = NullRepositoryView() Utility.initTimezone(Globals.options, self.view)