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
|
|
21 |
import string
|
|
22 |
import sys,os
|
|
23 |
import __init__
|
|
24 |
|
|
25 |
from cone.public import api,exceptions,utils
|
|
26 |
from cone.storage import stringstorage
|
|
27 |
|
|
28 |
class TestLayer(unittest.TestCase):
|
|
29 |
storage_class = stringstorage.StringStorage
|
|
30 |
|
|
31 |
def test_create_layer(self):
|
|
32 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
33 |
layer = api.Layer(store, "foo")
|
|
34 |
self.assertTrue(layer)
|
|
35 |
|
|
36 |
# def test_create_layer_with_kwargs(self):
|
|
37 |
# store = self.storage_class.open("temp/layertest.pk","w")
|
|
38 |
# layer = api.Layer(store, "foo",confml_path="foobar", implml_path="")
|
|
39 |
# self.assertTrue(layer)
|
|
40 |
# self.assertEquals(layer.confml_folder.get_current_path(),"foo/foobar")
|
|
41 |
# self.assertEquals(layer.implml_folder.get_current_path(),"foo")
|
|
42 |
# layer = api.Layer(store, "foo",confml_path="f", implml_path="test", content_path="data", doc_path="foo")
|
|
43 |
# self.assertEquals(layer.confml_folder.get_current_path(),"foo/f")
|
|
44 |
# self.assertEquals(layer.implml_folder.get_current_path(),"foo/test")
|
|
45 |
# self.assertEquals(layer.content_folder.get_current_path(),"foo/data")
|
|
46 |
# self.assertEquals(layer.doc_folder.get_current_path(),"foo/foo")
|
|
47 |
# layer = api.Layer(store, "foo")
|
|
48 |
# self.assertEquals(layer.confml_folder.get_current_path(),"foo/confml")
|
|
49 |
# self.assertEquals(layer.implml_folder.get_current_path(),"foo/implml")
|
|
50 |
# self.assertEquals(layer.content_folder.get_current_path(),"foo/content")
|
|
51 |
# self.assertEquals(layer.doc_folder.get_current_path(),"foo/doc")
|
|
52 |
|
|
53 |
def test_get_path(self):
|
|
54 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
55 |
layer = api.Layer(store, "foo")
|
|
56 |
self.assertTrue(layer)
|
|
57 |
self.assertEquals(layer.get_current_path(),"foo")
|
|
58 |
|
|
59 |
def test_open_resource(self):
|
|
60 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
61 |
layer = api.Layer(store, "foo")
|
|
62 |
self.assertTrue(layer)
|
|
63 |
res = layer.open_resource("confml/test.confml","w")
|
|
64 |
res.write("foo.conf")
|
|
65 |
res.close()
|
|
66 |
self.assertEquals(layer.list_resources("", True),["confml/test.confml"])
|
|
67 |
self.assertEquals(store.list_resources("", True),["foo/confml/test.confml"])
|
|
68 |
|
|
69 |
def test_create_two_layers_and_open_resource(self):
|
|
70 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
71 |
foo_layer = api.Layer(store, "foo")
|
|
72 |
bar_layer = api.Layer(store, "bar")
|
|
73 |
res = foo_layer.open_resource("confml/test.confml","w")
|
|
74 |
res.write("foo.conf")
|
|
75 |
res.close()
|
|
76 |
res = foo_layer.open_resource("root.confml","w")
|
|
77 |
res.close()
|
|
78 |
res = bar_layer.open_resource("confml/root.confml","w")
|
|
79 |
res.write("foo.conf")
|
|
80 |
res.close()
|
|
81 |
self.assertEquals(foo_layer.list_resources("", True),['confml/test.confml', 'root.confml'])
|
|
82 |
self.assertEquals(store.list_resources("", True),['bar/confml/root.confml','foo/confml/test.confml','foo/root.confml'])
|
|
83 |
foo_layer.delete_resource("confml/test.confml")
|
|
84 |
self.assertEquals(foo_layer.list_resources("", True),["root.confml"])
|
|
85 |
self.assertEquals(store.list_resources("", True),["bar/confml/root.confml","foo/root.confml"])
|
|
86 |
|
|
87 |
def test_list_confml(self):
|
|
88 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
89 |
layer = api.Layer(store, "foo")
|
|
90 |
res = layer.open_resource("confml/test.confml","w")
|
|
91 |
res.write("foo.conf")
|
|
92 |
res.close()
|
|
93 |
res = layer.open_resource("confml/foo.confml","w")
|
|
94 |
res.write("foo.conf")
|
|
95 |
res.close()
|
|
96 |
res = layer.open_resource("root.confml","w")
|
|
97 |
res.write("foo.conf")
|
|
98 |
res.close()
|
|
99 |
self.assertEquals(layer.list_confml(),['confml/foo.confml', 'confml/test.confml'])
|
|
100 |
|
|
101 |
def test_list_implml(self):
|
|
102 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
103 |
layer = api.Layer(store, "foo")
|
|
104 |
res = layer.open_resource("implml/stuff/test.confml","w")
|
|
105 |
res.write("foo.conf")
|
|
106 |
res.close()
|
|
107 |
res = layer.open_resource("confml/foo.confml","w")
|
|
108 |
res.write("foo.conf")
|
|
109 |
res.close()
|
|
110 |
res = layer.open_resource("root.confml","w")
|
|
111 |
res.write("foo.conf")
|
|
112 |
res.close()
|
|
113 |
self.assertEquals(layer.list_implml(),['implml/stuff/test.confml'])
|
|
114 |
|
|
115 |
def test_list_content(self):
|
|
116 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
117 |
layer = api.Layer(store, "foo")
|
|
118 |
res = layer.open_resource("content/bar/test.txt","w")
|
|
119 |
res.write("foo.conf")
|
|
120 |
res.close()
|
|
121 |
res = layer.open_resource("content/foo.confml","w")
|
|
122 |
res.write("foo.conf")
|
|
123 |
res.close()
|
|
124 |
res = layer.open_resource("root.confml","w")
|
|
125 |
res.write("foo.conf")
|
|
126 |
res.close()
|
|
127 |
self.assertEquals(layer.list_content(),['content/bar/test.txt', 'content/foo.confml'])
|
|
128 |
|
|
129 |
def test_list_doc(self):
|
|
130 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
131 |
layer = api.Layer(store, "foo")
|
|
132 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
133 |
res.write("foo.conf")
|
|
134 |
res.close()
|
|
135 |
res = layer.open_resource("doc/foo.confml","w")
|
|
136 |
res.write("foo.conf")
|
|
137 |
res.close()
|
|
138 |
res = layer.open_resource("root.confml","w")
|
|
139 |
res.write("foo.conf")
|
|
140 |
res.close()
|
|
141 |
self.assertEquals(layer.list_doc(),['doc/bar/test.txt', 'doc/foo.confml'])
|
|
142 |
|
|
143 |
def test_list_layer_resources(self):
|
|
144 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
145 |
layer = api.Layer(store, "foo")
|
|
146 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
147 |
res.write("foo.conf")
|
|
148 |
res.close()
|
|
149 |
res = layer.open_resource("confml/foo.confml","w")
|
|
150 |
res.write("foo.conf")
|
|
151 |
res.close()
|
|
152 |
res = layer.open_resource("confml/bar.confml","w")
|
|
153 |
res.write("foo.conf")
|
|
154 |
res.close()
|
|
155 |
res = layer.open_resource("content/data/abc.txt","w")
|
|
156 |
res.write("foo.conf")
|
|
157 |
res.close()
|
|
158 |
res = layer.open_resource("foo.txt","w")
|
|
159 |
res.write("foo.conf")
|
|
160 |
res.close()
|
|
161 |
self.assertEquals(layer.list_all_resources(),['confml/bar.confml',
|
|
162 |
'confml/foo.confml',
|
|
163 |
'content/data/abc.txt',
|
|
164 |
'doc/bar/test.txt'])
|
|
165 |
|
|
166 |
def test_list_layer_with_sublayer(self):
|
|
167 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
168 |
layer = api.Layer(store, "foo", layers=[api.Layer(store, "bar")])
|
|
169 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
170 |
res.write("foo.conf")
|
|
171 |
res.close()
|
|
172 |
res = layer.open_resource("confml/foo.confml","w")
|
|
173 |
res.write("foo.conf")
|
|
174 |
res.close()
|
|
175 |
res = layer.open_resource("confml/bar.confml","w")
|
|
176 |
res.write("foo.conf")
|
|
177 |
res.close()
|
|
178 |
res = layer.open_resource("content/data/abc.txt","w")
|
|
179 |
res.write("foo.conf")
|
|
180 |
res.close()
|
|
181 |
res = layer.open_resource("foo.txt","w")
|
|
182 |
res.write("foo.conf")
|
|
183 |
res.close()
|
|
184 |
barlayer = layer.get_layer('bar')
|
|
185 |
res = barlayer.open_resource("content/barcode.txt","w")
|
|
186 |
res.write("foo.conf")
|
|
187 |
res.close()
|
|
188 |
res = barlayer.open_resource("confml/hooo.confml","w")
|
|
189 |
res.write("foo.conf")
|
|
190 |
res.close()
|
|
191 |
|
|
192 |
self.assertEquals(layer.list_all_resources(),['confml/bar.confml',
|
|
193 |
'confml/foo.confml',
|
|
194 |
'content/data/abc.txt',
|
|
195 |
'doc/bar/test.txt',
|
|
196 |
'bar/confml/hooo.confml',
|
|
197 |
'bar/content/barcode.txt'])
|
|
198 |
|
|
199 |
self.assertEquals(layer.list_implml(),[])
|
|
200 |
self.assertEquals(layer.list_confml(),['confml/bar.confml',
|
|
201 |
'confml/foo.confml',
|
|
202 |
'bar/confml/hooo.confml'])
|
|
203 |
self.assertEquals(layer.list_content(),['content/data/abc.txt', 'bar/content/barcode.txt'])
|
|
204 |
self.assertEquals(layer.list_doc(),['doc/bar/test.txt'])
|
|
205 |
|
|
206 |
class TestCompositeLayer(unittest.TestCase):
|
|
207 |
storage_class = stringstorage.StringStorage
|
|
208 |
|
|
209 |
def test_create_compositelayer(self):
|
|
210 |
store = self.storage_class.open("temp/layertestcomposite.pk","w")
|
|
211 |
clayer = api.CompositeLayer()
|
|
212 |
self.assertTrue(clayer)
|
|
213 |
|
|
214 |
def test_create_with_layer(self):
|
|
215 |
store = self.storage_class.open("temp/layertestcomposite.pk","w")
|
|
216 |
clayer = api.CompositeLayer("sub",layers=[api.Layer(store,"test"), api.Layer(store,"foo/bar")])
|
|
217 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar'])
|
|
218 |
|
|
219 |
def test_create_with_layer_and_add(self):
|
|
220 |
store = self.storage_class.open("temp/layertestcomposite.pk","w")
|
|
221 |
clayer = api.CompositeLayer(layers=[api.Layer(store,"test"), api.Layer(store,"foo/bar")])
|
|
222 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar'])
|
|
223 |
clayer.add_layer(api.Layer(store,"res"))
|
|
224 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar', 'res'])
|
|
225 |
|
|
226 |
def test_get_layer(self):
|
|
227 |
store = self.storage_class.open("temp/layertestcomposite.pk","w")
|
|
228 |
clayer = api.CompositeLayer(layers=[api.Layer(store,"test"), api.Layer(store,"foo/bar")])
|
|
229 |
self.assertEquals(clayer.list_layers(),['test', 'foo/bar'])
|
|
230 |
layer = clayer.get_layer('foo/bar')
|
|
231 |
self.assertEquals(layer.get_current_path(),'foo/bar')
|
|
232 |
|
|
233 |
def test_create_layers_with_resources_and_list_with_composite(self):
|
|
234 |
store = self.storage_class.open("temp/layertest.pk","w")
|
|
235 |
foolayer = api.Layer(store, "foo")
|
|
236 |
res = foolayer.open_resource("doc/bar/test.txt","w")
|
|
237 |
res.write("foo.conf")
|
|
238 |
res.close()
|
|
239 |
res = foolayer.open_resource("implml/foo2.crml","w")
|
|
240 |
res.write("foo.conf")
|
|
241 |
res.close()
|
|
242 |
res = foolayer.open_resource("confml/bar.confml","w")
|
|
243 |
res.write("foo.conf")
|
|
244 |
res.close()
|
|
245 |
res = foolayer.open_resource("content/data/abc.txt","w")
|
|
246 |
res.write("foo.conf")
|
|
247 |
res.close()
|
|
248 |
res = foolayer.open_resource("foo.txt","w")
|
|
249 |
res.write("foo.conf")
|
|
250 |
res.close()
|
|
251 |
barlayer = api.Layer(store, "bar")
|
|
252 |
res = barlayer.open_resource("doc/bar/test.txt","w")
|
|
253 |
res.write("foo.conf")
|
|
254 |
res.close()
|
|
255 |
res = barlayer.open_resource("implml/foo.crml","w")
|
|
256 |
res.write("foo.conf")
|
|
257 |
res.close()
|
|
258 |
res = barlayer.open_resource("confml/bar.confml","w")
|
|
259 |
res.write("foo.conf")
|
|
260 |
res.close()
|
|
261 |
res = barlayer.open_resource("content/data/abc.txt","w")
|
|
262 |
res.write("foo.conf")
|
|
263 |
res.close()
|
|
264 |
res = barlayer.open_resource("foo.txt","w")
|
|
265 |
res.write("foo.conf")
|
|
266 |
res.close()
|
|
267 |
clayer = api.CompositeLayer('test',layers=[foolayer,barlayer])
|
|
268 |
|
|
269 |
self.assertEquals(clayer.list_all_resources(),['foo/confml/bar.confml',
|
|
270 |
'foo/content/data/abc.txt',
|
|
271 |
'foo/doc/bar/test.txt',
|
|
272 |
'foo/implml/foo2.crml',
|
|
273 |
'bar/confml/bar.confml',
|
|
274 |
'bar/content/data/abc.txt',
|
|
275 |
'bar/doc/bar/test.txt',
|
|
276 |
'bar/implml/foo.crml',])
|
|
277 |
self.assertEquals(clayer.list_implml(),['foo/implml/foo2.crml','bar/implml/foo.crml'])
|
|
278 |
self.assertEquals(clayer.list_confml(),['foo/confml/bar.confml', 'bar/confml/bar.confml'])
|
|
279 |
self.assertEquals(clayer.list_content(),['foo/content/data/abc.txt', 'bar/content/data/abc.txt'])
|
|
280 |
self.assertEquals(clayer.list_doc(),['foo/doc/bar/test.txt', 'bar/doc/bar/test.txt'])
|
|
281 |
|
|
282 |
if __name__ == '__main__':
|
|
283 |
unittest.main()
|
|
284 |
|