1#!/usr/bin/env python 2# 3# Copyright 2021 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16"""Tests for acloud.internal.lib.oxygen_client.""" 17 18import subprocess 19 20import unittest 21 22from unittest import mock 23 24from acloud.internal.lib import driver_test_lib 25from acloud.internal.lib import oxygen_client 26 27 28class OxygenClentTest(driver_test_lib.BaseDriverTest): 29 """Test OxygenClient.""" 30 31 @staticmethod 32 @mock.patch.object(subprocess, "check_output") 33 def testLeaseDevice(mock_subprocess): 34 """Test LeaseDevice.""" 35 build_target = "fake_target" 36 build_id = "fake_id" 37 oxygen_client_path = "oxygen_client_path" 38 build_branch = "master-branch" 39 40 # Test mixed build lease request. 41 lease_args = "" 42 expected_cmd = [oxygen_client_path, "-lease", "-build_id", build_id, 43 "-build_target", build_target, "-build_branch", 44 build_branch, "-system_build_id", "system_build_id1", 45 "-system_build_target", "system_build_target1", 46 "-kernel_build_id", "kernel_build_id2", 47 "-kernel_build_target", "kernel_build_target2"] 48 oxygen_client.OxygenClient.LeaseDevice( 49 build_target, build_id, build_branch, "system_build_target1", 50 "system_build_id1", "kernel_build_target2", "kernel_build_id2", 51 oxygen_client_path, lease_args) 52 mock_subprocess.assert_called_with(expected_cmd, 53 stderr=subprocess.STDOUT, 54 encoding='utf-8') 55 56 # Test with lease command args. 57 lease_args = "-user user@gmail.com" 58 expected_cmd = [oxygen_client_path, "-lease", "-build_id", build_id, 59 "-build_target", build_target, "-build_branch", 60 build_branch, "-user", "user@gmail.com"] 61 oxygen_client.OxygenClient.LeaseDevice( 62 build_target, build_id, build_branch, "", "", "", "", 63 oxygen_client_path, lease_args) 64 mock_subprocess.assert_called_with(expected_cmd, 65 stderr=subprocess.STDOUT, 66 encoding='utf-8') 67 68 69if __name__ == "__main__": 70 unittest.main() 71