NoteCommandTest.py :  » Project-Management » Task-Coach » TaskCoach-1.0.3 » tests » unittests » commandTests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Project Management » Task Coach 
Task Coach » TaskCoach 1.0.3 » tests » unittests » commandTests » NoteCommandTest.py
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2009 Frank Niessink <frank@niessink.com>

Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

from unittests import asserts
from CommandTestCase import CommandTestCase
from taskcoachlib import command,patterns
from taskcoachlib.domain import note,category,task


class NoteCommandTestCase(CommandTestCase, asserts.CommandAsserts):
    def setUp(self):
        self.notes = note.NoteContainer()
        self.taskList = task.TaskList()


class NewNoteCommandTest(NoteCommandTestCase):
    def new(self, categories=None):
        newNoteCommand = command.NewNoteCommand(self.notes, 
                                                categories=categories or [])
        newNote = newNoteCommand.items[0]
        newNoteCommand.do()
        return newNote
        
    def testNewNote(self):
        newNote = self.new()
        self.assertDoUndoRedo(
            lambda: self.assertEqual([newNote], self.notes),
            lambda: self.assertEqual([], self.notes))
        
    def testNewNoteWithCategory(self):
        cat = category.Category('cat')
        newNote = self.new(categories=[cat])
        self.assertDoUndoRedo(
            lambda: self.assertEqual(set([cat]), newNote.categories()),
            lambda: self.assertEqual([], self.notes))


class AddNoteCommandTest(NoteCommandTestCase):
    def testAddedNoteIsRootItem(self):
        owner = note.NoteOwner()
        command.AddNoteCommand([owner], [owner]).do()
        self.failUnless(owner.notes()[0].parent() is None) # pylint: disable-msg=E1101
        

class NewSubNoteCommandTest(NoteCommandTestCase):
    def setUp(self):
        super(NewSubNoteCommandTest, self).setUp()
        self.note = note.Note(subject='Note')
        self.notes.append(self.note)
        
    def newSubNote(self, notes=None):
        newSubNote = command.NewSubNoteCommand(self.notes, notes or [])
        newSubNote.do()

    def testNewSubNote_WithoutSelection(self):
        self.newSubNote()
        self.assertDoUndoRedo(lambda: self.assertEqual([self.note], 
                                                       self.notes))

    def testNewSubNote(self):
        self.newSubNote([self.note])
        newSubNote = self.note.children()[0]
        self.assertDoUndoRedo(lambda: self.assertEqual([newSubNote], 
                                                       self.note.children()),
            lambda: self.assertEqual([self.note], self.notes))


class EditNoteCommandTest(NoteCommandTestCase):
    def setUp(self):
        super(EditNoteCommandTest, self).setUp()
        self.note = note.Note(subject='Note')
        self.notes.append(self.note)
        
    def editNote(self, notes=None):
        notesToEdit = notes or []
        editNote = command.EditNoteCommand(self.notes, notesToEdit)
        for noteToEdit in notesToEdit:
            noteToEdit.setSubject('new')
        editNote.do()
        
    def testEditNote_WithoutSelection(self):
        self.editNote()
        self.assertDoUndoRedo(lambda: self.assertEqual([self.note], 
                                                       self.notes))
        
    def testEditNote_Subject(self):
        self.editNote([self.note])
        self.assertDoUndoRedo(lambda: self.assertEqual('new', self.note.subject()),
            lambda: self.assertEqual('Note', self.note.subject()))


class DragAndDropNoteCommand(NoteCommandTestCase):
    def setUp(self):
        super(DragAndDropNoteCommand, self).setUp()
        self.parent = note.Note(subject='parent')
        self.child = note.Note(subject='child')
        self.grandchild = note.Note(subject='grandchild')
        self.parent.addChild(self.child)
        self.child.addChild(self.grandchild)
        self.notes.extend([self.parent])
    
    def dragAndDrop(self, dropTarget, notes=None):
        command.DragAndDropNoteCommand(self.notes, notes or [], 
                                       drop=dropTarget).do()
                                       
    def testCannotDropOnParent(self):
        self.dragAndDrop([self.parent], [self.child])
        self.failIf(patterns.CommandHistory().hasHistory())
        
    def testCannotDropOnChild(self):
        self.dragAndDrop([self.child], [self.parent])
        self.failIf(patterns.CommandHistory().hasHistory())
        
    def testCannotDropOnGrandchild(self):
        self.dragAndDrop([self.grandchild], [self.parent])
        self.failIf(patterns.CommandHistory().hasHistory())

    def testDropAsRootTask(self):
        self.dragAndDrop([], [self.grandchild])
        self.assertDoUndoRedo(lambda: self.assertEqual(None, 
            self.grandchild.parent()), lambda:
            self.assertEqual(self.child, self.grandchild.parent()))
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.