blob: fca8a736c6ba3d29e26fd6a124b87c33d3b9e168 [file] [log] [blame]
# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests to check Appium server and creates Appium driver."""
from __future__ import absolute_import
import unittest
import fixpath # This has to be the first local import.
import appium_driver_util
import mock
class TestInputFormatter(unittest.TestCase):
def execute_process_for_kill_by_port(self, mock_obj, processes):
def fake(*args):
if args[0] == ['ps', 'aux']:
return processes
mock_obj.side_effect = fake
@mock.patch('appium_driver_util.KillRunningProcess', autospec=True)
@mock.patch('utilities.util.ExecuteProcess', autospec=True)
def testKillAppiumServerByPort(self, mock_exec_process, mock_kill_process):
self.execute_process_for_kill_by_port(
mock_exec_process,
'\n'.join([
'root 21123 node /bin/appium 127.0.0.1 --port 4725 --log /path1',
'root 21120 node /bin/appium 127.0.0.1 --port 4721 --log /path2'
])
)
appium_driver_util.KillAppiumServerByPort('4725')
self.assertEqual(1, mock_kill_process.call_count)
mock_kill_process.assert_called_with(21123)
@mock.patch('appium_driver_util.KillRunningProcess', autospec=True)
@mock.patch('utilities.util.ExecuteProcess', autospec=True)
def testKillAppiumServerByPort_NotFoundProcess(self, mock_exec_process,
mock_kill_process):
self.execute_process_for_kill_by_port(
mock_exec_process,
'\n'.join([
'root 21123 node /bin/appium 127.0.0.1 --port 4722 --log /path1',
'root 21120 node /bin/appium 127.0.0.1 --port 4721 --log /path2'
])
)
appium_driver_util.KillAppiumServerByPort('4725')
self.assertEqual(0, mock_kill_process.call_count)
if __name__ == '__main__':
unittest.main()