|
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 try: |
|
25 from cElementTree import ElementTree |
|
26 except ImportError: |
|
27 try: |
|
28 from elementtree import ElementTree |
|
29 except ImportError: |
|
30 try: |
|
31 from xml.etree import cElementTree as ElementTree |
|
32 except ImportError: |
|
33 from xml.etree import ElementTree |
|
34 |
|
35 import __init__ |
|
36 from testautomation import unzip_file |
|
37 |
|
38 from cone.public import exceptions, utils, api |
|
39 from cone.storage.filestorage import FileStorage |
|
40 from cone.storage.zipstorage import ZipStorage |
|
41 |
|
42 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
43 temp_dir = os.path.join(ROOT_PATH, "temp/import") |
|
44 test_cpf = os.path.join(ROOT_PATH,"testdata/test_project.cpf") |
|
45 datafolder = os.path.join(ROOT_PATH,"../../storage/tests/data") |
|
46 |
|
47 |
|
48 class TestConeProjectImport(unittest.TestCase): |
|
49 def setUp(self): |
|
50 if not os.path.exists(temp_dir): |
|
51 os.makedirs(temp_dir) |
|
52 |
|
53 def test_import_to_zipstorage(self): |
|
54 test_project_dir = os.path.join(temp_dir, "test_project_1") |
|
55 unzip_file.unzip_file(test_cpf, test_project_dir, delete_if_exists=True) |
|
56 |
|
57 imported_zip = os.path.join(temp_dir, "imported1.zip") |
|
58 |
|
59 fs = FileStorage(test_project_dir) |
|
60 p = api.Project(fs) |
|
61 zs = ZipStorage(imported_zip,"w") |
|
62 zp = api.Project(zs) |
|
63 conf = p.get_configuration('root5.confml') |
|
64 conf_files = conf.list_resources() |
|
65 conf_files.append('.metadata') |
|
66 zp.import_configuration(conf) |
|
67 zp.close() |
|
68 p.close() |
|
69 self.assertTrue(os.path.exists(imported_zip)) |
|
70 zfile = zipfile.ZipFile(imported_zip,"r") |
|
71 files = zfile.namelist() |
|
72 conf_files.sort() |
|
73 files.sort() |
|
74 self.assertEquals(conf_files,files) |
|
75 zfile.close() |
|
76 os.unlink(imported_zip) |
|
77 |
|
78 def test_import_to_zipstorage_multiple_configurations(self): |
|
79 imported_zip = os.path.join(temp_dir, "imported2.zip") |
|
80 fs = FileStorage(datafolder) |
|
81 p = api.Project(fs) |
|
82 zs = ZipStorage(imported_zip,"w") |
|
83 zp = api.Project(zs) |
|
84 conf = p.get_configuration('morestuff.confml') |
|
85 conf_files = conf.list_resources() |
|
86 zp.import_configuration(conf) |
|
87 conf = p.get_configuration('prodX.confml') |
|
88 conf_files.extend(conf.list_resources()) |
|
89 zp.import_configuration(conf) |
|
90 zp.close() |
|
91 p.close() |
|
92 self.assertTrue(os.path.exists(imported_zip)) |
|
93 zfile = zipfile.ZipFile(imported_zip,"r") |
|
94 files = zfile.namelist() |
|
95 files.remove('.metadata') |
|
96 conf_files = utils.distinct_array(conf_files) |
|
97 conf_files.sort() |
|
98 files.sort() |
|
99 for i in range(len(conf_files)): |
|
100 self.assertEquals(conf_files[i], files[i]) |
|
101 zfile.close() |
|
102 os.unlink(imported_zip) |
|
103 |
|
104 def test_import_to_filestorage_multiple_configurations(self): |
|
105 fs = FileStorage(datafolder) |
|
106 p = api.Project(fs) |
|
107 fs2 = FileStorage("temp/imported","w") |
|
108 p2 = api.Project(fs2) |
|
109 conf = p.get_configuration('morestuff.confml') |
|
110 conf_files = conf.list_resources() |
|
111 p2.import_configuration(conf) |
|
112 conf = p.get_configuration('prodX.confml') |
|
113 conf_files.extend(conf.list_resources()) |
|
114 |
|
115 p2.import_configuration(conf) |
|
116 p2.close() |
|
117 self.assertTrue(os.path.exists("temp/imported")) |
|
118 files = fs2.list_resources("/",True) |
|
119 |
|
120 conf_files = utils.distinct_array(conf_files) |
|
121 conf_files.append('.metadata') |
|
122 files.sort() |
|
123 conf_files.sort() |
|
124 self.assertEquals(conf_files,files) |
|
125 shutil.rmtree("temp") |
|
126 |
|
127 def test_import_from_zipstorage_to_filestorage(self): |
|
128 imported_folder = os.path.join(temp_dir, 'imported1_folder') |
|
129 p = api.Project(api.Storage.open(test_cpf)) |
|
130 rp = api.Project(api.Storage.open(imported_folder,"w")) |
|
131 conf = p.get_configuration(p.get_storage().get_active_configuration()) |
|
132 conf_files = conf.list_resources() |
|
133 conf_files.append('.metadata') |
|
134 rp.import_configuration(conf) |
|
135 rp.close() |
|
136 p.close() |
|
137 self.assertTrue(os.path.exists(imported_folder)) |
|
138 store = api.Storage.open(imported_folder) |
|
139 files = store.list_resources('',True) |
|
140 conf_files.sort() |
|
141 files.sort() |
|
142 self.assertEquals(conf_files,files) |
|
143 shutil.rmtree(imported_folder) |
|
144 |
|
145 if __name__ == '__main__': |
|
146 unittest.main() |
|
147 |