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
|
|
23 |
import os
|
|
24 |
import subprocess
|
|
25 |
import shutil
|
|
26 |
import __init__
|
|
27 |
from testautomation.base_testcase import BaseTestCase
|
|
28 |
from testautomation import unzip_file
|
|
29 |
from scripttest_common import get_cmd
|
|
30 |
from cone.public import api
|
|
31 |
|
|
32 |
try:
|
|
33 |
from cElementTree import ElementTree
|
|
34 |
except ImportError:
|
|
35 |
try:
|
|
36 |
from elementtree import ElementTree
|
|
37 |
except ImportError:
|
|
38 |
try:
|
|
39 |
from xml.etree import cElementTree as ElementTree
|
|
40 |
except ImportError:
|
|
41 |
from xml.etree import ElementTree
|
|
42 |
|
|
43 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
44 |
TEMP_DIR = os.path.join(ROOT_PATH, 'temp/update')
|
|
45 |
TEST_PROJECT_CPF = os.path.join(ROOT_PATH, 'test_project.cpf')
|
|
46 |
|
|
47 |
class TestUpdate(BaseTestCase):
|
|
48 |
|
|
49 |
def test_get_help(self):
|
|
50 |
cmd = '%s -h' % get_cmd('update')
|
|
51 |
out = self.run_command(cmd)
|
|
52 |
lines = out.split('\r\n')
|
|
53 |
self.assertTrue('Options:' in lines)
|
|
54 |
self.assertTrue(' Update options:' in lines)
|
|
55 |
|
|
56 |
def test_add_and_remove_meta_in_filesystem_project(self):
|
|
57 |
TEST_PROJECT_DIR = os.path.join(ROOT_PATH, 'temp/update/project')
|
|
58 |
unzip_file.unzip_file(TEST_PROJECT_CPF, TEST_PROJECT_DIR, delete_if_exists=True)
|
|
59 |
|
|
60 |
rootfile = os.path.join(TEST_PROJECT_DIR, "root5.confml")
|
|
61 |
self._run_test_add_and_remove_meta_in_project(
|
|
62 |
project = TEST_PROJECT_DIR,
|
|
63 |
root_file_reader = lambda: self.read_data_from_file(rootfile))
|
|
64 |
|
|
65 |
def test_add_and_remove_meta_in_cpf(self):
|
|
66 |
cpf = os.path.join(ROOT_PATH, "temp/metadata/project.cpf")
|
|
67 |
self.remove_if_exists(cpf)
|
|
68 |
self.create_dir_for_file_path(cpf)
|
|
69 |
shutil.copy2(TEST_PROJECT_CPF, cpf)
|
|
70 |
|
|
71 |
self._run_test_add_and_remove_meta_in_project(
|
|
72 |
project = cpf,
|
|
73 |
root_file_reader = lambda: self.read_data_from_zip_file(cpf, "root5.confml"))
|
|
74 |
|
|
75 |
def _run_test_add_and_remove_meta_in_project(self, project, root_file_reader):
|
|
76 |
"""
|
|
77 |
Run test for adding and removing metadata in a project.
|
|
78 |
|
|
79 |
@param project: Path to the project that is being modified.
|
|
80 |
@param root_file_reader: Function that will be called to read the raw binary
|
|
81 |
data of the configuration project's root ConfML file.
|
|
82 |
"""
|
|
83 |
# -------------------------------------
|
|
84 |
# Step 1: Add metadata and description
|
|
85 |
# -------------------------------------
|
|
86 |
self.set_modification_reference_time(project)
|
|
87 |
cmd = ('%s '\
|
|
88 |
'--project "%s" --configuration root5.confml '\
|
|
89 |
'--add-meta owner="test person" '\
|
|
90 |
'--add-meta product="test product" '\
|
|
91 |
'--add-meta date="2009-05-11" '\
|
|
92 |
'--add-cpf-meta product_type="XYZ-123" '\
|
|
93 |
'--add-cpf-meta platform="Platform X" '\
|
|
94 |
'--add-cpf-meta platform_version="1.0.0" '\
|
|
95 |
'--add-desc "Testing description"') % (get_cmd('update'), project)
|
|
96 |
out = self.run_command(cmd)
|
|
97 |
#print out
|
|
98 |
self.assert_modified(project)
|
|
99 |
|
|
100 |
|
|
101 |
# Check that the metadata is correct
|
|
102 |
root_elem = ElementTree.fromstring(root_file_reader())
|
|
103 |
|
|
104 |
desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
|
|
105 |
self.assertEquals(desc_elem.text, "Testing description")
|
|
106 |
|
|
107 |
meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
|
|
108 |
self.assertEquals(self._get_meta_entry(meta_elem, 'owner'), 'test person')
|
|
109 |
self.assertEquals(self._get_meta_entry(meta_elem, 'product'), 'test product')
|
|
110 |
self.assertEquals(self._get_meta_entry(meta_elem, 'date'), '2009-05-11')
|
|
111 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'product_type'), 'XYZ-123')
|
|
112 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'platform'), 'Platform X')
|
|
113 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'platform_version'), '1.0.0')
|
|
114 |
|
|
115 |
|
|
116 |
# -----------------------------------------------
|
|
117 |
# Step 2: Remove and modify some of the metadata
|
|
118 |
# -----------------------------------------------
|
|
119 |
self.set_modification_reference_time(project)
|
|
120 |
cmd = ('%s '\
|
|
121 |
'--project "%s" --configuration root5.confml '\
|
|
122 |
'--add-meta product="Prod-1" '\
|
|
123 |
'--remove-meta date '\
|
|
124 |
'--add-cpf-meta platform_version=1.0.1 '\
|
|
125 |
'--remove-meta product_type ') % (get_cmd('update'), project)
|
|
126 |
out = self.run_command(cmd)
|
|
127 |
#print out
|
|
128 |
self.assert_modified(project)
|
|
129 |
|
|
130 |
# Check that the metadata is correct
|
|
131 |
root_elem = ElementTree.fromstring(root_file_reader())
|
|
132 |
|
|
133 |
desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
|
|
134 |
self.assertEquals(desc_elem.text, "Testing description")
|
|
135 |
|
|
136 |
meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
|
|
137 |
self.assertEquals(self._get_meta_entry(meta_elem, 'owner'), 'test person')
|
|
138 |
self.assertEquals(self._get_meta_entry(meta_elem, 'product'), 'Prod-1')
|
|
139 |
self.assertEquals(self._get_meta_entry(meta_elem, 'date'), None)
|
|
140 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'product_type'), None)
|
|
141 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'platform'), 'Platform X')
|
|
142 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'platform_version'), '1.0.1')
|
|
143 |
|
|
144 |
|
|
145 |
# ------------------------------------------------------------
|
|
146 |
# Step 3: Remove the description and the rest of the metadata
|
|
147 |
# ------------------------------------------------------------
|
|
148 |
self.set_modification_reference_time(project)
|
|
149 |
cmd = ('%s '\
|
|
150 |
'--project "%s" --configuration root5.confml '\
|
|
151 |
'--remove-meta owner '\
|
|
152 |
'--remove-meta product '\
|
|
153 |
'--remove-meta platform '\
|
|
154 |
'--remove-meta platform_version '\
|
|
155 |
'--remove-desc ') % (get_cmd('update'), project)
|
|
156 |
out = self.run_command(cmd)
|
|
157 |
#print out
|
|
158 |
self.assert_modified(project)
|
|
159 |
|
|
160 |
|
|
161 |
# Check that the metadata is correct
|
|
162 |
root_elem = ElementTree.fromstring(root_file_reader())
|
|
163 |
|
|
164 |
desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
|
|
165 |
self.assertEquals(desc_elem, None)
|
|
166 |
|
|
167 |
meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
|
|
168 |
self.assertEquals(0, len(meta_elem.getchildren()))
|
|
169 |
|
|
170 |
|
|
171 |
def _get_meta_entry(self, meta_elem, entry_name):
|
|
172 |
elem = meta_elem.find("{http://www.s60.com/xml/confml/2}%s" % entry_name)
|
|
173 |
if elem != None: return elem.text
|
|
174 |
else: return None
|
|
175 |
|
|
176 |
def _get_cpf_meta_entry(self, meta_elem, entry_name):
|
|
177 |
elem = None
|
|
178 |
for e in meta_elem.findall("{http://www.nokia.com/xml/cpf-id/1}configuration-property"):
|
|
179 |
if e.get('name') == entry_name:
|
|
180 |
elem = e
|
|
181 |
break
|
|
182 |
|
|
183 |
if elem != None: return elem.get('value')
|
|
184 |
else: return None
|
|
185 |
|
|
186 |
def test_add_data_to_cpf(self):
|
|
187 |
# Copy from the test data
|
|
188 |
cpf = os.path.join(ROOT_PATH, "temp/metadata/add_data_test_project.cpf")
|
|
189 |
self.remove_if_exists(cpf)
|
|
190 |
self.create_dir_for_file_path(cpf)
|
|
191 |
shutil.copy2(TEST_PROJECT_CPF, cpf)
|
|
192 |
|
|
193 |
CONFIG = 'root3.confml'
|
|
194 |
|
|
195 |
def get_setting_value(project_location, ref):
|
|
196 |
prj = api.Project(api.Storage.open(project_location, 'r'))
|
|
197 |
try:
|
|
198 |
config = prj.get_configuration(CONFIG)
|
|
199 |
dview = config.get_default_view()
|
|
200 |
feature = dview.get_feature(ref)
|
|
201 |
return feature.get_value()
|
|
202 |
finally:
|
|
203 |
prj.close()
|
|
204 |
|
|
205 |
self.assertEquals(get_setting_value(cpf, 'Feature1.BooleanSetting'), False)
|
|
206 |
|
|
207 |
self.set_modification_reference_time(cpf)
|
|
208 |
cmd = '%s -p "%s" -c %s --add-data Feature1.BooleanSetting=true' % (get_cmd('update'), cpf, CONFIG)
|
|
209 |
self.run_command(cmd)
|
|
210 |
self.assert_modified(cpf)
|
|
211 |
|
|
212 |
self.assertEquals(get_setting_value(cpf, 'Feature1.BooleanSetting'), True)
|
|
213 |
|
|
214 |
def _run_test_add_meta_to_multiple_roots_in_filesystem_project(self, project, args, updated_configs):
|
|
215 |
TEST_PROJECT_DIR = os.path.join(ROOT_PATH, 'temp/update', project)
|
|
216 |
unzip_file.unzip_file(TEST_PROJECT_CPF, TEST_PROJECT_DIR, delete_if_exists=True)
|
|
217 |
self.assert_exists_and_contains_something(TEST_PROJECT_DIR)
|
|
218 |
|
|
219 |
self.set_modification_reference_time(TEST_PROJECT_DIR)
|
|
220 |
cmd = ('%(cmd)s '\
|
|
221 |
'--project "%(project)s" %(args)s '\
|
|
222 |
'--add-meta owner="test person" '\
|
|
223 |
'--add-meta product="test product" '\
|
|
224 |
'--add-cpf-meta product_type="XYZ-123" '\
|
|
225 |
'--add-cpf-meta platform="Platform X" '\
|
|
226 |
'--add-desc "Testing description"')\
|
|
227 |
% {'cmd' : get_cmd('update'),
|
|
228 |
'project': TEST_PROJECT_DIR,
|
|
229 |
'args' : args}
|
|
230 |
out = self.run_command(cmd)
|
|
231 |
#print out
|
|
232 |
self.assert_modified(TEST_PROJECT_DIR)
|
|
233 |
|
|
234 |
# Check that the metadata is correct for all roots
|
|
235 |
project = api.Project(api.Storage.open(TEST_PROJECT_DIR, 'r'))
|
|
236 |
for config in project.list_configurations():
|
|
237 |
config_file_path = os.path.join(TEST_PROJECT_DIR, config)
|
|
238 |
root_elem = ElementTree.fromstring(self.read_data_from_file(config_file_path))
|
|
239 |
|
|
240 |
if config in updated_configs:
|
|
241 |
try:
|
|
242 |
desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
|
|
243 |
self.assertNotEquals(desc_elem, None)
|
|
244 |
self.assertEquals(desc_elem.text, "Testing description")
|
|
245 |
|
|
246 |
meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
|
|
247 |
self.assertEquals(self._get_meta_entry(meta_elem, 'owner'), 'test person')
|
|
248 |
self.assertEquals(self._get_meta_entry(meta_elem, 'product'), 'test product')
|
|
249 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'product_type'), 'XYZ-123')
|
|
250 |
self.assertEquals(self._get_cpf_meta_entry(meta_elem, 'platform'), 'Platform X')
|
|
251 |
except AssertionError:
|
|
252 |
self.fail("Root '%s' was not updated when it should have been!" % config)
|
|
253 |
else:
|
|
254 |
try:
|
|
255 |
desc_elem = root_elem.find("{http://www.s60.com/xml/confml/2}desc")
|
|
256 |
self.assertEquals(desc_elem, None)
|
|
257 |
|
|
258 |
meta_elem = root_elem.find("{http://www.s60.com/xml/confml/2}meta")
|
|
259 |
self.assertEquals(meta_elem, None)
|
|
260 |
except AssertionError:
|
|
261 |
self.fail("Root '%s' was updated when it should not have been!" % config)
|
|
262 |
|
|
263 |
def test_update_multiple_configurations(self):
|
|
264 |
self._run_test_add_meta_to_multiple_roots_in_filesystem_project(
|
|
265 |
project = 'multi_project',
|
|
266 |
args = '-c root2.confml '
|
|
267 |
'-c root4.confml',
|
|
268 |
updated_configs = ['root2.confml',
|
|
269 |
'root4.confml'])
|
|
270 |
|
|
271 |
def test_update_multiple_configurations_with_wildcard(self):
|
|
272 |
self._run_test_add_meta_to_multiple_roots_in_filesystem_project(
|
|
273 |
project = 'multi_project_wildcard',
|
|
274 |
args = '--config-wildcard root*.confml',
|
|
275 |
updated_configs = ['root1.confml',
|
|
276 |
'root2.confml',
|
|
277 |
'root3.confml',
|
|
278 |
'root4.confml',
|
|
279 |
'root5.confml'])
|
|
280 |
|
|
281 |
def test_update_multiple_configurations_with_regex(self):
|
|
282 |
self._run_test_add_meta_to_multiple_roots_in_filesystem_project(
|
|
283 |
project = 'multi_project_regex',
|
|
284 |
args = '--config-regex root[135].confml',
|
|
285 |
updated_configs = ['root1.confml',
|
|
286 |
'root3.confml',
|
|
287 |
'root5.confml'])
|
|
288 |
|
|
289 |
def test_update_multiple_configurations_with_mixed_args(self):
|
|
290 |
self._run_test_add_meta_to_multiple_roots_in_filesystem_project(
|
|
291 |
project = 'multi_project_mixed_args',
|
|
292 |
args = '-c root2.confml --config-regex root[13].confml',
|
|
293 |
updated_configs = ['root1.confml',
|
|
294 |
'root2.confml',
|
|
295 |
'root3.confml'])
|
|
296 |
|
|
297 |
if __name__ == '__main__':
|
|
298 |
unittest.main() |