1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/update-packaging/test_make_incremental_updates.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,151 @@ 1.4 +#!/usr/bin/python 1.5 +# This Source Code Form is subject to the terms of the Mozilla Public 1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 + 1.10 +import unittest 1.11 +import make_incremental_updates as mkup 1.12 +from make_incremental_updates import PatchInfo, MarFileEntry 1.13 + 1.14 +class TestPatchInfo(unittest.TestCase): 1.15 + def setUp(self): 1.16 + self.work_dir = 'work_dir' 1.17 + self.file_exclusion_list = ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files'] 1.18 + self.path_exclusion_list = ['/readme.txt'] 1.19 + self.patch_info = PatchInfo(self.work_dir, self.file_exclusion_list, self.path_exclusion_list) 1.20 + 1.21 + def testPatchInfo(self): 1.22 + self.assertEquals(self.work_dir, self.patch_info.work_dir) 1.23 + self.assertEquals([], self.patch_info.archive_files) 1.24 + self.assertEquals([], self.patch_info.manifestv2) 1.25 + self.assertEquals([], self.patch_info.manifestv3) 1.26 + self.assertEquals(self.file_exclusion_list, self.patch_info.file_exclusion_list) 1.27 + self.assertEquals(self.path_exclusion_list, self.patch_info.path_exclusion_list) 1.28 + 1.29 + def test_append_add_instruction(self): 1.30 + self.patch_info.append_add_instruction('file.test') 1.31 + self.assertEquals(['add "file.test"'], self.patch_info.manifestv2) 1.32 + self.assertEquals(['add "file.test"'], self.patch_info.manifestv3) 1.33 + 1.34 + def test_append_add_if_instruction(self): 1.35 + self.patch_info.append_add_instruction('distribution/extensions/extension/file.test') 1.36 + self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2) 1.37 + self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3) 1.38 + 1.39 + def test_append_add_if_not_instruction(self): 1.40 + self.patch_info.append_add_if_not_instruction('file.test') 1.41 + self.assertEquals([], self.patch_info.manifestv2) 1.42 + self.assertEquals(['add-if-not "file.test" "file.test"'], self.patch_info.manifestv3) 1.43 + 1.44 + def test_append_patch_instruction(self): 1.45 + self.patch_info.append_patch_instruction('file.test', 'patchname') 1.46 + self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv2) 1.47 + self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv3) 1.48 + 1.49 + def test_append_patch_if_instruction(self): 1.50 + self.patch_info.append_patch_instruction('distribution/extensions/extension/file.test', 'patchname') 1.51 + self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2) 1.52 + self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3) 1.53 + 1.54 + def test_append_remove_instruction(self): 1.55 + self.patch_info.append_remove_instruction('file.test') 1.56 + self.assertEquals(['remove "file.test"'], self.patch_info.manifestv2) 1.57 + self.assertEquals(['remove "file.test"'], self.patch_info.manifestv3) 1.58 + 1.59 + def test_append_rmdir_instruction(self): 1.60 + self.patch_info.append_remove_instruction('dirtest/') 1.61 + self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv2) 1.62 + self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv3) 1.63 + 1.64 + def test_append_rmrfdir_instruction(self): 1.65 + self.patch_info.append_remove_instruction('dirtest/*') 1.66 + self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv2) 1.67 + self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv3) 1.68 + 1.69 + """ FIXME touches the filesystem, need refactoring 1.70 + def test_create_manifest_file(self): 1.71 + self.patch_info.create_manifest_file() 1.72 + """ 1.73 + 1.74 + def test_build_marfile_entry_hash(self): 1.75 + self.assertEquals(({}, set([]), set([])), self.patch_info.build_marfile_entry_hash('root_path')) 1.76 + 1.77 +""" FIXME touches the filesystem, need refactoring 1.78 +class TestMarFileEntry(unittest.TestCase): 1.79 + def setUp(self): 1.80 + root_path = '.' 1.81 + self.filename = 'file.test' 1.82 + f = open(self.filename, 'w') 1.83 + f.write('Test data\n') 1.84 + f.close() 1.85 + self.mar_file_entry = MarFileEntry(root_path, self.filename) 1.86 + 1.87 + def test_calc_file_sha_digest(self): 1.88 + f = open('test.sha', 'r') 1.89 + goodSha = f.read() 1.90 + f.close() 1.91 + sha = self.mar_file_entry.calc_file_sha_digest(self.filename) 1.92 + self.assertEquals(goodSha, sha) 1.93 + 1.94 + def test_sha(self): 1.95 + f = open('test.sha', 'r') 1.96 + goodSha = f.read() 1.97 + f.close() 1.98 + sha = self.mar_file_entry.sha() 1.99 + self.assertEquals(goodSha, sha) 1.100 +""" 1.101 + 1.102 +class TestMakeIncrementalUpdates(unittest.TestCase): 1.103 + def setUp(self): 1.104 + work_dir = '.' 1.105 + self.patch_info = PatchInfo(work_dir, ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files'],['/readme.txt']) 1.106 + root_path = '/' 1.107 + filename = 'test.file' 1.108 + self.mar_file_entry = MarFileEntry(root_path, filename) 1.109 + 1.110 + """ FIXME makes direct shell calls, need refactoring 1.111 + def test_exec_shell_cmd(self): 1.112 + mkup.exec_shell_cmd('echo test') 1.113 + 1.114 + def test_copy_file(self): 1.115 + mkup.copy_file('src_file_abs_path', 'dst_file_abs_path') 1.116 + 1.117 + def test_bzip_file(self): 1.118 + mkup.bzip_file('filename') 1.119 + 1.120 + def test_bunzip_file(self): 1.121 + mkup.bunzip_file('filename') 1.122 + 1.123 + def test_extract_mar(self): 1.124 + mkup.extract_mar('filename', 'work_dir') 1.125 + 1.126 + def test_create_partial_patch_for_file(self): 1.127 + mkup.create_partial_patch_for_file('from_marfile_entry', 'to_marfile_entry', 'shas', self.patch_info) 1.128 + 1.129 + def test_create_add_patch_for_file(self): 1.130 + mkup.create_add_patch_for_file('to_marfile_entry', self.patch_info) 1.131 + 1.132 + def test_process_explicit_remove_files(self): 1.133 + mkup.process_explicit_remove_files('dir_path', self.patch_info) 1.134 + 1.135 + def test_create_partial_patch(self): 1.136 + mkup.create_partial_patch('from_dir_path', 'to_dir_path', 'patch_filename', 'shas', self.patch_info, 'forced_updates') 1.137 + 1.138 + def test_create_partial_patches(patches): 1.139 + mkup.create_partial_patches('patches') 1.140 + 1.141 + """ 1.142 + 1.143 + """ FIXME touches the filesystem, need refactoring 1.144 + def test_get_buildid(self): 1.145 + mkup.get_buildid('work_dir', 'platform') 1.146 + """ 1.147 + 1.148 + def test_decode_filename(self): 1.149 + expected = {'locale': 'lang', 'platform': 'platform', 'product': 'product', 'version': '1.0', 'type': 'complete'} 1.150 + self.assertEquals(expected, mkup.decode_filename('product-1.0.lang.platform.complete.mar')) 1.151 + self.assertRaises(Exception, mkup.decode_filename, 'fail') 1.152 + 1.153 +if __name__ == '__main__': 1.154 + unittest.main()