configurationengine/source/cone/public/tests/unittest_container.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
"""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
Test the CPF root file parsing routines
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
"""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
import zipfile
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
import unittest
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
import string
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
import sys,os,re
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 utils, container, exceptions
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
importpk   = os.path.join(ROOT_PATH,"Import.pk")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
class TestC(object):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
    def __init__(self, path=""):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
        self.path = path
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
    def test(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
        return "test string"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
class TestB(object):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
    def __init__(self, path=""):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
        self.path = path
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
    def test(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
        return "test string"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
class TestDataContainer(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
        pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
    def test_add_values_and_get_values(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
        cont = container.DataContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        cont.add_value('test/ff',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
        cont.add_value('test/ff','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
        self.assertEquals(cont.get_value('test/ff'),'test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
        self.assertEquals(cont.get_values('test/ff')[0],123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        self.assertEquals(cont.get_values('test/ff')[1],'test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
    def test_add_values_and_list_values(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
        cont = container.DataContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
        cont.add_value('test/ff',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
        cont.add_value('test/ff','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
        cont.add_value('test/foo','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
        keys = cont.list_keys()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
        self.assertEquals(len(keys),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
    def test_add_values_and_remove_one_value(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
        cont = container.DataContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
        cont.add_value('test/ff',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
        cont.add_value('test/ff','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
        cont.add_value('test/foo','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
        cont.add_value('test/foo','123')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
        cont.add_value('sss',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
        cont.remove_value('test/foo','test')        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
        self.assertEquals(cont.get_values('test/foo'),['123'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
    def test_add_values_and_remove_all_values_of_a_key(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
        cont = container.DataContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
        cont.add_value('test/ff',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
        cont.add_value('test/ff','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
        cont.add_value('test/foo','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
        cont.add_value('test/foo','123')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
        cont.add_value('test/foo','foobar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
        cont.add_value('sss',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
        for val in cont.get_values('test/foo'):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
            cont.remove_value('test/foo',val)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
        self.assertEquals(cont.get_values('test/foo'),[])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    86
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
    def test_add_values_and_remove_key(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
        cont = container.DataContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
        cont.add_value('test/ff',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
        cont.add_value('test/ff','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
        cont.add_value('test/foo','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
        cont.add_value('test/foo','123')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
        cont.add_value('test/foo','foobar')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
        cont.add_value('sss',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
        cont.remove_key('test/foo')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
        self.assertEquals(cont.list_keys(),['test/ff','sss'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    97
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
    def test_add_values_clear_all_data(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    99
        cont = container.DataContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   100
        cont.add_value('test/ff',123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   101
        cont.add_value('test/ff','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   102
        cont.add_value('test/foo','test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
        cont.add_value('test/foo','123')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   104
        cont.clear()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   105
        self.assertEquals(len(cont.list_keys()),0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   106
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   107
    def test_conatainer_flatten(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   108
        data = container.DataContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   109
        data.add_value('test', 1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   110
        data.add_value('test', 2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   111
        data.add_value('test', 3)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   112
        data.add_value('foo', 1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   113
        data.add_value('foo', 2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   114
        data.add_value('bar', 3)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   115
        self.assertEquals(data.flatten(),{'test': 3, 'foo' : 2,'bar': 3})
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   116
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   117
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   118
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   119
class TestObjectProxy(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   120
    def test_create_object_proxy_for_test(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   121
        cont = container.ObjectProxy(TestC("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   122
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   123
        self.assertEquals(cont.test(),"test string")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   124
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   125
    def test_create_none_proxy(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   126
        cont = container.ObjectProxy("")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   127
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   128
        try: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   129
            cont.test()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   130
            self.fail("calling None succeeds?")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   131
        except AttributeError:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   132
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   133
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   134
    def test_create_object_proxy_for_string(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   135
        cont = container.ObjectProxy("test string")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   136
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   137
        self.assertEquals(cont.startswith("test"),True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   138
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   139
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   140
def graph(obj, filters=None):
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   141
    if obj._parent:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   142
        return ["%s -> %s" % (obj._parent._name, obj._name)]
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   143
    return []
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   144
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   145
class TestObjectContainer(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   146
    def test_create_object_container(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   147
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   148
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   149
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   150
    def test_add_incorrect_type(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   151
        cont = container.ObjectContainer()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   152
        try: 
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   153
            cont._add(container.DataContainer())
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   154
            self.fail("Adding incorrect class type to container succeeds?")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   155
        except exceptions.IncorrectClassError,e:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   156
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   157
            
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   158
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   159
    def test_add_child(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   160
        cont = container.ObjectContainer("root")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   161
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   162
        cont._add(obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   163
        cont._add(container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   164
        self.assertEquals(cont._list(),['test','foo'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   165
        self.assertEquals(cont.test,obj)
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   166
    
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   167
    def test_add_children_from_list_with_different_policies(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   168
        def check(policy, expected):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   169
            cont = container.ObjectContainer("root")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   170
            cont._add(container.ObjectContainer("test1"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   171
            cont._add(container.ObjectContainer("foo"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   172
            cont._add(container.ObjectContainer("test2"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   173
            
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   174
            objs = [container.ObjectContainer("foo"),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   175
                    container.ObjectContainer("foo"),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   176
                    container.ObjectContainer("foo")]
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   177
            for i, obj in enumerate(objs): obj.test_attr = i
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   178
            
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   179
            cont._add(objs, policy)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   180
            
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   181
            actual = [(o._name, getattr(o, 'test_attr', None)) for o in cont._objects()]
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   182
            self.assertEquals(actual, expected)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   183
        
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   184
        check(container.REPLACE,
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   185
              [('test1', None),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   186
               ('foo', 0),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   187
               ('foo', 1),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   188
               ('foo', 2),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   189
               ('test2', None),])
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   190
        
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   191
        check(container.APPEND,
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   192
              [('test1', None),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   193
               ('foo', None),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   194
               ('foo', 0),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   195
               ('foo', 1),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   196
               ('foo', 2),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   197
               ('test2', None),])
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   198
        
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   199
        check(container.PREPEND,
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   200
              [('test1', None),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   201
               ('foo', 0),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   202
               ('foo', 1),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   203
               ('foo', 2),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   204
               ('foo', None),
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   205
               ('test2', None),])
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   206
        
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   207
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   208
    def test_add_internal_child(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   209
        cont = container.ObjectContainer("root")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   210
        obj = container.ObjectContainer("?test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   211
        cont._add(obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   212
        cont._add(container.ObjectContainer("foo"))
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   213
        cont._add(container.ObjectContainer("bar"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   214
        self.assertEquals(cont._list(),['foo', 'bar'])
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   215
        self.assertEquals(cont._get('?test'),obj)
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   216
        self.assertEquals(cont._list(),['foo', 'bar'])
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   217
        cont._remove('?test')
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   218
        self.assertRaises(exceptions.NotFound,cont._get,'?test')
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   219
        self.assertEquals(cont._list(),['foo','bar'])
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   220
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   221
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   222
    def test_add_child_to_path(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   223
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   224
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   225
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   226
        self.assertEquals(cont._list(),['com'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   227
        self.assertEquals(cont.com.nokia._list(),['test'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   228
        self.assertEquals(cont.com.nokia.test,obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   229
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   230
    def test_add_child_to_path_and_replace_parent(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   231
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   232
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   233
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   234
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   235
        com = container.ObjectContainer("com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   236
        cont._add(com)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   237
        self.assertEquals(cont._list(),['com'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   238
        self.assertEquals(cont.com._list(),['nokia','bar'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   239
        self.assertEquals(cont.com.bar._parent,com)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   240
        self.assertEquals(cont.com.nokia._list(),['test'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   241
        self.assertEquals(cont.com.nokia.test,obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   242
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   243
    def test_append(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   244
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   245
        cont._append(container.ObjectContainer('test'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   246
        self.assertEquals(len(utils.get_list(cont.test)), 1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   247
        cont._append(container.ObjectContainer('test'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   248
        self.assertEquals(len(cont.test), 2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   249
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   250
    def test_prepend(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   251
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   252
        cont._prepend(container.ObjectContainer('test'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   253
        self.assertEquals(len(utils.get_list(cont.test)), 1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   254
        cont._prepend(container.ObjectContainer('test'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   255
        self.assertEquals(len(cont.test), 2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   256
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   257
    def test_replace(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   258
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   259
        t1 = container.ObjectContainer('test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   260
        cont._replace(t1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   261
        self.assertEquals(cont.test, t1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   262
        t2 = container.ObjectContainer('test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   263
        cont._replace(t2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   264
        self.assertEquals(cont.test, t2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   265
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   266
    def test_error(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   267
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   268
        t1 = container.ObjectContainer('test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   269
        cont._error(t1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   270
        self.assertEquals(cont.test, t1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   271
        t2 = container.ObjectContainer('test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   272
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   273
            cont._error(t2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   274
            self.fail("adding same with error succeeds")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   275
        except exceptions.AlreadyExists, e:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   276
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   277
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   278
    def test_add_child_to_existing_path_with_error(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   279
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   280
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   281
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   282
        com = container.ObjectContainer("com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   283
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   284
            cont._add(com, policy=container.ERROR)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   285
            self.fail("Adding an existing object succeeds with ERROR policy")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   286
        except exceptions.AlreadyExists, e:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   287
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   288
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   289
    def test__traverse_depth(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   290
        cont = container.ObjectContainer("cont")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   291
        obj1 = container.ObjectContainer("test1")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   292
        obj2 = container.ObjectContainer("test2")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   293
        cont._add_to_path("com.nokia", obj1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   294
        cont._add_to_path("com.nokia", obj2)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   295
        self.assertEquals(len(cont._traverse()), 4)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   296
        self.assertEquals(len(cont._traverse(depth=1)), 1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   297
        self.assertEquals(len(cont._traverse(depth=2)), 2)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   298
        self.assertEquals(len(cont._traverse(depth=3)), 4)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   299
        
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   300
    def test_add_child_to_existing_path_append(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   301
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   302
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   303
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   304
        cont._add_to_path("com.nokia", container.ObjectContainer("test"), container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   305
        com = container.ObjectContainer("com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   306
        cont._add(com, policy=container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   307
        self.assertEquals(len(cont._get('com')),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   308
        self.assertEquals(cont._get('com')[1],com)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   309
        self.assertEquals(len(cont._objects()),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   310
        self.assertEquals(len(cont.com[0].nokia.test),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   311
        self.assertEquals(len(cont._get('com[0].nokia.test')),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   312
        self.assertEquals([e._name for e in cont._traverse()],['com', 'nokia', 'test', 'test', 'com'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   313
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   314
    def test_add_child_to_existing_path_append_and_objects(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   315
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   316
        cont._add(container.ObjectContainer("dummy"),container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   317
        cont._add(container.ObjectContainer("child"),container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   318
        cont._add(container.ObjectContainer("child"),container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   319
        cont._add(container.ObjectContainer("child"),container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   320
        self.assertEquals(len(cont._objects()),4)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   321
        cont._remove('child[1]')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   322
        self.assertEquals(len(cont._objects()),3)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   323
        cont._remove('child[0]')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   324
        cont._remove('child[0]')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   325
        self.assertEquals(len(cont._objects()),1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   326
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   327
    def test_add_child_and_access_via_index(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   328
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   329
        cont._add(container.ObjectContainer("dummy"),container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   330
        d1 = cont._get('dummy')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   331
        d2 = cont._get('dummy[0]')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   332
        self.assertEquals(d1,d2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   333
        try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   334
            cont._get('dummy[1]')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   335
            self.fail("getting dummy")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   336
        except exceptions.NotFound:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   337
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   338
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   339
    def test_add_child_to_existing_path_append_and_remove(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   340
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   341
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   342
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   343
        com = container.ObjectContainer("com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   344
        cont._add(com, policy=container.APPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   345
        self.assertEquals(len(cont._get('com')),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   346
        self.assertEquals(cont._get('com')[1],com)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   347
        self.assertEquals(cont._list(),['com'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   348
        cont._remove('com')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   349
        self.assertEquals(cont._list(), [])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   350
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   351
    def test_add_child_to_existing_path_prepend(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   352
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   353
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   354
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   355
        com = container.ObjectContainer("com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   356
        cont._add(com, policy=container.PREPEND)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   357
        self.assertEquals(len(cont._get('com')),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   358
        self.assertEquals(cont._get('com')[0],com)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   359
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   360
    def test_add_child_and_get(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   361
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   362
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   363
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   364
        self.assertEquals(cont._get('com.nokia.test'),obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   365
        self.assertEquals(cont.com._get('nokia.test'),obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   366
        self.assertEquals(cont.com.nokia._get('test'),obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   367
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   368
    def test_add_child_and_remove_one(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   369
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   370
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   371
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   372
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   373
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   374
        self.assertEquals(len(cont._traverse()),5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   375
        cont._remove("com.nokia.foo")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   376
        self.assertEquals(len(cont._traverse()),4)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   377
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   378
    def test_add_child_and_remove_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   379
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   380
        obj = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   381
        cont._add_to_path("com.nokia", obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   382
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   383
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   384
        self.assertEquals(len(cont._traverse()),5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   385
        for item in cont._list():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   386
            cont._remove(item)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   387
        self.assertEquals(len(cont._list()),0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   388
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   389
    def test_add_children_and_list_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   390
        cont = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   391
        obj = TestC()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   392
        cont._add_to_path("com.nokia", container.ObjectContainer("test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   393
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   394
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   395
        self.assertEquals(len(cont._traverse()),5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   396
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   397
    def test_create_hieararchy_and_remove_child(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   398
        root = container.ObjectContainer("test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   399
        root._add(container.ObjectContainer("child1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   400
        root._add(container.ObjectContainer("child2"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   401
        root.child1._add(container.ObjectContainer("child11"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   402
        root.child1._add(container.ObjectContainer("child12"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   403
        root.child2._add(container.ObjectContainer("child21"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   404
        self.assertEquals(root._list_traverse(),
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   405
                          ['child1', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   406
                          'child1.child11', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   407
                          'child1.child12',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   408
                          'child2',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   409
                          'child2.child21'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   410
        root.child2._remove('child21')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   411
        self.assertEquals(root._list_traverse()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   412
                          ,['child1',  
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   413
                                           'child1.child11', 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   414
                                           'child1.child12',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   415
                                           'child2'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   416
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   417
    def test_add_children_and_traverse_and_get_path(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   418
        cont = container.ObjectContainer("default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   419
        cont._add_to_path("com.nokia", container.ObjectContainer("test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   420
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   421
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   422
        cont.com._list()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   423
        self.assertEquals(cont._traverse()[0]._path(),"default.com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   424
        self.assertEquals(cont._traverse()[0]._path(cont),"com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   425
        self.assertEquals(cont._traverse()[0]._path(cont.com),"")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   426
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   427
    def test_add_children_and_traverse_filter_name_and_get_path(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   428
        cont = container.ObjectContainer("default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   429
        cont._add_to_path("com.nokia", container.ObjectContainer("test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   430
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   431
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   432
        cont.com._list()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   433
        ret = cont._traverse(name="^t.*$")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   434
        self.assertEquals(len(ret),1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   435
        self.assertEquals(ret[0]._path(),"default.com.nokia.test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   436
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   437
    def test_add_children_and_traverse_filter_name_many(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   438
        cont = container.ObjectContainer("default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   439
        cont._add_to_path("com.nokia", container.ObjectContainer("test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   440
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   441
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   442
        cont.com._list()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   443
        ret = cont._traverse(path=".*nokia.*")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   444
        self.assertEquals(len(ret),3)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   445
        self.assertEquals(ret[0]._path(),"default.com.nokia")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   446
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   447
    def test_add_children_tail_recurse_with_function(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   448
        cont = container.ObjectContainer("default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   449
        cont._add_to_path("com.nokia", container.ObjectContainer("test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   450
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   451
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   452
        ret = cont._tail_recurse(graph)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   453
        self.assertEquals(ret,['default -> com', 'com -> nokia', 'nokia -> test', 'nokia -> foo', 'com -> bar'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   454
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   455
    def test_add_children_head_recurse_with_function(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   456
        cont = container.ObjectContainer("default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   457
        cont._add_to_path("com.nokia", container.ObjectContainer("test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   458
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   459
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   460
        ret = cont._head_recurse(graph)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   461
        self.assertEquals(ret,['nokia -> test', 'nokia -> foo', 'com -> nokia', 'com -> bar', 'default -> com'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   462
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   463
    def test_add_children_and_find_parent(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   464
        cont = container.ObjectContainer("default", container=True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   465
        cont._add(container.ObjectContainer("com",housut="test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   466
        cont._add_to_path("com.nokia", container.ObjectContainer("test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   467
        cont._add_to_path("com.nokia", container.ObjectContainer("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   468
        cont._add_to_path("com", container.ObjectContainer("bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   469
        child = cont._get('com.nokia.test')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   470
        self.assertEquals(child._find_parent()._name, 'nokia')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   471
        self.assertEquals(child._find_parent(container=True)._name, 'default')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   472
        self.assertEquals(child._find_parent(housut="test")._name, 'com')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   473
        self.assertEquals(child._find_parent(__class__=container.ObjectContainer)._name, 'nokia')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   474
        self.assertEquals(child._find_parent(type=container.ObjectContainer)._name, 'nokia')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   475
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   476
class TestObjectProxyContainer(unittest.TestCase):    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   477
    def test_create_object_container_for_test(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   478
        cont = container.ObjectProxyContainer(TestC("foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   479
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   480
        self.assertEquals(cont.test(),"test string")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   481
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   482
    def test_create_none_container(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   483
        cont = container.ObjectProxyContainer(None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   484
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   485
        try: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   486
            cont.test()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   487
            self.fail("calling None succeeds?")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   488
        except AttributeError:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   489
            pass
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   490
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   491
    def test_create_object_container_for_string(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   492
        cont = container.ObjectProxyContainer("Test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   493
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   494
        self.assertEquals(cont.startswith("Test"),True)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   495
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   496
    def test_create_object_container(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   497
        cont = container.ObjectProxyContainer(TestC())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   498
        self.assertTrue(cont)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   499
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   500
    def test_add_child(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   501
        cont = container.ObjectProxyContainer(None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   502
        obj = TestC()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   503
        cont._add(container.ObjectProxyContainer(obj,"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   504
        self.assertEquals(cont._list(),['test'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   505
        self.assertEquals(cont.test._obj,obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   506
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   507
    def test_add_child_to_path(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   508
        cont = container.ObjectProxyContainer(None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   509
        obj = TestC()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   510
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj,"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   511
        self.assertEquals(cont._list(),['com'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   512
        self.assertEquals(cont.com.nokia._list(),['test'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   513
        self.assertEquals(cont.com.nokia.test._obj,obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   514
        self.assertEquals(cont.com.nokia.test.test(),"test string")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   515
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   516
    def test_add_child_and_get(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   517
        cont = container.ObjectProxyContainer(None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   518
        obj = TestC()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   519
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj,"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   520
        self.assertEquals(cont._get('com.nokia.test')._obj,obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   521
        self.assertEquals(cont.com._get('nokia.test')._obj,obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   522
        self.assertEquals(cont.com.nokia._get('test')._obj,obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   523
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   524
    def test_add_child_and_remove_one(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   525
        cont = container.ObjectProxyContainer(None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   526
        obj = TestC()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   527
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj,"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   528
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   529
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   530
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   531
        self.assertEquals(len(cont._traverse()),5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   532
        cont._remove("com.nokia.foo")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   533
        self.assertEquals(len(cont._traverse()),4)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   534
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   535
    def test_add_child_and_remove_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   536
        cont = container.ObjectProxyContainer(None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   537
        obj = TestC()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   538
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj,"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   539
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   540
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   541
        self.assertEquals(len(cont._traverse()),5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   542
        for item in cont._list():
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   543
            cont._remove(item)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   544
        self.assertEquals(len(cont._list()),0)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   545
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   546
    def test_add_children_and_list_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   547
        cont = container.ObjectProxyContainer(None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   548
        obj = TestC()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   549
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(obj,"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   550
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   551
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   552
        self.assertEquals(len(cont._traverse()),5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   553
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   554
    def test_add_children_and_traverse_and_get_path(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   555
        cont = container.ObjectProxyContainer(None,"default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   556
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   557
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   558
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   559
        cont.com._list()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   560
        self.assertEquals(cont._traverse()[0]._path(),"default.com")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   561
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   562
    def test_add_children_and_traverse_filter_name_and_get_path(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   563
        cont = container.ObjectProxyContainer(None,"default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   564
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   565
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   566
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   567
        cont.com._list()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   568
        ret = cont._traverse(name="^t.*$")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   569
        self.assertEquals(len(ret),1)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   570
        self.assertEquals(ret[0]._path(),"default.com.nokia.test")
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   571
#        ret = cont._traverse(type=TestC)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   572
#        self.assertEquals(len(ret),1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   573
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   574
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   575
    def test_add_children_and_traverse_filter_name_many(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   576
        cont = container.ObjectProxyContainer(None,"default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   577
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   578
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   579
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   580
        cont.com._list()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   581
        ret = cont._traverse(path=".*nokia.*")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   582
        self.assertEquals(len(ret),3)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   583
        self.assertEquals(ret[0]._path(),"default.com.nokia")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   584
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   585
    def test_add_children_and_traverse_filter_class(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   586
        cont = container.ObjectProxyContainer(None,"default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   587
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   588
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   589
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   590
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestB(),"bee"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   591
        cont.com.nokia._add(container.ObjectProxyContainer(TestB(),"vee"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   592
        ret = cont._traverse(filters=[lambda x: hasattr(x,'_obj') and isinstance(x._obj, TestB)])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   593
        self.assertEquals(len(ret),2)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   594
        self.assertEquals(ret[0]._path(cont),"com.nokia.bee")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   595
        self.assertEquals(ret[1]._path(cont),"com.nokia.vee")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   596
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   597
    def test_add_children_and_traverse_filter_class_proxies(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   598
        cont = container.ObjectProxyContainer(None,"default")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   599
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   600
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestC(),"foo"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   601
        cont._add_to_path("com", container.ObjectProxyContainer(TestC(),"bar"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   602
        cont._add_to_path("com.nokia", container.ObjectProxyContainer(TestB(),"bee"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   603
        cont.com.nokia._add(container.ObjectProxyContainer(TestB(),"vee"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   604
        ret = cont._traverse(filters=[lambda x: isinstance(x, container.ObjectProxyContainer)])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   605
        self.assertEquals(len(ret),5)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   606
        self.assertEquals(ret[0]._path(cont),"com.nokia.test")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   607
        self.assertEquals(ret[1]._path(cont),"com.nokia.foo")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   608
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   609
class TestLoadProxy(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   610
    def test_create_load_proxy(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   611
        proxy = container.LoadProxy(importpk, container.LoadInterface())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   612
        proxy._load()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   613
        self.assertTrue(proxy._obj != None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   614
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   615
    def test_create_load_proxy_and_get(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   616
        proxy = container.LoadProxy(importpk, container.LoadInterface())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   617
        self.assertEquals(proxy.list_resources(''),['test1.txt', 'test2.txt', 'test3.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   618
        self.assertTrue(proxy._obj != None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   619
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   620
    def test_create_load_proxy_and_unload(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   621
        proxy = container.LoadProxy(importpk, container.LoadInterface())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   622
        self.assertEquals(proxy.list_resources(''),['test1.txt', 'test2.txt', 'test3.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   623
        proxy.set('path',"unload.pk")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   624
        proxy._unload()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   625
        self.assertTrue(proxy._obj == None)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   626
        proxy =None
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   627
        proxy2 = container.LoadProxy("unload.pk", container.LoadInterface())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   628
        self.assertEquals(proxy2.list_resources(''),['test1.txt', 'test2.txt', 'test3.txt'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   629
        os.unlink("unload.pk")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   630
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   631
class TestLoadContainer(unittest.TestCase):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   632
    def test_create_load_container(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   633
        cont = container.LoadContainer(importpk, container.LoadInterface())
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   634
        cont._load()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   635
        self.assertEquals(len(cont._objects()), 1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   636
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   637
    def test_create_load_link__unload(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   638
        cont = container.LoadContainer(importpk, container.LoadInterface())
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   639
        cont._load()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   640
        self.assertEquals(len(cont._objects()), 1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   641
        cont._unload()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   642
        self.assertEquals(cont._container, None)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   643
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   644
    def test_create_load_link__get_objects(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   645
        cont = container.LoadContainer(importpk, container.LoadInterface())
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   646
        self.assertEquals(len(cont._objects()), 1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   647
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   648
    def test_create_load_link__traverse(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   649
        cont = container.LoadContainer(importpk, container.LoadInterface())
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   650
        self.assertEquals(len(cont._traverse()), 4)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   651
        print cont._traverse()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   652
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   653
    def test_create_load_link__list(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   654
        cont = container.LoadContainer(importpk, container.LoadInterface())
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   655
        self.assertEquals(os.path.basename(cont._list()[0]), 'Import_pk')
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   656
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   657
class TestLoadContainerWrite(unittest.TestCase):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   658
    def test_create_load_container__add_data(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   659
        cont = container.LoadContainer(importpk)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   660
        cont._add(container.ObjectContainer("Test"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   661
        self.assertEquals(len(cont._objects()), 1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   662
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   663
    def test_create_load_container__add_data_unload(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   664
        cont = container.LoadContainer(importpk)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   665
        cont._add(container.ObjectContainer("Test"))
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   666
        self.assertEquals(len(cont._objects()), 1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   667
        cont._unload()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   668
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   669
class TestLoadLink(unittest.TestCase):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   670
    def test_create_load_link(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   671
        link = container.LoadLink(importpk, container.LoadInterface())
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   672
        objs = link._load()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   673
        self.assertEquals(len(objs), 1)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   674
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   675
    def test_create_load_link_and_populate(self):
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   676
        cont = container.ObjectContainer("Test")
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   677
        link = container.LoadLink(importpk, container.LoadInterface())
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   678
        cont._add(link)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   679
        link.populate()
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   680
        self.assertEquals(len(cont._objects()), 2)
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   681
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   682
if __name__ == '__main__':
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   683
    unittest.main()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   684
      
3
e7e0ae78773e ConE 1.2.11 release
m2lahtel
parents: 0
diff changeset
   685