configurationengine/source/cone/public/tests/unittest_project.py
author m2lahtel
Tue, 10 Aug 2010 14:29:28 +0300
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
permissions -rw-r--r--
ConE 1.2.11 release
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
# All rights reserved.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
# This component and the accompanying materials are made available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
# which accompanies this distribution, and is available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
# Initial Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
# Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
# Description: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
"""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
Test the CPF configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
"""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
import unittest
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
import string
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
import sys,os,shutil
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
from cone.public import *
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
from cone.storage import persistentdictionary
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
class TestProjectOpen(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
    def test_open_project(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
        p = api.Project(api.Storage(""))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
        self.assertTrue(p)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
    def test_open_project_of_non_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
        fs = ""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
        try:
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    37
            p = api.Project("")
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
            self.fail("Opening on top of non storage succeeds!!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
        except exceptions.StorageException:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
            self.assertTrue(True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
class TestProjectConfigurations(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
        self.prj = api.Project(api.Storage(""))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
    def test_create_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
        self.prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
        self.assertTrue(self.prj.test_confml)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
        self.assertEquals(self.prj.test_confml.get_path(),"test.confml")
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    50
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    51
    def test_create_configuration_already_existing(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    52
        self.prj.create_configuration("test.confml")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    53
        try:
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    54
            self.prj.create_configuration("test.confml")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    55
            self.fail("Succeeded to create already existing configuration")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    56
        except exceptions.AlreadyExists:
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    57
            pass
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    58
        try:
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    59
            self.prj.add_configuration(api.Configuration("test.confml"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    60
            self.fail("Succeeded to create already existing configuration")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    61
        except exceptions.AlreadyExists:
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    62
            pass
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    63
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    64
    def test_create_configuration_already_existing_with_overwrite(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    65
        self.prj.create_configuration("test.confml")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    66
        self.prj.create_configuration("test.confml", True)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    67
        self.prj.add_configuration(api.Configuration("test.confml"), True)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
    68
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
    def test_create_and_getconfiguration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
        self.prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
        self.assertEquals(self.prj.get_configuration("test.confml").get_path(), "test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
    def test_create_multi_and_list(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
        self.assertEquals(self.prj.list_configurations(), ["test1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
                                                           "test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
                                                           "test3.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
    def test_create_multi_and_list_with_filters(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    86
        self.prj.create_configuration("test4.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
        self.prj.create_configuration("foo1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
        self.prj.create_configuration("foo2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
        self.assertEquals(self.prj.list_configurations(r'test[24]\.confml'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
                          ["test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
                           "test4.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
        self.assertEquals(self.prj.list_configurations([r'test[24]\.confml', r'foo\d\.confml']),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
                          ["test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
                           "test4.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
                           "foo1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
                           "foo2.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    97
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
    def test_create_multi_and_remove_one(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    99
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   100
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   101
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   102
        self.prj.remove_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
        self.assertEquals(self.prj.list_configurations(), ["test1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   104
                                                           "test3.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   105
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   106
    def test_create_multi_and_remove_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   107
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   108
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   109
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   110
        for c in self.prj.list_configurations():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   111
            self.prj.remove_configuration(c)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   112
        self.assertEquals(self.prj.list_configurations(), [])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   113
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   114
    def test_create_multi_and_add_subconfigurations(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   115
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   116
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   117
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   118
        self.prj.test2_confml.create_configuration("foo/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   119
        conf = self.prj.test2_confml.create_configuration("fii/root.confml")
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   120
        conf.add_configuration(api.Configuration("confml/data.confml"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   121
        self.assertEquals(conf.get_full_path(),'fii/root.confml')
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   122
        self.assertEquals(conf.get_configuration("confml/data.confml").get_path(),'confml/data.confml')
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   123
        self.assertEquals(conf.get_configuration("confml/data.confml").get_full_path(),'fii/confml/data.confml')
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   124
        self.assertTrue(self.prj.is_configuration("test3.confml"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   125
        # TODO: this is not working at the moment due to performance problem in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   126
        # Project.list_all_configurations()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   127
        # self.assertTrue(self.prj.is_configuration("fii/root.confml"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   128
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   129
        self.assertEquals(self.prj.list_configurations(), ["test1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   130
                                                           "test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   131
                                                           "test3.confml"])
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   132
        self.assertEquals(self.prj.list_all_configurations(), ['test1.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   133
                                                               'test2.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   134
                                                               'foo/root.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   135
                                                               'fii/root.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   136
                                                               'fii/confml/data.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   137
                                                               'test3.confml'])
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   138
        self.assertEquals(self.prj.test2_confml.list_configurations(), ["foo/root.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   139
                                                                 "fii/root.confml",])
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   140
        self.assertEquals(self.prj.test2_confml.list_all_configurations(), ["foo/root.confml",
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   141
                                                                            "fii/root.confml",
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   142
                                                                            "fii/confml/data.confml"])
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   143
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   144
    def test_create_multi_and_add_subconfigurations_and_features(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   145
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   146
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   147
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   148
        self.prj.test2_confml.create_configuration("foo/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   149
        self.prj.test2_confml.create_configuration("fii/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   150
        self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   151
        self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   152
        self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea11"),"testfea1")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   153
        self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea3"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   154
        self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea4"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   155
        self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea31"),"testfea3")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   156
        self.assertEquals(self.prj.test2_confml.list_all_features(), ['testfea1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   157
                                                           'testfea1.testfea11',  
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   158
                                                           'testfea2', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   159
                                                           'testfea3', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   160
                                                           'testfea3.testfea31', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   161
                                                           'testfea4'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   162
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   163
class TestProjectConfigurationsStorage(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   164
    def test_create_configuration_and_store_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   165
        prj = api.Project(api.Storage.open("temp/testproject.pk", "w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   166
        prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   167
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   168
        self.assertTrue(os.path.exists("temp/testproject.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   169
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   170
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   171
    def test_create_configuration_and_store_storage_and_open(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   172
        prj = api.Project(api.Storage.open("temp/testproject1.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   173
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   174
        config.desc = "Descriptions"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   175
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   176
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   177
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   178
        prj2 = api.Project(api.Storage.open("temp/testproject1.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   179
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   180
        self.assertEquals(prj2.test_confml.desc, "Descriptions")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   181
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   182
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   183
    def test_create_configuration_hierarchy_and_store_storage_and_open(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   184
        prj = api.Project(api.Storage.open("temp/testproject2.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   185
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   186
        config.desc = "Descriptions"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   187
        prj.test_confml.create_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   188
        prj.test_confml.s60__root_confml.add_feature(api.Feature("feature1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   189
        prj.test_confml.create_configuration("ncp/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   190
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   191
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   192
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   193
        prj2 = api.Project(api.Storage.open("temp/testproject2.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   194
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   195
        self.assertEquals(prj2.test_confml.desc, "Descriptions")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   196
        self.assertEquals(prj2.test_confml.list_all_features(),['feature1'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   197
        prj2.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   198
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   199
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   200
    def test_dump_configuration_with_include(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   201
        prj = api.Project(api.Storage.open("temp/testprojectinc.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   202
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   203
        config.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   204
        dumped = persistentdictionary.DictWriter().dumps(config)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   205
        children = dumped['Configuration']['children']
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   206
        self.assertEquals(children,[{'ConfigurationProxy': {'dict': {'path': 'foo/foo.confml'}}}])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   207
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   208
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   209
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   210
    def test_create_configuration_project_with_includes_and_reopen_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   211
        prj = api.Project(api.Storage.open("temp/testprojectinc2.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   212
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   213
        config.desc = "Descriptions"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   214
        config2 = config.create_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   215
        config2.add_feature(api.Feature("feature1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   216
        config2.save()        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   217
        config2.close()        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   218
        prj.test_confml.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   219
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   220
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   221
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   222
        prj2 = api.Project(api.Storage.open("temp/testprojectinc2.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   223
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   224
        self.assertEquals(prj2.test_confml.list_configurations(), ['foo/foo.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   225
        foo = prj2.test_confml.get_configuration('foo/foo.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   226
        self.assertEquals(prj2.get_configuration('test.confml').list_all_features(), ['feature1'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   227
        self.assertEquals(prj2.test_confml.get_default_view().list_features(), ['feature1'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   228
        prj2.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   229
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   230
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   231
    def test_create_configuration_project_with_multiincludes_and_reopen_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   232
        prj = api.Project(api.Storage.open("temp/testprojectinc3.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   233
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   234
        prj.add_configuration(api.Configuration("s60/root.confml", namespace="com.nokia.s60"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   235
        prj.create_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   236
        prj.test_confml.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   237
        prj.test_confml.include_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   238
        foofea = api.Feature("foofea")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   239
        foofea.add_feature(api.Feature("foofea_setting1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   240
        foofea.add_feature(api.Feature("foofea_setting2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   241
        prj.test_confml.foo__foo_confml.add_feature(foofea)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   242
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   243
        s60fea = api.Feature("s60fea")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   244
        s60fea.add_feature(api.Feature("wlanset1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   245
        s60fea.add_feature(api.Feature("wlan_set2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   246
        prj.test_confml.s60__root_confml.add_feature(s60fea)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   247
        dview = prj.test_confml.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   248
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   249
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   250
        prj2 = api.Project(api.Storage.open("temp/testprojectinc3.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   251
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   252
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   253
        dview2 = prj2.test_confml.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   254
        self.assertEquals(dview.list_all_features(),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   255
                          dview2.list_all_features())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   256
        testconf = prj2.get_configuration('test.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   257
        my_view = testconf.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   258
        my_view.com.nokia.s60.s60fea.wlanset1.data = 1
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   259
        prj2.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   260
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   261
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   262
    def test_create_configuration_project_with_multiincludes_and_test_layer_actions(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   263
        prj = api.Project(api.Storage.open("temp/testprojectlayers.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   264
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   265
        prj.add_configuration(api.Configuration("s60/root.confml", namespace="com.nokia.s60"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   266
        prj.create_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   267
        prj.create_configuration("foo/confml/component.confml").close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   268
        prj.test_confml.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   269
        prj.test_confml.include_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   270
        prj.test_confml.foo__foo_confml.create_configuration("data.confml")
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   271
        prj.test_confml.foo__foo_confml.add_configuration(api.Configuration("confml/test.confml"))
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   272
        foofea = api.Feature("foofea")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   273
        foofea.add_feature(api.Feature("foofea_setting1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   274
        foofea.add_feature(api.Feature("foofea_setting2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   275
        prj.test_confml.foo__foo_confml.add_feature(foofea)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   276
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   277
        foo_config = prj.test_confml.get_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   278
        layer = foo_config.get_layer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   279
        res = layer.open_resource("confml/component1.confml","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   280
        res.write("foo.conf")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   281
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   282
        res = layer.content_folder().open_resource("foobar.txt","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   283
        res.write("foo bar")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   284
        res.close()
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   285
        self.assertEquals(layer.list_confml(), ['confml/component.confml', 'confml/component1.confml', 'confml/test.confml'])
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   286
        self.assertEquals(layer.list_content(), ['content/foobar.txt'])
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   287
        self.assertEquals(layer.list_all_resources(), ['confml/component.confml', 'confml/component1.confml', 'confml/test.confml', 'content/foobar.txt'])
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   288
        self.assertEquals(foo_config.list_resources(), ['foo/foo.confml',
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   289
                                                        'foo/data.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   290
                                                        'foo/confml/test.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   291
                                                        'foo/confml/component.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   292
                                                        'foo/confml/component1.confml', 
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   293
                                                        'foo/content/foobar.txt'])
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   294
        self.assertEquals(prj.test_confml.list_resources(), ['test.confml',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   295
                                                      'foo/foo.confml',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   296
                                                      'foo/data.confml',
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   297
                                                      'foo/confml/test.confml',
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   298
                                                      's60/root.confml',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   299
                                                      'foo/confml/component.confml', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   300
                                                      'foo/confml/component1.confml', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   301
                                                      'foo/content/foobar.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   302
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   303
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   304
        s60_config = prj.test_confml.get_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   305
        layer = s60_config.get_layer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   306
        res = layer.open_resource("confml/component1.confml","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   307
        res.write("foo.conf")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   308
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   309
        res = layer.content_folder().open_resource("s60.txt","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   310
        res.write("foo bar")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   311
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   312
        res = layer.content_folder().open_resource("foobar.txt","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   313
        res.write("foo bar")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   314
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   315
        self.assertEquals(layer.list_confml(), ['confml/component1.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   316
        self.assertEquals(layer.list_content(), ['content/foobar.txt', 'content/s60.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   317
        self.assertEquals(prj.test_confml.layered_content().list_keys(), ['foobar.txt', 's60.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   318
        self.assertEquals(prj.test_confml.layered_content().get_values('foobar.txt'), ['foo/content/foobar.txt', 's60/content/foobar.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   319
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   320
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   321
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   322
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   323
if __name__ == '__main__':
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   324
    unittest.main()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   325