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,shutil
|
|
23 |
import difflib, zipfile
|
|
24 |
|
|
25 |
from cone.public import exceptions,utils, api
|
|
26 |
from cone.storage.filestorage import FileStorage
|
|
27 |
from cone.storage.zipstorage import ZipStorage
|
|
28 |
from testautomation import unzip_file
|
|
29 |
from testautomation.base_testcase import BaseTestCase
|
|
30 |
|
|
31 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
32 |
temp_dir = os.path.join(ROOT_PATH,"temp/export")
|
|
33 |
test_cpf = os.path.join(ROOT_PATH,"testdata/test_project.cpf")
|
|
34 |
datafolder = os.path.join(ROOT_PATH,"../../storage/tests/data")
|
|
35 |
tempzip = os.path.join(temp_dir, "exported.zip")
|
|
36 |
|
|
37 |
class TestConeProjectExport(BaseTestCase):
|
|
38 |
def setUp(self):
|
|
39 |
if not os.path.exists(temp_dir):
|
|
40 |
os.makedirs(temp_dir)
|
|
41 |
|
|
42 |
def test_export_to_zipstorage(self):
|
|
43 |
test_project_dir = os.path.join(temp_dir, "test_project_1")
|
|
44 |
unzip_file.unzip_file(test_cpf, test_project_dir, delete_if_exists=True)
|
|
45 |
|
|
46 |
export_zip = os.path.join(temp_dir, "configexport.zip")
|
|
47 |
|
|
48 |
fs = FileStorage(test_project_dir)
|
|
49 |
p = api.Project(fs)
|
|
50 |
conf = p.get_configuration('root5.confml')
|
|
51 |
zs = ZipStorage(export_zip,"w")
|
|
52 |
zp = api.Project(zs)
|
|
53 |
conf_files = conf.list_resources()
|
|
54 |
files1 = ['.metadata']
|
|
55 |
files1.extend(conf_files)
|
|
56 |
p.export_configuration(conf,zs)
|
|
57 |
zp.close()
|
|
58 |
self.assertTrue(os.path.exists(export_zip))
|
|
59 |
zfile = zipfile.ZipFile(export_zip,"r")
|
|
60 |
files2 = zfile.namelist()
|
|
61 |
zfile.close()
|
|
62 |
files1.sort()
|
|
63 |
files2.sort()
|
|
64 |
for i in range(len(files1)):
|
|
65 |
self.assertEquals(files1[i],files2[i])
|
|
66 |
os.unlink(export_zip)
|
|
67 |
|
5
|
68 |
def test_export_with_include_content_filter(self):
|
|
69 |
include_content_filter = ".*layer4.*"
|
|
70 |
include_filters = {'content':include_content_filter}
|
|
71 |
test_project_dir = os.path.join(temp_dir, "test_project_1")
|
|
72 |
unzip_file.unzip_file(test_cpf, test_project_dir, delete_if_exists=True)
|
|
73 |
|
|
74 |
export_zip = os.path.join(temp_dir, "configexport.zip")
|
|
75 |
|
|
76 |
fs = FileStorage(test_project_dir)
|
|
77 |
p = api.Project(fs)
|
|
78 |
conf = p.get_configuration('root5.confml')
|
|
79 |
zs = ZipStorage(export_zip,"w")
|
|
80 |
zp = api.Project(zs)
|
|
81 |
p.export_configuration(conf,zs,include_filters = include_filters)
|
|
82 |
zp.close()
|
|
83 |
|
|
84 |
zs = ZipStorage(export_zip,"r")
|
|
85 |
zp = api.Project(zs)
|
|
86 |
conf = zp.get_configuration('root5.confml')
|
|
87 |
rel = conf.get_layer().list_all_related()
|
|
88 |
|
|
89 |
exp = ['Layer1/implml/bitmask_test_12341002.crml',
|
|
90 |
'Layer1/implml/feature1_12341000.crml',
|
|
91 |
'Layer1/implml/feature1_12341001.crml',
|
|
92 |
'Layer1/implml/feature1_sequence.gcfml',
|
|
93 |
'Layer1/implml/feature2_ABCD0000.crml',
|
|
94 |
'Layer1/implml/time_types_test_12341003.crml',
|
|
95 |
'Layer4/content/seq/layer4_file.txt']
|
|
96 |
zs.close()
|
|
97 |
self.assertEquals(exp,rel)
|
|
98 |
os.unlink(export_zip)
|
|
99 |
|
|
100 |
def test_export_with_exclude_content_filter(self):
|
|
101 |
exclude_content_filter = ".*(layer1|layer2).*"
|
|
102 |
exclude_filters = {'content':exclude_content_filter}
|
|
103 |
test_project_dir = os.path.join(temp_dir, "test_project_1")
|
|
104 |
unzip_file.unzip_file(test_cpf, test_project_dir, delete_if_exists=True)
|
|
105 |
|
|
106 |
export_zip = os.path.join(temp_dir, "configexport.zip")
|
|
107 |
|
|
108 |
fs = FileStorage(test_project_dir)
|
|
109 |
p = api.Project(fs)
|
|
110 |
conf = p.get_configuration('root5.confml')
|
|
111 |
zs = ZipStorage(export_zip,"w")
|
|
112 |
zp = api.Project(zs)
|
|
113 |
p.export_configuration(conf,zs,exclude_filters = exclude_filters)
|
|
114 |
zp.close()
|
|
115 |
|
|
116 |
zs = ZipStorage(export_zip,"r")
|
|
117 |
zp = api.Project(zs)
|
|
118 |
conf = zp.get_configuration('root5.confml')
|
|
119 |
rel = conf.get_layer().list_all_related()
|
|
120 |
|
|
121 |
exp = ['Layer1/implml/bitmask_test_12341002.crml',
|
|
122 |
'Layer1/implml/feature1_12341000.crml',
|
|
123 |
'Layer1/implml/feature1_12341001.crml',
|
|
124 |
'Layer1/implml/feature1_sequence.gcfml',
|
|
125 |
'Layer1/implml/feature2_ABCD0000.crml',
|
|
126 |
'Layer1/implml/time_types_test_12341003.crml',
|
|
127 |
'Layer3/content/seq/layer3_file.txt',
|
|
128 |
'Layer4/content/seq/layer4_file.txt',
|
|
129 |
'Layer5/content/content.txt',
|
|
130 |
'Layer5/content/folder/abc.txt']
|
|
131 |
zs.close()
|
|
132 |
self.assertEquals(exp,rel)
|
|
133 |
os.unlink(export_zip)
|
|
134 |
|
|
135 |
def test_export_with_include_exclude_content_filters(self):
|
|
136 |
exclude_content_filter = ".*def.+\.txt"
|
|
137 |
include_content_filter = ".*layer5.*"
|
|
138 |
exclude_filters = {'content':exclude_content_filter}
|
|
139 |
include_filters = {'content':include_content_filter}
|
|
140 |
test_project_dir = os.path.join(temp_dir, "test_project_1")
|
|
141 |
unzip_file.unzip_file(test_cpf, test_project_dir, delete_if_exists=True)
|
|
142 |
|
|
143 |
export_zip = os.path.join(temp_dir, "configexport.zip")
|
|
144 |
|
|
145 |
fs = FileStorage(test_project_dir)
|
|
146 |
p = api.Project(fs)
|
|
147 |
conf = p.get_configuration('root5.confml')
|
|
148 |
zs = ZipStorage(export_zip,"w")
|
|
149 |
zp = api.Project(zs)
|
|
150 |
p.export_configuration(conf,zs,exclude_filters = exclude_filters,
|
|
151 |
include_filters = include_filters)
|
|
152 |
zp.close()
|
|
153 |
|
|
154 |
zs = ZipStorage(export_zip,"r")
|
|
155 |
zp = api.Project(zs)
|
|
156 |
conf = zp.get_configuration('root5.confml')
|
|
157 |
rel = conf.get_layer().list_all_related()
|
|
158 |
|
|
159 |
exp = ['Layer1/implml/bitmask_test_12341002.crml',
|
|
160 |
'Layer1/implml/feature1_12341000.crml',
|
|
161 |
'Layer1/implml/feature1_12341001.crml',
|
|
162 |
'Layer1/implml/feature1_sequence.gcfml',
|
|
163 |
'Layer1/implml/feature2_ABCD0000.crml',
|
|
164 |
'Layer1/implml/time_types_test_12341003.crml',
|
|
165 |
'Layer5/content/content.txt',
|
|
166 |
'Layer5/content/folder/abc.txt']
|
|
167 |
|
|
168 |
zs.close()
|
|
169 |
self.assertEquals(exp,rel)
|
|
170 |
os.unlink(export_zip)
|
|
171 |
|
0
|
172 |
def test_export_from_files_to_zipstorage_add(self):
|
|
173 |
test_project_dir = os.path.join(temp_dir, "test_project_1")
|
|
174 |
unzip_file.unzip_file(test_cpf, test_project_dir, delete_if_exists=True)
|
|
175 |
|
|
176 |
export_zip = os.path.join(temp_dir, "configexport2.zip")
|
|
177 |
|
|
178 |
fs = FileStorage(test_project_dir)
|
|
179 |
p = api.Project(fs)
|
|
180 |
exportconf = p.get_configuration('root4.confml')
|
|
181 |
compareconf = p.get_configuration('root5.confml')
|
|
182 |
zs = ZipStorage(export_zip,"w")
|
|
183 |
zp = api.Project(zs)
|
|
184 |
conf_files = compareconf.list_resources()
|
|
185 |
files1 = ['.metadata']
|
|
186 |
files1.extend(conf_files)
|
|
187 |
p.export_configuration(exportconf,zs)
|
|
188 |
zp.close()
|
|
189 |
self.assertTrue(os.path.exists(export_zip))
|
|
190 |
|
|
191 |
#Re-opening in append mode for adding new layers.
|
|
192 |
zs = ZipStorage(export_zip,"a")
|
|
193 |
zp = api.Project(zs)
|
|
194 |
conf = p.get_configuration('Layer5/root.confml')
|
|
195 |
p.export_configuration(conf,zs)
|
|
196 |
zp.save()
|
|
197 |
zp.close()
|
|
198 |
|
|
199 |
zfile = zipfile.ZipFile(export_zip,"r")
|
|
200 |
files2 = zfile.namelist()
|
|
201 |
#Root file renaming.
|
|
202 |
files2[files2.index('root4.confml')] = 'root5.confml'
|
|
203 |
zfile.close()
|
|
204 |
files1.sort()
|
|
205 |
files2.sort()
|
|
206 |
|
|
207 |
for i in range(len(files1)):
|
|
208 |
self.assertEquals(files1[i],files2[i])
|
|
209 |
os.unlink(export_zip)
|
|
210 |
|
|
211 |
|
|
212 |
def test_export_from_zip_to_zipstorage_add(self):
|
|
213 |
export_zip = os.path.join(temp_dir, "configexport2.zip")
|
|
214 |
zs_source = ZipStorage(test_cpf,'r')
|
|
215 |
p = api.Project(zs_source)
|
|
216 |
exportconf = p.get_configuration('root4.confml')
|
|
217 |
compareconf = p.get_configuration('root5.confml')
|
|
218 |
|
|
219 |
zs_target = ZipStorage(export_zip,"w")
|
|
220 |
zp = api.Project(zs_target)
|
|
221 |
conf_files = compareconf.list_resources()
|
|
222 |
files1 = ['.metadata']
|
|
223 |
files1.extend(conf_files)
|
|
224 |
p.export_configuration(exportconf,zs_target)
|
|
225 |
zp.close()
|
|
226 |
self.assertTrue(os.path.exists(export_zip))
|
|
227 |
|
|
228 |
#Re-opening in append mode for adding new layers.
|
|
229 |
zs_target = ZipStorage(export_zip,"a")
|
|
230 |
zp = api.Project(zs_target)
|
|
231 |
conf = p.get_configuration('Layer5/root.confml')
|
|
232 |
p.export_configuration(conf,zs_target)
|
|
233 |
zp.save()
|
|
234 |
zp.close()
|
|
235 |
|
|
236 |
zfile = zipfile.ZipFile(export_zip,"r")
|
|
237 |
files2 = zfile.namelist()
|
|
238 |
#Root file renaming.
|
|
239 |
files2[files2.index('root4.confml')] = 'root5.confml'
|
|
240 |
zfile.close()
|
|
241 |
files1.sort()
|
|
242 |
files2.sort()
|
|
243 |
|
|
244 |
for i in range(len(files1)):
|
|
245 |
self.assertEquals(files1[i],files2[i])
|
|
246 |
os.unlink(export_zip)
|
|
247 |
|
|
248 |
|
|
249 |
def test_export_from_zipstorage(self):
|
|
250 |
output_dir = os.path.join(temp_dir, "export_from_zipstorage")
|
|
251 |
self.remove_if_exists(output_dir)
|
|
252 |
|
|
253 |
zs = ZipStorage(test_cpf,"r")
|
|
254 |
p = api.Project(zs)
|
|
255 |
fs = FileStorage(output_dir,"w")
|
|
256 |
r = api.Project(fs)
|
|
257 |
conf = p.get_configuration('root5.confml')
|
|
258 |
conf_files = conf.list_resources()
|
|
259 |
conf_files.append('.metadata')
|
|
260 |
p.export_configuration(conf,fs)
|
|
261 |
p.close()
|
|
262 |
r.close()
|
|
263 |
self.assertTrue(os.path.exists(output_dir))
|
|
264 |
|
|
265 |
|
3
|
266 |
def _test_export_to_filestorage_multiple_configurations(self):
|
0
|
267 |
fs = FileStorage(datafolder)
|
|
268 |
p = api.Project(fs)
|
3
|
269 |
fs2 = FileStorage(os.path.join(temp_dir,"multiple"),"w")
|
0
|
270 |
p2 = api.Project(fs2)
|
|
271 |
conf = p.get_configuration('morestuff.confml')
|
|
272 |
conf_files = conf.list_resources()
|
|
273 |
p.export_configuration(conf,fs2)
|
|
274 |
conf = p.get_configuration('prodX.confml')
|
|
275 |
conf_files.extend(conf.list_resources())
|
3
|
276 |
fs2.save()
|
0
|
277 |
p.export_configuration(conf,fs2)
|
|
278 |
p2.close()
|
|
279 |
self.assertTrue(os.path.exists("temp/exported"))
|
|
280 |
|
|
281 |
files = fs2.list_resources("/",True)
|
|
282 |
conf_files = utils.distinct_array(conf_files)
|
|
283 |
files.sort()
|
|
284 |
conf_files.append('.metadata')
|
|
285 |
conf_files.sort()
|
3
|
286 |
self.assertEquals(sorted(conf_files),sorted(files))
|
|
287 |
#shutil.rmtree("temp")
|
0
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
if __name__ == '__main__':
|
|
292 |
unittest.main()
|
|
293 |
|