16 |
16 |
17 """ |
17 """ |
18 Test the configuration |
18 Test the configuration |
19 """ |
19 """ |
20 import unittest |
20 import unittest |
21 import string |
21 import os |
22 import sys,os, shutil |
|
23 import __init__ |
|
24 |
22 |
25 from cone.public import api,exceptions,utils |
23 from cone.storage import filestorage, zipstorage |
26 from cone.storage import filestorage |
24 from cone.public.tests import unittest_layer |
|
25 from testautomation.utils import remove_if_exists |
27 |
26 |
28 class TestLayer(unittest.TestCase): |
27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
29 storage_class = filestorage.FileStorage |
28 LAYER_TMP_FOLDER = os.path.join(ROOT_PATH, "temp/layertest") |
|
29 LAYER_TMP_ZIP = os.path.join(ROOT_PATH, "temp/layertest.zip") |
30 |
30 |
31 def test_create_layer(self): |
31 ########################################################################## |
32 store = self.storage_class("temp/layertest","w") |
32 # FileStorage tests for folder and layer actions |
33 layer = api.Layer(store, "foo") |
|
34 self.assertTrue(layer) |
|
35 shutil.rmtree("temp/layertest") |
|
36 |
33 |
37 # def test_create_layer_with_kwargs(self): |
34 class TestFolderOnFileStorage(unittest_layer.TestFolder): |
38 # store = self.storage_class("temp/layertest","w") |
35 def setUp(self): |
39 # layer = api.Layer(store, "foo",confml_path="foobar", implml_path="") |
36 self.store = filestorage.FileStorage(LAYER_TMP_FOLDER,"w") |
40 # self.assertTrue(layer) |
|
41 # self.assertEquals(layer.confml_folder.get_current_path(),"foo/foobar") |
|
42 # self.assertEquals(layer.implml_folder.get_current_path(),"foo") |
|
43 # layer = api.Layer(store, "foo",confml_path="f", implml_path="test", content_path="data", doc_path="foo") |
|
44 # self.assertEquals(layer.confml_folder.get_current_path(),"foo/f") |
|
45 # self.assertEquals(layer.implml_folder.get_current_path(),"foo/test") |
|
46 # self.assertEquals(layer.content_folder.get_current_path(),"foo/data") |
|
47 # self.assertEquals(layer.doc_folder.get_current_path(),"foo/foo") |
|
48 # layer = api.Layer(store, "foo") |
|
49 # self.assertEquals(layer.confml_folder.get_current_path(),"foo/confml") |
|
50 # self.assertEquals(layer.implml_folder.get_current_path(),"foo/implml") |
|
51 # self.assertEquals(layer.content_folder.get_current_path(),"foo/content") |
|
52 # self.assertEquals(layer.doc_folder.get_current_path(),"foo/doc") |
|
53 # shutil.rmtree("temp/layertest") |
|
54 |
37 |
55 def test_get_path(self): |
38 def tearDown(self): |
56 store = self.storage_class("temp/layertest","w") |
39 remove_if_exists(LAYER_TMP_FOLDER) |
57 layer = api.Layer(store, "foo") |
|
58 self.assertTrue(layer) |
|
59 self.assertEquals(layer.get_current_path(),"foo") |
|
60 shutil.rmtree("temp/layertest") |
|
61 |
40 |
62 def test_open_resource(self): |
41 class TestLayerOnFileStorage(unittest_layer.TestLayer): |
63 store = self.storage_class("temp/layertest","w") |
42 def setUp(self): |
64 layer = api.Layer(store, "foo") |
43 self.store = filestorage.FileStorage(LAYER_TMP_FOLDER,"w") |
65 self.assertTrue(layer) |
|
66 res = layer.open_resource("confml/test.confml","w") |
|
67 res.write("foo.conf") |
|
68 res.close() |
|
69 self.assertEquals(layer.list_resources("", True),["confml/test.confml"]) |
|
70 self.assertEquals(store.list_resources("", True),["foo/confml/test.confml"]) |
|
71 shutil.rmtree("temp/layertest") |
|
72 |
44 |
73 def test_create_two_layers_and_open_resource(self): |
45 def tearDown(self): |
74 store = self.storage_class("temp/layertest","w") |
46 remove_if_exists(LAYER_TMP_FOLDER) |
75 foo_layer = api.Layer(store, "foo") |
|
76 bar_layer = api.Layer(store, "bar") |
|
77 res = foo_layer.open_resource("confml/test.confml","w") |
|
78 res.write("foo.conf") |
|
79 res.close() |
|
80 res = foo_layer.open_resource("root.confml","w") |
|
81 res.close() |
|
82 res = bar_layer.open_resource("confml/root.confml","w") |
|
83 res.write("foo.conf") |
|
84 res.close() |
|
85 self.assertEquals(foo_layer.list_resources("", True),['root.confml', 'confml/test.confml']) |
|
86 self.assertEquals(store.list_resources("", True),['bar/confml/root.confml','foo/root.confml','foo/confml/test.confml']) |
|
87 foo_layer.delete_resource("confml/test.confml") |
|
88 self.assertEquals(foo_layer.list_resources("", True),["root.confml"]) |
|
89 self.assertEquals(store.list_resources("", True),["bar/confml/root.confml","foo/root.confml"]) |
|
90 shutil.rmtree("temp/layertest") |
|
91 |
47 |
92 def test_list_confml(self): |
48 class TestCompositeLayerOnFileStorage(unittest_layer.TestCompositeLayer): |
93 store = self.storage_class("temp/layertest","w") |
49 def setUp(self): |
94 layer = api.Layer(store, "foo") |
50 self.store = filestorage.FileStorage(LAYER_TMP_FOLDER,"w") |
95 res = layer.open_resource("confml/test.confml","w") |
|
96 res.write("foo.conf") |
|
97 res.close() |
|
98 res = layer.open_resource("confml/foo.confml","w") |
|
99 res.write("foo.conf") |
|
100 res.close() |
|
101 res = layer.open_resource("root.confml","w") |
|
102 res.write("foo.conf") |
|
103 res.close() |
|
104 self.assertEquals(layer.list_confml(),['confml/foo.confml', 'confml/test.confml']) |
|
105 shutil.rmtree("temp/layertest") |
|
106 |
51 |
107 def test_list_implml(self): |
52 def tearDown(self): |
108 store = self.storage_class("temp/layertest","w") |
53 remove_if_exists(LAYER_TMP_FOLDER) |
109 layer = api.Layer(store, "foo") |
|
110 res = layer.open_resource("implml/stuff/test.confml","w") |
|
111 res.write("foo.conf") |
|
112 res.close() |
|
113 res = layer.open_resource("confml/foo.confml","w") |
|
114 res.write("foo.conf") |
|
115 res.close() |
|
116 res = layer.open_resource("root.confml","w") |
|
117 res.write("foo.conf") |
|
118 res.close() |
|
119 self.assertEquals(layer.list_implml(),['implml/stuff/test.confml']) |
|
120 shutil.rmtree("temp/layertest") |
|
121 |
54 |
122 def test_list_content(self): |
55 ########################################################################## |
123 store = self.storage_class("temp/layertest","w") |
56 # ZipStorage |
124 layer = api.Layer(store, "foo") |
|
125 res = layer.open_resource("content/bar/test.txt","w") |
|
126 res.write("foo.conf") |
|
127 res.close() |
|
128 res = layer.open_resource("content/foo.confml","w") |
|
129 res.write("foo.conf") |
|
130 res.close() |
|
131 res = layer.open_resource("root.confml","w") |
|
132 res.write("foo.conf") |
|
133 res.close() |
|
134 self.assertEquals(layer.list_content(),['content/foo.confml', 'content/bar/test.txt']) |
|
135 shutil.rmtree("temp/layertest") |
|
136 |
57 |
137 def test_list_doc(self): |
58 |
138 store = self.storage_class("temp/layertest","w") |
59 #class TestFolderOnZipStorage(unittest_layer.TestFolder): |
139 layer = api.Layer(store, "foo") |
60 # def setUp(self): |
140 res = layer.open_resource("doc/bar/test.txt","w") |
61 # self.store = zipstorage.ZipStorage(LAYER_TMP_ZIP,"w") |
141 res.write("foo.conf") |
62 # |
142 res.close() |
63 # def tearDown(self): |
143 res = layer.open_resource("doc/foo.confml","w") |
64 # self.store.close() |
144 res.write("foo.conf") |
65 # remove_if_exists(LAYER_TMP_ZIP) |
145 res.close() |
66 # |
146 res = layer.open_resource("root.confml","w") |
67 #class TestLayerOnZipStorage(unittest_layer.TestLayer): |
147 res.write("foo.conf") |
68 # def setUp(self): |
148 res.close() |
69 # self.store = zipstorage.ZipStorage(LAYER_TMP_ZIP,"w") |
149 self.assertEquals(layer.list_doc(),['doc/foo.confml', 'doc/bar/test.txt']) |
70 # |
150 shutil.rmtree("temp/layertest") |
71 # def tearDown(self): |
|
72 # self.store.close() |
|
73 # remove_if_exists(LAYER_TMP_ZIP) |
|
74 # |
|
75 #class TestCompositeLayerOnZipStorage(unittest_layer.TestCompositeLayer): |
|
76 # def setUp(self): |
|
77 # self.store = zipstorage.ZipStorage(LAYER_TMP_ZIP,"w") |
|
78 # |
|
79 # def tearDown(self): |
|
80 # self.store.close() |
|
81 # remove_if_exists(LAYER_TMP_ZIP) |
|
82 |
151 |
83 |
152 if __name__ == '__main__': |
84 if __name__ == '__main__': |
153 unittest.main() |
85 unittest.main() |
154 |
86 |