configurationengine/source/cone/public/tests/unittest_options.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 sets
       
    19 """
       
    20 import unittest
       
    21 import sets
       
    22 import sys
       
    23 import os
       
    24 import __init__
       
    25 
       
    26 from cone.public import api,exceptions,utils
       
    27 
       
    28 
       
    29 class TestOption(unittest.TestCase):
       
    30     def test_create_option(self):
       
    31         elem = api.Option('test','123')
       
    32         self.assertTrue(elem)
       
    33         self.assertTrue(elem.get_name(),'test')
       
    34         self.assertTrue(elem.get_value(),'123')
       
    35     
       
    36     def test_add_option(self):
       
    37         fea = api.Feature('test')
       
    38         fea.add_option(api.Option('foo','1'))
       
    39         fea.add_option(api.Option('test','2'))
       
    40         self.assertEquals(fea.list_options(), ['value_1','value_2'])
       
    41     
       
    42     def test_add_option_invalid_param(self):
       
    43         fea = api.Feature('test')
       
    44         self.assertRaises(TypeError, fea.add_option, object())
       
    45 
       
    46     def test_option_compare(self):
       
    47         elem1 = api.Option('test','1')
       
    48         elem2 = api.Option('foo','2')
       
    49         elem3 = api.Option('test','3')
       
    50         self.assertFalse(elem1==elem2)
       
    51         self.assertFalse(elem1==elem3)
       
    52         self.assertTrue(elem1=='opt_value_1')
       
    53         self.assertTrue(elem2=='opt_value_2')
       
    54         self.assertTrue('opt_value_2' == elem2)
       
    55 
       
    56     def test_create_feature_with_options(self):
       
    57         fea = api.Feature('test')
       
    58         fea.create_option('foo','3')
       
    59         fea.create_option('test','4')
       
    60         self.assertEquals(fea.list_options(), ['value_3','value_4'])
       
    61         self.assertEquals(fea.opt_value_3.get_name(),'foo')
       
    62         self.assertEquals(fea.opt_value_3.get_value(),'3')
       
    63         self.assertEquals(fea.opt_value_4.get_name(),'test')
       
    64         self.assertEquals(fea.opt_value_4.get_value(),'4')
       
    65     
       
    66     def test_list_and_get_options(self):
       
    67         fea = api.Feature('test')
       
    68         fea.create_option('foo','1')
       
    69         fea.create_option('test','2')
       
    70         fea.create_option('bar','3')
       
    71         
       
    72         self.assertEquals(fea.list_options(), ['value_1', 'value_2', 'value_3'])
       
    73         
       
    74         self.assertEquals(fea.get_option('value_1').get_name(), 'foo')
       
    75         self.assertEquals(fea.get_option('value_2').get_name(), 'test')
       
    76         self.assertEquals(fea.get_option('value_3').get_name(), 'bar')
       
    77     
       
    78     def test_get_option_nonexistent(self):
       
    79         fea = api.Feature('test')
       
    80         self.assertRaises(exceptions.NotFound, fea.get_option, 'foo')
       
    81     
       
    82     def test_get_option_invalid_type(self):
       
    83         fea = api.Feature('test')
       
    84         fea.add(api.Feature('opt_foo'))
       
    85         self.assertRaises(TypeError, fea.get_option, 'foo')
       
    86     
       
    87     def test_remove_option(self):
       
    88         fea = api.Feature('test')
       
    89         fea.create_option('foo','1')
       
    90         fea.create_option('test','2')
       
    91         fea.create_option('bar','3')
       
    92         self.assertEquals(fea.list_options(), ['value_1', 'value_2', 'value_3'])
       
    93         
       
    94         fea.remove_option('value_2')
       
    95         self.assertEquals(fea.list_options(), ['value_1', 'value_3'])
       
    96     
       
    97     def test_remove_option_nonexistent(self):
       
    98         fea = api.Feature('test')
       
    99         self.assertRaises(exceptions.NotFound, fea.remove_option, 'xyz')
       
   100     
       
   101     def test_remove_option_invalid_param(self):
       
   102         fea = api.Feature('test')
       
   103         fea.add(api.Feature('opt_xyz'))
       
   104         self.assertRaises(TypeError, fea.remove_option, 'xyz')