1*c2e18aaaSAndroid Build Coastguard Worker#!/usr/bin/env python3 2*c2e18aaaSAndroid Build Coastguard Worker# 3*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2020 - The Android Open Source Project 4*c2e18aaaSAndroid Build Coastguard Worker# 5*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*c2e18aaaSAndroid Build Coastguard Worker# 9*c2e18aaaSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*c2e18aaaSAndroid Build Coastguard Worker# 11*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License. 16*c2e18aaaSAndroid Build Coastguard Worker 17*c2e18aaaSAndroid Build Coastguard Worker"""Unittests for deployment.""" 18*c2e18aaaSAndroid Build Coastguard Workerimport os 19*c2e18aaaSAndroid Build Coastguard Workerimport shutil 20*c2e18aaaSAndroid Build Coastguard Workerimport subprocess 21*c2e18aaaSAndroid Build Coastguard Workerimport tempfile 22*c2e18aaaSAndroid Build Coastguard Workerimport unittest 23*c2e18aaaSAndroid Build Coastguard Workerfrom unittest import mock 24*c2e18aaaSAndroid Build Coastguard Worker 25*c2e18aaaSAndroid Build Coastguard Workerfrom plugin_lib.deployment import PluginDeployment 26*c2e18aaaSAndroid Build Coastguard Worker 27*c2e18aaaSAndroid Build Coastguard Worker 28*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=protected-access 29*c2e18aaaSAndroid Build Coastguard Workerfrom aidegen.lib import config 30*c2e18aaaSAndroid Build Coastguard Worker 31*c2e18aaaSAndroid Build Coastguard Worker 32*c2e18aaaSAndroid Build Coastguard Workerclass DeploymentUnittests(unittest.TestCase): 33*c2e18aaaSAndroid Build Coastguard Worker """Unit tests for deployment.py.""" 34*c2e18aaaSAndroid Build Coastguard Worker 35*c2e18aaaSAndroid Build Coastguard Worker _TMP_DIR = None 36*c2e18aaaSAndroid Build Coastguard Worker 37*c2e18aaaSAndroid Build Coastguard Worker def setUp(self): 38*c2e18aaaSAndroid Build Coastguard Worker """Prepare the testdata related path.""" 39*c2e18aaaSAndroid Build Coastguard Worker DeploymentUnittests._TMP_DIR = tempfile.mkdtemp() 40*c2e18aaaSAndroid Build Coastguard Worker config.AidegenConfig._CONFIG_DIR = os.path.join( 41*c2e18aaaSAndroid Build Coastguard Worker DeploymentUnittests._TMP_DIR, '.config', 'asuite', 'aidegen') 42*c2e18aaaSAndroid Build Coastguard Worker config.AidegenConfig._CONFIG_FILE_PATH = os.path.join( 43*c2e18aaaSAndroid Build Coastguard Worker config.AidegenConfig._CONFIG_DIR, 44*c2e18aaaSAndroid Build Coastguard Worker config.AidegenConfig._DEFAULT_CONFIG_FILE) 45*c2e18aaaSAndroid Build Coastguard Worker 46*c2e18aaaSAndroid Build Coastguard Worker def tearDown(self): 47*c2e18aaaSAndroid Build Coastguard Worker """Clear the testdata related path.""" 48*c2e18aaaSAndroid Build Coastguard Worker shutil.rmtree(DeploymentUnittests._TMP_DIR) 49*c2e18aaaSAndroid Build Coastguard Worker 50*c2e18aaaSAndroid Build Coastguard Worker @mock.patch('builtins.input') 51*c2e18aaaSAndroid Build Coastguard Worker def test_ask_for_install(self, mock_input): 52*c2e18aaaSAndroid Build Coastguard Worker """Test _ask_for_install.""" 53*c2e18aaaSAndroid Build Coastguard Worker mock_input.return_value = 'y' 54*c2e18aaaSAndroid Build Coastguard Worker PluginDeployment()._ask_for_install() 55*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mock_input.call) 56*c2e18aaaSAndroid Build Coastguard Worker 57*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(subprocess, 'check_call') 58*c2e18aaaSAndroid Build Coastguard Worker def test_build_jars(self, mock_check_call): 59*c2e18aaaSAndroid Build Coastguard Worker """Test _build_jars.""" 60*c2e18aaaSAndroid Build Coastguard Worker PluginDeployment()._build_jars() 61*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mock_check_call.call) 62*c2e18aaaSAndroid Build Coastguard Worker 63*c2e18aaaSAndroid Build Coastguard Worker def test_write_read_selection(self): 64*c2e18aaaSAndroid Build Coastguard Worker """Test _read_selection and _write_selection.""" 65*c2e18aaaSAndroid Build Coastguard Worker PluginDeployment._user_selection = 'yes' 66*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(PluginDeployment._user_selection, 'yes') 67*c2e18aaaSAndroid Build Coastguard Worker PluginDeployment._user_selection = 'no' 68*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(PluginDeployment._user_selection, 'no') 69