File: Outline_tests.py

package info (click to toggle)
zope-zwiki 0.60.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,216 kB
  • ctags: 1,895
  • sloc: python: 12,397; ansic: 2,058; lisp: 118; haskell: 68; xml: 47; makefile: 30; sh: 2
file content (206 lines) | stat: -rw-r--r-- 8,072 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
from testsupport import *
ZopeTestCase.installProduct('ZCatalog')
ZopeTestCase.installProduct('ZWiki')
from Products.ZWiki.Outline import Outline
#or to test it alone, just set up your pythonpath and do
#from Outline import Outline

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(Tests))
    return suite

class Tests(unittest.TestCase):
    def setUp(self):
        self.outline = Outline(
            {
            'RootPage':[],
            'ChildPage':['RootPage'],
            'GrandChildPage':['ChildPage'],
            'SingletonPage':[],
            'TestPage':[],
            })

    def test_init(self):
        o = Outline({1:[],2:[],3:[]})
        self.assertEquals(o.nodeCount(),3)

    def test_parentmap(self):
        o = self.outline
        parentmap = o.parentmap()
        self.assertEquals(len(parentmap.keys()),5)
        self.assertEquals(parentmap['RootPage'],[])
        self.assertEquals(parentmap['ChildPage'],['RootPage'])
        self.assertEquals(parentmap['GrandChildPage'],['ChildPage'])
        self.assertEquals(parentmap['SingletonPage'],[])
        self.assertEquals(parentmap['TestPage'],[])

    def test_childmap(self):
        o = self.outline
        childmap = o.childmap()
        self.assertEquals(len(childmap.keys()),5)
        self.assertEquals(childmap['RootPage'],['ChildPage'])
        self.assertEquals(childmap['ChildPage'],['GrandChildPage'])
        self.assertEquals(childmap['GrandChildPage'],[])
        self.assertEquals(childmap['SingletonPage'],[])
        self.assertEquals(childmap['TestPage'],[])

    def test_roots(self):
        o = self.outline
        self.assertEquals(o.roots(),['RootPage','SingletonPage','TestPage'])

    def test_nodes(self):
        o = self.outline
        self.assertEquals(o.nodes(),
                          ['ChildPage','GrandChildPage','RootPage',
                           'SingletonPage','TestPage'])

    def test_flat(self):
        o = self.outline
        self.assertEquals(o.flat(),
                          ['RootPage','ChildPage','GrandChildPage',
                           'SingletonPage','TestPage'])

    def test_nesting(self):
        o = self.outline
        self.assertEquals(o.nesting(),
                          [
                           ['RootPage',
                            ['ChildPage',
                             'GrandChildPage']],
                           'SingletonPage',
                           'TestPage',
                           ])
        
    def test_next(self):
        o = self.outline
        self.assertEquals(o.next('RootPage'),'ChildPage')
        self.assertEquals(o.next('GrandChildPage'),'SingletonPage')
        self.assertEquals(o.next('TestPage'),None)

    def test_previous(self):
        o = self.outline
        self.assertEquals(o.previous('RootPage'),None)
        self.assertEquals(o.previous('ChildPage'),'RootPage')
        self.assertEquals(o.previous('SingletonPage'),'GrandChildPage')

    def test_ancestors(self):
        o = self.outline
        self.assertEquals(o.ancestors('RootPage'),[['RootPage']])
        self.assertEquals(o.ancestors('ChildPage'),[['RootPage','ChildPage']])
        self.assertEquals(o.ancestors('GrandChildPage'),
                          [['RootPage',['ChildPage','GrandChildPage']]])

    def test_ancestorsAndSiblings(self):
        o = self.outline
        self.assertEquals(o.ancestorsAndSiblings('RootPage'),
                          [['RootPage']])
        self.assertEquals(o.ancestorsAndSiblings('ChildPage'),
                          [['RootPage', 'ChildPage']])
        self.assertEquals(o.ancestorsAndSiblings('GrandChildPage'),
                          [['RootPage',['ChildPage','GrandChildPage']]])

    def test_ancestorsAndChildren(self):
        o = self.outline
        self.assertEquals(o.ancestorsAndChildren('RootPage'),
                          [['RootPage','ChildPage']])
        self.assertEquals(o.ancestorsAndChildren('ChildPage'),
                          [['RootPage', ['ChildPage','GrandChildPage']]])
        self.assertEquals(o.ancestorsAndChildren('GrandChildPage'),
                          [['RootPage',['ChildPage','GrandChildPage']]])

    def test_offspring(self):
        o = self.outline
        self.assertEquals(o.offspring(['RootPage']),
                          [['RootPage',['ChildPage','GrandChildPage']]])
        self.assertEquals(o.offspring(['ChildPage']),
                          [['ChildPage','GrandChildPage']])
        self.assertEquals(o.offspring(['GrandChildPage']),
                          ['GrandChildPage'])
        self.assertEquals(o.offspring(['RootPage'],depth=1),
                          [['RootPage','ChildPage']])
        self.assertEquals(o.offspring(['RootPage'],depth=2),
                          [['RootPage',['ChildPage','GrandChildPage']]])
    
    def test_parents(self):
        o = self.outline
        self.assertEquals(o.parents('RootPage'),[])
        self.assertEquals(o.parents('ChildPage'),['RootPage'])

    def test_siblings(self):
        o = self.outline
        self.assertEquals(o.siblings('RootPage'),['SingletonPage','TestPage'])
        self.assertEquals(o.siblings('ChildPage'),[])

    def test_children(self):
        o = self.outline
        self.assertEquals(o.children('RootPage'),['ChildPage'])
        self.assertEquals(o.children('GrandChildPage'),[])

    def test_add(self):
        o = self.outline
        self.assert_(not o.hasNode('NewPageOne'))
        o.add('NewPageOne')
        self.assert_(o.hasNode('NewPageOne'))

    def test_delete(self):
        o = self.outline
        count = o.nodeCount()
        o.delete('TestPage')
        self.assertEquals(o.nodeCount(),count-1)
        # any children should be reparented
        self.assertEquals(o.nesting(),
                          [
                           ['RootPage',
                            ['ChildPage',
                             'GrandChildPage']],
                           'SingletonPage',
                           ])
        o.delete('ChildPage')
        self.assertEquals(o.nesting(),
                          [
                           ['RootPage',
                            'GrandChildPage'],
                           'SingletonPage',
                           ])
        parentmap = o.parentmap()
        self.assertEquals(len(parentmap.keys()),3)
        self.assertEquals(parentmap['RootPage'],[])
        self.assertEquals(parentmap['GrandChildPage'],['RootPage'])
        self.assertEquals(parentmap['SingletonPage'],[])
        childmap = o.childmap()
        self.assertEquals(len(childmap.keys()),3)
        self.assertEquals(childmap['RootPage'],['GrandChildPage'])
        self.assertEquals(childmap['GrandChildPage'],[])
        self.assertEquals(childmap['SingletonPage'],[])
        o.delete('RootPage')
        self.assertEquals(o.nesting(),
                          [
                           'GrandChildPage',
                           'SingletonPage',
                           ])
        parentmap = o.parentmap()
        self.assertEquals(len(parentmap.keys()),2)
        self.assertEquals(parentmap['GrandChildPage'],[])
        self.assertEquals(parentmap['SingletonPage'],[])
        childmap = o.childmap()
        self.assertEquals(len(childmap.keys()),2)
        self.assertEquals(childmap['GrandChildPage'],[])
        self.assertEquals(childmap['SingletonPage'],[])

    def test_replace(self):
        o = self.outline
        self.assert_(o.hasNode('TestPage'))
        self.assert_(not o.hasNode('RenamedPage'))
        children = o.children('TestPage')
        o.replace('TestPage','RenamedPage')
        self.assert_(not o.hasNode('TestPage'))
        self.assert_(o.hasNode('RenamedPage'))
        self.assertEquals(o.children('RenamedPage'),children)

    def test_reparent(self):
        o = self.outline
        self.assertEquals(o.parents('ChildPage'),['RootPage'])
        o.reparent('ChildPage',['TestPage'])
        self.assertEquals(o.parents('ChildPage'),['TestPage'])