Refactored code, added log and emulator skins

This commit is contained in:
butomo1989
2017-02-27 14:53:48 +01:00
parent 87ed3c6a1f
commit 30b2205987
130 changed files with 1303 additions and 264 deletions
View File
View File
+33
View File
@@ -0,0 +1,33 @@
"""Unit test for android.py."""
from unittest import TestCase
import mock
from src import android
@mock.patch('src.android.get_available_sdk_packages')
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, mocked_packages):
mocked_packages.return_value = ['9- SDK Platform Android 4.4.2, API 19, revision 4',
'10- SDK Platform Android 4.3.1, API 18, revision 3',
'11- SDK Platform Android 4.2.2, API 17, revision 3']
api_level = android.get_api_level(self.android_version)
self.assertEqual(api_level, '17')
def test_empty_packages(self, mocked_packages):
mocked_packages.return_value = None
with self.assertRaises(RuntimeError):
android.get_api_level(self.android_version)
def test_index_error(self, mocked_packages):
mocked_packages.return_value = ['9 SDK Platform Android 4.4.2, API 19, revision 4',
'10 SDK Platform Android 4.3.1, API 18, revision 3',
'11 SDK Platform Android 4.2.2, API 17, revision 3']
android.get_api_level(self.android_version)
self.assertRaises(IndexError)
@@ -0,0 +1,28 @@
"""Unit test for android.py."""
from unittest import TestCase
import mock
from src import android
class TestAvailablePackages(TestCase):
"""Unit test class to test method get_available_sdk_packages."""
@mock.patch('subprocess.check_output')
def test_valid_output(self, mocked_output):
mocked_output.return_value = 'package 1 \n package 2'
output = android.get_available_sdk_packages()
self.assertEqual(['package 1', 'package 2'], output)
@mock.patch('subprocess.check_output')
def test_without_line_break(self, mocked_output):
mocked_output.return_value = 'package 1, package 2'
output = android.get_available_sdk_packages()
self.assertEqual(['package 1, package 2'], output)
@mock.patch('subprocess.check_output')
def test_empty_string(self, mocked_output):
mocked_output.return_value = None
output = android.get_available_sdk_packages()
self.assertEqual(None, output)
+28
View File
@@ -0,0 +1,28 @@
"""Unit test for android.py."""
from unittest import TestCase
import mock
from src import android
class TestAvd(TestCase):
"""Unit test class to test method create_avd."""
def setUp(self):
self.android_path = '/root'
self.avd_name = 'test'
self.api_level = 21
@mock.patch('os.symlink')
@mock.patch('subprocess.check_call')
def test_avd_creation(self, mocked_sys_link, mocked_suprocess):
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(self.android_path, self.avd_name, self.api_level)
self.assertTrue(mocked_list_dir.called)
self.assertTrue(mocked_sys_link.called)
self.assertTrue(mocked_suprocess.called)
+25
View File
@@ -0,0 +1,25 @@
"""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.android_path = '/root'
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.android_path, self.emulator_file, self.api_level, self.sys_img)
self.assertTrue(mocked_sys_link.called)
self.assertTrue(mocked_suprocess.called)
+27
View File
@@ -0,0 +1,27 @@
"""Unit test for android.py."""
from unittest import TestCase
from src import android
class TestItemPosition(TestCase):
"""Unit test class to test method get_item_position."""
def setUp(self):
self.items = ['android 4.1', 'android 4.2.2', 'android 4.3', 'android 4.4', 'android 4.4.2']
def test_valid_params(self):
keyword = '4.2'
output = android.get_item_position(keyword, self.items)
self.assertEqual(1, output)
def test_invalid_keyword(self):
keyword = 'fake'
output = android.get_item_position(keyword, self.items)
self.assertEqual(0, output)
def test_empty_array(self):
items = []
keyword = '4.2'
output = android.get_item_position(keyword, items)
self.assertEqual(0, output)
View File
+16
View File
@@ -0,0 +1,16 @@
"""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)
+47
View File
@@ -0,0 +1,47 @@
"""Unit test for appium.py."""
from unittest import TestCase
import os
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']