• 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 LocalImageRemoteInstance."""
15
16import unittest
17
18from unittest import mock
19
20from acloud.create import create_common
21from acloud.create import local_image_remote_instance
22from acloud.internal import constants
23from acloud.internal.lib import driver_test_lib
24from acloud.internal.lib import utils
25from acloud.public import report
26from acloud.public.actions import common_operations
27from acloud.public.actions import remote_instance_cf_device_factory
28from acloud.public.actions import remote_instance_fvp_device_factory
29
30
31class LocalImageRemoteInstanceTest(driver_test_lib.BaseDriverTest):
32    """Test LocalImageRemoteInstance method."""
33
34    def setUp(self):
35        """Initialize new LocalImageRemoteInstance."""
36        super().setUp()
37        self.local_image_remote_instance = local_image_remote_instance.LocalImageRemoteInstance()
38
39    # pylint: disable=protected-access
40    @mock.patch.object(utils, "LaunchVNCFromReport")
41    @mock.patch.object(utils, "LaunchBrowserFromReport")
42    @mock.patch.object(remote_instance_fvp_device_factory,
43                       "RemoteInstanceDeviceFactory")
44    @mock.patch.object(remote_instance_cf_device_factory,
45                       "RemoteInstanceDeviceFactory")
46    def testCreateAVD(self, mock_cf_factory, mock_fvp_factory,
47                      mock_launch_browser, mock_launch_vnc):
48        """Test CreateAVD."""
49        spec = mock.MagicMock()
50        spec.avd_type = constants.TYPE_CF
51        spec.instance_type = constants.INSTANCE_TYPE_REMOTE
52        spec.image_source = constants.IMAGE_SRC_LOCAL
53        spec.connect_vnc = False
54        spec.connect_webrtc = True
55        create_report = mock.Mock()
56        create_report.status = report.Status.SUCCESS
57        self.Patch(common_operations, "CreateDevices",
58                   return_value=create_report)
59        self.Patch(create_common, "GetCvdHostPackage")
60        # cuttfish with webrtc
61        self.local_image_remote_instance._CreateAVD(
62            spec, no_prompts=True)
63        mock_cf_factory.assert_called_once()
64        mock_launch_browser.assert_called_once()
65
66        # fvp with vnc
67        spec.avd_type = constants.TYPE_FVP
68        spec.connect_vnc = True
69        spec.connect_webrtc = False
70        self.local_image_remote_instance._CreateAVD(
71            spec, no_prompts=True)
72        mock_fvp_factory.assert_called_once()
73        mock_launch_vnc.assert_called_once()
74
75
76if __name__ == "__main__":
77    unittest.main()
78