• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RemoteImageRemoteHost."""
15
16import unittest
17
18from unittest import mock
19
20from acloud.create import avd_spec
21from acloud.create import create
22from acloud.create import remote_image_remote_host
23from acloud.internal import constants
24from acloud.internal.lib import driver_test_lib
25from acloud.internal.lib import utils
26from acloud.public.actions import common_operations
27from acloud.public.actions import remote_host_cf_device_factory
28
29class RemoteImageRemoteHostTest(driver_test_lib.BaseDriverTest):
30    """Test RemoteImageRemoteHost method."""
31
32    def setUp(self):
33        """Initialize new RemoteImageRemoteHost."""
34        super().setUp()
35        self.remote_image_remote_host = remote_image_remote_host.RemoteImageRemoteHost()
36
37    # pylint: disable=no-member
38    def testRun(self):
39        """Test Create AVD of cuttlefish remote image remote Host."""
40        args = mock.MagicMock()
41        args.skip_pre_run_check = True
42        spec = mock.MagicMock()
43        spec.avd_type = constants.TYPE_CF
44        spec.instance_type = constants.INSTANCE_TYPE_HOST
45        spec.image_source = constants.IMAGE_SRC_REMOTE
46        spec.connect_vnc = False
47        self.Patch(avd_spec, "AVDSpec", return_value=spec)
48        self.Patch(remote_host_cf_device_factory, "RemoteHostDeviceFactory")
49        self.Patch(common_operations, "CreateDevices")
50        create.Run(args)
51        remote_host_cf_device_factory.RemoteHostDeviceFactory.assert_called_once()
52        common_operations.CreateDevices.assert_called_once()
53
54        spec.connect_vnc = True
55        self.Patch(avd_spec, "AVDSpec", return_value=spec)
56        self.Patch(utils, "LaunchVNCFromReport")
57        create.Run(args)
58        utils.LaunchVNCFromReport.assert_called_once()
59
60
61if __name__ == '__main__':
62    unittest.main()
63