blob: 672110af2c4bfa07071291579087744ddc7e05f3 [file] [log] [blame]
# Copyright 2017 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.
import mock
import unittest
import app_info
class TestAppInfo(unittest.TestCase):
@mock.patch('app_info._ExecuteCommand', autospec=True)
def testGetIOSAppInformation(self, mock_execute_command):
"""Tests creating an app_info object for iOS.
"""
test_bundle_id = 'test_bundle'
test_name = 'test_name'
test_version = '12.34.56.78'
mock_execute_command.side_effect = [
test_bundle_id, test_name, test_version]
info_object = app_info.GetIOSAppInformation('fake_path')
self.assertEqual(info_object.id, test_bundle_id)
self.assertEqual(info_object.name, test_name)
self.assertEqual(info_object.version, test_version)
@mock.patch('app_info._ExecuteCommand', autospec=True)
def testGetAndroidDeviceInformation(self, mock_execute_command):
"""Tests creating an app_info object for Android.
"""
test_bundle_id = 'testpackagename'
test_bundle_id_search = "package: name='%s'" % test_bundle_id
test_name = 'Chrome Beta Test'
test_name_search = "application: label='%s'" % test_name
test_version = '12.34.56.78'
test_version_search = "versionName='%s'" % test_version
test_output = '\n'.join(
[test_bundle_id_search, test_name_search, test_version_search])
mock_execute_command.return_value = test_output
info_object = app_info.GetAndroidAppInformation('fake_path')
self.assertEqual(info_object.id, test_bundle_id)
self.assertEqual(info_object.name, test_name)
self.assertEqual(info_object.version, test_version)
def testExecuteCommand(self):
"""Runs a smoke test of Exectue Command.
"""
test_word = 'foobar'
command = ['echo', test_word]
result = app_info._ExecuteCommand(command).strip()
self.assertEqual(test_word, result)
if __name__ == '__main__':
unittest.main()