configurationengine/source/cone/storage/tests/unittest_webstorage.py
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
equal deleted inserted replaced
-1:000000000000 0:2e8eeb919028
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 #
       
    16 
       
    17 import unittest
       
    18 import string
       
    19 import sys,os
       
    20 import pickle
       
    21 import time
       
    22 import __init__
       
    23 
       
    24 from cone.public import api, exceptions
       
    25 from cone.storage import webstorage
       
    26 from cone.carbon import model
       
    27 import simplewebserver
       
    28 
       
    29 ROOT_PATH   = os.path.dirname(os.path.abspath(__file__))
       
    30 TEST_SERVER = simplewebserver.SimpleWebServer(os.path.join(ROOT_PATH,'carbondata'), 8001)
       
    31 #
       
    32 #def runserver():
       
    33 #    if not TEST_SERVER.active:
       
    34 #        TEST_SERVER.start()
       
    35 #        time.sleep(1)
       
    36 #
       
    37 #def stopserver():
       
    38 #    if TEST_SERVER.active:
       
    39 #        TEST_SERVER.stop()
       
    40 #
       
    41 #class TestWebStorage(unittest.TestCase):
       
    42 #    def setUp(self):
       
    43 #        runserver()
       
    44 #
       
    45 #    def __del__(self):
       
    46 #        stopserver()
       
    47 #
       
    48 #    def test_create_web_storage(self):
       
    49 #        store = webstorage.WebStorage('localhost:8001/extapp')
       
    50 #
       
    51 #
       
    52 #    def test__get_stringio_from_path(self):
       
    53 #        store = webstorage.WebStorage('localhost:8001/extapp')
       
    54 #        strio = store._get_stringio_from_path('alvin.confml')
       
    55 #        self.assertTrue(len(strio.getvalue()) > 0)
       
    56 #
       
    57 #    def test__get_stringio_from_path_fails(self):
       
    58 #        
       
    59 #        store = webstorage.WebStorage('localhost:8001/extapp')
       
    60 #        try:
       
    61 #            strio = store._get_stringio_from_path('foobar.confml')
       
    62 #            self.fail('Getting nonexistent file succeeds?')
       
    63 #        except exceptions.NotResource:
       
    64 #            pass
       
    65 #
       
    66 #
       
    67 #    def test_get_resource_from_path(self):
       
    68 #        store = webstorage.WebStorage('localhost:8001/extapp')
       
    69 #        wres = store.open_resource('test/empty.confml')
       
    70 #        self.assertTrue(len(wres.read()) == 0)
       
    71 #
       
    72 #    def test_get_resource_fails(self):
       
    73 #        store = webstorage.WebStorage('localhost:8001/extapp')
       
    74 #        try:
       
    75 #            wres = store.open_resource('foobar.confml')
       
    76 #            self.fail('test')
       
    77 #        except exceptions.NotResource:
       
    78 #            pass
       
    79 
       
    80 class TestResourceCache(unittest.TestCase):
       
    81 #    def test_create_resource_cache_add_configurations(self):
       
    82 #        rc = webstorage.ResourceCache()
       
    83 #        conf = model.ConfigurationResource(**{'parent_config': 'hessu', 'path': 'NCP/Testing', 'version_identifier': '0.1', 'configuration_name': 'Testing'})
       
    84 #        rc.add_configuration(conf)
       
    85 #        self.assertEquals(rc.list_resources('/'), ['Testing.confml'])
       
    86 #        self.assertEquals(rc.list_resources('/', True), ['Testing.confml', 'NCP/Testing/root.confml'])
       
    87 #        self.assertEquals(rc.get_resource('Testing.confml').name, 'Testing_confml')
       
    88 #        self.assertEquals(isinstance(rc.get_resource('Testing.confml'),model.CarbonConfiguration),True)
       
    89 #        self.assertEquals(rc.get_resource('Testing.confml').list_configurations(),['NCP/Testing/root.confml'])
       
    90 
       
    91     def test_create_resource_cache_from_resource_list(self):
       
    92         reslist = ['test.configurationroot',
       
    93                    'test.configurationlayer',
       
    94                    'test.featurelist']
       
    95         rc = webstorage.ResourceCache()
       
    96         for res in reslist:
       
    97             rc.add_resource(res)
       
    98         self.assertEquals(rc.list_resources('/'), ['test.confml'])
       
    99         self.assertEquals(rc.list_resources('/', True), ['test/root.confml',
       
   100                                                    'featurelists/test.confml',
       
   101                                                    'test.confml'])
       
   102         self.assertEquals(rc.get_resource_link('test.confml'), 'test.configurationroot')
       
   103         self.assertEquals(rc.get_resource_link('featurelists/test.confml'), 'test.featurelist')
       
   104         self.assertEquals(rc.get_resource_link('test/root.confml'), 'test.configurationlayer')
       
   105     
       
   106 
       
   107 
       
   108 if __name__ == '__main__':
       
   109     unittest.main()
       
   110