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

Side by Side Diff: autoupdate_unittest.py

Issue 5057005: Revert "Reworked devserver so that update images generated are cached in directories named after" (Closed) Base URL: http://git.chromium.org/git/dev-util.git@master
Patch Set: Created 10 years, 1 month 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') | devserver.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 cherrypy 9 import cherrypy
10 import mox 10 import mox
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 63 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateUpdateImage')
64 'GenerateUpdateImageWithCache')
65 autoupdate.Autoupdate._GetLatestImageDir(self.test_board).AndReturn( 64 autoupdate.Autoupdate._GetLatestImageDir(self.test_board).AndReturn(
66 '%s/%s/%s' % (self.build_root, self.test_board, self.latest_dir)) 65 '%s/%s/%s' % (self.build_root, self.test_board, self.latest_dir))
67 autoupdate.Autoupdate.GenerateUpdateImageWithCache( 66 autoupdate.Autoupdate.GenerateUpdateImage(
68 '%s/%s/%s/chromiumos_image.bin' % (self.build_root, self.test_board, 67 '%s/%s/%s/chromiumos_image.bin' % (self.build_root, self.test_board,
69 self.latest_dir), 68 self.latest_dir),
70 static_image_dir=self.static_image_dir).AndReturn('update.gz') 69 move_to_static_dir=True,
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, 80 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateUpdateImage')
81 'GenerateUpdateImageWithCache')
82 81
83 test_data = _TEST_REQUEST % self.test_dict 82 test_data = _TEST_REQUEST % self.test_dict
84 83
85 autoupdate.Autoupdate.GenerateUpdateImageWithCache( 84 autoupdate.Autoupdate.GenerateUpdateImage(
86 self.forced_image_path, 85 self.forced_image_path,
87 static_image_dir=self.static_image_dir).AndReturn('update.gz') 86 move_to_static_dir=True,
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( 110 self.test_board, 'ForcedUpdate', self.static_image_dir).AndReturn(True)
111 'update.gz')
112 autoupdate.Autoupdate._GetHash(os.path.join( 111 autoupdate.Autoupdate._GetHash(os.path.join(
113 self.static_image_dir, 'update.gz')).AndReturn(self.hash) 112 self.static_image_dir, 'update.gz')).AndReturn(self.hash)
114 autoupdate.Autoupdate._GetSHA256(os.path.join( 113 autoupdate.Autoupdate._GetSHA256(os.path.join(
115 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) 114 self.static_image_dir, 'update.gz')).AndReturn(self.sha256)
116 autoupdate.Autoupdate._GetSize(os.path.join( 115 autoupdate.Autoupdate._GetSize(os.path.join(
117 self.static_image_dir, 'update.gz')).AndReturn(self.size) 116 self.static_image_dir, 'update.gz')).AndReturn(self.size)
118 autoupdate.Autoupdate.GetUpdatePayload( 117 autoupdate.Autoupdate.GetUpdatePayload(
119 self.hash, self.sha256, self.size, self.url, False).AndReturn( 118 self.hash, self.sha256, self.size, self.url, False).AndReturn(
120 self.payload) 119 self.payload)
121 120
122 self.mox.ReplayAll() 121 self.mox.ReplayAll()
123 au_mock = self._DummyAutoupdateConstructor() 122 au_mock = self._DummyAutoupdateConstructor()
124 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) 123 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
125 self.mox.VerifyAll() 124 self.mox.VerifyAll()
126 125
127 def testHandleUpdatePingForArchivedBuild(self): 126 def testHandleUpdatePingForArchivedBuild(self):
128 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateImageFromZip') 127 self.mox.StubOutWithMock(autoupdate.Autoupdate, 'GenerateImageFromZip')
129 128
130 test_data = _TEST_REQUEST % self.test_dict 129 test_data = _TEST_REQUEST % self.test_dict
131 130
132 autoupdate.Autoupdate.GenerateImageFromZip( 131 autoupdate.Autoupdate.GenerateImageFromZip(
133 self.static_image_dir).AndReturn('update.gz') 132 self.static_image_dir).AndReturn(True)
134 autoupdate.Autoupdate._GetHash(os.path.join( 133 autoupdate.Autoupdate._GetHash(os.path.join(
135 self.static_image_dir, 'update.gz')).AndReturn(self.hash) 134 self.static_image_dir, 'update.gz')).AndReturn(self.hash)
136 autoupdate.Autoupdate._GetSHA256(os.path.join( 135 autoupdate.Autoupdate._GetSHA256(os.path.join(
137 self.static_image_dir, 'update.gz')).AndReturn(self.sha256) 136 self.static_image_dir, 'update.gz')).AndReturn(self.sha256)
138 autoupdate.Autoupdate._GetSize(os.path.join( 137 autoupdate.Autoupdate._GetSize(os.path.join(
139 self.static_image_dir, 'update.gz')).AndReturn(self.size) 138 self.static_image_dir, 'update.gz')).AndReturn(self.size)
140 autoupdate.Autoupdate.GetUpdatePayload( 139 autoupdate.Autoupdate.GetUpdatePayload(
141 self.hash, self.sha256, self.size, 140 self.hash, self.sha256, self.size,
142 'http://%s/static/archive/update.gz' % self.hostname, 141 'http://%s/static/archive/update.gz' % self.hostname,
143 False).AndReturn( 142 False).AndReturn(
144 self.payload) 143 self.payload)
145 144
146 self.mox.ReplayAll() 145 self.mox.ReplayAll()
147 au_mock = self._DummyAutoupdateConstructor() 146 au_mock = self._DummyAutoupdateConstructor()
148 au_mock.serve_only = True 147 au_mock.serve_only = True
149 au_mock.static_urlbase = 'http://%s/static/archive' % self.hostname 148 au_mock.static_urlbase = 'http://%s/static/archive' % self.hostname
150 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload) 149 self.assertEqual(au_mock.HandleUpdatePing(test_data), self.payload)
151 self.mox.VerifyAll() 150 self.mox.VerifyAll()
152 151
153 152
154 if __name__ == '__main__': 153 if __name__ == '__main__':
155 unittest.main() 154 unittest.main()
OLDNEW
« no previous file with comments | « autoupdate.py ('k') | devserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698