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 CPF configuration
|
|
19 |
"""
|
|
20 |
import unittest
|
|
21 |
import string
|
|
22 |
import sys,os
|
|
23 |
import shutil
|
|
24 |
import __init__
|
|
25 |
from testautomation.base_testcase import BaseTestCase
|
|
26 |
|
|
27 |
from cone.public import exceptions, api
|
|
28 |
from cone.confml.model import ConfmlMeta, ConfmlDescription
|
|
29 |
from cone.storage.filestorage import FileStorage
|
|
30 |
from cone.confml import model
|
|
31 |
|
|
32 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
33 |
temp_dir = os.path.join(ROOT_PATH, "temp/project_on_filestorage")
|
|
34 |
datafolder= os.path.join(ROOT_PATH,"../../storage/tests/data")
|
|
35 |
|
|
36 |
class TestConeProjectOpen(unittest.TestCase):
|
|
37 |
def setUp(self):
|
|
38 |
pass
|
|
39 |
|
|
40 |
def test_open_storage(self):
|
|
41 |
p = api.Storage.open(datafolder)
|
|
42 |
self.assertTrue(p)
|
|
43 |
|
|
44 |
def test_open_project_of_non_storage(self):
|
|
45 |
fs = "foobar_dummy"
|
|
46 |
try:
|
|
47 |
p = api.Storage.open(fs)
|
|
48 |
self.fail("Opening on top of non storage succeeds!!")
|
|
49 |
except exceptions.StorageException:
|
|
50 |
self.assertTrue(True)
|
|
51 |
|
|
52 |
|
|
53 |
class TestConeProjectMethodsRead(unittest.TestCase):
|
|
54 |
def setUp(self):
|
|
55 |
self.project = api.Project(api.Storage.open(datafolder))
|
|
56 |
|
|
57 |
def test_list_configurations(self):
|
|
58 |
confs = self.project.list_configurations()
|
|
59 |
self.assertTrue(confs)
|
|
60 |
self.assertEquals(confs[0],"morestuff.confml")
|
|
61 |
|
|
62 |
def test_get_configuration(self):
|
|
63 |
conf = self.project.get_configuration("morestuff.confml")
|
|
64 |
self.assertTrue(conf)
|
|
65 |
self.assertTrue(isinstance(conf,api.ConfigurationProxy))
|
|
66 |
|
|
67 |
def test_get_configuration_non_existing(self):
|
|
68 |
try:
|
|
69 |
conf = self.project.get_configuration("foo.confml")
|
|
70 |
self.fail("Opening non existing configuration succeeds!")
|
|
71 |
except exceptions.NotFound,e:
|
|
72 |
self.assertTrue(True)
|
|
73 |
|
|
74 |
def test_get_configuration_and_list_layers(self):
|
|
75 |
conf = self.project.get_configuration("morestuff.confml")
|
|
76 |
layers = conf.list_configurations()
|
|
77 |
self.assertTrue(layers)
|
|
78 |
self.assertEquals(layers[0],'platform/s60/root.confml')
|
|
79 |
self.assertEquals(layers[1],'familyX/root.confml')
|
|
80 |
|
|
81 |
def test_get_is_configuration(self):
|
|
82 |
self.assertTrue(self.project.is_configuration("morestuff.confml"))
|
|
83 |
# TODO: this is not working at the moment due to performance problem in
|
|
84 |
# Project.list_all_configurations()
|
|
85 |
#self.assertTrue(self.project.is_configuration("platform/s60/root.confml"))
|
|
86 |
#self.assertFalse(self.project.is_configuration("platform/foo/root.confml"))
|
|
87 |
|
|
88 |
def test_get_configuration_and_get_layer(self):
|
|
89 |
conf = self.project.get_configuration("morestuff.confml")
|
|
90 |
s60layer = conf.get_configuration('platform/s60/root.confml')
|
|
91 |
self.assertTrue(s60layer)
|
|
92 |
self.assertTrue(isinstance(s60layer.get_layer(),api.Layer))
|
|
93 |
|
|
94 |
def test_get_configuration_and_get_layer_path(self):
|
|
95 |
conf = self.project.get_configuration("morestuff.confml")
|
|
96 |
s60layer = conf.get_configuration('platform/s60/root.confml')
|
|
97 |
self.assertEquals(s60layer.get_path(),'platform/s60/root.confml')
|
|
98 |
|
|
99 |
def test_get_configuration_and_get_layer_and_get_layer_resources(self):
|
|
100 |
conf = self.project.get_configuration("morestuff.confml")
|
|
101 |
s60layer = conf.get_configuration('platform/s60/root.confml')
|
|
102 |
files = s60layer.list_resources()
|
|
103 |
self.assertEquals(files[0],'platform/s60/root.confml')
|
|
104 |
|
|
105 |
def test_get_configuration_and_get_layer_and_get_a_layer_resource(self):
|
|
106 |
conf = self.project.get_configuration("morestuff.confml")
|
|
107 |
s60layer = conf.get_configuration('platform/s60/root.confml')
|
|
108 |
res = s60layer.get_resource('root.confml')
|
|
109 |
self.assertTrue(res)
|
|
110 |
|
|
111 |
def test_get_configuration_and_list_all_configuration_resources(self):
|
|
112 |
conf = self.project.get_configuration("morestuff.confml")
|
|
113 |
resources = conf.list_resources()
|
|
114 |
self.assertEquals(resources[0],'morestuff.confml')
|
|
115 |
|
|
116 |
def test_get_configuration_and_get_first_layer_by_index(self):
|
|
117 |
conf = self.project.get_configuration("morestuff.confml")
|
|
118 |
s60config = conf.get_configuration_by_index(0)
|
|
119 |
self.assertEquals(s60config.get_path(),'platform/s60/root.confml')
|
|
120 |
|
|
121 |
def test_get_configuration_and_get_last_layer_by_index(self):
|
|
122 |
conf = self.project.get_configuration("morestuff.confml")
|
|
123 |
config = conf.get_configuration_by_index(-1)
|
|
124 |
self.assertEquals(config.get_path(),'familyX/prodX/root.confml')
|
|
125 |
|
|
126 |
def test_get_all_resources(self):
|
|
127 |
conf = self.project.get_configuration("morestuff.confml")
|
|
128 |
resources = conf.get_all_resources()
|
|
129 |
self.assertEquals(resources[0].get_path(),'morestuff.confml')
|
|
130 |
self.assertEquals(resources[1].get_path(),'platform/s60/root.confml')
|
|
131 |
|
|
132 |
def test_list_confmls(self):
|
|
133 |
conf = self.project.get_configuration("morestuff.confml")
|
|
134 |
confmls = conf.list_resources()
|
|
135 |
self.assertEquals(confmls[0],'morestuff.confml')
|
|
136 |
self.assertEquals(confmls[1],'platform/s60/root.confml')
|
|
137 |
|
|
138 |
def test_list_implmls(self):
|
|
139 |
conf = self.project.get_configuration("morestuff.confml")
|
|
140 |
implmls = conf.get_configuration('platform/s60/root.confml').get_layer().list_implml()
|
|
141 |
self.assertEquals(implmls[0],'implml/accessoryserver_1020505A.crml')
|
|
142 |
|
|
143 |
# def test_list_content(self):
|
|
144 |
# conf = self.project.get_configuration("morestuff.confml")
|
|
145 |
# contents = conf.list_content()
|
|
146 |
# self.assertEquals(contents[0],'platform/s60/content/.svn/all-wcprops')
|
|
147 |
|
|
148 |
def test_layered_content(self):
|
|
149 |
conf = self.project.get_configuration("morestuff.confml")
|
|
150 |
contents = conf.layered_content()
|
|
151 |
self.assertEquals(contents.get_value('test/s60.txt'),'platform/s60/content/test/s60.txt')
|
|
152 |
self.assertEquals(contents.get_value('test/override.txt'),'familyX/content/test/override.txt')
|
|
153 |
self.assertEquals(contents.get_value('test/shout.txt'),'familyX/content/test/shout.txt')
|
|
154 |
|
|
155 |
def test_layer_name(self):
|
|
156 |
conf = self.project.get_configuration("morestuff.confml")
|
|
157 |
s60layer = conf.get_configuration('platform/s60/root.confml')
|
|
158 |
self.assertEquals(s60layer.get_ref(),'platform__s60__root_confml')
|
|
159 |
|
|
160 |
|
|
161 |
def test_layered_content_with_one_layer(self):
|
|
162 |
conf = self.project.get_configuration("morestuff.confml")
|
|
163 |
contents = conf.layered_content([-2])
|
|
164 |
self.assertEquals(contents.get_value('test/override.txt'),'familyX/content/test/override.txt')
|
|
165 |
self.assertEquals(contents.get_value('test/shout.txt'),'familyX/content/test/shout.txt')
|
|
166 |
try:
|
|
167 |
contents.get_value('test/s60.txt')
|
|
168 |
self.fail("Fetching content from s60 layer succeeds!")
|
|
169 |
except KeyError:
|
|
170 |
pass
|
|
171 |
|
|
172 |
def test_layered_content_with_two_layers(self):
|
|
173 |
conf = self.project.get_configuration("morestuff.confml")
|
|
174 |
contents = conf.layered_content([-2,-1])
|
|
175 |
self.assertEquals(contents.get_value('test/override.txt'),'familyX/content/test/override.txt')
|
|
176 |
self.assertEquals(contents.get_value('test/shout.txt'),'familyX/content/test/shout.txt')
|
|
177 |
self.assertEquals(contents.get_value('prodX/jee/ProdX_specific.txt'),'familyX/prodX/content/prodX/jee/ProdX_specific.txt')
|
|
178 |
try:
|
|
179 |
contents.get_value('test/s60.txt')
|
|
180 |
self.fail("Fetching content from s60 layer succeeds!")
|
|
181 |
except KeyError:
|
|
182 |
pass
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
class TestConeProjectMethodsWrite(BaseTestCase):
|
|
188 |
def setUp(self):
|
|
189 |
if not os.path.exists(temp_dir):
|
|
190 |
os.makedirs(temp_dir)
|
|
191 |
|
|
192 |
if not os.path.exists('newtempproject'):
|
|
193 |
os.mkdir('newtempproject')
|
|
194 |
fs = api.Storage.open("newtempproject","a")
|
|
195 |
self.project = api.Project(fs)
|
|
196 |
|
|
197 |
def tearDown(self):
|
|
198 |
self.project.close()
|
|
199 |
shutil.rmtree('newtempproject')
|
|
200 |
pass
|
|
201 |
|
|
202 |
def test_create_configuration(self):
|
|
203 |
conf = self.project.create_configuration("dummy.confml")
|
|
204 |
self.assertTrue(conf)
|
|
205 |
self.assertEquals(conf.get_ref(),'dummy_confml')
|
|
206 |
self.assertTrue(isinstance(conf,api.Configuration))
|
|
207 |
conf.close()
|
|
208 |
|
|
209 |
def test_create_close_open_configuration(self):
|
|
210 |
tempdir_orig = os.path.normpath(os.path.join(temp_dir, "temp1_orig"))
|
|
211 |
tempdir_copy = os.path.normpath(os.path.join(temp_dir, "temp1_copy"))
|
|
212 |
self.remove_if_exists([tempdir_orig, tempdir_copy])
|
|
213 |
|
|
214 |
project = api.Project(api.Storage.open(tempdir_orig,"w"))
|
|
215 |
conf = project.create_configuration("dummy2.confml")
|
|
216 |
conf.set_name("dummy")
|
|
217 |
prop1 = model.ConfmlMetaProperty('owner', 'some guy')
|
|
218 |
prop2 = model.ConfmlMetaProperty('purpose', 'for testing')
|
|
219 |
conf.meta = model.ConfmlMeta([prop1, prop2])
|
|
220 |
conf.desc = "Testing to see a configuration created"
|
|
221 |
conf.create_configuration("test/path/to/somewhere/r.confml")
|
|
222 |
conf.create_configuration("test/path/to/elsewhere/r.confml")
|
|
223 |
conf.save()
|
|
224 |
project.save()
|
|
225 |
project.close()
|
|
226 |
|
|
227 |
# Make a copy of the created directory
|
|
228 |
shutil.copytree(tempdir_orig, tempdir_copy)
|
|
229 |
# If everything has been closed properly, the original directory
|
|
230 |
# should now be removable
|
|
231 |
shutil.rmtree(tempdir_orig)
|
|
232 |
|
|
233 |
project2 = api.Project(api.Storage.open(tempdir_copy))
|
|
234 |
conf2 = project2.get_configuration("dummy2.confml")
|
|
235 |
|
|
236 |
self.assertEquals(conf.get_name(),conf2.get_name())
|
|
237 |
self.assertEquals(conf2.get_name(),'dummy')
|
|
238 |
self.assertEquals(conf2.meta[0].tag ,'owner')
|
|
239 |
self.assertEquals(conf2.meta[0].value ,'some guy')
|
|
240 |
self.assertEquals(conf.desc,conf2.desc)
|
|
241 |
self.assertEquals(conf.list_configurations(),conf2.list_configurations())
|
|
242 |
project2.close()
|
|
243 |
|
|
244 |
def test_remove_configuration_non_existing(self):
|
|
245 |
try:
|
|
246 |
self.project.remove_configuration("dummystring.txt")
|
|
247 |
self.fail("Removing non existing configuration succeds!")
|
|
248 |
except exceptions.NotFound,e:
|
|
249 |
self.assertTrue(True)
|
|
250 |
|
|
251 |
def test_create_remove_configuration(self):
|
|
252 |
conf = self.project.create_configuration("remove.confml")
|
|
253 |
conf.save()
|
|
254 |
conf.close()
|
|
255 |
|
|
256 |
self.project.remove_configuration("remove.confml")
|
|
257 |
try:
|
|
258 |
conf = self.project.get_configuration("remove.confml")
|
|
259 |
self.fail("Opening of removed configuration succeeds!")
|
|
260 |
except exceptions.NotFound,e:
|
|
261 |
self.assertTrue(True)
|
|
262 |
|
|
263 |
def test_create_configuration_in_sub_configuration(self):
|
|
264 |
fs = api.Storage.open("newproject","w")
|
|
265 |
project = api.Project(fs)
|
|
266 |
conf = project.create_configuration("croot.confml")
|
|
267 |
subconf = conf.create_configuration("test/root.confml")
|
|
268 |
subconf.create_configuration('confml/data.confml')
|
|
269 |
conf.save()
|
|
270 |
self.assertTrue(project.get_storage().is_resource('test/confml/data.confml'))
|
|
271 |
conf = project.get_configuration("croot.confml")
|
|
272 |
subconf = conf.create_configuration("test2\\root.confml")
|
|
273 |
subconf.create_configuration('confml/data.confml')
|
|
274 |
subconf.close()
|
|
275 |
conf.save()
|
|
276 |
self.assertTrue(project.get_storage().is_resource('test2/confml/data.confml'))
|
|
277 |
project.close()
|
|
278 |
shutil.rmtree("newproject")
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
if __name__ == '__main__':
|
|
283 |
unittest.main()
|
|
284 |
|