michael@0: #!/usr/bin/python michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: import unittest michael@0: import make_incremental_updates as mkup michael@0: from make_incremental_updates import PatchInfo, MarFileEntry michael@0: michael@0: class TestPatchInfo(unittest.TestCase): michael@0: def setUp(self): michael@0: self.work_dir = 'work_dir' michael@0: self.file_exclusion_list = ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files'] michael@0: self.path_exclusion_list = ['/readme.txt'] michael@0: self.patch_info = PatchInfo(self.work_dir, self.file_exclusion_list, self.path_exclusion_list) michael@0: michael@0: def testPatchInfo(self): michael@0: self.assertEquals(self.work_dir, self.patch_info.work_dir) michael@0: self.assertEquals([], self.patch_info.archive_files) michael@0: self.assertEquals([], self.patch_info.manifestv2) michael@0: self.assertEquals([], self.patch_info.manifestv3) michael@0: self.assertEquals(self.file_exclusion_list, self.patch_info.file_exclusion_list) michael@0: self.assertEquals(self.path_exclusion_list, self.patch_info.path_exclusion_list) michael@0: michael@0: def test_append_add_instruction(self): michael@0: self.patch_info.append_add_instruction('file.test') michael@0: self.assertEquals(['add "file.test"'], self.patch_info.manifestv2) michael@0: self.assertEquals(['add "file.test"'], self.patch_info.manifestv3) michael@0: michael@0: def test_append_add_if_instruction(self): michael@0: self.patch_info.append_add_instruction('distribution/extensions/extension/file.test') michael@0: self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2) michael@0: self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3) michael@0: michael@0: def test_append_add_if_not_instruction(self): michael@0: self.patch_info.append_add_if_not_instruction('file.test') michael@0: self.assertEquals([], self.patch_info.manifestv2) michael@0: self.assertEquals(['add-if-not "file.test" "file.test"'], self.patch_info.manifestv3) michael@0: michael@0: def test_append_patch_instruction(self): michael@0: self.patch_info.append_patch_instruction('file.test', 'patchname') michael@0: self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv2) michael@0: self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv3) michael@0: michael@0: def test_append_patch_if_instruction(self): michael@0: self.patch_info.append_patch_instruction('distribution/extensions/extension/file.test', 'patchname') michael@0: self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2) michael@0: self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3) michael@0: michael@0: def test_append_remove_instruction(self): michael@0: self.patch_info.append_remove_instruction('file.test') michael@0: self.assertEquals(['remove "file.test"'], self.patch_info.manifestv2) michael@0: self.assertEquals(['remove "file.test"'], self.patch_info.manifestv3) michael@0: michael@0: def test_append_rmdir_instruction(self): michael@0: self.patch_info.append_remove_instruction('dirtest/') michael@0: self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv2) michael@0: self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv3) michael@0: michael@0: def test_append_rmrfdir_instruction(self): michael@0: self.patch_info.append_remove_instruction('dirtest/*') michael@0: self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv2) michael@0: self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv3) michael@0: michael@0: """ FIXME touches the filesystem, need refactoring michael@0: def test_create_manifest_file(self): michael@0: self.patch_info.create_manifest_file() michael@0: """ michael@0: michael@0: def test_build_marfile_entry_hash(self): michael@0: self.assertEquals(({}, set([]), set([])), self.patch_info.build_marfile_entry_hash('root_path')) michael@0: michael@0: """ FIXME touches the filesystem, need refactoring michael@0: class TestMarFileEntry(unittest.TestCase): michael@0: def setUp(self): michael@0: root_path = '.' michael@0: self.filename = 'file.test' michael@0: f = open(self.filename, 'w') michael@0: f.write('Test data\n') michael@0: f.close() michael@0: self.mar_file_entry = MarFileEntry(root_path, self.filename) michael@0: michael@0: def test_calc_file_sha_digest(self): michael@0: f = open('test.sha', 'r') michael@0: goodSha = f.read() michael@0: f.close() michael@0: sha = self.mar_file_entry.calc_file_sha_digest(self.filename) michael@0: self.assertEquals(goodSha, sha) michael@0: michael@0: def test_sha(self): michael@0: f = open('test.sha', 'r') michael@0: goodSha = f.read() michael@0: f.close() michael@0: sha = self.mar_file_entry.sha() michael@0: self.assertEquals(goodSha, sha) michael@0: """ michael@0: michael@0: class TestMakeIncrementalUpdates(unittest.TestCase): michael@0: def setUp(self): michael@0: work_dir = '.' michael@0: self.patch_info = PatchInfo(work_dir, ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files'],['/readme.txt']) michael@0: root_path = '/' michael@0: filename = 'test.file' michael@0: self.mar_file_entry = MarFileEntry(root_path, filename) michael@0: michael@0: """ FIXME makes direct shell calls, need refactoring michael@0: def test_exec_shell_cmd(self): michael@0: mkup.exec_shell_cmd('echo test') michael@0: michael@0: def test_copy_file(self): michael@0: mkup.copy_file('src_file_abs_path', 'dst_file_abs_path') michael@0: michael@0: def test_bzip_file(self): michael@0: mkup.bzip_file('filename') michael@0: michael@0: def test_bunzip_file(self): michael@0: mkup.bunzip_file('filename') michael@0: michael@0: def test_extract_mar(self): michael@0: mkup.extract_mar('filename', 'work_dir') michael@0: michael@0: def test_create_partial_patch_for_file(self): michael@0: mkup.create_partial_patch_for_file('from_marfile_entry', 'to_marfile_entry', 'shas', self.patch_info) michael@0: michael@0: def test_create_add_patch_for_file(self): michael@0: mkup.create_add_patch_for_file('to_marfile_entry', self.patch_info) michael@0: michael@0: def test_process_explicit_remove_files(self): michael@0: mkup.process_explicit_remove_files('dir_path', self.patch_info) michael@0: michael@0: def test_create_partial_patch(self): michael@0: mkup.create_partial_patch('from_dir_path', 'to_dir_path', 'patch_filename', 'shas', self.patch_info, 'forced_updates') michael@0: michael@0: def test_create_partial_patches(patches): michael@0: mkup.create_partial_patches('patches') michael@0: michael@0: """ michael@0: michael@0: """ FIXME touches the filesystem, need refactoring michael@0: def test_get_buildid(self): michael@0: mkup.get_buildid('work_dir', 'platform') michael@0: """ michael@0: michael@0: def test_decode_filename(self): michael@0: expected = {'locale': 'lang', 'platform': 'platform', 'product': 'product', 'version': '1.0', 'type': 'complete'} michael@0: self.assertEquals(expected, mkup.decode_filename('product-1.0.lang.platform.complete.mar')) michael@0: self.assertRaises(Exception, mkup.decode_filename, 'fail') michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()