mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 07:56:06 -03:30
Merge pull request #1617 from anoek/unit-test-cleanup
Test cleanup and slow test separation
This commit is contained in:
5
Makefile
5
Makefile
@@ -427,16 +427,17 @@ pylint: reports
|
|||||||
|
|
||||||
check: flake8 pep8 # pyflakes pylint
|
check: flake8 pep8 # pyflakes pylint
|
||||||
|
|
||||||
|
TEST_DIRS=awx/main/tests
|
||||||
# Run all API unit tests.
|
# Run all API unit tests.
|
||||||
test:
|
test:
|
||||||
py.test awx/main/tests awx/api/tests
|
py.test $(TEST_DIRS)
|
||||||
|
|
||||||
test_unit:
|
test_unit:
|
||||||
py.test awx/main/tests/unit
|
py.test awx/main/tests/unit
|
||||||
|
|
||||||
# Run all API unit tests with coverage enabled.
|
# Run all API unit tests with coverage enabled.
|
||||||
test_coverage:
|
test_coverage:
|
||||||
py.test --create-db --cov=awx --cov-report=xml --junitxml=./reports/junit.xml awx/main/tests awx/api/tests
|
py.test --create-db --cov=awx --cov-report=xml --junitxml=./reports/junit.xml $(TEST_DIRS)
|
||||||
|
|
||||||
# Output test coverage as HTML (into htmlcov directory).
|
# Output test coverage as HTML (into htmlcov directory).
|
||||||
coverage_html:
|
coverage_html:
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
# Copyright (c) 2015 Ansible, Inc.
|
|
||||||
# All Rights Reserved.
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
from .decorator_paginated import PaginatedDecoratorTests # noqa
|
|
||||||
from .job_tasks import JobTasksTests # noqa
|
|
||||||
@@ -7,6 +7,8 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import mock
|
import mock
|
||||||
|
import unittest2 as unittest
|
||||||
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -58,6 +60,7 @@ class BaseAdHocCommandTest(BaseJobExecutionTest):
|
|||||||
return self.credential
|
return self.credential
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class RunAdHocCommandTest(BaseAdHocCommandTest):
|
class RunAdHocCommandTest(BaseAdHocCommandTest):
|
||||||
'''
|
'''
|
||||||
Test cases for RunAdHocCommand celery task.
|
Test cases for RunAdHocCommand celery task.
|
||||||
@@ -375,6 +378,7 @@ class RunAdHocCommandTest(BaseAdHocCommandTest):
|
|||||||
def run_pexpect_mock(self, *args, **kwargs):
|
def run_pexpect_mock(self, *args, **kwargs):
|
||||||
return 'successful', 0
|
return 'successful', 0
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class AdHocCommandApiTest(BaseAdHocCommandTest):
|
class AdHocCommandApiTest(BaseAdHocCommandTest):
|
||||||
'''
|
'''
|
||||||
Test API list/detail views for ad hoc commands.
|
Test API list/detail views for ad hoc commands.
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ grandchild
|
|||||||
parent
|
parent
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
class BaseCommandMixin(object):
|
class BaseCommandMixin(object):
|
||||||
'''
|
'''
|
||||||
Base class for tests that run management commands.
|
Base class for tests that run management commands.
|
||||||
@@ -381,6 +382,7 @@ class CleanupJobsTest(BaseCommandMixin, BaseLiveServerTest):
|
|||||||
self.assertFalse(ad_hoc_commands_after)
|
self.assertFalse(ad_hoc_commands_after)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class CleanupActivityStreamTest(BaseCommandMixin, BaseTest):
|
class CleanupActivityStreamTest(BaseCommandMixin, BaseTest):
|
||||||
'''
|
'''
|
||||||
Test cases for cleanup_activitystream management command.
|
Test cases for cleanup_activitystream management command.
|
||||||
@@ -447,6 +449,7 @@ class CleanupActivityStreamTest(BaseCommandMixin, BaseTest):
|
|||||||
'create took %0.3fs, cleanup took %0.3fs, expected < %0.3fs' % (create_elapsed, cleanup_elapsed, create_elapsed / 4))
|
'create took %0.3fs, cleanup took %0.3fs, expected < %0.3fs' % (create_elapsed, cleanup_elapsed, create_elapsed / 4))
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class InventoryImportTest(BaseCommandMixin, BaseLiveServerTest):
|
class InventoryImportTest(BaseCommandMixin, BaseLiveServerTest):
|
||||||
'''
|
'''
|
||||||
Test cases for inventory_import management command.
|
Test cases for inventory_import management command.
|
||||||
@@ -935,6 +938,11 @@ class InventoryImportTest(BaseCommandMixin, BaseLiveServerTest):
|
|||||||
self.assertNotEqual(new_inv.total_groups, 0)
|
self.assertNotEqual(new_inv.total_groups, 0)
|
||||||
self.assertElapsedLessThan(60)
|
self.assertElapsedLessThan(60)
|
||||||
|
|
||||||
|
@unittest.skipIf(True,
|
||||||
|
'This test is deprecated and being removed from '
|
||||||
|
'integration and unit tests in favor of writing '
|
||||||
|
'an explicit unit test around what the original '
|
||||||
|
'problem was')
|
||||||
def test_splunk_inventory(self):
|
def test_splunk_inventory(self):
|
||||||
new_inv = self.organizations[0].inventories.create(name='splunk')
|
new_inv = self.organizations[0].inventories.create(name='splunk')
|
||||||
self.assertEqual(new_inv.hosts.count(), 0)
|
self.assertEqual(new_inv.hosts.count(), 0)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import os
|
|||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
import unittest2 as unittest
|
||||||
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -37,6 +39,7 @@ inventory['group-\u037c\u03b4\u0138\u0137\u03cd\u03a1\u0121\u0137\u0138\u01a1'].
|
|||||||
print json.dumps(inventory)
|
print json.dumps(inventory)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class InventoryTest(BaseTest):
|
class InventoryTest(BaseTest):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -1097,6 +1100,7 @@ class InventoryTest(BaseTest):
|
|||||||
self.assertEqual(response['hosts']['failed'], 8)
|
self.assertEqual(response['hosts']['failed'], 8)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
@override_settings(CELERY_ALWAYS_EAGER=True,
|
@override_settings(CELERY_ALWAYS_EAGER=True,
|
||||||
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
||||||
IGNORE_CELERY_INSPECTOR=True,
|
IGNORE_CELERY_INSPECTOR=True,
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
# Python
|
# Python
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
|
import unittest2 as unittest
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
import django
|
import django
|
||||||
@@ -15,6 +17,7 @@ import yaml
|
|||||||
|
|
||||||
__all__ = ['JobTemplateLaunchTest', 'JobTemplateLaunchPasswordsTest']
|
__all__ = ['JobTemplateLaunchTest', 'JobTemplateLaunchPasswordsTest']
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class JobTemplateLaunchTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
class JobTemplateLaunchTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(JobTemplateLaunchTest, self).setUp()
|
super(JobTemplateLaunchTest, self).setUp()
|
||||||
@@ -183,6 +186,7 @@ class JobTemplateLaunchTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
|||||||
with self.current_user(self.user_sue):
|
with self.current_user(self.user_sue):
|
||||||
self.post(self.launch_url, {}, expect=400)
|
self.post(self.launch_url, {}, expect=400)
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class JobTemplateLaunchPasswordsTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
class JobTemplateLaunchPasswordsTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(JobTemplateLaunchPasswordsTest, self).setUp()
|
super(JobTemplateLaunchPasswordsTest, self).setUp()
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import struct
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import urlparse
|
import urlparse
|
||||||
|
import os
|
||||||
|
import unittest2 as unittest
|
||||||
|
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
import django.test
|
import django.test
|
||||||
@@ -183,6 +186,7 @@ TEST_SURVEY_REQUIREMENTS = '''
|
|||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class JobTemplateTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
class JobTemplateTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
||||||
|
|
||||||
JOB_TEMPLATE_FIELDS = ('id', 'type', 'url', 'related', 'summary_fields',
|
JOB_TEMPLATE_FIELDS = ('id', 'type', 'url', 'related', 'summary_fields',
|
||||||
@@ -501,6 +505,7 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
|||||||
with self.current_user(self.user_doug):
|
with self.current_user(self.user_doug):
|
||||||
self.get(detail_url, expect=403)
|
self.get(detail_url, expect=403)
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class JobTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
class JobTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
||||||
|
|
||||||
def test_get_job_list(self):
|
def test_get_job_list(self):
|
||||||
@@ -653,6 +658,7 @@ class JobTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
|||||||
# and that jobs come back nicely serialized with related resources and so on ...
|
# and that jobs come back nicely serialized with related resources and so on ...
|
||||||
# that we can drill all the way down and can get at host failure lists, etc ...
|
# that we can drill all the way down and can get at host failure lists, etc ...
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
@override_settings(CELERY_ALWAYS_EAGER=True,
|
@override_settings(CELERY_ALWAYS_EAGER=True,
|
||||||
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
||||||
ANSIBLE_TRANSPORT='local')
|
ANSIBLE_TRANSPORT='local')
|
||||||
@@ -1028,6 +1034,7 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase):
|
|||||||
self.post(url, data, expect=400, remote_addr=host_ip)
|
self.post(url, data, expect=400, remote_addr=host_ip)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
@override_settings(CELERY_ALWAYS_EAGER=True,
|
@override_settings(CELERY_ALWAYS_EAGER=True,
|
||||||
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
||||||
ANSIBLE_TRANSPORT='local')
|
ANSIBLE_TRANSPORT='local')
|
||||||
@@ -1092,6 +1099,7 @@ class JobTransactionTest(BaseJobTestMixin, django.test.LiveServerTestCase):
|
|||||||
self.assertEqual(job.status, 'successful', job.result_stdout)
|
self.assertEqual(job.status, 'successful', job.result_stdout)
|
||||||
self.assertFalse(errors)
|
self.assertFalse(errors)
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class JobTemplateSurveyTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
class JobTemplateSurveyTest(BaseJobTestMixin, django.test.TransactionTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(JobTemplateSurveyTest, self).setUp()
|
super(JobTemplateSurveyTest, self).setUp()
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
# Python
|
# Python
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
import os
|
||||||
|
import unittest2 as unittest
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
@@ -15,6 +17,7 @@ from awx.main.tests.job_base import BaseJobTestMixin
|
|||||||
|
|
||||||
__all__ = ['JobStartCancelTest',]
|
__all__ = ['JobStartCancelTest',]
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class JobStartCancelTest(BaseJobTestMixin, BaseLiveServerTest):
|
class JobStartCancelTest(BaseJobTestMixin, BaseLiveServerTest):
|
||||||
|
|
||||||
def test_job_start(self):
|
def test_job_start(self):
|
||||||
|
|||||||
@@ -237,6 +237,7 @@ TEST_VAULT_PLAYBOOK = '''$ANSIBLE_VAULT;1.1;AES256
|
|||||||
|
|
||||||
TEST_VAULT_PASSWORD = '1234'
|
TEST_VAULT_PASSWORD = '1234'
|
||||||
|
|
||||||
|
@unittest.skipIf(os.environ.get('SKIP_SLOW_TESTS', False), 'Skipping slow test')
|
||||||
class RunJobTest(BaseJobExecutionTest):
|
class RunJobTest(BaseJobExecutionTest):
|
||||||
'''
|
'''
|
||||||
Test cases for RunJob celery task.
|
Test cases for RunJob celery task.
|
||||||
@@ -337,10 +338,9 @@ class RunJobTest(BaseJobExecutionTest):
|
|||||||
print
|
print
|
||||||
qs = self.super_django_user.get_queryset(JobEvent)
|
qs = self.super_django_user.get_queryset(JobEvent)
|
||||||
for je in qs.filter(job=job):
|
for je in qs.filter(job=job):
|
||||||
print je.get_event_display2()
|
print(je.get_event_display2())
|
||||||
print je.event, je, je.failed
|
print(je.event, je, je.failed)
|
||||||
print je.event_data
|
print(je.event_data)
|
||||||
print
|
|
||||||
for job_event in job_events:
|
for job_event in job_events:
|
||||||
unicode(job_event) # For test coverage.
|
unicode(job_event) # For test coverage.
|
||||||
job_event.save()
|
job_event.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user