19 """ |
19 """ |
20 import unittest |
20 import unittest |
21 import string |
21 import string |
22 import sys,os |
22 import sys,os |
23 |
23 |
24 import __init__ |
|
25 from cone.public import api, plugin |
24 from cone.public import api, plugin |
26 from cone.core import * |
25 from cone.core import * |
27 |
26 |
28 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
29 test_project = os.path.join(ROOT_PATH,"testdata/test_project.cpf") |
28 test_project = os.path.join(ROOT_PATH,"testdata/test_project.cpf") |
30 multiroot_project = os.path.join(ROOT_PATH,"testdata/multiroot_test.zip") |
29 multiroot_project = os.path.join(ROOT_PATH,"testdata/multiroot_test.zip") |
|
30 LAYERED_RES_PROJECT = os.path.join(ROOT_PATH,"testdata/layered_res_test.zip") |
|
31 |
31 |
32 |
32 class TestConfiguration(unittest.TestCase): |
33 class TestConfiguration(unittest.TestCase): |
33 def setUp(self): |
34 def setUp(self): |
34 pass |
35 pass |
35 |
36 |
36 # @test |
37 def test_layered_resources_invalid_resource_type(self): |
|
38 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
39 config = p.get_configuration('root.confml') |
|
40 self.assertRaises(ValueError, config.layered_resources, resource_type='foo') |
|
41 |
|
42 def test_layered_resource_invalid_params(self): |
|
43 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
44 config = p.get_configuration('root.confml') |
|
45 |
|
46 # Both folder and resource_type specified |
|
47 self.assertRaises(ValueError, config.layered_resources, folder='foo', resource_type='implml') |
|
48 |
|
49 # Neither folder nor resource_type specified |
|
50 self.assertRaises(ValueError, config.layered_resources, folder=None, resource_type=None) |
|
51 |
|
52 def test_layered_resources(self): |
|
53 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
54 config = p.get_configuration('root.confml') |
|
55 |
|
56 data = config.layered_resources(resource_type='confml').data |
|
57 self.assertEquals(data, {'test.confml': ['layer1/confml/test.confml', |
|
58 'layer2/confml/test.confml']}) |
|
59 |
|
60 data = config.layered_resources(resource_type='implml').data |
|
61 self.assertEquals(data, {'test.implml': ['layer1/implml/test.implml', |
|
62 'layer2/implml/test.implml']}) |
|
63 |
|
64 data = config.layered_resources(resource_type='content').data |
|
65 self.assertEquals(data, {'foo.txt': ['layer1/content/foo.txt', |
|
66 'layer2/content/foo.txt']}) |
|
67 |
|
68 data = config.layered_resources(resource_type='doc').data |
|
69 self.assertEquals(data, {'bar.txt': ['layer1/doc/bar.txt', |
|
70 'layer2/doc/bar.txt']}) |
|
71 |
|
72 def test_layered_resources_custom_folder(self): |
|
73 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
74 config = p.get_configuration('root.confml') |
|
75 |
|
76 data = config.layered_resources(folder='foo').data |
|
77 self.assertEquals(data, {'bar.txt': ['layer1/foo/bar.txt', |
|
78 'layer2/foo/bar.txt']}) |
|
79 |
|
80 def test_layered_resources_directly_from_layer(self): |
|
81 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
82 config = p.get_configuration('layer1/root.confml') |
|
83 |
|
84 self.assertEquals(config.layered_resources(resource_type='confml').data, |
|
85 {'test.confml': ['layer1/confml/test.confml']}) |
|
86 |
|
87 self.assertEquals(config.layered_resources(resource_type='implml').data, |
|
88 {'test.implml': ['layer1/implml/test.implml']}) |
|
89 |
|
90 def test_layered_resources_with_empty_folders(self): |
|
91 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
92 config = p.get_configuration('root.confml') |
|
93 |
|
94 data = config.layered_resources(empty_folders=True, resource_type='confml').data |
|
95 self.assertEquals(data, {'test.confml': ['layer1/confml/test.confml', |
|
96 'layer2/confml/test.confml'], |
|
97 'empty': ['layer1/confml/empty', |
|
98 'layer2/confml/empty']}) |
|
99 |
|
100 data = config.layered_resources(empty_folders=True, resource_type='implml').data |
|
101 self.assertEquals(data, {'test.implml': ['layer1/implml/test.implml', |
|
102 'layer2/implml/test.implml'], |
|
103 'empty': ['layer1/implml/empty', |
|
104 'layer2/implml/empty']}) |
|
105 |
|
106 data = config.layered_resources(empty_folders=True, resource_type='content').data |
|
107 self.assertEquals(data, {'foo.txt': ['layer1/content/foo.txt', |
|
108 'layer2/content/foo.txt'], |
|
109 'empty': ['layer1/content/empty', |
|
110 'layer2/content/empty']}) |
|
111 |
|
112 data = config.layered_resources(empty_folders=True, resource_type='doc').data |
|
113 self.assertEquals(data, {'bar.txt': ['layer1/doc/bar.txt', |
|
114 'layer2/doc/bar.txt'], |
|
115 'empty': ['layer1/doc/empty', |
|
116 'layer2/doc/empty']}) |
|
117 |
|
118 def test_layered_resources_specific_layers(self): |
|
119 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
120 config = p.get_configuration('root.confml') |
|
121 |
|
122 self.assertEquals(config.layered_resources(layers=[-1], resource_type='confml').data, |
|
123 {'test.confml': ['layer2/confml/test.confml']}) |
|
124 self.assertEquals(config.layered_resources(layers=[0], resource_type='confml').data, |
|
125 {'test.confml': ['layer1/confml/test.confml']}) |
|
126 |
|
127 def test_layered_resources_shortcuts(self): |
|
128 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
129 config = p.get_configuration('root.confml') |
|
130 |
|
131 data = config.layered_confml().data |
|
132 self.assertEquals(data, {'test.confml': ['layer1/confml/test.confml', |
|
133 'layer2/confml/test.confml']}) |
|
134 |
|
135 data = config.layered_implml().data |
|
136 self.assertEquals(data, {'test.implml': ['layer1/implml/test.implml', |
|
137 'layer2/implml/test.implml']}) |
|
138 |
|
139 data = config.layered_content().data |
|
140 self.assertEquals(data, {'foo.txt': ['layer1/content/foo.txt', |
|
141 'layer2/content/foo.txt']}) |
|
142 |
|
143 data = config.layered_doc().data |
|
144 self.assertEquals(data, {'bar.txt': ['layer1/doc/bar.txt', |
|
145 'layer2/doc/bar.txt']}) |
|
146 |
|
147 |
|
148 def test_implml_override(self): |
|
149 p = api.Project(api.Storage.open(LAYERED_RES_PROJECT)) |
|
150 config = p.get_configuration('root.confml') |
|
151 |
|
152 impl_set = plugin.get_impl_set(config) |
|
153 self.assertEquals([impl.ref for impl in impl_set], ['layer2/implml/test.implml']) |
|
154 |
|
155 impl_set = plugin.filtered_impl_set(config) |
|
156 self.assertEquals([impl.ref for impl in impl_set], ['layer2/implml/test.implml']) |
|
157 |
|
158 |
37 def test_create_configuration(self): |
159 def test_create_configuration(self): |
38 conf = api.Configuration("foobar/testmee.confml") |
160 conf = api.Configuration("foobar/testmee.confml") |
39 self.assertTrue(conf) |
161 self.assertTrue(conf) |
40 |
162 |
41 def test_get_root(self): |
163 def test_get_root(self): |