File: CategorizableCommandsTest.py

package info (click to toggle)
taskcoach 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,496 kB
  • ctags: 17,810
  • sloc: python: 72,170; makefile: 254; ansic: 120; xml: 29; sh: 16
file content (142 lines) | stat: -rw-r--r-- 7,651 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>

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 taskcoachlib import command
from taskcoachlib.domain import category, categorizable
from CommandTestCase import CommandTestCase


class ToggleCategoryCommandTestCase(CommandTestCase):
    def setUp(self):
        super(ToggleCategoryCommandTestCase, self).setUp()
        self.category = category.Category('Cat')
        self.categorizable = categorizable.CategorizableCompositeObject(subject='Categorizable')
        
    def toggleItem(self, items=None, category=None):
        check = command.ToggleCategoryCommand(category=category or self.category, 
                                              items=items or [])
        check.do()


class ToggleCategory(ToggleCategoryCommandTestCase):
    def testToggleCategory_AffectsCategorizable(self):
        self.toggleItem([self.categorizable])
        self.assertDoUndoRedo(\
            lambda: self.assertEqual(set([self.category]), self.categorizable.categories()),
            lambda: self.assertEqual(set(), self.categorizable.categories()))
        
    def testToggleCategory_AffectsCategory(self):
        self.toggleItem([self.categorizable])
        self.assertDoUndoRedo(\
            lambda: self.assertEqual(set([self.categorizable]), self.category.categorizables()),
            lambda: self.assertEqual(set(), self.category.categorizables()))
        
    def testToggleCategory_AffectsCategorizableThatIsInCategory(self):
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable])
        self.assertDoUndoRedo(\
            lambda: self.assertEqual(set(), self.categorizable.categories()),
            lambda: self.assertEqual(set([self.category]), self.categorizable.categories()))
        
    def testToggleCategory_AffectsCategoryThatAlreadyContainsCategorizable(self):
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable])
        self.assertDoUndoRedo(\
            lambda: self.assertEqual(set(), self.category.categorizables()),
            lambda: self.assertEqual(set([self.categorizable]), self.category.categorizables()))
        
    def testToggleCategory_WhenSomeCategorizablesAreInCategory(self):
        ''' If some of the selected categorizables are in the category and some
            are not, toggle category puts all categorizables in the category, 
            rather than toggling all categorizables. '''
        categorizable2 = categorizable.CategorizableCompositeObject(subject='Categorizable2')
        categorizable2.addCategory(self.category)
        self.category.addCategorizable(categorizable2)
        self.toggleItem([self.categorizable, categorizable2])
        self.assertDoUndoRedo(\
            lambda: self.assertEqual(set([self.categorizable, categorizable2]), self.category.categorizables()), 
            lambda: self.assertEqual(set([categorizable2]), self.category.categorizables()))


class ToggleMutualExclusiveCategories(ToggleCategoryCommandTestCase):
    def setUp(self):
        super(ToggleMutualExclusiveCategories, self).setUp()
        self.subCategory1, self.subCategory2 = self.addMutualExclusiveSubcategories(self.category)
        
    def addMutualExclusiveSubcategories(self, parentCategory): 
        subCategory1 = category.Category('subCategory1')
        subCategory2 = category.Category('subCategory2')
        parentCategory.addChild(subCategory1)
        parentCategory.addChild(subCategory2)
        parentCategory.makeSubcategoriesExclusive()
        return subCategory1, subCategory2

    def testToggleMutualExclusiveSubcategory(self):
        self.categorizable.addCategory(self.subCategory1)
        self.subCategory1.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable], self.subCategory2)
        self.assertDoUndoRedo(
            lambda: self.assertEqual(set([self.subCategory2]), self.categorizable.categories()),
            lambda: self.assertEqual(set([self.subCategory1]), self.categorizable.categories()))

    def testToggleMutualExclusiveSubcategoryThatIsAlreadyChecked(self):
        self.categorizable.addCategory(self.subCategory1)
        self.subCategory1.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable], self.subCategory1)
        self.assertDoUndoRedo(
            lambda: self.assertEqual(set(), self.categorizable.categories()),
            lambda: self.assertEqual(set([self.subCategory1]), self.categorizable.categories()))
        
    def testToggleMutualExclusiveSubcategoryUnchecksParent(self):
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable], self.subCategory1)
        self.assertDoUndoRedo(
            lambda: self.assertEqual(set(), self.category.categorizables()),
            lambda: self.assertEqual(set([self.categorizable]), self.category.categorizables()))

    def testToggleMutualExclusiveCategoryUnchecksCheckedChild(self):
        self.categorizable.addCategory(self.subCategory1)
        self.subCategory1.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable], self.category)
        self.assertDoUndoRedo(
            lambda: self.assertEqual(set(), self.subCategory1.categorizables()),
            lambda: self.assertEqual(set([self.categorizable]), self.subCategory1.categorizables()))

    def testToggleMutualExclusiveSubcategoryDoesNotUncheckMutualExclusiveParent(self):
        subCategory1_1, subCategory1_2 = self.addMutualExclusiveSubcategories(self.subCategory1)
        self.categorizable.addCategory(self.subCategory1)
        self.subCategory1.addCategorizable(self.categorizable)
        self.categorizable.addCategory(subCategory1_1)
        subCategory1_1.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable], subCategory1_2)
        self.assertDoUndoRedo(
            lambda: self.assertEqual(set([self.categorizable]), self.subCategory1.categorizables()))

    def testToggleMutualExclusiveSubcategoryRecursivelyUnchecksCheckedChildren(self):
        subCategory1_1 = self.addMutualExclusiveSubcategories(self.subCategory1)[0]
        self.categorizable.addCategory(self.subCategory1)
        self.subCategory1.addCategorizable(self.categorizable)
        self.categorizable.addCategory(subCategory1_1)
        subCategory1_1.addCategorizable(self.categorizable)
        self.toggleItem([self.categorizable], self.subCategory2)
        self.assertDoUndoRedo(
            lambda: self.assertEqual(set(), subCategory1_1.categorizables()),
            lambda: self.assertEqual(set([self.categorizable]), subCategory1_1.categorizables()))