CategoryTest.py :  » Project-Management » Task-Coach » TaskCoach-1.0.3 » tests » unittests » domainTests » 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 » domainTests » CategoryTest.py
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2010 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/>.
'''

import test, wx
from taskcoachlib import patterns
from taskcoachlib.domain import category,categorizable,note


class CategoryTest(test.TestCase):
    def setUp(self):
        self.category = category.Category(subject='category')
        self.subCategory = category.Category(subject='subcategory')
        self.categorizable = categorizable.CategorizableCompositeObject(subject='parent')
        self.child = categorizable.CategorizableCompositeObject(subject='child')
        
    # State:
        
    def testGetState_Subject(self):
        self.assertEqual('category', self.category.__getstate__()['subject'])
        
    def testGetState_Description(self):
        self.assertEqual('', self.category.__getstate__()['description'])

    def testGetState_ForegroundColor(self):
        self.assertEqual(None, self.category.__getstate__()['fgColor'])
        
    def testGetState_BackgroundColor(self):
        self.assertEqual(None, self.category.__getstate__()['bgColor'])
        
    def testGetState_ExclusiveSubcategories(self):
        self.assertEqual(False, self.category.__getstate__()['exclusiveSubcategories'])
        
    def testSetState_ExclusiveSubcategories(self):
        state = self.category.__getstate__()
        self.category.makeSubcategoriesExclusive()
        self.category.__setstate__(state)
        self.failIf(self.category.hasExclusiveSubcategories())
        
    def testSetState_OneNotification(self):
        newState = dict(subject='New subject', description='New description',
                        fgColor=wx.WHITE, bgColor=wx.RED, font=wx.SWISS_FONT,
                        status=self.category.STATUS_DELETED,
                        parent=None, children=[self.subCategory], id=self.category.id(),
                        categorizables=[self.categorizable], notes=[],
                        attachments=[], filtered=True, exclusiveSubcategories=True,
                        icon='icon', selectedIcon='selected')
        for eventType in self.category.modificationEventTypes():
            self.registerObserver(eventType)
        self.category.__setstate__(newState)
        self.assertEqual(1, len(self.events))
        
    # Subject:
        
    def testCreateWithSubject(self):
        self.assertEqual('category', self.category.subject())
    
    def testSetSubject(self):
        self.category.setSubject('New')
        self.assertEqual('New', self.category.subject())
        
    def testSetSubjectNotification(self):
        eventType = category.Category.subjectChangedEventType()
        self.registerObserver(eventType)
        self.category.setSubject('New')
        self.assertEqual([patterns.Event(eventType, self.category, 'New')], 
            self.events)
        
    def testSetSubjectCausesNoNotificationWhenNewSubjectEqualsOldSubject(self):
        eventType = category.Category.subjectChangedEventType()
        self.registerObserver(eventType)
        self.category.setSubject(self.category.subject())
        self.failIf(self.events)
        
    # Description:
        
    def testCreateWithDescription(self):
        aCategory = category.Category('subject', description='Description')
        self.assertEqual('Description', aCategory.description())
        
    # Categorizables:

    def testNoCategorizablesAfterCreation(self):
        self.assertEqual(set(), self.category.categorizables())
      
    def testAddCategorizable(self):
        self.category.addCategorizable(self.categorizable)
        self.assertEqual(set([self.categorizable]), self.category.categorizables())
        
    def testAddCategorizableDoesNotAddCategoryToCategorizable(self):
        self.category.addCategorizable(self.categorizable)
        self.assertEqual(set([]), self.categorizable.categories())
        
    def testAddCategorizableTwice(self):
        self.category.addCategorizable(self.categorizable)
        self.category.addCategorizable(self.categorizable)
        self.assertEqual(set([self.categorizable]), self.category.categorizables())
        
    def testRemoveCategorizable(self):
        self.category.addCategorizable(self.categorizable)
        self.category.removeCategorizable(self.categorizable)
        self.failIf(self.category.categorizables())
        self.failIf(self.categorizable.categories())
        
    def testRemovecategorizableThatsNotInThisCategory(self):
        self.category.removeCategorizable(self.categorizable)
        self.failIf(self.category.categorizables())
        self.failIf(self.categorizable.categories())
    
    def testCreateWithCategorizable(self):
        cat = category.Category('category', [self.categorizable])
        self.assertEqual(set([self.categorizable]), cat.categorizables())
        
    def testCreateWithCategorizableDoesNotSetCategorizableCategories(self):
        category.Category('category', [self.categorizable])
        self.assertEqual(set([]), self.categorizable.categories())
    
    def testAddCategorizableToSubCategory(self):
        self.category.addChild(self.subCategory)
        self.subCategory.addCategorizable(self.categorizable)
        self.assertEqual(set([self.categorizable]), 
                         self.category.categorizables(recursive=True))
        
    # Subcategories:
     
    def testAddSubCategory(self):
        self.category.addChild(self.subCategory)
        self.assertEqual([self.subCategory], self.category.children())
    
    def testCreateWithSubCategories(self):
        cat = category.Category('category', children=[self.subCategory])
        self.assertEqual([self.subCategory], cat.children())
     
    def testParentOfSubCategory(self):
        self.category.addChild(self.subCategory)
        self.assertEqual(self.category, self.subCategory.parent())
        
    def testParentOfRootCategory(self):
        self.assertEqual(None, self.category.parent())
        
    # Equality:
        
    def testEquality_SameSubjectAndNoParents(self):
        self.assertNotEqual(category.Category(self.category.subject()), 
                            self.category)
        self.assertNotEqual(self.category,
                            category.Category(self.category.subject()))
                     
    def testEquality_SameSubjectDifferentParents(self):
        self.category.addChild(self.subCategory)
        self.assertNotEqual(category.Category(self.subCategory.subject()), 
                            self.subCategory)
        
    # Filter:
   
    def testNotFilteredByDefault(self):
        self.failIf(self.category.isFiltered())
        
    def testSetFilteredOn(self):
        self.category.setFiltered()
        self.failUnless(self.category.isFiltered())
        
    def testSetFilteredOff(self):
        self.category.setFiltered(False)
        self.failIf(self.category.isFiltered())
    
    def testSetFilteredViaConstructor(self):
        filteredCategory = category.Category('test', filtered=True)
        self.failUnless(filteredCategory.isFiltered())
        
    # Contains:
        
    def testContains_NoCategorizables(self):
        self.failIf(self.category.contains(self.categorizable))
        
    def testContains_CategorizablesInCategory(self):
        self.category.addCategorizable(self.categorizable)
        self.failUnless(self.category.contains(self.categorizable))
        
    def testContains_CategorizableInSubCategory(self):
        self.subCategory.addCategorizable(self.categorizable)
        self.category.addChild(self.subCategory)
        self.failUnless(self.category.contains(self.categorizable))
        
    def testContains_ParentInCategory(self):
        self.category.addCategorizable(self.categorizable)
        self.categorizable.addChild(self.child)
        self.failUnless(self.category.contains(self.child))
        
    def testContains_ParentInSubCategory(self):
        self.subCategory.addCategorizable(self.categorizable)
        self.category.addChild(self.subCategory)
        self.categorizable.addChild(self.child)
        self.failUnless(self.category.contains(self.child))
    
    def testContains_ChildInCategory(self):
        self.categorizable.addChild(self.child)
        self.category.addCategorizable(self.child)
        self.failIf(self.category.contains(self.categorizable))
        
    def testContains_ChildInSubCategory(self):
        self.categorizable.addChild(self.child)
        self.subCategory.addCategorizable(self.child)
        self.category.addChild(self.subCategory)
        self.failIf(self.category.contains(self.categorizable))
        
    def testRecursiveContains_ChildInCategory(self):
        self.categorizable.addChild(self.child)
        self.category.addCategorizable(self.child)
        self.failUnless(self.category.contains(self.categorizable, treeMode=True))
        
    def testRecursiveContains_ChildInSubcategory(self):
        self.categorizable.addChild(self.child)
        self.subCategory.addCategorizable(self.child)
        self.category.addChild(self.subCategory)
        self.failUnless(self.category.contains(self.categorizable, treeMode=True))
        
    # Copy:
        
    def testCopy_SubjectIsCopied(self):
        self.category.setSubject('New subject')
        copy = self.category.copy()
        self.assertEqual(copy.subject(), self.category.subject())

    def testCopy_IdIsDifferent(self):
        copy = self.category.copy()
        self.assertNotEqual(copy.id(), self.category.id())

    def testCopy_StatusIsNew(self):
        self.category.markDeleted()
        copy = self.category.copy()
        self.assertEqual(copy.getStatus(), copy.STATUS_NEW)

    # pylint: disable-msg=E1101
        
    def testCopy_SubjectIsDifferentFromOriginalSubject(self):
        self.subCategory.setSubject('New subject')
        self.category.addChild(self.subCategory)
        copy = self.category.copy()
        self.subCategory.setSubject('Other subject')
        self.assertEqual('New subject', copy.children()[0].subject())
        
    def testCopy_FilteredStatusIsCopied(self):
        self.category.setFiltered()
        copy = self.category.copy()
        self.assertEqual(copy.isFiltered(), self.category.isFiltered())
        
    def testCopy_CategorizablesAreCopied(self):
        self.category.addCategorizable(self.categorizable)
        copy = self.category.copy()
        self.assertEqual(copy.categorizables(), self.category.categorizables())
        
    def testCopy_CategorizablesAreCopiedIntoADifferentList(self):
        copy = self.category.copy()
        self.category.addCategorizable(self.categorizable)
        self.failIf(self.categorizable in copy.categorizables())

    def testCopy_ChildrenAreCopied(self):
        self.category.addChild(self.subCategory)
        copy = self.category.copy()
        self.assertEqual(self.subCategory.subject(), copy.children()[0].subject())
        
    # Notifications: 

    def testAddTaskNotification(self):
        eventType = category.Category.categorizableAddedEventType()
        self.registerObserver(eventType)
        self.category.addCategorizable(self.categorizable)
        self.assertEqual(1, len(self.events))
        
    def testRemoveTaskNotification(self):
        eventType = category.Category.categorizableRemovedEventType()
        self.registerObserver(eventType)
        self.category.addCategorizable(self.categorizable)
        self.category.removeCategorizable(self.categorizable)
        self.assertEqual(1, len(self.events))
        
    # Color:

    def testGetDefaultForegroundColor(self):
        self.assertEqual(None, self.category.foregroundColor())
        
    def testGetDefaultBackgroundColor(self):
        self.assertEqual(None, self.category.backgroundColor())

    def testSetForegroundColor(self):
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(wx.RED, self.category.foregroundColor())
        
    def testSetBackgroundColor(self):
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(wx.RED, self.category.backgroundColor())

    def testCopy_ForegroundColorIsCopied(self):
        self.category.setForegroundColor(wx.RED)
        copy = self.category.copy()
        self.assertEqual(wx.RED, copy.foregroundColor())
        
    def testCopy_BackgroundColorIsCopied(self):
        self.category.setBackgroundColor(wx.RED)
        copy = self.category.copy()
        self.assertEqual(wx.RED, copy.backgroundColor())

    def testForegroundColorChangeNotification(self):
        eventType = category.Category.foregroundColorChangedEventType()
        self.registerObserver(eventType)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(1, len(self.events))
        
    def testBackgroundColorChangeNotification(self):
        eventType = category.Category.backgroundColorChangedEventType()
        self.registerObserver(eventType)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(1, len(self.events))
    
    def testSubCategoryWithoutForegroundColorHasParentForegroundColor(self):
        self.category.addChild(self.subCategory)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(wx.RED, self.subCategory.foregroundColor())
        
    def testSubCategoryWithoutBackgroundColorHasParentBackgroundColor(self):
        self.category.addChild(self.subCategory)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(wx.RED, self.subCategory.backgroundColor())

    def testSubCategoryWithoutForegroundColorHasNoOwnForegroundColor(self):
        self.category.addChild(self.subCategory)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(None, self.subCategory.foregroundColor(recursive=False))
        
    def testSubCategoryWithoutBackgroundColorHasNoOwnBackgroundColor(self):
        self.category.addChild(self.subCategory)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(None, self.subCategory.backgroundColor(recursive=False))

    def testParentForegroundColorChangeNotification(self):
        eventType = category.Category.foregroundColorChangedEventType()
        self.registerObserver(eventType)
        self.category.addChild(self.subCategory)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(1, len(self.events))
                
    def testParentBackgroundColorChangeNotification(self):
        eventType = category.Category.backgroundColorChangedEventType()
        self.registerObserver(eventType)
        self.category.addChild(self.subCategory)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(1, len(self.events))

    # Icon:

    def testIconChangedNotification(self):
        eventType = categorizable.CategorizableCompositeObject.iconChangedEventType()
        self.registerObserver(eventType)
        self.category.addCategorizable(self.categorizable)
        self.category.setIcon('icon')
        self.assertEqual([patterns.Event(eventType, self.categorizable, '')],
                         self.events)

    def testSelectedIconChangedNotification(self):
        eventType = categorizable.CategorizableCompositeObject.selectedIconChangedEventType()
        self.registerObserver(eventType)
        self.category.addCategorizable(self.categorizable)
        self.category.setSelectedIcon('icon')
        self.assertEqual([patterns.Event(eventType, self.categorizable, '')],
                         self.events)

    # Notes:
        
    def testAddNote(self):
        aNote = note.Note(subject='Note')
        self.category.addNote(aNote)
        self.assertEqual([aNote], self.category.notes())
        
    # Exclusive subcategories:
        
    def testSubcategoriesAreNotExclusiveByDefault(self):
        self.failIf(self.category.hasExclusiveSubcategories())
        
    def testMakeSubcategoriesExclusive(self):
        self.category.makeSubcategoriesExclusive()
        self.failUnless(self.category.hasExclusiveSubcategories())
        
    def testMakeSubcategoriesNotExclusive(self):
        self.category.makeSubcategoriesExclusive()
        self.category.makeSubcategoriesExclusive(False)
        self.failIf(self.category.hasExclusiveSubcategories())

    def testCreateWithExclusiveSubcategories(self):
        aCategory = category.Category('subject', exclusiveSubcategories=True)
        self.failUnless(aCategory.hasExclusiveSubcategories())

    def testExclusiveSubcategoriesNotification(self):
        eventType = category.Category.exclusiveSubcategoriesChangedEventType()
        self.registerObserver(eventType)
        self.category.makeSubcategoriesExclusive()
        self.assertEqual([patterns.Event(eventType, self.category, True)], 
            self.events)

    def testNoExclusiveSubcategoriesNotificationWhenNotChanged(self):
        eventType = category.Category.exclusiveSubcategoriesChangedEventType()
        self.registerObserver(eventType)
        self.category.makeSubcategoriesExclusive(False)
        self.failIf(self.events)
        
    def testMakeSubcategoriesExclusiveUnchecksAllSubcategories(self):
        self.subCategory.setFiltered(True)
        self.category.addChild(self.subCategory)
        self.category.makeSubcategoriesExclusive(True)
        self.failIf(self.subCategory.isFiltered())

    def testMakeSubcategoriesNonExclusiveUnchecksAllSubcategories(self):
        self.category.makeSubcategoriesExclusive(True)
        self.subCategory.setFiltered(True)
        self.category.addChild(self.subCategory)
        self.category.makeSubcategoriesExclusive(False)
        self.failIf(self.subCategory.isFiltered())        
        
    # Event types:
        
    def testModificationEventTypes(self): # pylint: disable-msg=E1003
        self.assertEqual(super(category.Category,
                               self.category).modificationEventTypes() + \
                         [self.category.filterChangedEventType(), 
                          self.category.categorizableAddedEventType(),
                          self.category.categorizableRemovedEventType(),
                          self.category.exclusiveSubcategoriesChangedEventType()], 
                         self.category.modificationEventTypes())

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.