autoupdater_unittest.py revision 7f79551b1fd8d8742b8d1013ceb5d023fec07f83
1#!/usr/bin/python 2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import mox 7import unittest 8 9import common 10 11import autoupdater 12 13 14class TestAutoUpdater(mox.MoxTestBase): 15 """Test autoupdater module.""" 16 17 18 def testParseBuildFromUpdateUrlwithUpdate(self): 19 """Test that we properly parse the build from an update_url.""" 20 update_url = ('http://172.22.50.205:8082/update/lumpy-release/' 21 'R27-3837.0.0') 22 expected_value = 'lumpy-release/R27-3837.0.0' 23 self.assertEqual(autoupdater.url_to_image_name(update_url), 24 expected_value) 25 26 27 def testCheckVersion_1(self): 28 """Test version check methods work for any build. 29 30 Test two methods used to check version, check_version and 31 check_version_to_confirm_install, for: 32 1. trybot paladin build. 33 update version: trybot-lumpy-paladin/R27-3837.0.0-b123 34 booted version: 3837.0.2013_03_21_1340 35 36 """ 37 update_url = ('http://172.22.50.205:8082/update/trybot-lumpy-paladin/' 38 'R27-1111.0.0-b123') 39 updater = autoupdater.ChromiumOSUpdater(update_url) 40 41 self.mox.UnsetStubs() 42 self.mox.StubOutWithMock(updater, 'get_build_id') 43 updater.get_build_id().MultipleTimes().AndReturn( 44 '1111.0.2013_03_21_1340') 45 self.mox.ReplayAll() 46 47 self.assertFalse(updater.check_version()) 48 self.assertTrue(updater.check_version_to_confirm_install()) 49 50 self.mox.UnsetStubs() 51 self.mox.StubOutWithMock(updater, 'get_build_id') 52 updater.get_build_id().MultipleTimes().AndReturn('1111.0.0-rc1') 53 self.mox.ReplayAll() 54 55 self.assertFalse(updater.check_version()) 56 self.assertFalse(updater.check_version_to_confirm_install()) 57 58 self.mox.UnsetStubs() 59 self.mox.StubOutWithMock(updater, 'get_build_id') 60 updater.get_build_id().MultipleTimes().AndReturn('1111.0.0') 61 self.mox.ReplayAll() 62 63 self.assertFalse(updater.check_version()) 64 self.assertFalse(updater.check_version_to_confirm_install()) 65 66 def testCheckVersion_2(self): 67 """Test version check methods work for any build. 68 69 Test two methods used to check version, check_version and 70 check_version_to_confirm_install, for: 71 2. trybot release build. 72 update version: trybot-lumpy-release/R27-3837.0.0-b456 73 booted version: 3837.0.0 74 75 """ 76 update_url = ('http://172.22.50.205:8082/update/trybot-lumpy-release/' 77 'R27-2222.0.0-b456') 78 updater = autoupdater.ChromiumOSUpdater(update_url) 79 80 self.mox.UnsetStubs() 81 self.mox.StubOutWithMock(updater, 'get_build_id') 82 updater.get_build_id().MultipleTimes().AndReturn( 83 '2222.0.2013_03_21_1340') 84 self.mox.ReplayAll() 85 86 self.assertFalse(updater.check_version()) 87 self.assertFalse(updater.check_version_to_confirm_install()) 88 89 self.mox.UnsetStubs() 90 self.mox.StubOutWithMock(updater, 'get_build_id') 91 updater.get_build_id().MultipleTimes().AndReturn('2222.0.0-rc1') 92 self.mox.ReplayAll() 93 94 self.assertFalse(updater.check_version()) 95 self.assertFalse(updater.check_version_to_confirm_install()) 96 97 self.mox.UnsetStubs() 98 self.mox.StubOutWithMock(updater, 'get_build_id') 99 updater.get_build_id().MultipleTimes().AndReturn('2222.0.0') 100 self.mox.ReplayAll() 101 102 self.assertFalse(updater.check_version()) 103 self.assertTrue(updater.check_version_to_confirm_install()) 104 105 106 def testCheckVersion_3(self): 107 """Test version check methods work for any build. 108 109 Test two methods used to check version, check_version and 110 check_version_to_confirm_install, for: 111 3. buildbot official release build. 112 update version: lumpy-release/R27-3837.0.0 113 booted version: 3837.0.0 114 115 """ 116 update_url = ('http://172.22.50.205:8082/update/lumpy-release/' 117 'R27-3333.0.0') 118 updater = autoupdater.ChromiumOSUpdater(update_url) 119 120 self.mox.UnsetStubs() 121 self.mox.StubOutWithMock(updater, 'get_build_id') 122 updater.get_build_id().MultipleTimes().AndReturn( 123 '3333.0.2013_03_21_1340') 124 self.mox.ReplayAll() 125 126 self.assertFalse(updater.check_version()) 127 self.assertFalse(updater.check_version_to_confirm_install()) 128 129 self.mox.UnsetStubs() 130 self.mox.StubOutWithMock(updater, 'get_build_id') 131 updater.get_build_id().MultipleTimes().AndReturn('3333.0.0-rc1') 132 self.mox.ReplayAll() 133 134 self.assertFalse(updater.check_version()) 135 self.assertFalse(updater.check_version_to_confirm_install()) 136 137 self.mox.UnsetStubs() 138 self.mox.StubOutWithMock(updater, 'get_build_id') 139 updater.get_build_id().MultipleTimes().AndReturn('3333.0.0') 140 self.mox.ReplayAll() 141 142 self.assertTrue(updater.check_version()) 143 self.assertTrue(updater.check_version_to_confirm_install()) 144 145 146 def testCheckVersion_4(self): 147 """Test version check methods work for any build. 148 149 Test two methods used to check version, check_version and 150 check_version_to_confirm_install, for: 151 4. non-official paladin rc build. 152 update version: lumpy-paladin/R27-3837.0.0-rc7 153 booted version: 3837.0.0-rc7 154 155 """ 156 update_url = ('http://172.22.50.205:8082/update/lumpy-paladin/' 157 'R27-4444.0.0-rc7') 158 updater = autoupdater.ChromiumOSUpdater(update_url) 159 160 self.mox.UnsetStubs() 161 self.mox.StubOutWithMock(updater, 'get_build_id') 162 updater.get_build_id().MultipleTimes().AndReturn( 163 '4444.0.2013_03_21_1340') 164 self.mox.ReplayAll() 165 166 self.assertFalse(updater.check_version()) 167 self.assertFalse(updater.check_version_to_confirm_install()) 168 169 self.mox.UnsetStubs() 170 self.mox.StubOutWithMock(updater, 'get_build_id') 171 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0-rc7') 172 self.mox.ReplayAll() 173 174 self.assertTrue(updater.check_version()) 175 self.assertTrue(updater.check_version_to_confirm_install()) 176 177 self.mox.UnsetStubs() 178 self.mox.StubOutWithMock(updater, 'get_build_id') 179 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0') 180 self.mox.ReplayAll() 181 182 self.assertFalse(updater.check_version()) 183 self.assertFalse(updater.check_version_to_confirm_install()) 184 185 186 def testCheckVersion_5(self): 187 """Test version check methods work for any build. 188 189 Test two methods used to check version, check_version and 190 check_version_to_confirm_install, for: 191 5. chrome-perf build. 192 update version: lumpy-chrome-perf/R28-3837.0.0-b2996 193 booted version: 3837.0.0 194 195 """ 196 update_url = ('http://172.22.50.205:8082/update/lumpy-chrome-perf/' 197 'R28-4444.0.0-b2996') 198 updater = autoupdater.ChromiumOSUpdater(update_url) 199 200 self.mox.UnsetStubs() 201 self.mox.StubOutWithMock(updater, 'get_build_id') 202 updater.get_build_id().MultipleTimes().AndReturn( 203 '4444.0.2013_03_21_1340') 204 self.mox.ReplayAll() 205 206 self.assertFalse(updater.check_version()) 207 self.assertFalse(updater.check_version_to_confirm_install()) 208 209 self.mox.UnsetStubs() 210 self.mox.StubOutWithMock(updater, 'get_build_id') 211 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0-rc7') 212 self.mox.ReplayAll() 213 214 self.assertFalse(updater.check_version()) 215 self.assertFalse(updater.check_version_to_confirm_install()) 216 217 self.mox.UnsetStubs() 218 self.mox.StubOutWithMock(updater, 'get_build_id') 219 updater.get_build_id().MultipleTimes().AndReturn('4444.0.0') 220 self.mox.ReplayAll() 221 222 self.assertFalse(updater.check_version()) 223 self.assertTrue(updater.check_version_to_confirm_install()) 224 225 226if __name__ == '__main__': 227 unittest.main() 228