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 17import mock 18 19from acloud import errors 20from acloud.create import create_args 21from acloud.internal import constants 22from acloud.internal.lib import driver_test_lib 23 24 25def _CreateArgs(): 26 """set default pass in arguments.""" 27 mock_args = mock.MagicMock( 28 flavor=None, 29 num=None, 30 adb_port=None, 31 hw_property=None, 32 stable_cheeps_host_image_name=None, 33 stable_cheeps_host_image_project=None, 34 username=None, 35 password=None, 36 local_image="", 37 local_system_image="", 38 system_branch=None, 39 system_build_id=None, 40 system_build_target=None, 41 local_instance=None, 42 remote_host=None, 43 host_user=constants.GCE_USER, 44 host_ssh_private_key_path=None, 45 avd_type=constants.TYPE_CF, 46 autoconnect=constants.INS_KEY_VNC) 47 return mock_args 48 49 50# pylint: disable=invalid-name,protected-access 51class CreateArgsTest(driver_test_lib.BaseDriverTest): 52 """Test create_args functions.""" 53 54 def testVerifyArgs(self): 55 """test VerifyArgs.""" 56 mock_args = _CreateArgs() 57 # Test args default setting shouldn't raise error. 58 self.assertEqual(None, create_args.VerifyArgs(mock_args)) 59 60 def testVerifyArgs_ConnectWebRTC(self): 61 """test VerifyArgs args.autconnect webrtc. 62 63 WebRTC only apply to remote cuttlefish instance 64 65 """ 66 mock_args = _CreateArgs() 67 mock_args.autoconnect = constants.INS_KEY_WEBRTC 68 # Test remote instance and avd_type cuttlefish(default) 69 # Test args.autoconnect webrtc shouldn't raise error. 70 self.assertEqual(None, create_args.VerifyArgs(mock_args)) 71 72 # Test pass in none-cuttlefish avd_type should raise error. 73 mock_args.avd_type = constants.TYPE_GF 74 self.assertRaises(errors.UnsupportedCreateArgs, 75 create_args.VerifyArgs, mock_args) 76 77 78if __name__ == "__main__": 79 unittest.main() 80