Пример #1
0
 def testTaskWithTwoAttachments(self):
     attachments = [
         attachment.FileAttachment('whatever.txt'),
         attachment.FileAttachment('/home/frank/attachment.doc')
     ]
     for a in attachments:
         self.task.addAttachments(a)
     for att in attachments:
         self.expectInXML(
             '<attachment id="%s" location="%s" status="1" subject="%s" type="file"/>'
             % (att.id(), att.location(), att.location()))
Пример #2
0
 def testObjectWithAttachmentWithNote(self):
     att = attachment.FileAttachment('whatever.txt', id='foo')
     self.task.addAttachments(att)
     att.addNote(note.Note(subject='attnote', id='spam'))
     self.expectInXML(
         '<attachment id="foo" location="whatever.txt" status="1" subject="whatever.txt" type="file">\n<note'
     )
Пример #3
0
 def testCategoryWithOneAttachment(self):
     cat = category.Category('cat')
     self.categoryContainer.append(cat)
     cat.addAttachments(attachment.FileAttachment('whatever.txt', id='foo'))
     self.expectInXML(
         '<attachment id="foo" location="whatever.txt" status="1" subject="whatever.txt" type="file"/>'
     )
Пример #4
0
    def testOpenAttachmentWithNonAsciiFileNameThrowsException(
            self):  # pragma: no cover
        ''' os.startfile() does not accept unicode filenames. This will be 
            fixed in Python 2.5. This test will fail if the bug is fixed. '''
        self.errorMessage = ''  # pylint: disable-msg=W0201

        def onError(*args, **kwargs):  # pylint: disable-msg=W0613
            self.errorMessage = args[0]

        att = attachment.FileAttachment(u'tést.é')
        openAttachment = uicommand.AttachmentOpen(\
            viewer=self.editor._interior[6].viewer,
            attachments=attachment.AttachmentList([att]),
            settings=self.settings)
        openAttachment.doCommand(None, showerror=onError)
        if '__WXMSW__' in wx.PlatformInfo:  # pragma: no cover
            if sys.version_info < (2, 5):
                errorMessageStart = "'ascii' codec can't encode character"
            else:
                errorMessageStart = ''
        elif '__WXMAC__' in wx.PlatformInfo and sys.version_info >= (2, 5):
            errorMessageStart = ''  # pragma: no cover
        elif '__WXGTK__' in wx.PlatformInfo:  # pragma: no cover
            errorMessageStart = ''
        else:
            errorMessageStart = '[Error 2] '
        self.failUnless(self.errorMessage.startswith(errorMessageStart))
 def fillContainers(self):
     # pylint: disable-msg=W0201
     self.description = 'Description\nLine 2'
     self.task = task.Task(subject='Subject', description=self.description, 
         startDateTime=date.Now() - date.TimeDelta(days=1), 
         dueDateTime=date.Now() + date.TimeDelta(days=1), 
         completionDateTime=date.Now() - date.TimeDelta(days=1), 
         budget=date.TimeDelta(hours=1), 
         priority=4, hourlyFee=100.5, fixedFee=1000, 
         recurrence=date.Recurrence('weekly', max=10, count=5, amount=2),
         reminder=date.DateTime(2004,1,1), fgColor=wx.BLUE, bgColor=wx.RED,
         font=wx.NORMAL_FONT, expandedContexts=['viewer1'], icon='icon',
         selectedIcon='selectedIcon',
         shouldMarkCompletedWhenAllChildrenCompleted=True,
         percentageComplete=67)
     self.child = task.Task()
     self.task.addChild(self.child)
     self.grandChild = task.Task()
     self.child.addChild(self.grandChild)
     self.task.addEffort(effort.Effort(self.task, start=date.DateTime(2004,1,1), 
         stop=date.DateTime(2004,1,2), description=self.description))
     self.category = category.Category('test', [self.task], filtered=True,
                                       description='Description', 
                                       exclusiveSubcategories=True)
     self.categories.append(self.category)
     # pylint: disable-msg=E1101
     self.task.addAttachments(attachment.FileAttachment('/home/frank/whatever.txt'))
     self.task.addNote(note.Note(subject='Task note'))
     self.task2 = task.Task('Task 2', priority=-1954)
     self.taskList.extend([self.task, self.task2])
     self.note = note.Note(subject='Note', description='Description', 
                           children=[note.Note(subject='Child')])
     self.notes.append(self.note)
     self.category.addCategorizable(self.note)
Пример #6
0
 def testNoteWithOneAttachment(self):
     note_attachment = attachment.FileAttachment('whatever.txt', id='foo')
     self.note.addAttachments(note_attachment)
     self.expectInXML('<attachment creationDateTime="%s" id="foo" '
                      'location="whatever.txt" status="1" '
                      'subject="whatever.txt" type="file" '
                      '/>' % note_attachment.creationDateTime())
Пример #7
0
 def __init__(self, *args, **kwargs):
     self.owners = []
     self.__attachments = kwargs.get('attachments', 
         [attachment.FileAttachment('', subject=_('New attachment'))])
     super(AddAttachmentCommand, self).__init__(*args, **kwargs)
     self.owners = self.items
     self.items = self.__attachments
     self.save_modification_datetimes()
Пример #8
0
 def testSelectedAttachmentIcon(self):
     att = attachment.FileAttachment('whatever.txt',
                                     id='foo',
                                     selectedIcon='icon')
     self.task.addAttachments(att)
     self.expectInXML('<attachment id="foo" location="whatever.txt" '
                      'selectedIcon="icon" status="1" '
                      'subject="whatever.txt" type="file"/>')
Пример #9
0
 def testAttachmentFont(self):
     att = attachment.FileAttachment('whatever.txt',
                                     id='foo',
                                     font=wx.SWISS_FONT)
     self.task.addAttachments(att)
     self.expectInXML('<attachment font="%s" id="foo" '
                      'location="whatever.txt" status="1" '
                      'subject="whatever.txt" type="file"/>' %
                      wx.SWISS_FONT.GetNativeFontInfoDesc())
Пример #10
0
 def testNonexistingAttachment(self): # pragma: no cover
     self.viewer.selection[0].addAttachment(attachment.FileAttachment('Attachment'))
     result = self.openAll.doCommand(None, showerror=self.showerror)
     # Don't test the error message itself, it differs per platform
     if self.errorKwargs:
         self.assertEqual(dict(caption='Error opening attachment',
                               style=wx.ICON_ERROR), self.errorKwargs)
     else:
         self.assertNotEqual(0, result)
Пример #11
0
 def testObjectWithAttachmentWithNote(self):
     att = attachment.FileAttachment('whatever.txt', id='foo')
     self.task.addAttachments(att)
     attachment_note = note.Note(subject='attnote', id='spam')
     att.addNote(attachment_note)
     self.expectInXML('<attachment creationDateTime="%s" id="foo" '
                      'location="whatever.txt" '
                      'status="1" subject="whatever.txt" type="file">\n'
                      '<note' % att.creationDateTime())
Пример #12
0
 def onDropFiles(self, item, filenames, **kwargs):
     ''' This method is called by the widget when one or more files
         are dropped on an item. '''
     attachmentBase = self.settings.get('file', 'attachmentbase')
     if attachmentBase:
         filenames = [attachment.getRelativePath(filename, attachmentBase) \
                      for filename in filenames]
     attachments = [attachment.FileAttachment(filename) for filename in filenames]
     self._addAttachments(attachments, item, **kwargs)
Пример #13
0
 def setUp(self):
     super(AttachmentEditorTest, self).setUp()
     self.settings = config.Settings(load=False)
     self.taskFile = persistence.TaskFile()
     self.attachment = attachment.FileAttachment('Attachment')
     self.attachments = attachment.AttachmentList()
     self.attachments.append(self.attachment)
     self.editor = gui.dialog.editor.AttachmentEditor(
         self.frame, self.attachments, self.settings, self.attachments,
         self.taskFile)
Пример #14
0
 def testCategoryWithOneAttachment(self):
     cat = category.Category('cat')
     self.categoryContainer.append(cat)
     category_attachment = attachment.FileAttachment('whatever.txt',
                                                     id='foo')
     cat.addAttachments(category_attachment)
     self.expectInXML('<attachment creationDateTime="%s" id="foo" '
                      'location="whatever.txt" status="1" '
                      'subject="whatever.txt" type="file" '
                      '/>' % category_attachment.creationDateTime())
Пример #15
0
 def testOpenAttachmentWithNonAsciiFileName(self):
     self.errorMessage = ''  # pylint: disable=W0201
     
     def onError(*args, **kwargs):  # pylint: disable=W0613
         self.errorMessage = args[0]  # pragma: no cover
         
     att = attachment.FileAttachment(u'tést.é')
     openAttachment = uicommand.AttachmentOpen(\
         viewer=self.editor._interior[6].viewer,
         attachments=attachment.AttachmentList([att]),
         settings=self.settings)
     openAttachment.doCommand(None, showerror=onError)
     self.failIf(self.errorMessage)
Пример #16
0
    def setUp(self):
        super(AttachmentTest, self).setUp()

        task.Task.settings = config.Settings(load=False)
        taskFile = persistence.TaskFile()
        self.task = task.Task()
        taskFile.tasks().extend([self.task])
        self.attachment = attachment.FileAttachment('Test')
        self.task.addAttachment(self.attachment)
        self.viewer = gui.dialog.editor.LocalAttachmentViewer(
            self.frame,
            taskFile,
            task.Task.settings,
            owner=self.task,
            settingsSection='attachmentviewer')
Пример #17
0
 def edit(self, tasks=None, edits=None):
     tasksToEdit = tasks or []
     editcommand = command.EditTaskCommand(self.taskList, tasksToEdit)
     for taskToEdit in tasksToEdit:
         taskToEdit.setSubject('New subject')
         taskToEdit.setDescription('New description')
         taskToEdit.setBudget(date.TimeDelta(hours=1))
         taskToEdit.setCompletionDateTime()
         taskToEdit.addPrerequisites([self.task2])
         att = attachment.FileAttachment('attachment')
         if att in taskToEdit.attachments():
             taskToEdit.removeAttachments(att)
         else:
             taskToEdit.addAttachments(att)
         if self.category in taskToEdit.categories():
             taskToEdit.removeCategory(self.category)
         else:
             taskToEdit.addCategory(self.category)
         for edit in edits or []:
             edit()
     editcommand.do()
Пример #18
0
 def createTasks(self):
     # pylint: disable=W0201
     self.task = task.Task('Task to edit')
     self.attachment = attachment.FileAttachment('some attachment')
     self.task.addAttachments(self.attachment)  # pylint: disable=E1101
     return [self.task]
Пример #19
0
 def testNewTaskWithAttachment(self):
     att = attachment.FileAttachment('filename')
     newTask = self.new(attachments=[att])
     self.assertDoUndoRedo(
         lambda: self.assertEqual([att], newTask.attachments()),
         lambda: self.assertTaskList(self.originalList))
Пример #20
0
 def addAttachment(self, selectedItems=None):
     self.attachment = attachment.FileAttachment('attachment')  # pylint: disable=W0201
     addAttachmentCommand = command.AddAttachmentCommand(
         self.container, selectedItems or [], attachments=[self.attachment])
     addAttachmentCommand.do()
Пример #21
0
 def createCategories(self):
     # pylint: disable=W0201
     self.category = category.Category('Category to edit')
     self.attachment = attachment.FileAttachment('some attachment')
     self.category.addAttachments(self.attachment)
     return [self.category]
Пример #22
0
 def testOnDropFiles(self):
     aTask = task.Task()
     self.taskList.append(aTask)
     self.viewer.onDropFiles(aTask, ['filename'])
     self.assertEqual([attachment.FileAttachment('filename')],
                      self.viewer.presentation()[0].attachments())
Пример #23
0
 def testRenderAttachment(self):
     att = attachment.FileAttachment('whatever')
     self.task.addAttachment(att)
     self.taskList.append(self.task)
     self.showColumn('attachments')
     self.assertIcon('paperclip_icon', column=1)
Пример #24
0
 def testNoteWithOneAttachment(self):
     self.note.addAttachments(
         attachment.FileAttachment('whatever.txt', id='foo'))
     self.expectInXML(
         '<attachment id="foo" location="whatever.txt" status="1" subject="whatever.txt" type="file"/>'
     )
Пример #25
0
 def setUp(self):
     self.filename = ''
     self.attachment = attachment.FileAttachment('filename')
     self.events = []
Пример #26
0
 def testOpenFileAttachmentWithAbsoluteFilenameAndWorkingDir(self):
     att = attachment.FileAttachment('/home/frank/attachment.txt')
     att.open('/home/jerome', openAttachment=self.openAttachment)
     self.assertEqual(
         os.path.normpath(os.path.join('/home/frank/attachment.txt')),
         self.filename)
Пример #27
0
 def testTypeImageIndex_WhenFileDoesExist(self):
     fileAttachment = attachment.FileAttachment('whatever')
     self.assertIcon('fileopen', fileAttachment, exists=lambda filename: True)
Пример #28
0
 def testTypeImageIndex_WhenFileDoesNotExist(self):
     fileAttachment = attachment.FileAttachment('whatever')
     self.assertIcon('fileopen_red', fileAttachment)
Пример #29
0
 def testRemoveAttachment(self):
     self.task1.addAttachments(attachment.FileAttachment('attachment'))
     self.edit([self.task1])
     self.assertDoUndoRedo(
         lambda: self.assertEqual([], self.task1.attachments()),
         lambda: self.assertEqual([attachment.FileAttachment('attachment')], self.task1.attachments()))
 def testShowAttachmentColumn(self):
     self.note.addAttachments(attachment.FileAttachment('whatever'))
     self.assertEqual(self.viewer.imageIndex['paperclip_icon'],
                      self.firstItemIcon(column=2))