587
|
1 |
#============================================================================
|
|
2 |
#Name : test_ctc.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
588
|
19 |
""" test ctc"""
|
587
|
20 |
|
|
21 |
import unittest
|
|
22 |
import ctc
|
|
23 |
import logging
|
|
24 |
import os
|
|
25 |
import fileutils
|
|
26 |
import tempfile
|
|
27 |
|
|
28 |
_logger = logging.getLogger('test.configuration')
|
|
29 |
logging.basicConfig(level=logging.INFO)
|
|
30 |
|
588
|
31 |
_root_test_dir = tempfile.mkdtemp()
|
587
|
32 |
_test_file_paths = [
|
|
33 |
"ctc/dir/component1/group/MON.SYM",
|
|
34 |
"ctc/dir/component2/group/",
|
|
35 |
"ctc/dir/component3/group/MON.SYM",
|
|
36 |
]
|
|
37 |
|
|
38 |
def _testpath(subpath):
|
|
39 |
""" Normalised path for test paths. """
|
588
|
40 |
return os.path.normpath(os.path.join(_root_test_dir, subpath))
|
587
|
41 |
|
|
42 |
_test_file_content = {}
|
|
43 |
|
|
44 |
def setup_module():
|
|
45 |
""" Setup files test config.
|
|
46 |
|
|
47 |
This creates a number of empty files in a temporary directory structure
|
|
48 |
for testing various file selection and archiving operations.
|
|
49 |
"""
|
|
50 |
for child_path in _test_file_paths:
|
588
|
51 |
path = os.path.join(_root_test_dir, child_path)
|
587
|
52 |
path_dir = path
|
|
53 |
path_dir = os.path.dirname(path)
|
|
54 |
|
|
55 |
if (not os.path.exists(path_dir)):
|
|
56 |
_logger.debug('Creating dir: ' + path_dir)
|
|
57 |
os.makedirs(path_dir)
|
|
58 |
|
|
59 |
if(not path.endswith('/') and not path.endswith('\\')):
|
|
60 |
_logger.debug('Creating file: ' + path)
|
|
61 |
handle = open(path, 'w')
|
|
62 |
# Write any file content that is needed
|
|
63 |
if _test_file_content.has_key(child_path):
|
|
64 |
handle.write(_test_file_content[child_path])
|
|
65 |
handle.close()
|
|
66 |
|
|
67 |
def teardown_module():
|
|
68 |
""" Teardown test config. """
|
588
|
69 |
if os.path.exists(_root_test_dir):
|
|
70 |
fileutils.rmtree(_root_test_dir)
|
587
|
71 |
|
|
72 |
|
|
73 |
class MockUploader(ctc.MonSymFTPUploader):
|
|
74 |
""" This class provides a mock MonSymFTPUploader """
|
|
75 |
def _open(self):
|
588
|
76 |
"""open"""
|
587
|
77 |
pass
|
|
78 |
|
|
79 |
def _close(self):
|
588
|
80 |
"""close"""
|
587
|
81 |
pass
|
|
82 |
|
628
|
83 |
def _ftpmkdirs(self, dir_):
|
588
|
84 |
"""ftp make dirs"""
|
587
|
85 |
pass
|
|
86 |
|
|
87 |
def _send(self, src, dst):
|
588
|
88 |
"""send"""
|
587
|
89 |
pass
|
|
90 |
|
|
91 |
class NestedConfigurationBuilderTest(unittest.TestCase):
|
|
92 |
""" Unit test for ctc uploader """
|
|
93 |
def test_uploader(self):
|
588
|
94 |
"""test uploader"""
|
587
|
95 |
paths = [ "ctc/dir/component1/group/MON.SYM",
|
|
96 |
"ctc/dir/component2/group/MON.SYM",
|
|
97 |
"ctc/dir/component3/group/MON.SYM",
|
|
98 |
]
|
|
99 |
uploader = MockUploader("server", [_testpath(p) for p in paths], "1234")
|
|
100 |
result = uploader.upload()
|
|
101 |
print result
|
|
102 |
assert len(result) == 2
|
628
|
103 |
assert result[0] == "1234/mon_syms/1/MON.SYM"
|
|
104 |
assert result[1] == "1234/mon_syms/2/MON.SYM"
|