configurationengine/source/cone/core/tests/unittest_configuration_project_on_zipstorage.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 """
       
    18 Test the CPF configuration
       
    19 """
       
    20 import unittest
       
    21 import string
       
    22 import sys,os, shutil
       
    23 import __init__
       
    24 
       
    25 from cone.public import exceptions, api
       
    26 from cone.core import *
       
    27 from testautomation.base_testcase import BaseTestCase
       
    28 from cone.confml import model
       
    29 
       
    30 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    31 temp_dir  = os.path.join(ROOT_PATH, "temp/project_on_zipstorage")
       
    32 datazip   = os.path.join(ROOT_PATH,"testdata/test_project.cpf")
       
    33 
       
    34 class TestConeProjectOpenZip(unittest.TestCase):    
       
    35     def test_open_project(self):        
       
    36         fs = api.Storage.open(datazip,"r")
       
    37         p = api.Project(fs)
       
    38         self.assertTrue(p)
       
    39         
       
    40     def test_open_project_of_non_storage(self):
       
    41         fs = ""
       
    42         try:
       
    43             p = api.Project(fs)
       
    44             self.fail("Opening on top of non storage succeeds!!")
       
    45         except exceptions.StorageException:
       
    46             self.assertTrue(True)
       
    47       
       
    48 
       
    49 class TestConeProjectMethodsReadZip(unittest.TestCase):
       
    50     def setUp(self):
       
    51         fs = api.Storage.open(datazip,"r")
       
    52         self.project = api.Project(fs)
       
    53         
       
    54     def test_list_configurations(self):
       
    55         confs =  self.project.list_configurations()
       
    56         self.assertEquals(
       
    57             sorted(confs),
       
    58             ["root1.confml",
       
    59              "root2.confml",
       
    60              "root3.confml",
       
    61              "root4.confml",
       
    62              "root5.confml"])
       
    63         
       
    64     def test_get_configuration(self):
       
    65         conf =  self.project.get_configuration("/root5.confml")
       
    66         self.assertTrue(conf)
       
    67         self.assertTrue(isinstance(conf,api.ConfigurationProxy))
       
    68             
       
    69     def test_get_configuration_non_existing(self):
       
    70         try:
       
    71             conf =  self.project.get_configuration("foo")
       
    72             self.fail("Opening non existing configuration succeeds!")
       
    73         except exceptions.NotFound,e:
       
    74             self.assertTrue(True)
       
    75 
       
    76     def test_get_configuration_and_list_layers(self):
       
    77         conf =  self.project.get_configuration("root5.confml")
       
    78         layers = conf.list_configurations()    
       
    79         self.assertEquals(
       
    80             layers,
       
    81             ['Layer1/root.confml',
       
    82              'Layer2/root.confml',
       
    83              'Layer3/root.confml',
       
    84              'Layer4/root.confml',
       
    85              'Layer5/root.confml'])
       
    86 
       
    87     def test_get_configuration_and_get_layer(self):
       
    88         conf =  self.project.get_configuration("root5.confml")
       
    89         layer1 = conf.get_configuration('Layer1/root.confml')
       
    90         self.assertTrue(layer1)
       
    91         self.assertTrue(isinstance(layer1,api.ConfigurationProxy))
       
    92 
       
    93     def test_get_configuration_and_get_layer_path(self):
       
    94         conf =  self.project.get_configuration("root5.confml")
       
    95         layer1 = conf.get_configuration('Layer1/root.confml')
       
    96         self.assertEquals(layer1.get_path(),'Layer1/root.confml')
       
    97     
       
    98     def test_get_configuration_and_get_layer_and_get_layer_resources(self):
       
    99         conf =  self.project.get_configuration("root5.confml")
       
   100         layer1 = conf.get_configuration('Layer1/root.confml')
       
   101         files = layer1.list_resources()
       
   102         self.assertTrue('Layer1/root.confml' in files)
       
   103         self.assertTrue('Layer1/confml/feature1.confml' in files)
       
   104         self.assertTrue('Layer1/implml/feature1_12341001.crml' in files)
       
   105         self.assertTrue('Layer1/content/default_file.txt' in files)
       
   106 
       
   107     def test_get_configuration_and_get_layer_and_get_a_layer_resource(self):
       
   108         conf =  self.project.get_configuration("root5.confml")
       
   109         layer1 = conf.get_configuration('Layer1/root.confml')
       
   110         res = layer1.get_resource('implml/feature1_12341001.crml')
       
   111         self.assertTrue(res)
       
   112 
       
   113     def test_get_configuration_and_list_all_configuration_resources(self):
       
   114         conf =  self.project.get_configuration("root5.confml")
       
   115         resources = conf.list_resources()
       
   116         self.assertTrue('root5.confml' in resources)
       
   117         self.assertTrue('Layer1/root.confml' in resources)
       
   118         self.assertTrue('Layer2/root.confml' in resources)
       
   119         self.assertTrue('Layer3/root.confml' in resources)
       
   120         self.assertTrue('Layer4/root.confml' in resources)
       
   121         self.assertTrue('Layer5/root.confml' in resources)
       
   122         self.assertTrue('Layer1/confml/feature1.confml' in resources)
       
   123         self.assertTrue('Layer1/implml/feature1_12341001.crml' in resources)
       
   124         self.assertTrue('Layer1/content/default_file.txt' in resources)
       
   125         self.assertTrue('Layer2/content/layer2_file.txt' in resources)
       
   126 
       
   127 class TestConeProjectMethodsWriteZip(BaseTestCase):
       
   128     def setUp(self):
       
   129         if not os.path.exists(temp_dir):
       
   130             os.makedirs(temp_dir)
       
   131             
       
   132     def test_create_configuration(self):
       
   133         tempzip = os.path.normpath(os.path.join(temp_dir, "temp1.zip"))
       
   134         self.remove_if_exists(tempzip)
       
   135         
       
   136         prj = None
       
   137         conf = None
       
   138         try:
       
   139             prj = api.Project(api.Storage.open(tempzip,"w"))
       
   140             conf = prj.create_configuration("dummy.confml")
       
   141             conf.set_name("dummy")
       
   142             self.assertTrue(conf)
       
   143             self.assertEquals(conf.get_name(),'dummy')
       
   144             self.assertTrue(isinstance(conf,api.Configuration))
       
   145         finally:
       
   146             if conf != None: conf.close()
       
   147             if prj != None:  prj.close()
       
   148 
       
   149     def test_create_close_open_configuration(self):
       
   150         tempzip_orig = os.path.normpath(os.path.join(temp_dir, "temp2_orig.zip"))
       
   151         tempzip_copy = os.path.normpath(os.path.join(temp_dir, "temp2_copy.zip"))
       
   152         self.remove_if_exists([tempzip_orig, tempzip_copy])
       
   153         
       
   154         prj = api.Project(api.Storage.open(tempzip_orig,"w"))
       
   155         conf = prj.create_configuration("dummy2.confml")
       
   156         conf.set_name("dummy")
       
   157         prop1 = model.ConfmlMetaProperty('owner', 'teemu rytkonen', 'http://www.s60.com/xml/confml/2')
       
   158         prop2 = model.ConfmlMetaProperty('purpose', 'for testing', 'http://www.s60.com/xml/confml/2')
       
   159         conf.meta = model.ConfmlMeta([prop1, prop2])        
       
   160         conf.desc = "Testing to see a configuration created"
       
   161         conf.create_configuration("test/path/to/somewhere/r.confml")
       
   162         conf.create_configuration("test/path/to/elsewhere/r.confml")
       
   163         conf.save()
       
   164         prj.save()
       
   165         prj.close()
       
   166         
       
   167         # Make a copy of the created zip file
       
   168         shutil.copy2(tempzip_orig, tempzip_copy)
       
   169         # If everything has been closed properly, the original zip file
       
   170         # should now be removable
       
   171         os.remove(tempzip_orig)
       
   172         
       
   173         # Read back data from the copy
       
   174         prj = api.Project(api.Storage.open(tempzip_copy,"r"))
       
   175         conf2 = prj.get_configuration("dummy2.confml")        
       
   176         self.assertEquals(conf.get_name(),conf2.get_name())
       
   177         self.assertEquals(conf.meta,conf2.meta)
       
   178         self.assertEquals(conf.desc,conf2.desc)
       
   179         self.assertEquals(conf.list_configurations(),conf2.list_configurations())
       
   180     
       
   181 if __name__ == '__main__':
       
   182     unittest.main()