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