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,os, shutil
|
|
23 |
import __init__
|
|
24 |
|
|
25 |
from cone.public import api,exceptions,utils
|
|
26 |
from cone.storage import filestorage
|
|
27 |
|
|
28 |
class TestLayer(unittest.TestCase):
|
|
29 |
storage_class = filestorage.FileStorage
|
|
30 |
|
|
31 |
def test_create_layer(self):
|
|
32 |
store = self.storage_class("temp/layertest","w")
|
|
33 |
layer = api.Layer(store, "foo")
|
|
34 |
self.assertTrue(layer)
|
|
35 |
shutil.rmtree("temp/layertest")
|
|
36 |
|
|
37 |
# def test_create_layer_with_kwargs(self):
|
|
38 |
# store = self.storage_class("temp/layertest","w")
|
|
39 |
# layer = api.Layer(store, "foo",confml_path="foobar", implml_path="")
|
|
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 |
|
|
55 |
def test_get_path(self):
|
|
56 |
store = self.storage_class("temp/layertest","w")
|
|
57 |
layer = api.Layer(store, "foo")
|
|
58 |
self.assertTrue(layer)
|
|
59 |
self.assertEquals(layer.get_current_path(),"foo")
|
|
60 |
shutil.rmtree("temp/layertest")
|
|
61 |
|
|
62 |
def test_open_resource(self):
|
|
63 |
store = self.storage_class("temp/layertest","w")
|
|
64 |
layer = api.Layer(store, "foo")
|
|
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 |
|
|
73 |
def test_create_two_layers_and_open_resource(self):
|
|
74 |
store = self.storage_class("temp/layertest","w")
|
|
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 |
|
|
92 |
def test_list_confml(self):
|
|
93 |
store = self.storage_class("temp/layertest","w")
|
|
94 |
layer = api.Layer(store, "foo")
|
|
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 |
|
|
107 |
def test_list_implml(self):
|
|
108 |
store = self.storage_class("temp/layertest","w")
|
|
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 |
|
|
122 |
def test_list_content(self):
|
|
123 |
store = self.storage_class("temp/layertest","w")
|
|
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 |
|
|
137 |
def test_list_doc(self):
|
|
138 |
store = self.storage_class("temp/layertest","w")
|
|
139 |
layer = api.Layer(store, "foo")
|
|
140 |
res = layer.open_resource("doc/bar/test.txt","w")
|
|
141 |
res.write("foo.conf")
|
|
142 |
res.close()
|
|
143 |
res = layer.open_resource("doc/foo.confml","w")
|
|
144 |
res.write("foo.conf")
|
|
145 |
res.close()
|
|
146 |
res = layer.open_resource("root.confml","w")
|
|
147 |
res.write("foo.conf")
|
|
148 |
res.close()
|
|
149 |
self.assertEquals(layer.list_doc(),['doc/foo.confml', 'doc/bar/test.txt'])
|
|
150 |
shutil.rmtree("temp/layertest")
|
|
151 |
|
|
152 |
if __name__ == '__main__':
|
|
153 |
unittest.main()
|
|
154 |
|