buildframework/helium/sf/python/pythoncore/lib/pythoncorecpythontests/test_configuration_model.py
author wbernard
Thu, 22 Jul 2010 17:08:43 +0300
branchhelium-9.0
changeset 618 df88fead2976
parent 587 85df38eb4012
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0.5-4399343f4f50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
#============================================================================ 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
#Name        : test_configuration_model.py 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
#All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
#Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
#Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
#Description:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
#===============================================================================
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import nose
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import configuration
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import configuration_model
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
logger = logging.getLogger('test.configuration_model')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
#logging.basicConfig(level=logging.DEBUG)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
class GroupDefTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
    """ Check config model groups are correctly defined. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
    def setUp(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
        """ Create model. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        self.model = configuration_model.DataModel(os.environ['TEST_DATA'] + '/data/data_model_test.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
    def test_init_model(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        """ Test groups can be created. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
        assert len(self.model.properties.keys()) == 3
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        assert len(self.model.groups.keys()) == 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        prop1 = self.model.properties['test.property.1']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        assert prop1.description == 'Test property one.'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
        prop2 = self.model.properties['test.property.2']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        assert prop2.description == 'Test property two.'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        assert self.model.groups['testGroup'] != None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
    def test_property_not_in_model(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        """ Property not in model is identified. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        data = {'missing.property': 'foobar', 'test.property.1': '1'}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        config = configuration.Configuration(data)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        items = self.model.validate_config(config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        assert len(items) == 2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
        assert isinstance(items[0], configuration_model.MissingFromDataModelItem)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
    def test_required_property_in_group_not_defined(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        """ Required property in a group missing from config is identified. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
        config = configuration.Configuration({'test.property.1': '1', 'test.property.3': '3'})
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
        items = self.model.validate_config(config)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        assert len(items) == 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
        assert isinstance(items[0], configuration_model.UndefinedRequiredInGroupItem)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
class MissingFromDataModelItemTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
    """ Item class operations. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
    def test_create(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        """ Basic validation item usage. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        item = configuration_model.MissingFromDataModelItem('test.property')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        self.assert_(str(item) == 'Property not in data model: test.property')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        item.log(logger)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
class DataModelTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
    """ Checks Data Model is properly defined """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
    def setUp(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        """ Create model. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        self.model = configuration_model.DataModel(os.environ['TEST_DATA'] + '/data/data_model_validation_test.xml')    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
       
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
    def test_init_model(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        """ Test groups can be created. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        assert len(self.model.properties.keys()) == 3
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        assert len(self.model.groups.keys()) == 1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        prop1 = self.model.properties['test.property.1']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
        assert prop1.type == 'string'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
        assert prop1.description == 'Test property one.'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        prop2 = self.model.properties['test.property.2']
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        assert prop2.type == 'string'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        assert prop2.description == 'Test property two.'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        assert self.model.groups['testGroup'] != None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
class DataModelPropertyTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
    """ Checks Data Model that an exception is thrown if properties are not properly defined """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
    @nose.tools.raises(Exception)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
    def setUp(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        """ Create model. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        self.model = configuration_model.DataModel(os.environ['TEST_DATA'] + '/data/data_model_validation__property_test.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
class DataModelGroupTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
    """ Checks Data Model that an exception is thrown if there is a required property in groups is missing"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
    @nose.tools.raises(Exception)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
    def setUp(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
        """ Create model. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
        self.model = configuration_model.DataModel(os.environ['TEST_DATA'] + '/data/data_model_validation_group_test.xml')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119