mirror of
https://github.com/ansible/awx.git
synced 2024-10-27 09:25:10 +03:00
Merge pull request #1766 from chrismeyersfsu/i_like_parallel_tests_and_I_can_not_lie
parallelize test running
This commit is contained in:
commit
7f214f5ad2
2
Makefile
2
Makefile
@ -379,7 +379,7 @@ test:
|
||||
@if [ "$(VENV_BASE)" ]; then \
|
||||
. $(VENV_BASE)/awx/bin/activate; \
|
||||
fi; \
|
||||
py.test $(TEST_DIRS)
|
||||
py.test -n auto $(TEST_DIRS)
|
||||
|
||||
test_combined: test_ansible test
|
||||
|
||||
|
@ -77,7 +77,7 @@ class InstanceManager(models.Manager):
|
||||
def me(self):
|
||||
"""Return the currently active instance."""
|
||||
# If we are running unit tests, return a stub record.
|
||||
if settings.IS_TESTING(sys.argv):
|
||||
if settings.IS_TESTING(sys.argv) or hasattr(sys, '_called_from_test'):
|
||||
return self.model(id=1,
|
||||
hostname='localhost',
|
||||
uuid='00000000-0000-0000-0000-000000000000')
|
||||
|
@ -15,6 +15,16 @@ from awx.main.tests.factories import (
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
import sys
|
||||
sys._called_from_test = True
|
||||
|
||||
|
||||
def pytest_unconfigure(config):
|
||||
import sys
|
||||
del sys._called_from_test
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_access():
|
||||
@contextmanager
|
||||
|
@ -102,21 +102,21 @@ class TestOAuth2Application:
|
||||
assert access.can_delete(app) is can_access
|
||||
|
||||
|
||||
def test_superuser_can_always_create(self, admin, org_admin, org_member, alice):
|
||||
def test_superuser_can_always_create(self, admin, org_admin, org_member, alice, organization):
|
||||
access = OAuth2ApplicationAccess(admin)
|
||||
for user in [admin, org_admin, org_member, alice]:
|
||||
assert access.can_add({
|
||||
'name': 'test app', 'user': user.pk, 'client_type': 'confidential',
|
||||
'authorization_grant_type': 'password', 'organization': 1
|
||||
'authorization_grant_type': 'password', 'organization': organization.id
|
||||
})
|
||||
|
||||
def test_normal_user_cannot_create(self, admin, org_admin, org_member, alice):
|
||||
def test_normal_user_cannot_create(self, admin, org_admin, org_member, alice, organization):
|
||||
for access_user in [org_member, alice]:
|
||||
access = OAuth2ApplicationAccess(access_user)
|
||||
for user in [admin, org_admin, org_member, alice]:
|
||||
assert not access.can_add({
|
||||
'name': 'test app', 'user': user.pk, 'client_type': 'confidential',
|
||||
'authorization_grant_type': 'password', 'organization': 1
|
||||
'authorization_grant_type': 'password', 'organization': organization.id
|
||||
})
|
||||
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
import tempfile
|
||||
import json
|
||||
import yaml
|
||||
|
||||
import pytest
|
||||
from itertools import count
|
||||
|
||||
from awx.main.utils.encryption import encrypt_value
|
||||
from awx.main.tasks import RunJob
|
||||
from awx.main.models import (
|
||||
@ -16,6 +17,15 @@ from awx.main.utils.safe_yaml import SafeLoader
|
||||
ENCRYPTED_SECRET = encrypt_value('secret')
|
||||
|
||||
|
||||
class DistinctParametrize(object):
|
||||
|
||||
def __init__(self):
|
||||
self._gen = count(0)
|
||||
|
||||
def __call__(self, value):
|
||||
return str(next(self._gen))
|
||||
|
||||
|
||||
@pytest.mark.survey
|
||||
class SurveyVariableValidation:
|
||||
|
||||
@ -243,7 +253,7 @@ def test_optional_survey_question_defaults(
|
||||
('password', 'foo', 5, {'extra_vars': {'x': ''}}, {'x': ''}),
|
||||
('password', ENCRYPTED_SECRET, 5, {'extra_vars': {'x': '$encrypted$'}}, {}),
|
||||
('password', ENCRYPTED_SECRET, 10, {'extra_vars': {'x': '$encrypted$'}}, {'x': ENCRYPTED_SECRET}),
|
||||
])
|
||||
], ids=DistinctParametrize())
|
||||
def test_survey_encryption_defaults(survey_spec_factory, question_type, default, maxlen, kwargs, expected):
|
||||
spec = survey_spec_factory([
|
||||
{
|
||||
|
@ -158,7 +158,7 @@ def test_jt_existing_values_are_nonsensitive(job_template_with_ids, user_unit):
|
||||
"""Assure that permission checks are not required if submitted data is
|
||||
identical to what the job template already has."""
|
||||
|
||||
data = model_to_dict(job_template_with_ids)
|
||||
data = model_to_dict(job_template_with_ids, exclude=['unifiedjobtemplate_ptr'])
|
||||
access = JobTemplateAccess(user_unit)
|
||||
|
||||
assert access.changes_are_non_sensitive(job_template_with_ids, data)
|
||||
|
@ -2155,7 +2155,7 @@ def test_aquire_lock_open_fail_logged(logging_getLogger, os_open):
|
||||
|
||||
ProjectUpdate = tasks.RunProjectUpdate()
|
||||
|
||||
with pytest.raises(OSError, errno=3, strerror='dummy message'):
|
||||
with pytest.raises(OSError, message='dummy message'):
|
||||
ProjectUpdate.acquire_lock(instance)
|
||||
assert logger.err.called_with("I/O error({0}) while trying to open lock file [{1}]: {2}".format(3, 'this_file_does_not_exist', 'dummy message'))
|
||||
|
||||
@ -2181,7 +2181,7 @@ def test_aquire_lock_acquisition_fail_logged(fcntl_flock, logging_getLogger, os_
|
||||
|
||||
ProjectUpdate = tasks.RunProjectUpdate()
|
||||
|
||||
with pytest.raises(IOError, errno=3, strerror='dummy message'):
|
||||
with pytest.raises(IOError, message='dummy message'):
|
||||
ProjectUpdate.acquire_lock(instance)
|
||||
os_close.assert_called_with(3)
|
||||
assert logger.err.called_with("I/O error({0}) while trying to aquire lock on file [{1}]: {2}".format(3, 'this_file_does_not_exist', 'dummy message'))
|
||||
|
9
awx/network_ui/tests/conftest.py
Normal file
9
awx/network_ui/tests/conftest.py
Normal file
@ -0,0 +1,9 @@
|
||||
import pytest
|
||||
from mock import PropertyMock
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _disable_database_settings(mocker):
|
||||
m = mocker.patch('awx.conf.settings.SettingsWrapper.all_supported_settings', new_callable=PropertyMock)
|
||||
m.return_value = []
|
||||
|
@ -4,7 +4,6 @@
|
||||
import os
|
||||
import re # noqa
|
||||
import sys
|
||||
import ldap
|
||||
import djcelery
|
||||
import six
|
||||
from datetime import timedelta
|
||||
@ -39,6 +38,13 @@ def IS_TESTING(argv=None):
|
||||
return is_testing(argv)
|
||||
|
||||
|
||||
if "pytest" in sys.modules:
|
||||
import mock
|
||||
with mock.patch('__main__.__builtins__.dir', return_value=[]):
|
||||
import ldap
|
||||
else:
|
||||
import ldap
|
||||
|
||||
DEBUG = True
|
||||
SQL_DEBUG = DEBUG
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
###############################################################################
|
||||
import os
|
||||
import urllib
|
||||
import sys
|
||||
|
||||
|
||||
def patch_broken_pipe_error():
|
||||
@ -66,7 +67,7 @@ DATABASES = {
|
||||
# Use SQLite for unit tests instead of PostgreSQL. If the lines below are
|
||||
# commented out, Django will create the test_awx-dev database in PostgreSQL to
|
||||
# run unit tests.
|
||||
if is_testing(sys.argv):
|
||||
if "pytest" in sys.modules:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
|
@ -6,12 +6,13 @@ unittest2
|
||||
pep8
|
||||
flake8
|
||||
pyflakes
|
||||
pytest==2.9.2
|
||||
pytest==3.5.1
|
||||
pytest-cov
|
||||
pytest-django
|
||||
pytest-pythonpath
|
||||
pytest-mock
|
||||
pytest-timeout
|
||||
pytest-xdist
|
||||
logutils
|
||||
flower
|
||||
uwsgitop
|
||||
|
Loading…
Reference in New Issue
Block a user