configurationengine/source/cone/storage/tests/unittest_stringstorage.py
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
permissions -rw-r--r--
Adding EPL version of configurationengine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
# All rights reserved.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
# This component and the accompanying materials are made available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
# which accompanies this distribution, and is available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
# Initial Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
# Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
# Description: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
import unittest
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
import string
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
import sys,os
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
import pickle
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
import __init__
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
from cone.public import api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
from cone.storage import stringstorage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
class TestStringStorage(unittest.TestCase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
    def test_internal_add_and_list(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
        store = api.Storage.open("test.pk","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
        store._add_to_path("test.foo.bar",stringstorage._StringStorageObject("test1.txt"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
        store._add_to_path("test.foo.bar",stringstorage._StringStorageObject("test2.txt"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
        self.assertEquals(store._get("test.foo.bar")._list(), 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
                          ['test1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
                          'test2'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
        store.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
        os.unlink("test.pk")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
    def test_internal_add_get_and_list(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
        store = api.Storage.open("test.pk","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
        obj = stringstorage._StringStorageObject("test1.txt")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
        store._add_to_path("test.foo.bar",obj)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
        store._add_to_path("test.foo.bar",stringstorage._StringStorageObject("test2.txt"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
        obj.data = "Fooo"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
        self.assertEquals(store._get("test.foo.bar")._list(), 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
                          ['test1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
                          'test2'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
        self.assertEquals(store.test.foo.bar.test1.data,'Fooo')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
        store.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
        os.unlink("test.pk")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
    def test_internal_add_get_and_list_all(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        store = api.Storage.open("test.pk","w")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
        store._add_to_path("test.foo.bar",stringstorage._StringStorageObject("test1.txt"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
        store._add_to_path("test.foo.bar",stringstorage._StringStorageObject("test2.txt"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
        store._add(stringstorage._StringStorageObject("root.txt"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
        self.assertEquals(store._list_traverse(type=stringstorage._StringStorageObject), ['test.foo.bar.test1',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
                                                      'test.foo.bar.test2',
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
                                                      'root'])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
        store.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
        os.unlink("test.pk")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60