1#!/usr/bin/env python3 2# 3# Copyright 2017 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import mock 18import unittest 19 20import os 21 22from acts.controllers import android_device 23from acts.libs.ota.ota_runners import ota_runner 24from acts.libs.ota.ota_tools import ota_tool 25from acts.libs.ota.ota_tools import adb_sideload_ota_tool 26 27 28def get_mock_android_device(serial='', ssh_connection=None): 29 """Returns a mocked AndroidDevice with a mocked adb/fastboot.""" 30 with mock.patch('acts.controllers.adb.AdbProxy') as adb_proxy, ( 31 mock.patch('acts.controllers.fastboot.FastbootProxy')) as fb_proxy: 32 fb_proxy.return_value.devices.return_value = "" 33 ret = mock.Mock( 34 android_device.AndroidDevice( 35 serial=serial, ssh_connection=ssh_connection)) 36 fb_proxy.reset_mock() 37 return ret 38 39 40class AdbSideloadOtaToolTest(unittest.TestCase): 41 """Tests the OtaTool class.""" 42 43 def test_init(self): 44 expected_value = 'commmand string' 45 self.assertEqual( 46 ota_tool.OtaTool(expected_value).command, expected_value) 47 48 def setUp(self): 49 self.sl4a_service_setup_time = ota_runner.SL4A_SERVICE_SETUP_TIME 50 ota_runner.SL4A_SERVICE_SETUP_TIME = 0 51 52 def tearDown(self): 53 ota_runner.SL4A_SERVICE_SETUP_TIME = self.sl4a_service_setup_time 54 55 @staticmethod 56 def test_start(): 57 # This test could have a bunch of verify statements, 58 # but its probably not worth it. 59 device = get_mock_android_device() 60 ota_package_path = os.path.join( 61 os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 62 'dummy_ota_package.zip') 63 tool = adb_sideload_ota_tool.AdbSideloadOtaTool(ota_package_path) 64 runner = ota_runner.SingleUseOtaRunner(tool, device, ota_package_path, 65 '') 66 runner.android_device.adb.getprop = mock.Mock(side_effect=['a', 'b']) 67 runner.update() 68