Enable preinstallation android packages

This commit is contained in:
butomo1989
2017-03-24 16:49:07 +01:00
parent ef3ead7067
commit 4fdf66f89f
27 changed files with 466 additions and 500 deletions
+49
View File
@@ -0,0 +1,49 @@
"""Unit test to test app."""
import os
from unittest import TestCase
import mock
from src import app
class TestApp(TestCase):
"""Unit test class to test other methods in the app."""
def test_valid_env(self):
key = 'ENV_1'
os.environ[key] = 'test'
app.get_or_raise(key)
del os.environ[key]
def test_invalid_env(self):
with self.assertRaises(RuntimeError):
app.get_or_raise('ENV_2')
def test_valid_bool(self):
self.assertEqual(app.str_to_bool('True'), True)
self.assertEqual(app.str_to_bool('t'), True)
self.assertEqual(app.str_to_bool('1'), True)
self.assertEqual(app.str_to_bool('YES'), True)
def test_invalid_bool(self):
self.assertEqual(app.str_to_bool(''), False)
self.assertEqual(app.str_to_bool('test'), False)
def test_invalid_format(self):
self.assertEqual(app.str_to_bool(True), None)
@mock.patch('src.app.prepare_avd')
def test_run_with_appium(self, mocked_avd):
with mock.patch('src.app.appium_run') as mocked_appium:
app.run()
self.assertTrue(mocked_avd.called)
self.assertTrue(mocked_appium.called)
@mock.patch('src.app.prepare_avd')
def test_run_withhout_appium(self, mocked_avd):
with mock.patch('src.app.appium_run') as mocked_appium:
os.environ['APPIUM'] = str(False)
app.run()
self.assertTrue(mocked_avd.called)
self.assertFalse(mocked_appium.called)
View File
-20
View File
@@ -1,20 +0,0 @@
"""Unit test for android.py."""
from unittest import TestCase
from src import android
class TestApiLevel(TestCase):
"""Unit test class to test method get_api_level."""
def setUp(self):
self.android_version = '4.2.2'
def test_get_api_level(self):
api_level = android.get_api_level('4.2')
self.assertEqual(api_level, 19)
def test_wrong_type(self):
api_level = android.get_api_level(4)
self.assertRaises(TypeError)
self.assertEqual(api_level, None)
-24
View File
@@ -1,24 +0,0 @@
"""Unit test for android.py."""
from unittest import TestCase
import mock
from src import android
class TestInstallPackage(TestCase):
"""Unit test class to test method install_package."""
def setUp(self):
self.emulator_file = 'emulator64-arm'
self.api_level = 21
self.sys_img = 'armeabi-v7a'
@mock.patch('os.symlink')
@mock.patch('subprocess.check_call')
def test_package_installation(self, mocked_sys_link, mocked_suprocess):
self.assertFalse(mocked_sys_link.called)
self.assertFalse(mocked_suprocess.called)
android.install_package(self.emulator_file, self.api_level, self.sys_img)
self.assertTrue(mocked_sys_link.called)
self.assertTrue(mocked_suprocess.called)
View File
-16
View File
@@ -1,16 +0,0 @@
"""Unit test for appium.py."""
import os
from unittest import TestCase
from src import CONFIG_FILE, appium
class TestAppiumConfig(TestCase):
"""Unit test class to test method create_node_config."""
def test_config_creation(self):
self.assertFalse(os.path.exists(CONFIG_FILE))
appium.create_node_config(CONFIG_FILE, 'emulator_name', '4.2.2', '127.0.0.1', 4723, '127.0.0.1', 4444)
self.assertTrue(os.path.exists(CONFIG_FILE))
os.remove(CONFIG_FILE)
-46
View File
@@ -1,46 +0,0 @@
"""Unit test for appium.py."""
import os
from unittest import TestCase
import mock
from src import appium
@mock.patch('subprocess.check_call')
class TestAppiumConfig(TestCase):
"""Unit test class to test method run."""
def setUp(self):
self.emulator_name = 'test'
self.android_version = '4.2.2'
def test_without_selenium_grid(self, mocked_subprocess):
with mock.patch('src.appium.create_node_config') as mocked_config:
self.assertFalse(mocked_config.called)
self.assertFalse(mocked_subprocess.called)
appium.run(False, self.emulator_name, self.android_version)
self.assertFalse(mocked_config.called)
self.assertTrue(mocked_subprocess.called)
def test_with_selenium_grid(self, mocked_subprocess):
with mock.patch('src.appium.create_node_config') as mocked_config:
self.assertFalse(mocked_config.called)
self.assertFalse(mocked_subprocess.called)
appium.run(True, self.emulator_name, self.android_version)
self.assertTrue(mocked_config.called)
self.assertTrue(mocked_subprocess.called)
def test_invalid_integer(self, mocked_subprocess):
os.environ['APPIUM_PORT'] = 'test'
with mock.patch('src.appium.create_node_config') as mocked_config:
self.assertFalse(mocked_config.called)
self.assertFalse(mocked_subprocess.called)
appium.run(True, self.emulator_name, self.android_version)
self.assertFalse(mocked_config.called)
self.assertTrue(mocked_subprocess.called)
self.assertRaises(ValueError)
def tearDown(self):
if os.getenv('APPIUM_PORT'):
del os.environ['APPIUM_PORT']
+54
View File
@@ -0,0 +1,54 @@
"""Unit test to test appium service."""
import os
from unittest import TestCase
import mock
from src import app
class TestAppium(TestCase):
"""Unit test class to test appium methods."""
def setUp(self):
os.environ['CONNECT_TO_GRID'] = str(True)
self.avd_name = 'test_avd'
@mock.patch('subprocess.check_call')
def test_without_selenium_grid(self, mocked_subprocess):
os.environ['CONNECT_TO_GRID'] = str(False)
self.assertFalse(mocked_subprocess.called)
app.appium_run(self.avd_name)
self.assertTrue(mocked_subprocess.called)
@mock.patch('subprocess.check_call')
def test_with_selenium_grid(self, mocked_subprocess):
with mock.patch('src.app.create_node_config') as mocked_config:
self.assertFalse(mocked_config.called)
self.assertFalse(mocked_subprocess.called)
app.appium_run(self.avd_name)
self.assertTrue(mocked_config.called)
self.assertTrue(mocked_subprocess.called)
@mock.patch('subprocess.check_call')
def test_invalid_integer(self, mocked_subprocess):
os.environ['APPIUM_PORT'] = 'test'
with mock.patch('src.app.create_node_config') as mocked_config:
self.assertFalse(mocked_config.called)
self.assertFalse(mocked_subprocess.called)
app.appium_run(self.avd_name)
self.assertFalse(mocked_config.called)
self.assertTrue(mocked_subprocess.called)
self.assertRaises(ValueError)
def test_config_creation(self):
from src import CONFIG_FILE
self.assertFalse(os.path.exists(CONFIG_FILE))
app.create_node_config('test', '127.0.0.1', 4723, '127.0.0.1', 4444)
self.assertTrue(os.path.exists(CONFIG_FILE))
os.remove(CONFIG_FILE)
def tearDown(self):
del os.environ['CONNECT_TO_GRID']
if os.getenv('APPIUM_PORT'):
del os.environ['APPIUM_PORT']
@@ -1,9 +1,10 @@
"""Unit test for android.py."""
"""Unit test for android virtual device creation.py."""
import os
from unittest import TestCase
import mock
from src import android
from src import app
@mock.patch('subprocess.check_call')
@@ -13,15 +14,14 @@ class TestAvd(TestCase):
def setUp(self):
self.avd_name = 'test_avd'
self.api_level = 21
def test_nexus_avd(self, mocked_suprocess, mocked_sys_link):
def test_nexus_avd_as_default(self, mocked_suprocess, mocked_sys_link):
with mock.patch('os.listdir') as mocked_list_dir:
mocked_list_dir.return_value = ['file1', 'file2']
self.assertFalse(mocked_list_dir.called)
self.assertFalse(mocked_sys_link.called)
self.assertFalse(mocked_suprocess.called)
android.create_avd('Nexus 5', self.avd_name, self.api_level)
app.prepare_avd('Nexus 5', self.avd_name)
self.assertTrue(mocked_list_dir.called)
self.assertTrue(mocked_sys_link.called)
self.assertTrue(mocked_suprocess.called)
@@ -32,16 +32,11 @@ class TestAvd(TestCase):
self.assertFalse(mocked_list_dir.called)
self.assertFalse(mocked_sys_link.called)
self.assertFalse(mocked_suprocess.called)
android.create_avd('Samsung Galaxy S6', self.avd_name, self.api_level)
app.prepare_avd('Samsung Galaxy S6', self.avd_name)
self.assertTrue(mocked_list_dir.called)
self.assertTrue(mocked_sys_link.called)
self.assertTrue(mocked_suprocess.called)
def test_default_avd(self, mocked_suprocess, mocked_sys_link):
with mock.patch('os.listdir') as mocked_list_dir:
mocked_list_dir.return_value = ['file1', 'file2']
self.assertFalse(mocked_list_dir.called)
self.assertFalse(mocked_sys_link.called)
self.assertFalse(mocked_suprocess.called)
android.create_avd('emulator', self.avd_name, self.api_level)
self.assertFalse(mocked_list_dir.called)
def tearDown(self):
if os.getenv('DEVICE'):
del os.environ['DEVICE']