mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 11:25:08 -02:30
Merge pull request #220 from chrismeyersfsu/explore-test_speedup
Explore test speedup
This commit is contained in:
@@ -6,6 +6,7 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import mock
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
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']
|
__all__ = ['RunAdHocCommandTest', 'AdHocCommandApiTest']
|
||||||
|
|
||||||
|
|
||||||
class BaseAdHocCommandTest(BaseJobExecutionTest):
|
class BaseAdHocCommandTest(BaseJobExecutionTest):
|
||||||
'''
|
'''
|
||||||
Common initialization for testing ad hoc commands.
|
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)
|
self.check_job_result(ad_hoc_command, 'error', expect_traceback=True)
|
||||||
|
|
||||||
|
|
||||||
|
def run_pexpect_mock(self, *args, **kwargs):
|
||||||
|
return 'successful', 0
|
||||||
|
|
||||||
class AdHocCommandApiTest(BaseAdHocCommandTest):
|
class AdHocCommandApiTest(BaseAdHocCommandTest):
|
||||||
'''
|
'''
|
||||||
Test API list/detail views for ad hoc commands.
|
Test API list/detail views for ad hoc commands.
|
||||||
@@ -385,7 +388,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
del data[k]
|
del data[k]
|
||||||
return self.post(url, data, expect=expect)
|
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')
|
url = reverse('api:ad_hoc_command_list')
|
||||||
|
|
||||||
# Retrieve the empty list of ad hoc commands.
|
# 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)
|
response = self.run_test_ad_hoc_command(become_enabled=True)
|
||||||
self.assertEqual(response['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'):
|
with self.current_user('admin'):
|
||||||
response1 = self.run_test_ad_hoc_command()
|
response1 = self.run_test_ad_hoc_command()
|
||||||
response2 = 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=204)
|
||||||
self.delete(url, expect=404)
|
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.
|
# Override setting so that ad hoc command isn't actually started.
|
||||||
with self.settings(CELERY_UNIT_TEST=False):
|
with self.settings(CELERY_UNIT_TEST=False):
|
||||||
with self.current_user('admin'):
|
with self.current_user('admin'):
|
||||||
@@ -674,7 +680,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
self.assertEqual(response['can_cancel'], False)
|
self.assertEqual(response['can_cancel'], False)
|
||||||
self.post(url, {}, expect=405)
|
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'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response = self.run_test_ad_hoc_command()
|
||||||
|
|
||||||
@@ -735,6 +742,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
response = self.post(url, {}, expect=400)
|
response = self.post(url, {}, expect=400)
|
||||||
|
|
||||||
def test_ad_hoc_command_events_list(self):
|
def test_ad_hoc_command_events_list(self):
|
||||||
|
# TODO: Create test events instead of relying on playbooks execution
|
||||||
|
|
||||||
with self.current_user('admin'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response = self.run_test_ad_hoc_command()
|
||||||
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)
|
self.delete(url, expect=401)
|
||||||
|
|
||||||
def test_ad_hoc_command_event_detail(self):
|
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'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response = self.run_test_ad_hoc_command()
|
||||||
|
|
||||||
@@ -877,7 +888,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
self.patch(url, {}, expect=401)
|
self.patch(url, {}, expect=401)
|
||||||
self.delete(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'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response = self.run_test_ad_hoc_command()
|
||||||
|
|
||||||
@@ -927,7 +939,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
self.patch(url, {}, expect=401)
|
self.patch(url, {}, expect=401)
|
||||||
self.delete(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'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response = self.run_test_ad_hoc_command()
|
||||||
response = self.run_test_ad_hoc_command(inventory=self.inventory2.pk)
|
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'])
|
self.assertTrue(response['can_run_ad_hoc_commands'])
|
||||||
|
|
||||||
def test_host_ad_hoc_commands_list(self):
|
def test_host_ad_hoc_commands_list(self):
|
||||||
|
# TODO: Figure out why this test needs pexpect
|
||||||
|
|
||||||
with self.current_user('admin'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response = self.run_test_ad_hoc_command()
|
||||||
response = self.run_test_ad_hoc_command(limit=self.host2.name)
|
response = self.run_test_ad_hoc_command(limit=self.host2.name)
|
||||||
@@ -1079,6 +1094,8 @@ class AdHocCommandApiTest(BaseAdHocCommandTest):
|
|||||||
self.delete(url, expect=401)
|
self.delete(url, expect=401)
|
||||||
|
|
||||||
def test_group_ad_hoc_commands_list(self):
|
def test_group_ad_hoc_commands_list(self):
|
||||||
|
# TODO: Figure out why this test needs pexpect
|
||||||
|
|
||||||
with self.current_user('admin'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command() # self.host + self.host2
|
response = self.run_test_ad_hoc_command() # self.host + self.host2
|
||||||
response = self.run_test_ad_hoc_command(limit=self.group.name) # self.host
|
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)
|
self.delete(url, expect=401)
|
||||||
|
|
||||||
def test_host_ad_hoc_command_events_list(self):
|
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'):
|
with self.current_user('admin'):
|
||||||
response = self.run_test_ad_hoc_command()
|
response = self.run_test_ad_hoc_command()
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import time
|
|||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
import re
|
import re
|
||||||
|
import mock
|
||||||
|
|
||||||
# PyYAML
|
# PyYAML
|
||||||
import yaml
|
import yaml
|
||||||
@@ -76,8 +77,14 @@ class QueueStartStopTestMixin(QueueTestMixin):
|
|||||||
super(QueueStartStopTestMixin, self).tearDown()
|
super(QueueStartStopTestMixin, self).tearDown()
|
||||||
self.terminate_queue()
|
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()
|
ansible_version = get_ansible_version()
|
||||||
class BaseTestMixin(QueueTestMixin):
|
class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
|
||||||
'''
|
'''
|
||||||
Mixin with shared code for use by all test cases.
|
Mixin with shared code for use by all test cases.
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -135,6 +135,13 @@ TEMPLATE_DIRS = (
|
|||||||
os.path.join(BASE_DIR, 'templates'),
|
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'
|
ROOT_URLCONF = 'awx.urls'
|
||||||
|
|
||||||
WSGI_APPLICATION = 'awx.wsgi.application'
|
WSGI_APPLICATION = 'awx.wsgi.application'
|
||||||
|
|||||||
Reference in New Issue
Block a user