buildframework/helium/sf/python/pythoncore/lib/pythoncoretests/test_ccm_object.py
author wbernard
Thu, 22 Jul 2010 17:08:43 +0300
branchhelium-9.0
changeset 618 df88fead2976
parent 587 85df38eb4012
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_ccm_object.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
""" Test cases for ccm python toolkit.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
    unitesting CCMObject functionality
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import ccm
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
# Uncomment this line to enable logging in this module, or configure logging elsewhere
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
logging.basicConfig(level=logging.DEBUG)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
logger = logging.getLogger('test.ccm_objects')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
#class CCMObjectTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
#    """ Module related to CCMObject (and related) function testing. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
#    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
#    def setUp(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
#        #vc1tltst
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
#        self.session = ccm.open_session(database = 'to1tobet')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
#        if self.session is None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
#            logger.error("Error creating connection.")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
#            raise Exception("Couldn't open a session.")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
#    def tearDown(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
#        """ End of test: close opened synergy sessions. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
#        if self.session is not None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
#            self.session.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
#            self.session = None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
#        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
#    def test_query(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
#        """ Test simple synergy query that returns an object list. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
#        result = self.session.execute("query \"name='mc'and type='project' and status='released'\" /u /f \"%objectname\"", ccm.ObjectListResult(self.session))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
#        for o in result.output:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
#            assert o.type == 'project'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
#            assert o['status'] == 'released'
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
#                    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
#    def _test_checkout(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
#        """ Test project checkout. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
#        project = self.session.create("mc-mc_4032_0728:project:vc1s60p1#1")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
#        release = self.session.create("mc/next")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
#        if not project.exists():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
#           logger.error("Project doesn't exists.")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
#           return       
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
#        if not release.exists():           
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
#           logger.error("Release doesn't exists.")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
#           return
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
#           
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
#        coproject = project.checkout(release).project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
#        assert coproject != None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
#        assert coproject.name == project.name
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
#        assert coproject.type == project.type
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
#        assert coproject.instance == project.instance
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
#        try:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
#            coproject2 = project.checkout(release, coproject.version).project
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
#            assert False, "Should fail as we are specifying an already existing version."
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
#        except Exception, e:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
#            pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
#        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
#
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
class MockResultSession(ccm.AbstractSession):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
    """ Fake session used to test Result"""
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
    def __init__(self, behave = {}, database="fakedb"):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        ccm.AbstractSession.__init__(self, None, None, None, None)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
        self._behave = behave
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
        self._database = database
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
    def database(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        return self._database
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    def execute(self, cmdline, result=None):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        logger.debug(cmdline)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        if result == None:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
            result = ccm.Result(self)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
        if self._behave.has_key(cmdline):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
            result.status = 0  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
            result.output = self._behave[cmdline]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        else:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
            result.status = -1  
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        return result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
class CCMObjectTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
    """ Unit test case for CCMObject functionality """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
    def test_get_baseline(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        behave = {'up -show baseline_project "foo-1.0:project:db#1" -f "%displayname" -u': """foo-1.0:project:db#1 does not have a baseline project.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
""",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
                  'up -show baseline_project "foo-2.0:project:db#1" -f "%displayname" -u': """foo-1.0:project:db#1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
"""}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        session = MockResultSession(behave)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        objv1 = session.create('foo-1.0:project:db#1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
        assert objv1.baseline == None
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
        objv2 = session.create('foo-2.0:project:db#1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
        assert objv2.baseline == objv1
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
    def test_delete_project(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
        """ Check project deletion """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
        behave = {'delete  -project "project-1:project:db#1"': "Deleting object 'project-1:project:db#1'"}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
        session = MockResultSession(behave)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
        project = session.create('project-1:project:db#1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        result = project.delete()        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        assert "Deleting object 'project-1:project:db#1'" in result.output
618
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   120
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   121
    def test_delete_project_scope(self):
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   122
        """ Check project deletion with custom scope """
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   123
        behave = {'delete  -scope "project_and_subproject_hierarchy" -project "project-1:project:db#1"': "Deleting object 'project-1:project:db#1'"}
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   124
        session = MockResultSession(behave)
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   125
        project = session.create('project-1:project:db#1')
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   126
        result = project.delete(scope='project_and_subproject_hierarchy')        
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   127
        assert "Deleting object 'project-1:project:db#1'" in result.output
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   128
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   129
    def test_delete_project_invalid_args(self):
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   130
        """ Check project synergy is failing in case of bad synergy parameters for delete """
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   131
        behave = {'delete  -project "project-1:project:db#1"': "Cannot use '-scope' option with '-r' option."}
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   132
        session = MockResultSession(behave)
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   133
        project = session.create('project-1:project:db#1')
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   134
        try:
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   135
            result = project.delete(recurse=True, scope='project_and_subproject_hierarchy')        
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   136
            assert False, "The delete method must fail in case of synergy failure"
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   137
        except:
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   138
            pass
df88fead2976 helium_9.0.5-4399343f4f50
wbernard
parents: 587
diff changeset
   139
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
    def test_delete_object(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
        """ Check object deletion """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
        behave = {'delete   "object-1:object:db#1"': "Deleting object 'object-1:object:db#1'"}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
        session = MockResultSession(behave)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   144
        o = session.create('object-1:object:db#1')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   145
        result = o.delete()        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   146
        assert "Deleting object 'object-1:object:db#1'" in result.output
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   147
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   148
if __name__ == "__main__":
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   149
    unittest.main()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   150
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   151