configurationengine/source/cone/core/tests/unittest_configuration_project_on_filestorage.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
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
import shutil
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
import __init__
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
from testautomation.base_testcase import BaseTestCase
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
from cone.public import exceptions, api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
from cone.confml.model import ConfmlMeta, ConfmlDescription
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
from cone.storage.filestorage import FileStorage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
from cone.confml import model
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
temp_dir  = os.path.join(ROOT_PATH, "temp/project_on_filestorage")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
datafolder= os.path.join(ROOT_PATH,"../../storage/tests/data")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
class TestConeProjectOpen(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
        pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
    def test_open_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
        p = api.Storage.open(datafolder)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
        self.assertTrue(p)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
    def test_open_project_of_non_storage(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
        fs = "foobar_dummy"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
            p = api.Storage.open(fs)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
            self.fail("Opening on top of non storage succeeds!!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
        except exceptions.StorageException:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
            self.assertTrue(True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
class TestConeProjectMethodsRead(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        self.project = api.Project(api.Storage.open(datafolder))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
    def test_list_configurations(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
        confs =  self.project.list_configurations()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
        self.assertTrue(confs)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
        self.assertEquals(confs[0],"morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
    def test_get_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
        self.assertTrue(conf)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
        self.assertTrue(isinstance(conf,api.ConfigurationProxy))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
    def test_get_configuration_non_existing(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
            conf =  self.project.get_configuration("foo.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
            self.fail("Opening non existing configuration succeeds!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
        except exceptions.NotFound,e:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
            self.assertTrue(True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
    def test_get_configuration_and_list_layers(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
        layers = conf.list_configurations()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
        self.assertTrue(layers)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
        self.assertEquals(layers[0],'platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
        self.assertEquals(layers[1],'familyX/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
    def test_get_is_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
        self.assertTrue(self.project.is_configuration("morestuff.confml"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
        # TODO: this is not working at the moment due to performance problem in
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
        # Project.list_all_configurations()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
        #self.assertTrue(self.project.is_configuration("platform/s60/root.confml"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    86
        #self.assertFalse(self.project.is_configuration("platform/foo/root.confml"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
    def test_get_configuration_and_get_layer(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
        s60layer = conf.get_configuration('platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
        self.assertTrue(s60layer)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
        self.assertTrue(isinstance(s60layer.get_layer(),api.Layer))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
    def test_get_configuration_and_get_layer_path(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
        s60layer = conf.get_configuration('platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    97
        self.assertEquals(s60layer.get_path(),'platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    99
    def test_get_configuration_and_get_layer_and_get_layer_resources(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   100
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   101
        s60layer = conf.get_configuration('platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   102
        files = s60layer.list_resources()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
        self.assertEquals(files[0],'platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   104
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   105
    def test_get_configuration_and_get_layer_and_get_a_layer_resource(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   106
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   107
        s60layer = conf.get_configuration('platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   108
        res = s60layer.get_resource('root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   109
        self.assertTrue(res)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   110
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   111
    def test_get_configuration_and_list_all_configuration_resources(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   112
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   113
        resources = conf.list_resources()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   114
        self.assertEquals(resources[0],'morestuff.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   115
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   116
    def test_get_configuration_and_get_first_layer_by_index(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   117
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   118
        s60config = conf.get_configuration_by_index(0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   119
        self.assertEquals(s60config.get_path(),'platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   120
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   121
    def test_get_configuration_and_get_last_layer_by_index(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   122
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   123
        config = conf.get_configuration_by_index(-1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   124
        self.assertEquals(config.get_path(),'familyX/prodX/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   125
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   126
    def test_get_all_resources(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   127
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   128
        resources = conf.get_all_resources()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   129
        self.assertEquals(resources[0].get_path(),'morestuff.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   130
        self.assertEquals(resources[1].get_path(),'platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   131
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   132
    def test_list_confmls(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   133
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   134
        confmls = conf.list_resources()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   135
        self.assertEquals(confmls[0],'morestuff.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   136
        self.assertEquals(confmls[1],'platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   137
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   138
    def test_list_implmls(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   139
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   140
        implmls = conf.get_configuration('platform/s60/root.confml').get_layer().list_implml()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   141
        self.assertEquals(implmls[0],'implml/accessoryserver_1020505A.crml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   142
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   143
#    def test_list_content(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   144
#        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   145
#        contents = conf.list_content()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   146
#        self.assertEquals(contents[0],'platform/s60/content/.svn/all-wcprops')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   147
            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   148
    def test_layered_content(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   149
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   150
        contents = conf.layered_content()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   151
        self.assertEquals(contents.get_value('test/s60.txt'),'platform/s60/content/test/s60.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   152
        self.assertEquals(contents.get_value('test/override.txt'),'familyX/content/test/override.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   153
        self.assertEquals(contents.get_value('test/shout.txt'),'familyX/content/test/shout.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   154
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   155
    def test_layer_name(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   156
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   157
        s60layer = conf.get_configuration('platform/s60/root.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   158
        self.assertEquals(s60layer.get_ref(),'platform__s60__root_confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   159
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   160
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   161
    def test_layered_content_with_one_layer(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   162
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   163
        contents = conf.layered_content([-2])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   164
        self.assertEquals(contents.get_value('test/override.txt'),'familyX/content/test/override.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   165
        self.assertEquals(contents.get_value('test/shout.txt'),'familyX/content/test/shout.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   166
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   167
            contents.get_value('test/s60.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   168
            self.fail("Fetching content from s60 layer succeeds!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   169
        except KeyError:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   170
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   171
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   172
    def test_layered_content_with_two_layers(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   173
        conf =  self.project.get_configuration("morestuff.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   174
        contents = conf.layered_content([-2,-1])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   175
        self.assertEquals(contents.get_value('test/override.txt'),'familyX/content/test/override.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   176
        self.assertEquals(contents.get_value('test/shout.txt'),'familyX/content/test/shout.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   177
        self.assertEquals(contents.get_value('prodX/jee/ProdX_specific.txt'),'familyX/prodX/content/prodX/jee/ProdX_specific.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   178
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   179
            contents.get_value('test/s60.txt')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   180
            self.fail("Fetching content from s60 layer succeeds!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   181
        except KeyError:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   182
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   183
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   184
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   185
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   186
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   187
class TestConeProjectMethodsWrite(BaseTestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   188
    def setUp(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   189
        if not os.path.exists(temp_dir):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   190
            os.makedirs(temp_dir)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   191
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   192
        if not os.path.exists('newtempproject'):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   193
            os.mkdir('newtempproject')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   194
        fs = api.Storage.open("newtempproject","a")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   195
        self.project = api.Project(fs)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   196
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   197
    def tearDown(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   198
        self.project.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   199
        shutil.rmtree('newtempproject')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   200
        pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   201
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   202
    def test_create_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   203
        conf = self.project.create_configuration("dummy.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   204
        self.assertTrue(conf)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   205
        self.assertEquals(conf.get_ref(),'dummy_confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   206
        self.assertTrue(isinstance(conf,api.Configuration))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   207
        conf.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   208
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   209
    def test_create_close_open_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   210
        tempdir_orig = os.path.normpath(os.path.join(temp_dir, "temp1_orig"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   211
        tempdir_copy = os.path.normpath(os.path.join(temp_dir, "temp1_copy"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   212
        self.remove_if_exists([tempdir_orig, tempdir_copy])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   213
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   214
        project = api.Project(api.Storage.open(tempdir_orig,"w"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   215
        conf = project.create_configuration("dummy2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   216
        conf.set_name("dummy")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   217
        prop1 = model.ConfmlMetaProperty('owner', 'some guy')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   218
        prop2 = model.ConfmlMetaProperty('purpose', 'for testing')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   219
        conf.meta = model.ConfmlMeta([prop1, prop2])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   220
        conf.desc = "Testing to see a configuration created"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   221
        conf.create_configuration("test/path/to/somewhere/r.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   222
        conf.create_configuration("test/path/to/elsewhere/r.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   223
        conf.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   224
        project.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   225
        project.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   226
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   227
        # Make a copy of the created directory
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   228
        shutil.copytree(tempdir_orig, tempdir_copy)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   229
        # If everything has been closed properly, the original directory
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   230
        # should now be removable
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   231
        shutil.rmtree(tempdir_orig)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   232
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   233
        project2 = api.Project(api.Storage.open(tempdir_copy))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   234
        conf2 = project2.get_configuration("dummy2.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   235
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   236
        self.assertEquals(conf.get_name(),conf2.get_name())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   237
        self.assertEquals(conf2.get_name(),'dummy')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   238
        self.assertEquals(conf2.meta[0].tag ,'owner')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   239
        self.assertEquals(conf2.meta[0].value ,'some guy')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   240
        self.assertEquals(conf.desc,conf2.desc)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   241
        self.assertEquals(conf.list_configurations(),conf2.list_configurations())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   242
        project2.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   243
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   244
    def test_remove_configuration_non_existing(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   245
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   246
            self.project.remove_configuration("dummystring.txt")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   247
            self.fail("Removing non existing configuration succeds!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   248
        except exceptions.NotFound,e:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   249
            self.assertTrue(True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   250
            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   251
    def test_create_remove_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   252
        conf = self.project.create_configuration("remove.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   253
        conf.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   254
        conf.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   255
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   256
        self.project.remove_configuration("remove.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   257
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   258
            conf =  self.project.get_configuration("remove.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   259
            self.fail("Opening of removed configuration succeeds!")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   260
        except exceptions.NotFound,e:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   261
            self.assertTrue(True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   262
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   263
    def test_create_configuration_in_sub_configuration(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   264
        fs = api.Storage.open("newproject","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   265
        project = api.Project(fs)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   266
        conf = project.create_configuration("croot.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   267
        subconf = conf.create_configuration("test/root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   268
        subconf.create_configuration('confml/data.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   269
        conf.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   270
        self.assertTrue(project.get_storage().is_resource('test/confml/data.confml'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   271
        conf = project.get_configuration("croot.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   272
        subconf = conf.create_configuration("test2\\root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   273
        subconf.create_configuration('confml/data.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   274
        subconf.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   275
        conf.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   276
        self.assertTrue(project.get_storage().is_resource('test2/confml/data.confml'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   277
        project.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   278
        shutil.rmtree("newproject")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   279
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   280
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   281
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   282
if __name__ == '__main__':
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   283
    unittest.main()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   284