buildframework/helium/sf/python/pythoncore/lib/pythoncoretests/test_ctc.py
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0-a7879c935424
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_ctc.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 unittest
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import ctc
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
import logging
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import os
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import fileutils
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
import tempfile
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
_logger = logging.getLogger('test.configuration')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
logging.basicConfig(level=logging.INFO)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
root_test_dir = tempfile.mkdtemp()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
_test_file_paths = [
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
                    "ctc/dir/component1/group/MON.SYM",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
                    "ctc/dir/component2/group/",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
                    "ctc/dir/component3/group/MON.SYM",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
def _testpath(subpath):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    """ Normalised path for test paths. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
    return os.path.normpath(os.path.join(root_test_dir, subpath))
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
_test_file_content = {}
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
def setup_module():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
    """ Setup files test config. 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
    This creates a number of empty files in a temporary directory structure
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    for testing various file selection and archiving operations.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
    """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    for child_path in _test_file_paths:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
        path = os.path.join(root_test_dir, child_path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
        path_dir = path
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
        path_dir = os.path.dirname(path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
        if (not os.path.exists(path_dir)):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
            _logger.debug('Creating dir:  ' + path_dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
            os.makedirs(path_dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        if(not path.endswith('/') and not path.endswith('\\')):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
            _logger.debug('Creating file: ' + path)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
            handle = open(path, 'w')
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
            # Write any file content that is needed
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
            if _test_file_content.has_key(child_path):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
                handle.write(_test_file_content[child_path])
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
            handle.close()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
def teardown_module():
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    """ Teardown test config. """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
    if os.path.exists(root_test_dir):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        fileutils.rmtree(root_test_dir)
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
class MockUploader(ctc.MonSymFTPUploader):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    """ This class provides a mock MonSymFTPUploader """
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
    def _open(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
    def _close(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
    def _ftpmkdirs(self, dir):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
        pass    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
    def _send(self, src, dst):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
        pass
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
class NestedConfigurationBuilderTest(unittest.TestCase):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
    """ Unit test for ctc uploader """    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
    def test_uploader(self):
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        paths = [   "ctc/dir/component1/group/MON.SYM",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
                    "ctc/dir/component2/group/MON.SYM",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
                    "ctc/dir/component3/group/MON.SYM",
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
                    ]
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
        uploader = MockUploader("server", [_testpath(p) for p in paths], "1234")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
        result = uploader.upload()
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
        print result
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
        assert len(result) == 2
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
        assert result[0] == "ctc_helium/1234/mon_syms/1/MON.SYM"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        assert result[1] == "ctc_helium/1234/mon_syms/2/MON.SYM"