def test_update_first_update_runs(self): runner = ota_runner.SingleUseOtaRunner(self.tool, self.device, '', '') try: with mock.patch.object(ota_runner.OtaRunner, '_update'): runner.update() except ota_runner.OtaError: self.fail('SingleUseOtaRunner threw an exception on the first ' 'update call.')
def test_update_second_update_raises_error(self): runner = ota_runner.SingleUseOtaRunner(self.tool, self.device, '', '') with mock.patch.object(ota_runner.OtaRunner, '_update'): runner.update() try: runner.update() except ota_runner.OtaError: return self.fail('SingleUseOtaRunner did not throw an exception on the second' 'update call.')
def test_start(): # This test could have a bunch of verify statements, # but its probably not worth it. device = get_mock_android_device() ota_package_path = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'dummy_ota_package.zip') tool = adb_sideload_ota_tool.AdbSideloadOtaTool(ota_package_path) runner = ota_runner.SingleUseOtaRunner(tool, device, ota_package_path, '') runner.android_device.adb.getprop = mock.Mock(side_effect=['a', 'b']) runner.update()
def test_update(self): ota_package_path = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'dummy_ota_package.zip') with mock.patch('tempfile.mkdtemp') as mkdtemp, ( mock.patch('shutil.rmtree')) as rmtree, ( mock.patch('acts.utils.unzip_maintain_permissions')): mkdtemp.return_value = '' rmtree.return_value = '' device = get_mock_android_device() tool = update_device_ota_tool.UpdateDeviceOtaTool(ota_package_path) runner = mock.Mock( ota_runner.SingleUseOtaRunner(tool, device, '', '')) runner.return_value.android_device = device with mock.patch('acts.libs.proc.job.run'): tool.update(runner) del tool
def create_from_package(ota_package, ota_sl4a, android_device, ota_tool, use_cached_runners=True): """ Args: ota_package: A string or list of strings corresponding to the update.zip package location(s) for running an OTA update. ota_sl4a: A string or list of strings corresponding to the sl4a.apk package location(s) for running an OTA update. ota_tool: The OtaTool to be paired with the returned OtaRunner android_device: The AndroidDevice to run the OTA Update on. use_cached_runners: Whether or not to use runners cached by previous create calls. Returns: An OtaRunner with the given properties from the arguments. """ if android_device in _bound_devices and use_cached_runners: logging.warning('Android device %s has already been assigned an ' 'OtaRunner. Returning previously created runner.') return _bound_devices[android_device] if type(ota_package) != type(ota_sl4a): raise TypeError( 'The ota_package and ota_sl4a must either both be strings, or ' 'both be lists. Device with serial "%s" has requested mismatched ' 'types.' % android_device.serial) if type(ota_package) is str: runner = ota_runner.SingleUseOtaRunner(ota_tool, android_device, ota_package, ota_sl4a) elif type(ota_package) is list: runner = ota_runner.MultiUseOtaRunner(ota_tool, android_device, ota_package, ota_sl4a) else: raise TypeError('The "ota_package" value in the acts config must be ' 'either a list or a string.') _bound_devices[android_device] = runner return runner
def test_get_sl4a_apk(self): runner = ota_runner.SingleUseOtaRunner(self.tool, self.device, 'a', 'b') self.assertEqual(runner.get_sl4a_apk(), 'b')
def test_get_ota_package(self): runner = ota_runner.SingleUseOtaRunner(self.tool, self.device, 'a', 'b') self.assertEqual(runner.get_ota_package(), 'a')
def test_can_update_has_updated_already(self): runner = ota_runner.SingleUseOtaRunner(self.tool, self.device, '', '') with mock.patch.object(ota_runner.OtaRunner, '_update'): runner.update() self.assertEqual(False, runner.can_update())
def test_can_update_no_updates_called(self): runner = ota_runner.SingleUseOtaRunner(self.tool, self.device, '', '') self.assertEqual(True, runner.can_update())