1# Copyright 2020 - The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Tests for create.""" 15 16import unittest 17 18from unittest import mock 19 20from acloud import errors 21from acloud.create import create_args 22from acloud.internal import constants 23from acloud.internal.lib import driver_test_lib 24 25 26def _CreateArgs(): 27 """set default pass in arguments.""" 28 mock_args = mock.MagicMock( 29 flavor=None, 30 num=1, 31 adb_port=None, 32 hw_property=None, 33 stable_cheeps_host_image_name=None, 34 stable_cheeps_host_image_project=None, 35 username=None, 36 password=None, 37 cheeps_betty_image=None, 38 local_image=None, 39 local_kernel_image=None, 40 local_system_image=None, 41 system_branch=None, 42 system_build_id=None, 43 system_build_target=None, 44 local_instance=None, 45 remote_host=None, 46 host_user=constants.GCE_USER, 47 host_ssh_private_key_path=None, 48 avd_type=constants.TYPE_CF, 49 autoconnect=constants.INS_KEY_VNC) 50 return mock_args 51 52 53# pylint: disable=invalid-name,protected-access 54class CreateArgsTest(driver_test_lib.BaseDriverTest): 55 """Test create_args functions.""" 56 57 def testVerifyArgs(self): 58 """test VerifyArgs.""" 59 mock_args = _CreateArgs() 60 # Test args default setting shouldn't raise error. 61 self.assertEqual(None, create_args.VerifyArgs(mock_args)) 62 63 def testVerifyArgs_ConnectWebRTC(self): 64 """test VerifyArgs args.autconnect webrtc. 65 66 WebRTC only apply to remote cuttlefish instance 67 68 """ 69 mock_args = _CreateArgs() 70 mock_args.autoconnect = constants.INS_KEY_WEBRTC 71 # Test remote instance and avd_type cuttlefish(default) 72 # Test args.autoconnect webrtc shouldn't raise error. 73 self.assertEqual(None, create_args.VerifyArgs(mock_args)) 74 75 # Test pass in none-cuttlefish avd_type should raise error. 76 mock_args.avd_type = constants.TYPE_GF 77 self.assertRaises(errors.UnsupportedCreateArgs, 78 create_args.VerifyArgs, mock_args) 79 80 81if __name__ == "__main__": 82 unittest.main() 83