configurationengine/source/cone/public/tests/unittest_project.py
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
permissions -rw-r--r--
Adding EPL version of configurationengine.
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
import __init__
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
from cone.public import *
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
#from cone.public import stringstorage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
from cone.storage import persistentdictionary
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
class TestProjectOpen(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
    def test_open_project(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
        p = api.Project(api.Storage(""))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
        self.assertTrue(p)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
    def test_open_project_of_non_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
        fs = ""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
            p = api.Project(fs)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
            self.fail("Opening on top of non storage succeeds!!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
        except exceptions.StorageException:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
            self.assertTrue(True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
class TestProjectConfigurations(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
        self.prj = api.Project(api.Storage(""))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
    def test_create_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
        self.prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        self.assertTrue(self.prj.test_confml)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
        self.assertEquals(self.prj.test_confml.get_path(),"test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
    def test_create_and_getconfiguration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        self.prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
        self.assertEquals(self.prj.get_configuration("test.confml").get_path(), "test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
    def test_create_multi_and_list(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
        self.assertEquals(self.prj.list_configurations(), ["test1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
                                                           "test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
                                                           "test3.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
    def test_create_multi_and_list_with_filters(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
        self.prj.create_configuration("test4.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
        self.prj.create_configuration("foo1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
        self.prj.create_configuration("foo2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
        self.assertEquals(self.prj.list_configurations(r'test[24]\.confml'),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
                          ["test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
                           "test4.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
        self.assertEquals(self.prj.list_configurations([r'test[24]\.confml', r'foo\d\.confml']),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
                          ["test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
                           "test4.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
                           "foo1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
                           "foo2.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_remove_one(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.remove_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
        self.assertEquals(self.prj.list_configurations(), ["test1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
                                                           "test3.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
    def test_create_multi_and_remove_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
        for c in self.prj.list_configurations():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
            self.prj.remove_configuration(c)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
        self.assertEquals(self.prj.list_configurations(), [])
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_add_subconfigurations(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.test2_confml.create_configuration("foo/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
        conf = self.prj.test2_confml.create_configuration("fii/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   104
        #self.assertEquals(conf.get_full_path(),'')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   105
        self.assertTrue(self.prj.is_configuration("test3.confml"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   106
        # TODO: this is not working at the moment due to performance problem in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   107
        # Project.list_all_configurations()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   108
        # self.assertTrue(self.prj.is_configuration("fii/root.confml"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   109
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   110
        self.assertEquals(self.prj.list_configurations(), ["test1.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   111
                                                           "test2.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   112
                                                           "test3.confml"])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   113
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   114
        self.assertEquals(self.prj.test2_confml.list_configurations(), ["foo/root.confml",
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   115
                                                                 "fii/root.confml",])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   116
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   117
    def test_create_multi_and_add_subconfigurations_and_features(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   118
        self.prj.create_configuration("test1.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   119
        self.prj.create_configuration("test2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   120
        self.prj.create_configuration("test3.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   121
        self.prj.test2_confml.create_configuration("foo/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   122
        self.prj.test2_confml.create_configuration("fii/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   123
        self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   124
        self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   125
        self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea11"),"testfea1")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   126
        self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea3"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   127
        self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea4"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   128
        self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea31"),"testfea3")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   129
        self.assertEquals(self.prj.test2_confml.list_all_features(), ['testfea1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   130
                                                           'testfea1.testfea11',  
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   131
                                                           'testfea2', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   132
                                                           'testfea3', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   133
                                                           'testfea3.testfea31', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   134
                                                           'testfea4'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   135
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   136
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   137
class TestProjectConfigurationsStorage(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   138
    def test_create_configuration_and_store_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   139
        prj = api.Project(api.Storage.open("temp/testproject.pk", "w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   140
        prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   141
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   142
        self.assertTrue(os.path.exists("temp/testproject.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   143
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   144
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   145
    def test_create_configuration_and_store_storage_and_open(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   146
        prj = api.Project(api.Storage.open("temp/testproject1.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   147
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   148
        config.desc = "Descriptions"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   149
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   150
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   151
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   152
        prj2 = api.Project(api.Storage.open("temp/testproject1.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   153
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   154
        self.assertEquals(prj2.test_confml.desc, "Descriptions")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   155
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   156
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   157
    def test_create_configuration_hierarchy_and_store_storage_and_open(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   158
        prj = api.Project(api.Storage.open("temp/testproject2.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   159
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   160
        config.desc = "Descriptions"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   161
        prj.test_confml.create_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   162
        prj.test_confml.s60__root_confml.add_feature(api.Feature("feature1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   163
        prj.test_confml.create_configuration("ncp/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   164
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   165
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   166
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   167
        prj2 = api.Project(api.Storage.open("temp/testproject2.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   168
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   169
        self.assertEquals(prj2.test_confml.desc, "Descriptions")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   170
        self.assertEquals(prj2.test_confml.list_all_features(),['feature1'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   171
        prj2.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   172
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   173
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   174
    def test_dump_configuration_with_include(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   175
        prj = api.Project(api.Storage.open("temp/testprojectinc.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   176
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   177
        config.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   178
        dumped = persistentdictionary.DictWriter().dumps(config)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   179
        children = dumped['Configuration']['children']
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   180
        self.assertEquals(children,[{'ConfigurationProxy': {'dict': {'path': 'foo/foo.confml'}}}])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   181
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   182
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   183
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   184
    def test_create_configuration_project_with_includes_and_reopen_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   185
        prj = api.Project(api.Storage.open("temp/testprojectinc2.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   186
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   187
        config.desc = "Descriptions"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   188
        config2 = config.create_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   189
        config2.add_feature(api.Feature("feature1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   190
        config2.save()        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   191
        config2.close()        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   192
        prj.test_confml.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   193
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   194
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   195
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   196
        prj2 = api.Project(api.Storage.open("temp/testprojectinc2.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   197
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   198
        self.assertEquals(prj2.test_confml.list_configurations(), ['foo/foo.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   199
        foo = prj2.test_confml.get_configuration('foo/foo.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   200
        self.assertEquals(prj2.get_configuration('test.confml').list_all_features(), ['feature1'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   201
        self.assertEquals(prj2.test_confml.get_default_view().list_features(), ['feature1'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   202
        prj2.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   203
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   204
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   205
    def test_create_configuration_project_with_multiincludes_and_reopen_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   206
        prj = api.Project(api.Storage.open("temp/testprojectinc3.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   207
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   208
        prj.add_configuration(api.Configuration("s60/root.confml", namespace="com.nokia.s60"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   209
        prj.create_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   210
        prj.test_confml.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   211
        prj.test_confml.include_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   212
        foofea = api.Feature("foofea")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   213
        foofea.add_feature(api.Feature("foofea_setting1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   214
        foofea.add_feature(api.Feature("foofea_setting2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   215
        prj.test_confml.foo__foo_confml.add_feature(foofea)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   216
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   217
        s60fea = api.Feature("s60fea")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   218
        s60fea.add_feature(api.Feature("wlanset1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   219
        s60fea.add_feature(api.Feature("wlan_set2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   220
        prj.test_confml.s60__root_confml.add_feature(s60fea)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   221
        dview = prj.test_confml.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   222
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   223
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   224
        prj2 = api.Project(api.Storage.open("temp/testprojectinc3.pk"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   225
        self.assertEquals(prj2.list_configurations(), ['test.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   226
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   227
        dview2 = prj2.test_confml.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   228
        self.assertEquals(dview.list_all_features(),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   229
                          dview2.list_all_features())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   230
        testconf = prj2.get_configuration('test.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   231
        my_view = testconf.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   232
        my_view.com.nokia.s60.s60fea.wlanset1.data = 1
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   233
        prj2.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   234
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   235
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   236
    def test_create_configuration_project_with_multiincludes_and_test_layer_actions(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   237
        prj = api.Project(api.Storage.open("temp/testprojectlayers.pk","w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   238
        config = prj.create_configuration("test.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   239
        prj.add_configuration(api.Configuration("s60/root.confml", namespace="com.nokia.s60"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   240
        prj.create_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   241
        prj.create_configuration("foo/confml/component.confml").close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   242
        prj.test_confml.include_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   243
        prj.test_confml.include_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   244
        prj.test_confml.foo__foo_confml.create_configuration("data.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   245
        foofea = api.Feature("foofea")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   246
        foofea.add_feature(api.Feature("foofea_setting1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   247
        foofea.add_feature(api.Feature("foofea_setting2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   248
        prj.test_confml.foo__foo_confml.add_feature(foofea)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   249
        prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   250
        foo_config = prj.test_confml.get_configuration("foo/foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   251
        layer = foo_config.get_layer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   252
        res = layer.open_resource("confml/component1.confml","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   253
        res.write("foo.conf")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   254
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   255
        res = layer.content_folder().open_resource("foobar.txt","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   256
        res.write("foo bar")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   257
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   258
        self.assertEquals(layer.list_confml(), ['confml/component.confml', 'confml/component1.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   259
        self.assertEquals(layer.list_content(), ['content/foobar.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   260
        self.assertEquals(layer.list_all_resources(), ['confml/component.confml', 'confml/component1.confml', 'content/foobar.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   261
        self.assertEquals(foo_config.list_resources(), ['foo/foo.confml','foo/data.confml', 'foo/confml/component.confml', 'foo/confml/component1.confml', 'foo/content/foobar.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   262
        self.assertEquals(prj.test_confml.list_resources(), ['test.confml',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   263
                                                      'foo/foo.confml',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   264
                                                      'foo/data.confml',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   265
                                                      's60/root.confml',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   266
                                                      'foo/confml/component.confml', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   267
                                                      'foo/confml/component1.confml', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   268
                                                      'foo/content/foobar.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   269
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   270
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   271
        s60_config = prj.test_confml.get_configuration("s60/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   272
        layer = s60_config.get_layer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   273
        res = layer.open_resource("confml/component1.confml","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   274
        res.write("foo.conf")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   275
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   276
        res = layer.content_folder().open_resource("s60.txt","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   277
        res.write("foo bar")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   278
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   279
        res = layer.content_folder().open_resource("foobar.txt","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   280
        res.write("foo bar")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   281
        res.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   282
        self.assertEquals(layer.list_confml(), ['confml/component1.confml'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   283
        self.assertEquals(layer.list_content(), ['content/foobar.txt', 'content/s60.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   284
        self.assertEquals(prj.test_confml.layered_content().list_keys(), ['foobar.txt', 's60.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   285
        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
   286
        prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   287
        shutil.rmtree("temp")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   288
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   289
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   290
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   291
if __name__ == '__main__':
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   292
    unittest.main()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   293