diff --git a/awx/main/tests/ad_hoc.py b/awx/main/tests/ad_hoc.py index b5155ed155..76c89c79f6 100644 --- a/awx/main/tests/ad_hoc.py +++ b/awx/main/tests/ad_hoc.py @@ -6,6 +6,7 @@ import glob import os import subprocess import tempfile +import mock # Django from django.conf import settings @@ -21,7 +22,6 @@ from awx.main.tests.tasks import TEST_SSH_KEY_DATA, TEST_SSH_KEY_DATA_LOCKED, TE __all__ = ['RunAdHocCommandTest', 'AdHocCommandApiTest'] - class BaseAdHocCommandTest(BaseJobExecutionTest): ''' Common initialization for testing ad hoc commands. @@ -360,6 +360,9 @@ class RunAdHocCommandTest(BaseAdHocCommandTest): self.check_job_result(ad_hoc_command, 'error', expect_traceback=True) +def run_pexpect_mock(self, *args, **kwargs): + return 'successful', 0 + class AdHocCommandApiTest(BaseAdHocCommandTest): ''' Test API list/detail views for ad hoc commands. @@ -385,7 +388,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): del data[k] return self.post(url, data, expect=expect) - def test_ad_hoc_command_list(self): + @mock.patch('awx.main.tasks.BaseTask.run_pexpect', side_effect=run_pexpect_mock) + def test_ad_hoc_command_list(self, ignore): url = reverse('api:ad_hoc_command_list') # Retrieve the empty list of ad hoc commands. @@ -558,7 +562,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): response = self.run_test_ad_hoc_command(become_enabled=True) self.assertEqual(response['become_enabled'], True) - def test_ad_hoc_command_detail(self): + @mock.patch('awx.main.tasks.BaseTask.run_pexpect', side_effect=run_pexpect_mock) + def test_ad_hoc_command_detail(self, ignore): with self.current_user('admin'): response1 = self.run_test_ad_hoc_command() response2 = self.run_test_ad_hoc_command() @@ -622,7 +627,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.delete(url, expect=204) self.delete(url, expect=404) - def test_ad_hoc_command_cancel(self): + @mock.patch('awx.main.tasks.BaseTask.run_pexpect', side_effect=run_pexpect_mock) + def test_ad_hoc_command_cancel(self, ignore): # Override setting so that ad hoc command isn't actually started. with self.settings(CELERY_UNIT_TEST=False): with self.current_user('admin'): @@ -674,7 +680,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.assertEqual(response['can_cancel'], False) self.post(url, {}, expect=405) - def test_ad_hoc_command_relaunch(self): + @mock.patch('awx.main.tasks.BaseTask.run_pexpect', side_effect=run_pexpect_mock) + def test_ad_hoc_command_relaunch(self, ignore): with self.current_user('admin'): response = self.run_test_ad_hoc_command() @@ -735,6 +742,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): response = self.post(url, {}, expect=400) def test_ad_hoc_command_events_list(self): + # TODO: Create test events instead of relying on playbooks execution + with self.current_user('admin'): response = self.run_test_ad_hoc_command() response = self.run_test_ad_hoc_command() @@ -823,6 +832,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.delete(url, expect=401) def test_ad_hoc_command_event_detail(self): + # TODO: Mock pexpect. Create test events instead of relying on playbooks execution + with self.current_user('admin'): response = self.run_test_ad_hoc_command() @@ -877,7 +888,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.patch(url, {}, expect=401) self.delete(url, expect=401) - def test_ad_hoc_command_activity_stream(self): + @mock.patch('awx.main.tasks.BaseTask.run_pexpect', side_effect=run_pexpect_mock) + def test_ad_hoc_command_activity_stream(self, ignore): with self.current_user('admin'): response = self.run_test_ad_hoc_command() @@ -927,7 +939,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.patch(url, {}, expect=401) self.delete(url, expect=401) - def test_inventory_ad_hoc_commands_list(self): + @mock.patch('awx.main.tasks.BaseTask.run_pexpect', side_effect=run_pexpect_mock) + def test_inventory_ad_hoc_commands_list(self, ignore): with self.current_user('admin'): response = self.run_test_ad_hoc_command() response = self.run_test_ad_hoc_command(inventory=self.inventory2.pk) @@ -1030,6 +1043,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.assertTrue(response['can_run_ad_hoc_commands']) def test_host_ad_hoc_commands_list(self): + # TODO: Figure out why this test needs pexpect + with self.current_user('admin'): response = self.run_test_ad_hoc_command() response = self.run_test_ad_hoc_command(limit=self.host2.name) @@ -1079,6 +1094,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.delete(url, expect=401) def test_group_ad_hoc_commands_list(self): + # TODO: Figure out why this test needs pexpect + with self.current_user('admin'): response = self.run_test_ad_hoc_command() # self.host + self.host2 response = self.run_test_ad_hoc_command(limit=self.group.name) # self.host @@ -1133,6 +1150,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest): self.delete(url, expect=401) def test_host_ad_hoc_command_events_list(self): + # TODO: Mock run_pexpect. Create test events instead of relying on playbooks execution + with self.current_user('admin'): response = self.run_test_ad_hoc_command() diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index bb38e21d79..095b795651 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -14,6 +14,7 @@ import time from multiprocessing import Process from subprocess import Popen import re +import mock # PyYAML import yaml @@ -76,8 +77,14 @@ class QueueStartStopTestMixin(QueueTestMixin): super(QueueStartStopTestMixin, self).tearDown() self.terminate_queue() +class MockCommonlySlowTestMixin(object): + def __init__(self, *args, **kwargs): + from awx.api import generics + mock.patch.object(generics, 'get_view_description', return_value=None).start() + super(MockCommonlySlowTestMixin, self).__init__(*args, **kwargs) + ansible_version = get_ansible_version() -class BaseTestMixin(QueueTestMixin): +class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin): ''' Mixin with shared code for use by all test cases. ''' diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 18146a9042..1c0e07cd8b 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -135,6 +135,13 @@ TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'), ) +TEMPLATE_LOADERS = ( + ('django.template.loaders.cached.Loader', ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + )), +) + ROOT_URLCONF = 'awx.urls' WSGI_APPLICATION = 'awx.wsgi.application'