0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
"""
|
|
18 |
Test the configuration
|
|
19 |
"""
|
|
20 |
import unittest
|
3
|
21 |
|
|
22 |
|
|
23 |
from cone.public import api
|
|
24 |
from cone.storage import stringstorage
|
|
25 |
|
|
26 |
class TestFolder(unittest.TestCase):
|
|
27 |
storage_class = stringstorage.StringStorage
|
|
28 |
def setUp(self):
|
|
29 |
self.store = self.storage_class.open("temp/layertest.pk","w")
|
|
30 |
|
|
31 |
def test_create_folder(self):
|
|
32 |
folder = api.Folder(self.store, "subfolder")
|
|
33 |
self.assertTrue(folder)
|
|
34 |
|
|
35 |
def test_get_path(self):
|
|
36 |
folder = api.Folder(self.store, "foo")
|
|
37 |
self.assertEquals(folder.get_current_path(),"foo")
|
|
38 |
|
|
39 |
def test_open_resource(self):
|
|
40 |
folder = api.Folder(self.store, "foo")
|
|
41 |
res = folder.open_resource("confml/test.confml","w")
|
|
42 |
res.write("foo.conf")
|
|
43 |
res.close()
|
|
44 |
self.assertEquals(folder.list_resources("", recurse=True),["confml/test.confml"])
|
|
45 |
self.assertEquals(self.store.list_resources("", recurse=True),["foo/confml/test.confml"])
|
0
|
46 |
|
3
|
47 |
def test_open_non_existing_resource(self):
|
|
48 |
folder = api.Folder(self.store, "foo")
|
|
49 |
try:
|
|
50 |
folder.open_resource("confml/test.confml","r")
|
|
51 |
except Exception:
|
|
52 |
pass
|
|
53 |
self.assertEquals(folder.storage.curpath, '')
|
|
54 |
|
|
55 |
def test_create_two_layers_and_open_resource(self):
|
|
56 |
foo_folder = api.Folder(self.store, "foo")
|
|
57 |
bar_folder = api.Folder(self.store, "bar")
|
|
58 |
res = foo_folder.open_resource("confml/test.confml","w")
|
|
59 |
res.write("foo.conf")
|
|
60 |
res.close()
|
|
61 |
res = foo_folder.open_resource("root.confml","w")
|
|
62 |
res.close()
|
|
63 |
res = bar_folder.open_resource("confml/root.confml","w")
|
|
64 |
res.write("foo.conf")
|
|
65 |
res.close()
|
|
66 |
self.assertEquals(foo_folder.list_resources("", recurse=True),[ 'root.confml',
|
|
67 |
'confml/test.confml'])
|
|
68 |
self.assertEquals(self.store.list_resources("", recurse=True),['bar/confml/root.confml',
|
|
69 |
'foo/root.confml',
|
|
70 |
'foo/confml/test.confml'])
|
|
71 |
foo_folder.delete_resource("confml/test.confml")
|
|
72 |
self.assertEquals(foo_folder.list_resources("", recurse=True),["root.confml"])
|
|
73 |
self.assertEquals(self.store.list_resources("", recurse=True),["bar/confml/root.confml",
|
|
74 |
"foo/root.confml"])
|
|
75 |
|
0
|
76 |
|
|
77 |
class TestLayer(unittest.TestCase):
|
|
78 |
storage_class = stringstorage.StringStorage
|
3
|
79 |
def setUp(self):
|
|
80 |
self.store = self.storage_class.open("temp/layertest.pk","w")
|
0
|
81 |
|
|
82 |
def test_create_layer(self):
|
3
|
83 |
layer = api.Layer(self.store, "foo")
|
0
|
84 |
self.assertTrue(layer)
|
|
85 |
|
|
86 |
# def test_create_layer_with_kwargs(self):
|
3
|
87 |
# self.store = self.storage_class.open("temp/layertest.pk","w")
|
|
88 |
# layer = api.Layer(self.store, "foo",confml_path="foobar", implml_path="")
|
0
|
89 |
# self.assertTrue(layer)
|
|
90 |
# self.assertEquals(layer.confml_folder.get_current_path(),"foo/foobar")
|
|
91 |
# self.assertEquals(layer.implml_folder.get_current_path(),"foo")
|
3
|
92 |
# layer = api.Layer(self.store, "foo",confml_path="f", implml_path="test", content_path="data", doc_path="foo")
|
0
|
93 |
# self.assertEquals(layer.confml_folder.get_current_path(),"foo/f")
|
|
94 |
# self.assertEquals(layer.implml_folder.get_current_path(),"foo/test")
|
|
95 |
# self.assertEquals(layer.content_folder.get_current_path(),"foo/data")
|
|
96 |
# self.assertEquals(layer.doc_folder.get_current_path(),"foo/foo")
|
3
|
97 |
# layer = api.Layer(self.store, "foo")
|
0
|
98 |
# self.assertEquals(layer.confml_folder.get_current_path(),"foo/confml")
|
|
99 |
# self.assertEquals(layer.implml_folder.get_current_path(),"foo/implml")
|
|
100 |
# self.assertEquals(layer.content_folder.get_current_path(),"foo/content")
|
|
101 |
# self.assertEquals(layer.doc_folder.get_current_path(),"foo/doc")
|
|
102 |
|
|
103 |
def test_get_path(self):
|
3
|
104 |
layer = api.Layer(self.store, "foo")
|
0
|
105 |
self.assertTrue(layer)
|
|
106 |
self.assertEquals(layer.get_current_path(),"foo")
|
|
107 |
|
|
108 |
def test_open_resource(self):
|
3
|
109 |
layer = api.Layer(self.store, "foo")
|
0
|
110 |
self.assertTrue(layer)
|
|
111 |
res = layer.open_resource("confml/test.confml","w")
|
|
112 |
res.write("foo.conf")
|
|
113 |
res.close()
|
3
|
114 |
self.assertEquals(layer.list_resources("", recurse=True),["confml/test.confml"])
|
|
115 |
self.assertEquals(self.store.list_resources("", recurse=True),["foo/confml/test.confml"])
|
0
|
116 |
|
|
117 |
def test_create_two_layers_and_open_resource(self):
|
3
|
118 |
foo_layer = api.Layer(self.store, "foo")
|
|
119 |
bar_layer = api.Layer(self.store, "bar")
|
0
|
120 |
res = foo_layer.open_resource("confml/test.confml","w")
|
|
121 |
res.write("foo.conf")
|
|
122 |
res.close()
|
|
123 |
res = foo_layer.open_resource("root.confml","w")
|
|
124 |
res.close()
|
|
125 |
res = bar_layer.open_resource("confml/root.confml","w")
|
|
126 |
res.write("foo.conf")
|
|
127 |
res.close()
|
3
|
128 |
self.assertEquals(foo_layer.list_resources("", recurse=True),['root.confml', 'confml/test.confml'])
|
|
129 |
self.assertEquals(self.store.list_resources("", recurse=True),['bar/confml/root.confml', 'foo/root.confml', 'foo/confml/test.confml'])
|
0
|
130 |
foo_layer.delete_resource("confml/test.confml")
|
3
|
131 |
self.assertEquals(foo_layer.list_resources("", recurse=True),["root.confml"])
|
|
132 |
self.assertEquals(self.store.list_resources("", recurse=True),["bar/confml/root.confml","foo/root.confml"])
|
0
|
133 |
|
|
134 |
def test_list_confml(self):
|
3
|
135 |
layer = api.Layer(self.store, "foo")
|
0
|
136 |
res = layer.open_resource("confml/test.confml","w")
|
|
137 |
res.write("foo.conf")
|
|
138 |
res.close()
|
|
139 |
res = layer.open_resource("confml/foo.confml","w")
|
|
140 |
res.write("foo.conf")
|
|
141 |
res.close()
|
|
142 |
res = layer.open_resource("root.confml","w")
|
|
143 |
res.write("foo.conf")
|
|
144 |
res.close()
|
|
145 |
self.assertEquals(layer.list_confml(),['confml/foo.confml', 'confml/test.confml'])
|
|
146 |
|
|
147 |
def test_list_implml(self):
|
3
|
148 |
layer = api.Layer(self.store, "foo")
|
0
|
149 |
res = layer.open_resource("implml/stuff/test.confml","w")
|
|
150 |
res.write("foo.conf")
|
|
151 |
res.close()
|
|
152 |
res = layer.open_resource("confml/foo.confml","w")
|
|
153 |
res.write("foo.conf")
|
|
154 |
res.close()
|
|
155 |
res = layer.open_resource("root.confml","w")
|
|
156 |
res.write("foo.conf")
|
|
157 |
res.close()
|
|
158 |
self.assertEquals(layer.list_implml(),['implml/stuff/test.confml'])
|
|
159 |
|
|
160 |
def test_list_content(self):
|
3
|
161 |
layer = api.Layer(self.store, "foo")
|
0
|
162 |
res = layer.open_resource("content/bar/test.txt","w")
|
|
163 |
res.write("foo.conf")
|
|
164 |
res.close()
|
|
165 |
res = layer.open_resource("content/foo.confml","w")
|
|
166 |
res.write("foo.conf")
|
|
167 |
res.close()
|
|
168 |
res = layer.open_resource("root.confml","w")
|
|
169 |
res.write("foo.conf")
|
|
170 |
res.close()
|
3
|
171 |
self.assertEquals(layer.list_content(),[ 'content/foo.confml', 'content/bar/test.txt'])
|
0
|
172 |
|
|
173 |
def test_list_doc(self):
|
3
|
174 |
layer = api.Layer(self.store, "foo")
|
0
|
175 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
176 |
res.write("foo.conf")
|
|
177 |
res.close()
|
|
178 |
res = layer.open_resource("doc/foo.confml","w")
|
|
179 |
res.write("foo.conf")
|
|
180 |
res.close()
|
|
181 |
res = layer.open_resource("root.confml","w")
|
|
182 |
res.write("foo.conf")
|
|
183 |
res.close()
|
3
|
184 |
self.assertEquals(layer.list_doc(),['doc/foo.confml', 'doc/bar/test.txt' ])
|
0
|
185 |
|
|
186 |
def test_list_layer_resources(self):
|
3
|
187 |
layer = api.Layer(self.store, "foo")
|
0
|
188 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
189 |
res.write("foo.conf")
|
|
190 |
res.close()
|
|
191 |
res = layer.open_resource("confml/foo.confml","w")
|
|
192 |
res.write("foo.conf")
|
|
193 |
res.close()
|
|
194 |
res = layer.open_resource("confml/bar.confml","w")
|
|
195 |
res.write("foo.conf")
|
|
196 |
res.close()
|
|
197 |
res = layer.open_resource("content/data/abc.txt","w")
|
|
198 |
res.write("foo.conf")
|
|
199 |
res.close()
|
|
200 |
res = layer.open_resource("foo.txt","w")
|
|
201 |
res.write("foo.conf")
|
|
202 |
res.close()
|
|
203 |
self.assertEquals(layer.list_all_resources(),['confml/bar.confml',
|
|
204 |
'confml/foo.confml',
|
|
205 |
'content/data/abc.txt',
|
|
206 |
'doc/bar/test.txt'])
|
|
207 |
|
|
208 |
def test_list_layer_with_sublayer(self):
|
3
|
209 |
layer = api.Layer(self.store, "foo", layers=[api.Layer(self.store, "bar")])
|
0
|
210 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
211 |
res.write("foo.conf")
|
|
212 |
res.close()
|
|
213 |
res = layer.open_resource("confml/foo.confml","w")
|
|
214 |
res.write("foo.conf")
|
|
215 |
res.close()
|
|
216 |
res = layer.open_resource("confml/bar.confml","w")
|
|
217 |
res.write("foo.conf")
|
|
218 |
res.close()
|
|
219 |
res = layer.open_resource("content/data/abc.txt","w")
|
|
220 |
res.write("foo.conf")
|
|
221 |
res.close()
|
|
222 |
res = layer.open_resource("foo.txt","w")
|
|
223 |
res.write("foo.conf")
|
|
224 |
res.close()
|
|
225 |
barlayer = layer.get_layer('bar')
|
|
226 |
res = barlayer.open_resource("content/barcode.txt","w")
|
|
227 |
res.write("foo.conf")
|
|
228 |
res.close()
|
|
229 |
res = barlayer.open_resource("confml/hooo.confml","w")
|
|
230 |
res.write("foo.conf")
|
|
231 |
res.close()
|
|
232 |
|
|
233 |
self.assertEquals(layer.list_all_resources(),['confml/bar.confml',
|
|
234 |
'confml/foo.confml',
|
|
235 |
'content/data/abc.txt',
|
|
236 |
'doc/bar/test.txt',
|
|
237 |
'bar/confml/hooo.confml',
|
|
238 |
'bar/content/barcode.txt'])
|
|
239 |
|
|
240 |
self.assertEquals(layer.list_implml(),[])
|
|
241 |
self.assertEquals(layer.list_confml(),['confml/bar.confml',
|
|
242 |
'confml/foo.confml',
|
|
243 |
'bar/confml/hooo.confml'])
|
|
244 |
self.assertEquals(layer.list_content(),['content/data/abc.txt', 'bar/content/barcode.txt'])
|
|
245 |
self.assertEquals(layer.list_doc(),['doc/bar/test.txt'])
|
|
246 |
|
3
|
247 |
def test_list_all_related(self):
|
|
248 |
layer = api.Layer(self.store, "foo")
|
|
249 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
250 |
res.write("foo.conf")
|
|
251 |
res.close()
|
|
252 |
res = layer.open_resource("confml/foo.confml","w")
|
|
253 |
res.write("foo.conf")
|
|
254 |
res.close()
|
|
255 |
res = layer.open_resource("confml/bar.confml","w")
|
|
256 |
res.write("foo.conf")
|
|
257 |
res.close()
|
|
258 |
res = layer.open_resource("content/data/abc.txt","w")
|
|
259 |
res.write("foo.conf")
|
|
260 |
res.close()
|
|
261 |
res = layer.open_resource("foo.txt","w")
|
|
262 |
res.write("foo.conf")
|
|
263 |
res.close()
|
|
264 |
|
|
265 |
self.assertEquals(layer.list_all_related(),['content/data/abc.txt', 'doc/bar/test.txt'])
|
|
266 |
|
|
267 |
def test_list_all_related_with_filter(self):
|
|
268 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
269 |
layer = api.Layer(self.store, "foo")
|
|
270 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
271 |
res.write("foo.conf")
|
|
272 |
res.close()
|
|
273 |
res = layer.open_resource("confml/foo.confml","w")
|
|
274 |
res.write("foo.conf")
|
|
275 |
res.close()
|
|
276 |
res = layer.open_resource("confml/bar.confml","w")
|
|
277 |
res.write("foo.conf")
|
|
278 |
res.close()
|
|
279 |
res = layer.open_resource("content/data/abc.txt","w")
|
|
280 |
res.write("foo.conf")
|
|
281 |
res.close()
|
|
282 |
res = layer.open_resource("foo.txt","w")
|
|
283 |
res.write("foo.conf")
|
|
284 |
res.close()
|
|
285 |
|
|
286 |
self.assertEquals(layer.list_all_related(exclude_filters={'content':'.*\.txt'}), ['doc/bar/test.txt'])
|
|
287 |
self.assertEquals(layer.list_all_related(exclude_filters={'doc':'.*\.txt'}), ['content/data/abc.txt'])
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
0
|
292 |
class TestCompositeLayer(unittest.TestCase):
|
|
293 |
storage_class = stringstorage.StringStorage
|
3
|
294 |
def setUp(self):
|
|
295 |
self.store = self.storage_class.open("temp/layertest.pk","w")
|
0
|
296 |
|
|
297 |
def test_create_compositelayer(self):
|
3
|
298 |
clayer = api.CompositeLayer(self.store)
|
0
|
299 |
self.assertTrue(clayer)
|
|
300 |
|
|
301 |
def test_create_with_layer(self):
|
3
|
302 |
clayer = api.CompositeLayer("sub",layers=[api.Layer(self.store,"test"), api.Layer(self.store,"foo/bar")])
|
0
|
303 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar'])
|
|
304 |
|
|
305 |
def test_create_with_layer_and_add(self):
|
3
|
306 |
self.store = self.storage_class.open("temp/layertestcomposite.pk","w")
|
|
307 |
clayer = api.CompositeLayer(self.store, layers=[api.Layer(self.store,"test"), api.Layer(self.store,"foo/bar")])
|
0
|
308 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar'])
|
3
|
309 |
clayer.add_layer(api.Layer(self.store,"res"))
|
0
|
310 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar', 'res'])
|
|
311 |
|
|
312 |
def test_get_layer(self):
|
3
|
313 |
clayer = api.CompositeLayer(self.store, layers=[api.Layer(self.store,"test"), api.Layer(self.store,"foo/bar")])
|
0
|
314 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar'])
|
|
315 |
layer = clayer.get_layer('foo/bar')
|
|
316 |
self.assertEquals(layer.get_current_path(),'foo/bar')
|
|
317 |
|
|
318 |
def test_create_layers_with_resources_and_list_with_composite(self):
|
3
|
319 |
foolayer = api.Layer(self.store, "foo")
|
0
|
320 |
res = foolayer.open_resource("doc/bar/test.txt","w")
|
|
321 |
res.write("foo.conf")
|
|
322 |
res.close()
|
|
323 |
res = foolayer.open_resource("implml/foo2.crml","w")
|
|
324 |
res.write("foo.conf")
|
|
325 |
res.close()
|
|
326 |
res = foolayer.open_resource("confml/bar.confml","w")
|
|
327 |
res.write("foo.conf")
|
|
328 |
res.close()
|
|
329 |
res = foolayer.open_resource("content/data/abc.txt","w")
|
|
330 |
res.write("foo.conf")
|
|
331 |
res.close()
|
|
332 |
res = foolayer.open_resource("foo.txt","w")
|
|
333 |
res.write("foo.conf")
|
|
334 |
res.close()
|
3
|
335 |
barlayer = api.Layer(self.store, "bar")
|
0
|
336 |
res = barlayer.open_resource("doc/bar/test.txt","w")
|
|
337 |
res.write("foo.conf")
|
|
338 |
res.close()
|
|
339 |
res = barlayer.open_resource("implml/foo.crml","w")
|
|
340 |
res.write("foo.conf")
|
|
341 |
res.close()
|
|
342 |
res = barlayer.open_resource("confml/bar.confml","w")
|
|
343 |
res.write("foo.conf")
|
|
344 |
res.close()
|
|
345 |
res = barlayer.open_resource("content/data/abc.txt","w")
|
|
346 |
res.write("foo.conf")
|
|
347 |
res.close()
|
|
348 |
res = barlayer.open_resource("foo.txt","w")
|
|
349 |
res.write("foo.conf")
|
|
350 |
res.close()
|
|
351 |
clayer = api.CompositeLayer('test',layers=[foolayer,barlayer])
|
|
352 |
|
|
353 |
self.assertEquals(clayer.list_all_resources(),['foo/confml/bar.confml',
|
|
354 |
'foo/content/data/abc.txt',
|
|
355 |
'foo/doc/bar/test.txt',
|
|
356 |
'foo/implml/foo2.crml',
|
|
357 |
'bar/confml/bar.confml',
|
|
358 |
'bar/content/data/abc.txt',
|
|
359 |
'bar/doc/bar/test.txt',
|
|
360 |
'bar/implml/foo.crml',])
|
|
361 |
self.assertEquals(clayer.list_implml(),['foo/implml/foo2.crml','bar/implml/foo.crml'])
|
|
362 |
self.assertEquals(clayer.list_confml(),['foo/confml/bar.confml', 'bar/confml/bar.confml'])
|
|
363 |
self.assertEquals(clayer.list_content(),['foo/content/data/abc.txt', 'bar/content/data/abc.txt'])
|
|
364 |
self.assertEquals(clayer.list_doc(),['foo/doc/bar/test.txt', 'bar/doc/bar/test.txt'])
|
|
365 |
|
|
366 |
if __name__ == '__main__':
|
|
367 |
unittest.main()
|
|
368 |
|