| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Unit tests for autoupdate.py.""" | 7 """Unit tests for autoupdate.py.""" |
| 8 | 8 |
| 9 import cherrypy | 9 import cherrypy |
| 10 import mox | 10 import mox |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 def _DummyAutoupdateConstructor(self): | 54 def _DummyAutoupdateConstructor(self): |
| 55 """Creates a dummy autoupdater. Used to avoid using constructor.""" | 55 """Creates a dummy autoupdater. Used to avoid using constructor.""" |
| 56 dummy = autoupdate.Autoupdate(root_dir=None, | 56 dummy = autoupdate.Autoupdate(root_dir=None, |
| 57 static_dir=self.static_image_dir, | 57 static_dir=self.static_image_dir, |
| 58 port=self.port) | 58 port=self.port) |
| 59 dummy.client_prefix = 'ChromeOSUpdateEngine' | 59 dummy.client_prefix = 'ChromeOSUpdateEngine' |
| 60 return dummy | 60 return dummy |
| 61 | 61 |
| 62 def testGenerateLatestUpdateImageWithForced(self): | 62 def testGenerateLatestUpdateImageWithForced(self): |
| 63 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateUpdateImage') | 63 self.mox.StubOutWithMock(autoupdate.Autoupdate, |
| 64 'GenerateUpdateImageWithCache') |
| 64 autoupdate.Autoupdate._GetLatestImageDir(self.test_board).AndReturn( | 65 autoupdate.Autoupdate._GetLatestImageDir(self.test_board).AndReturn( |
| 65 '%s/%s/%s' % (self.build_root, self.test_board, self.latest_dir)) | 66 '%s/%s/%s' % (self.build_root, self.test_board, self.latest_dir)) |
| 66 autoupdate.Autoupdate.GenerateUpdateImage( | 67 autoupdate.Autoupdate.GenerateUpdateImageWithCache( |
| 67 '%s/%s/%s/chromiumos_image.bin' % (self.build_root, self.test_board, | 68 '%s/%s/%s/chromiumos_image.bin' % (self.build_root, self.test_board, |
| 68 self.latest_dir), | 69 self.latest_dir), |
| 69 move_to_static_dir=True, | 70 static_image_dir=self.static_image_dir).AndReturn('update.gz') |
| 70 static_image_dir=self.static_image_dir).AndReturn(True) | |
| 71 | 71 |
| 72 self.mox.ReplayAll() | 72 self.mox.ReplayAll() |
| 73 au_mock = self._DummyAutoupdateConstructor() | 73 au_mock = self._DummyAutoupdateConstructor() |
| 74 self.assertTrue(au_mock.GenerateLatestUpdateImage(self.test_board, | 74 self.assertTrue(au_mock.GenerateLatestUpdateImage(self.test_board, |
| 75 'ForcedUpdate', | 75 'ForcedUpdate', |
| 76 self.static_image_dir)) | 76 self.static_image_dir)) |
| 77 self.mox.VerifyAll() | 77 self.mox.VerifyAll() |
| 78 | 78 |
| 79 def testHandleUpdatePingForForcedImage(self): | 79 def testHandleUpdatePingForForcedImage(self): |
| 80 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateUpdateImage') | 80 self.mox.StubOutWithMock(autoupdate.Autoupdate, |
| 81 'GenerateUpdateImageWithCache') |
| 81 | 82 |
| 82 test_data = _TEST_REQUEST % self.test_dict | 83 test_data = _TEST_REQUEST % self.test_dict |
| 83 | 84 |
| 84 autoupdate.Autoupdate.GenerateUpdateImage( | 85 autoupdate.Autoupdate.GenerateUpdateImageWithCache( |
| 85 self.forced_image_path, | 86 self.forced_image_path, |
| 86 move_to_static_dir=True, | 87 static_image_dir=self.static_image_dir).AndReturn('update.gz') |
| 87 static_image_dir=self.static_image_dir).AndReturn(True) | |
| 88 autoupdate.Autoupdate._GetHash(os.path.join( | 88 autoupdate.Autoupdate._GetHash(os.path.join( |
| 89 self.static_image_dir, 'update.gz')).AndReturn(self.hash) | 89 self.static_image_dir, 'update.gz')).AndReturn(self.hash) |
| 90 autoupdate.Autoupdate._GetSHA256(os.path.join( | 90 autoupdate.Autoupdate._GetSHA256(os.path.join( |
| 91 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) | 91 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) |
| 92 autoupdate.Autoupdate._GetSize(os.path.join( | 92 autoupdate.Autoupdate._GetSize(os.path.join( |
| 93 self.static_image_dir, 'update.gz')).AndReturn(self.size) | 93 self.static_image_dir, 'update.gz')).AndReturn(self.size) |
| 94 autoupdate.Autoupdate.GetUpdatePayload( | 94 autoupdate.Autoupdate.GetUpdatePayload( |
| 95 self.hash, self.sha256, self.size, self.url, False).AndReturn( | 95 self.hash, self.sha256, self.size, self.url, False).AndReturn( |
| 96 self.payload) | 96 self.payload) |
| 97 | 97 |
| 98 self.mox.ReplayAll() | 98 self.mox.ReplayAll() |
| 99 au_mock = self._DummyAutoupdateConstructor() | 99 au_mock = self._DummyAutoupdateConstructor() |
| 100 au_mock.forced_image = self.forced_image_path | 100 au_mock.forced_image = self.forced_image_path |
| 101 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) | 101 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) |
| 102 self.mox.VerifyAll() | 102 self.mox.VerifyAll() |
| 103 | 103 |
| 104 def testHandleUpdatePingForLatestImage(self): | 104 def testHandleUpdatePingForLatestImage(self): |
| 105 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateLatestUpdateImage') | 105 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateLatestUpdateImage') |
| 106 | 106 |
| 107 test_data = _TEST_REQUEST % self.test_dict | 107 test_data = _TEST_REQUEST % self.test_dict |
| 108 | 108 |
| 109 autoupdate.Autoupdate.GenerateLatestUpdateImage( | 109 autoupdate.Autoupdate.GenerateLatestUpdateImage( |
| 110 self.test_board, 'ForcedUpdate', self.static_image_dir).AndReturn(True) | 110 self.test_board, 'ForcedUpdate', self.static_image_dir).AndReturn( |
| 111 'update.gz') |
| 111 autoupdate.Autoupdate._GetHash(os.path.join( | 112 autoupdate.Autoupdate._GetHash(os.path.join( |
| 112 self.static_image_dir, 'update.gz')).AndReturn(self.hash) | 113 self.static_image_dir, 'update.gz')).AndReturn(self.hash) |
| 113 autoupdate.Autoupdate._GetSHA256(os.path.join( | 114 autoupdate.Autoupdate._GetSHA256(os.path.join( |
| 114 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) | 115 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) |
| 115 autoupdate.Autoupdate._GetSize(os.path.join( | 116 autoupdate.Autoupdate._GetSize(os.path.join( |
| 116 self.static_image_dir, 'update.gz')).AndReturn(self.size) | 117 self.static_image_dir, 'update.gz')).AndReturn(self.size) |
| 117 autoupdate.Autoupdate.GetUpdatePayload( | 118 autoupdate.Autoupdate.GetUpdatePayload( |
| 118 self.hash, self.sha256, self.size, self.url, False).AndReturn( | 119 self.hash, self.sha256, self.size, self.url, False).AndReturn( |
| 119 self.payload) | 120 self.payload) |
| 120 | 121 |
| 121 self.mox.ReplayAll() | 122 self.mox.ReplayAll() |
| 122 au_mock = self._DummyAutoupdateConstructor() | 123 au_mock = self._DummyAutoupdateConstructor() |
| 123 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) | 124 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) |
| 124 self.mox.VerifyAll() | 125 self.mox.VerifyAll() |
| 125 | 126 |
| 126 def testHandleUpdatePingForArchivedBuild(self): | 127 def testHandleUpdatePingForArchivedBuild(self): |
| 127 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateImageFromZip') | 128 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateImageFromZip') |
| 128 | 129 |
| 129 test_data = _TEST_REQUEST % self.test_dict | 130 test_data = _TEST_REQUEST % self.test_dict |
| 130 | 131 |
| 131 autoupdate.Autoupdate.GenerateImageFromZip( | 132 autoupdate.Autoupdate.GenerateImageFromZip( |
| 132 self.static_image_dir).AndReturn(True) | 133 self.static_image_dir).AndReturn('update.gz') |
| 133 autoupdate.Autoupdate._GetHash(os.path.join( | 134 autoupdate.Autoupdate._GetHash(os.path.join( |
| 134 self.static_image_dir, 'update.gz')).AndReturn(self.hash) | 135 self.static_image_dir, 'update.gz')).AndReturn(self.hash) |
| 135 autoupdate.Autoupdate._GetSHA256(os.path.join( | 136 autoupdate.Autoupdate._GetSHA256(os.path.join( |
| 136 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) | 137 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) |
| 137 autoupdate.Autoupdate._GetSize(os.path.join( | 138 autoupdate.Autoupdate._GetSize(os.path.join( |
| 138 self.static_image_dir, 'update.gz')).AndReturn(self.size) | 139 self.static_image_dir, 'update.gz')).AndReturn(self.size) |
| 139 autoupdate.Autoupdate.GetUpdatePayload( | 140 autoupdate.Autoupdate.GetUpdatePayload( |
| 140 self.hash, self.sha256, self.size, | 141 self.hash, self.sha256, self.size, |
| 141 'http://%s/static/archive/update.gz' % self.hostname, | 142 'http://%s/static/archive/update.gz' % self.hostname, |
| 142 False).AndReturn( | 143 False).AndReturn( |
| 143 self.payload) | 144 self.payload) |
| 144 | 145 |
| 145 self.mox.ReplayAll() | 146 self.mox.ReplayAll() |
| 146 au_mock = self._DummyAutoupdateConstructor() | 147 au_mock = self._DummyAutoupdateConstructor() |
| 147 au_mock.serve_only = True | 148 au_mock.serve_only = True |
| 148 au_mock.static_urlbase = 'http://%s/static/archive' % self.hostname | 149 au_mock.static_urlbase = 'http://%s/static/archive' % self.hostname |
| 149 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) | 150 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) |
| 150 self.mox.VerifyAll() | 151 self.mox.VerifyAll() |
| 151 | 152 |
| 152 | 153 |
| 153 if __name__ == '__main__': | 154 if __name__ == '__main__': |
| 154 unittest.main() | 155 unittest.main() |
| OLD | NEW |