xref: /aosp_15_r20/tools/acloud/create/local_image_remote_host_test.py (revision 800a58d989c669b8eb8a71d8df53b1ba3d411444)
1# Copyright 2021 - 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 LocalImageRemoteHost."""
15
16import unittest
17
18from unittest import mock
19
20from acloud.create import avd_spec
21from acloud.create import create
22from acloud.create import create_common
23from acloud.create import local_image_remote_host
24from acloud.internal import constants
25from acloud.internal.lib import driver_test_lib
26from acloud.internal.lib import utils
27from acloud.public.actions import common_operations
28from acloud.public.actions import remote_host_cf_device_factory
29
30class LocalImageRemoteHostTest(driver_test_lib.BaseDriverTest):
31    """Test LocalImageRemoteHost method."""
32
33    def setUp(self):
34        """Initialize new LocalImageRemoteHost."""
35        super().setUp()
36        self.local_image_remote_host = local_image_remote_host.LocalImageRemoteHost()
37
38    # pylint: disable=no-member
39    def testRun(self):
40        """Test Create AVD of cuttlefish local image remote host."""
41        args = mock.MagicMock()
42        args.skip_pre_run_check = True
43        spec = mock.MagicMock()
44        spec.avd_type = constants.TYPE_CF
45        spec.instance_type = constants.INSTANCE_TYPE_HOST
46        spec.image_source = constants.IMAGE_SRC_LOCAL
47        spec.connect_vnc = False
48        self.Patch(avd_spec, "AVDSpec", return_value=spec)
49        self.Patch(remote_host_cf_device_factory, "RemoteHostDeviceFactory")
50        self.Patch(create_common, "GetCvdHostPackage")
51        self.Patch(common_operations, "CreateDevices")
52        create.Run(args)
53        remote_host_cf_device_factory.RemoteHostDeviceFactory.assert_called_once()
54        common_operations.CreateDevices.assert_called_once()
55
56        spec.connect_vnc = True
57        self.Patch(avd_spec, "AVDSpec", return_value=spec)
58        self.Patch(utils, "LaunchVNCFromReport")
59        create.Run(args)
60        utils.LaunchVNCFromReport.assert_called_once()
61
62
63if __name__ == '__main__':
64    unittest.main()
65