tools/update-packaging/test_make_incremental_updates.py

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 #!/usr/bin/python
michael@0 2 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 5
michael@0 6
michael@0 7 import unittest
michael@0 8 import make_incremental_updates as mkup
michael@0 9 from make_incremental_updates import PatchInfo, MarFileEntry
michael@0 10
michael@0 11 class TestPatchInfo(unittest.TestCase):
michael@0 12 def setUp(self):
michael@0 13 self.work_dir = 'work_dir'
michael@0 14 self.file_exclusion_list = ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files']
michael@0 15 self.path_exclusion_list = ['/readme.txt']
michael@0 16 self.patch_info = PatchInfo(self.work_dir, self.file_exclusion_list, self.path_exclusion_list)
michael@0 17
michael@0 18 def testPatchInfo(self):
michael@0 19 self.assertEquals(self.work_dir, self.patch_info.work_dir)
michael@0 20 self.assertEquals([], self.patch_info.archive_files)
michael@0 21 self.assertEquals([], self.patch_info.manifestv2)
michael@0 22 self.assertEquals([], self.patch_info.manifestv3)
michael@0 23 self.assertEquals(self.file_exclusion_list, self.patch_info.file_exclusion_list)
michael@0 24 self.assertEquals(self.path_exclusion_list, self.patch_info.path_exclusion_list)
michael@0 25
michael@0 26 def test_append_add_instruction(self):
michael@0 27 self.patch_info.append_add_instruction('file.test')
michael@0 28 self.assertEquals(['add "file.test"'], self.patch_info.manifestv2)
michael@0 29 self.assertEquals(['add "file.test"'], self.patch_info.manifestv3)
michael@0 30
michael@0 31 def test_append_add_if_instruction(self):
michael@0 32 self.patch_info.append_add_instruction('distribution/extensions/extension/file.test')
michael@0 33 self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2)
michael@0 34 self.assertEquals(['add-if "distribution/extensions/extension" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3)
michael@0 35
michael@0 36 def test_append_add_if_not_instruction(self):
michael@0 37 self.patch_info.append_add_if_not_instruction('file.test')
michael@0 38 self.assertEquals([], self.patch_info.manifestv2)
michael@0 39 self.assertEquals(['add-if-not "file.test" "file.test"'], self.patch_info.manifestv3)
michael@0 40
michael@0 41 def test_append_patch_instruction(self):
michael@0 42 self.patch_info.append_patch_instruction('file.test', 'patchname')
michael@0 43 self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv2)
michael@0 44 self.assertEquals(['patch "patchname" "file.test"'], self.patch_info.manifestv3)
michael@0 45
michael@0 46 def test_append_patch_if_instruction(self):
michael@0 47 self.patch_info.append_patch_instruction('distribution/extensions/extension/file.test', 'patchname')
michael@0 48 self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv2)
michael@0 49 self.assertEquals(['patch-if "distribution/extensions/extension" "patchname" "distribution/extensions/extension/file.test"'], self.patch_info.manifestv3)
michael@0 50
michael@0 51 def test_append_remove_instruction(self):
michael@0 52 self.patch_info.append_remove_instruction('file.test')
michael@0 53 self.assertEquals(['remove "file.test"'], self.patch_info.manifestv2)
michael@0 54 self.assertEquals(['remove "file.test"'], self.patch_info.manifestv3)
michael@0 55
michael@0 56 def test_append_rmdir_instruction(self):
michael@0 57 self.patch_info.append_remove_instruction('dirtest/')
michael@0 58 self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv2)
michael@0 59 self.assertEquals(['rmdir "dirtest/"'], self.patch_info.manifestv3)
michael@0 60
michael@0 61 def test_append_rmrfdir_instruction(self):
michael@0 62 self.patch_info.append_remove_instruction('dirtest/*')
michael@0 63 self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv2)
michael@0 64 self.assertEquals(['rmrfdir "dirtest/"'], self.patch_info.manifestv3)
michael@0 65
michael@0 66 """ FIXME touches the filesystem, need refactoring
michael@0 67 def test_create_manifest_file(self):
michael@0 68 self.patch_info.create_manifest_file()
michael@0 69 """
michael@0 70
michael@0 71 def test_build_marfile_entry_hash(self):
michael@0 72 self.assertEquals(({}, set([]), set([])), self.patch_info.build_marfile_entry_hash('root_path'))
michael@0 73
michael@0 74 """ FIXME touches the filesystem, need refactoring
michael@0 75 class TestMarFileEntry(unittest.TestCase):
michael@0 76 def setUp(self):
michael@0 77 root_path = '.'
michael@0 78 self.filename = 'file.test'
michael@0 79 f = open(self.filename, 'w')
michael@0 80 f.write('Test data\n')
michael@0 81 f.close()
michael@0 82 self.mar_file_entry = MarFileEntry(root_path, self.filename)
michael@0 83
michael@0 84 def test_calc_file_sha_digest(self):
michael@0 85 f = open('test.sha', 'r')
michael@0 86 goodSha = f.read()
michael@0 87 f.close()
michael@0 88 sha = self.mar_file_entry.calc_file_sha_digest(self.filename)
michael@0 89 self.assertEquals(goodSha, sha)
michael@0 90
michael@0 91 def test_sha(self):
michael@0 92 f = open('test.sha', 'r')
michael@0 93 goodSha = f.read()
michael@0 94 f.close()
michael@0 95 sha = self.mar_file_entry.sha()
michael@0 96 self.assertEquals(goodSha, sha)
michael@0 97 """
michael@0 98
michael@0 99 class TestMakeIncrementalUpdates(unittest.TestCase):
michael@0 100 def setUp(self):
michael@0 101 work_dir = '.'
michael@0 102 self.patch_info = PatchInfo(work_dir, ['update.manifest','updatev2.manifest','updatev3.manifest','removed-files'],['/readme.txt'])
michael@0 103 root_path = '/'
michael@0 104 filename = 'test.file'
michael@0 105 self.mar_file_entry = MarFileEntry(root_path, filename)
michael@0 106
michael@0 107 """ FIXME makes direct shell calls, need refactoring
michael@0 108 def test_exec_shell_cmd(self):
michael@0 109 mkup.exec_shell_cmd('echo test')
michael@0 110
michael@0 111 def test_copy_file(self):
michael@0 112 mkup.copy_file('src_file_abs_path', 'dst_file_abs_path')
michael@0 113
michael@0 114 def test_bzip_file(self):
michael@0 115 mkup.bzip_file('filename')
michael@0 116
michael@0 117 def test_bunzip_file(self):
michael@0 118 mkup.bunzip_file('filename')
michael@0 119
michael@0 120 def test_extract_mar(self):
michael@0 121 mkup.extract_mar('filename', 'work_dir')
michael@0 122
michael@0 123 def test_create_partial_patch_for_file(self):
michael@0 124 mkup.create_partial_patch_for_file('from_marfile_entry', 'to_marfile_entry', 'shas', self.patch_info)
michael@0 125
michael@0 126 def test_create_add_patch_for_file(self):
michael@0 127 mkup.create_add_patch_for_file('to_marfile_entry', self.patch_info)
michael@0 128
michael@0 129 def test_process_explicit_remove_files(self):
michael@0 130 mkup.process_explicit_remove_files('dir_path', self.patch_info)
michael@0 131
michael@0 132 def test_create_partial_patch(self):
michael@0 133 mkup.create_partial_patch('from_dir_path', 'to_dir_path', 'patch_filename', 'shas', self.patch_info, 'forced_updates')
michael@0 134
michael@0 135 def test_create_partial_patches(patches):
michael@0 136 mkup.create_partial_patches('patches')
michael@0 137
michael@0 138 """
michael@0 139
michael@0 140 """ FIXME touches the filesystem, need refactoring
michael@0 141 def test_get_buildid(self):
michael@0 142 mkup.get_buildid('work_dir', 'platform')
michael@0 143 """
michael@0 144
michael@0 145 def test_decode_filename(self):
michael@0 146 expected = {'locale': 'lang', 'platform': 'platform', 'product': 'product', 'version': '1.0', 'type': 'complete'}
michael@0 147 self.assertEquals(expected, mkup.decode_filename('product-1.0.lang.platform.complete.mar'))
michael@0 148 self.assertRaises(Exception, mkup.decode_filename, 'fail')
michael@0 149
michael@0 150 if __name__ == '__main__':
michael@0 151 unittest.main()

mercurial