configurationengine/source/scripts/tests/unittest_packvariant.py
changeset 3 e7e0ae78773e
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
       
     1 # *-* coding: utf-8 *-*
       
     2 #
       
     3 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 # This component and the accompanying materials are made available
       
     6 # under the terms of "Eclipse Public License v1.0"
       
     7 # which accompanies this distribution, and is available
       
     8 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Nokia Corporation - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 #
       
    15 # Description:
       
    16 #
       
    17 ## 
       
    18 # @author Teemu Rytkonen
       
    19 
       
    20 import os, unittest
       
    21 
       
    22 from testautomation import unzip_file
       
    23 from testautomation.base_testcase import BaseTestCase
       
    24 from scripttest_common import get_cmd
       
    25 
       
    26 
       
    27 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    28 rootconf = 'testprod_custvariant_root.confml'
       
    29 
       
    30 TESTDATA_DIR = os.path.join(ROOT_PATH, 'testdata/packvariant')
       
    31 TEMP_DIR = os.path.join(ROOT_PATH, 'temp/packvariant')
       
    32 
       
    33 class TestPackvariant(BaseTestCase):
       
    34     def test_get_help(self):
       
    35         cmd = '%s -h' % get_cmd('packvariant')
       
    36         out = self.run_command(cmd)
       
    37         lines = out.split(os.linesep)
       
    38         self.assertTrue('Options:' in lines)
       
    39         self.assertTrue('  Packvariant options:' in lines)
       
    40 
       
    41     def test_packvariant(self):
       
    42         PROJECT_DIR = os.path.join(ROOT_PATH, TESTDATA_DIR, 'project')
       
    43         REMOTE_ZIP = os.path.join(ROOT_PATH, TEMP_DIR, 'output/packvariant.zip')
       
    44         EXPECTED_ZIP = os.path.join(ROOT_PATH, TESTDATA_DIR, 'expected/packvariant.zip')
       
    45 
       
    46         self.remove_if_exists(REMOTE_ZIP)
       
    47         cmd = '%s -p "%s" -c "%s" -r "%s"' % (get_cmd('packvariant'),PROJECT_DIR,rootconf,REMOTE_ZIP)
       
    48         out = self.run_command(cmd)
       
    49         self.assert_exists_and_contains_something(REMOTE_ZIP)
       
    50         
       
    51         REMOTE_TEMP_DIR = os.path.join(TEMP_DIR, 'output/remote')
       
    52         EXPECTED_TEMP_DIR = os.path.join(TEMP_DIR, 'output/expected')
       
    53 
       
    54         self.remove_if_exists(REMOTE_TEMP_DIR)    
       
    55         self.remove_if_exists(EXPECTED_TEMP_DIR)    
       
    56 
       
    57         unzip_file.unzip_file(
       
    58             REMOTE_ZIP,
       
    59             REMOTE_TEMP_DIR)
       
    60         unzip_file.unzip_file(
       
    61             EXPECTED_ZIP,
       
    62             EXPECTED_TEMP_DIR)
       
    63         
       
    64         self.assert_dir_contents_equal(REMOTE_TEMP_DIR, EXPECTED_TEMP_DIR, ignore=['.svn'])
       
    65 
       
    66     def test_packvariant_project_does_not_exist(self):
       
    67         PROJECT_DIR = os.path.join(ROOT_PATH, TESTDATA_DIR, 'project_does_not_exist')
       
    68         REMOTE_ZIP = os.path.join(ROOT_PATH, TEMP_DIR, 'output/packvariant.zip')
       
    69 
       
    70         self.remove_if_exists(REMOTE_ZIP)
       
    71         cmd = '%s -p "%s" -c "%s" -r "%s"' % (get_cmd('packvariant'),PROJECT_DIR,rootconf,REMOTE_ZIP)
       
    72         
       
    73         self._run_test(
       
    74            cmd, 2,
       
    75            "Could not create Zip archive: The given data folder for storage does not exist!")
       
    76 
       
    77 
       
    78     def test_packvariant_configuration_does_not_exist(self):
       
    79         PROJECT_DIR = os.path.join(ROOT_PATH, TESTDATA_DIR, 'project')
       
    80         REMOTE_ZIP = os.path.join(ROOT_PATH, TEMP_DIR, 'output', 'packvariant.zip')
       
    81         rootconf = 'root_does_not_exist.confml'
       
    82         expected_msg = "Could not create Zip archive: Child root_does_not_exist_confml not found from Project"
       
    83         
       
    84         self.remove_if_exists(REMOTE_ZIP)
       
    85         cmd = '%s -p "%s" -c "%s" -r "%s"' % (get_cmd('packvariant'),PROJECT_DIR,rootconf,REMOTE_ZIP)
       
    86         out = self.run_command(cmd, None)
       
    87         
       
    88         self.assertTrue(expected_msg in out,
       
    89                 "Expected message '%s' not in output ('%s')" % (expected_msg, out))
       
    90         
       
    91 
       
    92     def test_packvariant_project_is_not_a_folder(self):
       
    93         PROJECT_DIR = os.path.join(ROOT_PATH, TESTDATA_DIR, 'packvariant/project/testprod_custvariant_root.confml')
       
    94         REMOTE_ZIP = os.path.join(ROOT_PATH, TEMP_DIR, 'output/packvariant.zip')
       
    95 
       
    96         self.remove_if_exists(REMOTE_ZIP)
       
    97         cmd = '%s -p "%s" -c "%s" -r "%s"' % (get_cmd('packvariant'),PROJECT_DIR,rootconf,REMOTE_ZIP)
       
    98         
       
    99         self._run_test(
       
   100            cmd, 1,
       
   101            "ERROR: --Project must be a directory. Terminating the program.")
       
   102 
       
   103 
       
   104     def _run_test(self, args, expected_return_code, expected_msg):
       
   105         if not isinstance(args, basestring):
       
   106             args = ' '.join(args)
       
   107         
       
   108         cmd = get_cmd('packvariant') + ' ' + args
       
   109         out = self.run_command(cmd, expected_return_code = None)
       
   110         
       
   111         self.assertTrue(expected_msg in out,
       
   112                         "Expected message '%s' not in output ('%s')" % (expected_msg, out))
       
   113 
       
   114 if __name__ == '__main__':
       
   115     unittest.main()