Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: autoupdate_unittest.py

Issue 3708004: Move dev server to use cherrypy. (Closed) Base URL: http://git.chromium.org/git/dev-util.git
Patch Set: last Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « autoupdate.py ('k') | buildutil.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 mox 9 import mox
10 import os 10 import os
11 import socket
11 import unittest 12 import unittest
12 import web
13 13
14 import autoupdate 14 import autoupdate
15 15
16 _TEST_REQUEST = """ 16 _TEST_REQUEST = """
17 <client_test xmlns:o="http://www.google.com/update2/request" updaterversion="%(c lient)s" > 17 <client_test xmlns:o="http://www.google.com/update2/request" updaterversion="%(c lient)s" >
18 <o:app version="%(version)s" track="%(track)s" board="%(board)s" /> 18 <o:app version="%(version)s" track="%(track)s" board="%(board)s" />
19 <o:updatecheck /> 19 <o:updatecheck />
20 </client_test>""" 20 </client_test>"""
21 21
22 22
23 class AutoupdateTest(mox.MoxTestBase): 23 class AutoupdateTest(mox.MoxTestBase):
24 def setUp(self): 24 def setUp(self):
25 mox.MoxTestBase.setUp(self) 25 mox.MoxTestBase.setUp(self)
26 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetSize') 26 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetSize')
27 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetHash') 27 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetHash')
28 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetSHA256') 28 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetSHA256')
29 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GetUpdatePayload') 29 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GetUpdatePayload')
30 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetLatestImageDir') 30 self.mox.StubOutWithMock(autoupdate.Autoupdate, '_GetLatestImageDir')
31 self.port = 8080
31 self.test_board = 'test-board' 32 self.test_board = 'test-board'
32 self.build_root = '/src_path/build/images' 33 self.build_root = '/src_path/build/images'
33 self.latest_dir = '12345_af_12-a1' 34 self.latest_dir = '12345_af_12-a1'
34 self.latest_verision = '12345_af_12' 35 self.latest_verision = '12345_af_12'
35 self.static_image_dir = '/tmp/static-dir/' 36 self.static_image_dir = '/tmp/static-dir/'
36 self.hostname = 'fake-host' 37 self.hostname = '%s:%s' % (socket.gethostname(), self.port)
37 self.test_dict = { 'client': 'ChromeOSUpdateEngine-1.0', 38 self.test_dict = { 'client': 'ChromeOSUpdateEngine-1.0',
38 'version': 'ForcedUpdate', 39 'version': 'ForcedUpdate',
39 'track': 'unused_var', 40 'track': 'unused_var',
40 'board': self.test_board 41 'board': self.test_board
41 } 42 }
42 self.test_data = _TEST_REQUEST % self.test_dict 43 self.test_data = _TEST_REQUEST % self.test_dict
43 self.forced_image_path = '/path_to_force/chromiumos_image.bin' 44 self.forced_image_path = '/path_to_force/chromiumos_image.bin'
44 self.hash = 12345 45 self.hash = 12345
45 self.size = 54321 46 self.size = 54321
46 self.url = 'http://%s/static/update.gz' % self.hostname 47 self.url = 'http://%s/static/update.gz' % self.hostname
47 self.payload = 'My payload' 48 self.payload = 'My payload'
48 self.sha256 = 'SHA LA LA' 49 self.sha256 = 'SHA LA LA'
49 50
50 def _DummyAutoupdateConstructor(self): 51 def _DummyAutoupdateConstructor(self):
51 """Creates a dummy autoupdater. Used to avoid using constructor.""" 52 """Creates a dummy autoupdater. Used to avoid using constructor."""
52 dummy = autoupdate.Autoupdate(root_dir=None, 53 dummy = autoupdate.Autoupdate(root_dir=None,
53 static_dir=self.static_image_dir) 54 static_dir=self.static_image_dir,
55 port=self.port)
54 dummy.client_prefix = 'ChromeOSUpdateEngine' 56 dummy.client_prefix = 'ChromeOSUpdateEngine'
55
56 # Set to fool the web.
57 web.ctx.host = self.hostname
58 return dummy 57 return dummy
59 58
60 def testGenerateLatestUpdateImageWithForced(self): 59 def testGenerateLatestUpdateImageWithForced(self):
61 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateUpdateImage') 60 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateUpdateImage')
62 autoupdate.Autoupdate._GetLatestImageDir(self.test_board).AndReturn( 61 autoupdate.Autoupdate._GetLatestImageDir(self.test_board).AndReturn(
63 '%s/%s/%s' % (self.build_root, self.test_board, self.latest_dir)) 62 '%s/%s/%s' % (self.build_root, self.test_board, self.latest_dir))
64 autoupdate.Autoupdate.GenerateUpdateImage( 63 autoupdate.Autoupdate.GenerateUpdateImage(
65 '%s/%s/%s/chromiumos_image.bin' % (self.build_root, self.test_board, 64 '%s/%s/%s/chromiumos_image.bin' % (self.build_root, self.test_board,
66 self.latest_dir), 65 self.latest_dir),
67 move_to_static_dir=True, 66 move_to_static_dir=True,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 self.mox.ReplayAll() 139 self.mox.ReplayAll()
141 au_mock = self._DummyAutoupdateConstructor() 140 au_mock = self._DummyAutoupdateConstructor()
142 au_mock.serve_only = True 141 au_mock.serve_only = True
143 au_mock.static_urlbase = 'http://%s/static/archive' % self.hostname 142 au_mock.static_urlbase = 'http://%s/static/archive' % self.hostname
144 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) 143 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
145 self.mox.VerifyAll() 144 self.mox.VerifyAll()
146 145
147 146
148 if __name__ == '__main__': 147 if __name__ == '__main__':
149 unittest.main() 148 unittest.main()
OLDNEW
« no previous file with comments | « autoupdate.py ('k') | buildutil.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698