|
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 import unittest |
|
19 import string |
|
20 import sys |
|
21 import os |
|
22 import shutil |
|
23 import __init__ |
|
24 import datetime |
|
25 |
|
26 from cone.public import api, exceptions |
|
27 from cone.carbon import persistentjson, model |
|
28 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
29 |
|
30 class TestConfigurationResource(unittest.TestCase): |
|
31 def test_create(self): |
|
32 c = model.ConfigurationResource(configuration_name='test') |
|
33 self.assertTrue(c) |
|
34 self.assertEquals(c.name, 'test') |
|
35 |
|
36 def test_create_from_dict(self): |
|
37 confdict = {'parent_config': 'hessu', 'path': 'Testing', 'version_identifier': '0.1', 'configuration_name': 'Testing'} |
|
38 c = model.ConfigurationResource(**confdict) |
|
39 self.assertTrue(c) |
|
40 self.assertEquals(c.name, 'Testing') |
|
41 self.assertEquals(c.path, 'Testing') |
|
42 self.assertEquals(c.parent_config, 'hessu') |
|
43 self.assertEquals(c.version, '0.1') |
|
44 self.assertEquals(c.get_path(), 'Testing/root.confml') |
|
45 |
|
46 class TestFeatureListResource(unittest.TestCase): |
|
47 def test_create(self): |
|
48 c = model.FeatureListResource(path='test', list_id=1, list_version_id=1) |
|
49 self.assertTrue(c) |
|
50 self.assertEquals(c.path, 'test') |
|
51 self.assertEquals(c.list_id, 1) |
|
52 self.assertEquals(c.list_version_id, 1) |
|
53 |
|
54 def test_create_from_dict(self): |
|
55 fldict = { |
|
56 "list_version_id": 30, |
|
57 "expanded": True, |
|
58 "version_identifier": "working", |
|
59 "is_latest_version": True, |
|
60 "list_id": 33, |
|
61 "path": "ESTART", |
|
62 "version_title": "ESTART (working)", |
|
63 "can_be_released": True, |
|
64 "type": "featurelist", |
|
65 "has_external_relations": False |
|
66 } |
|
67 c = model.FeatureListResource(**fldict) |
|
68 self.assertTrue(c) |
|
69 self.assertEquals(c.list_version_id, 30) |
|
70 self.assertEquals(c.expanded, True) |
|
71 self.assertEquals(c.version_identifier, "working") |
|
72 self.assertEquals(c.is_latest_version, True) |
|
73 self.assertEquals(c.list_id, 33) |
|
74 self.assertEquals(c.path, 'ESTART') |
|
75 self.assertEquals(c.version_title, "ESTART (working)") |
|
76 self.assertEquals(c.can_be_released, True) |
|
77 self.assertEquals(c.type, "featurelist") |
|
78 self.assertEquals(c.has_external_relations, False) |
|
79 |
|
80 |
|
81 class TestCarbonConfiguration(unittest.TestCase): |
|
82 def test_create_carbon_configuration(self): |
|
83 config = model.CarbonConfiguration(path='foo/bar/test.confml', version_identifier='testing') |
|
84 self.assertEquals(config.version_identifier,'testing') |
|
85 self.assertEquals(config.path,'foo/bar/test.confml') |
|
86 self.assertEquals(config.ref,'foo__bar__test_confml') |
|
87 self.assertEquals(config.name,'test') |
|
88 |
|
89 config = model.CarbonConfiguration(ref='foo/bar/test.confml') |
|
90 self.assertEquals(config.path,'foo/bar/test.confml') |
|
91 self.assertEquals(config.ref,'foo__bar__test_confml') |
|
92 self.assertEquals(config.name,'test') |
|
93 |
|
94 def test_create_carbon_configuration_with_current_week_version(self): |
|
95 config = model.CarbonConfiguration(path='foo/bar/test.confml') |
|
96 dt = datetime.datetime.today() |
|
97 self.assertEquals(config.version_identifier,"%dwk%02d" % dt.isocalendar()[0:2]) |
|
98 |
|
99 class TestResourceList(unittest.TestCase): |
|
100 def test_create_resource_list(self): |
|
101 rl = model.ResourceList() |
|
102 self.assertTrue(rl != None) |
|
103 |
|
104 def test_add_resource(self): |
|
105 rl = model.ResourceList() |
|
106 c = model.ConfigurationResource(**{'parent_config': 'hessu', 'path': 'Testing', 'version_identifier': '0.1', 'configuration_name': 'Testing'}) |
|
107 rl.add_resource(c) |
|
108 |
|
109 def test_list_resources(self): |
|
110 rl = model.ResourceList() |
|
111 rl.add_resource(model.ConfigurationResource(**{'parent_config': 'hessu', 'path': 'Testing', 'version_identifier': '0.1', 'configuration_name': 'Testing'})) |
|
112 rl.add_resource(model.ConfigurationResource(**{'parent_config': 'hessu', 'path': 'Foobar', 'version_identifier': '0.1', 'configuration_name': 'Foobar'})) |
|
113 self.assertEquals(rl.list_resources(),['Testing/root.confml','Foobar/root.confml']) |
|
114 |
|
115 def test_iterate_resources(self): |
|
116 rl = model.ResourceList() |
|
117 rl.add_resource(model.ConfigurationResource(**{'parent_config': 'hessu', 'path': 'Testing', 'version_identifier': '0.1', 'configuration_name': 'Testing'})) |
|
118 rl.add_resource(model.ConfigurationResource(**{'parent_config': 'hessu', 'path': 'Foobar', 'version_identifier': '0.1', 'configuration_name': 'Foobar'})) |
|
119 for res in rl: |
|
120 self.assertTrue(isinstance(res,model.ConfigurationResource)) |
|
121 |
|
122 class TestFeatureList(unittest.TestCase): |
|
123 def test_create(self): |
|
124 c = model.FeatureList(name='test') |
|
125 self.assertTrue(c) |
|
126 self.assertEquals(c.name, 'test') |
|
127 self.assertEquals(c.meta.get('type'), 'featurelist') |
|
128 self.assertEquals(c.path, 'test.confml') |
|
129 |
|
130 def test_create_with_path(self): |
|
131 c = model.FeatureList(path='featurelists/test.confml') |
|
132 self.assertTrue(c) |
|
133 self.assertEquals(c.name, '') |
|
134 self.assertEquals(c.meta.get('type'), 'featurelist') |
|
135 self.assertEquals(c.path, 'featurelists/test.confml') |
|
136 self.assertEquals(c.version_identifier, 'WORKING') |
|
137 |
|
138 class TestFeature(unittest.TestCase): |
|
139 def test_create(self): |
|
140 c = model.CarbonFeature(ref='test') |
|
141 self.assertTrue(c) |
|
142 self.assertEquals(c.name, 'test') |
|
143 self.assertEquals(c.ref, 'test') |