mirror of
https://github.com/budtmo/docker-android.git
synced 2026-07-30 19:23:22 +00:00
Added End-2-End Test
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""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.convert_str_to_bool('True'), True)
|
||||
self.assertEqual(app.convert_str_to_bool('t'), True)
|
||||
self.assertEqual(app.convert_str_to_bool('1'), True)
|
||||
self.assertEqual(app.convert_str_to_bool('YES'), True)
|
||||
|
||||
def test_invalid_bool(self):
|
||||
self.assertEqual(app.convert_str_to_bool(''), False)
|
||||
self.assertEqual(app.convert_str_to_bool('test'), False)
|
||||
|
||||
def test_invalid_format(self):
|
||||
self.assertEqual(app.convert_str_to_bool(True), None)
|
||||
|
||||
@mock.patch('src.app.prepare_avd')
|
||||
@mock.patch('subprocess.Popen')
|
||||
def test_run_with_appium(self, mocked_avd, mocked_subprocess):
|
||||
with mock.patch('src.app.appium_run') as mocked_appium:
|
||||
os.environ['APPIUM'] = str(True)
|
||||
app.run()
|
||||
self.assertTrue(mocked_avd.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
self.assertTrue(mocked_appium.called)
|
||||
|
||||
@mock.patch('src.app.prepare_avd')
|
||||
@mock.patch('subprocess.Popen')
|
||||
def test_run_withhout_appium(self, mocked_avd, mocked_subprocess):
|
||||
with mock.patch('src.app.appium_run') as mocked_appium:
|
||||
os.environ['APPIUM'] = str(False)
|
||||
app.run()
|
||||
self.assertTrue(mocked_avd.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
self.assertFalse(mocked_appium.called)
|
||||
@@ -0,0 +1,63 @@
|
||||
"""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('os.popen')
|
||||
@mock.patch('subprocess.check_call')
|
||||
def test_without_selenium_grid(self, mocked_os, mocked_subprocess):
|
||||
os.environ['CONNECT_TO_GRID'] = str(False)
|
||||
self.assertFalse(mocked_os.called)
|
||||
self.assertFalse(mocked_subprocess.called)
|
||||
app.appium_run(self.avd_name)
|
||||
self.assertTrue(mocked_os.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
|
||||
@mock.patch('os.popen')
|
||||
@mock.patch('subprocess.check_call')
|
||||
def test_with_selenium_grid(self, mocked_os, mocked_subprocess):
|
||||
with mock.patch('src.app.create_node_config') as mocked_config:
|
||||
self.assertFalse(mocked_config.called)
|
||||
self.assertFalse(mocked_os.called)
|
||||
self.assertFalse(mocked_subprocess.called)
|
||||
app.appium_run(self.avd_name)
|
||||
self.assertTrue(mocked_config.called)
|
||||
self.assertTrue(mocked_os.called)
|
||||
self.assertTrue(mocked_subprocess.called)
|
||||
|
||||
@mock.patch('os.popen')
|
||||
@mock.patch('subprocess.check_call')
|
||||
def test_invalid_integer(self, mocked_os, 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_os.called)
|
||||
self.assertFalse(mocked_subprocess.called)
|
||||
app.appium_run(self.avd_name)
|
||||
self.assertFalse(mocked_config.called)
|
||||
self.assertTrue(mocked_os.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', 'android', '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']
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Unit test for android virtual device creation.py."""
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
import mock
|
||||
|
||||
from src import app
|
||||
|
||||
|
||||
@mock.patch('subprocess.check_call')
|
||||
@mock.patch('os.symlink')
|
||||
class TestAvd(TestCase):
|
||||
"""Unit test class to test method create_avd."""
|
||||
|
||||
def setUp(self):
|
||||
self.avd_name = 'test_avd'
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
def test_samsung_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)
|
||||
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 tearDown(self):
|
||||
if os.getenv('DEVICE'):
|
||||
del os.environ['DEVICE']
|
||||
Reference in New Issue
Block a user