Files
awx/awx/main/tests/unit/conftest.py
AlanCoding 8ae979908c Enforce unified list field consistency
Discovered via bug: controller_node field present in
project update list but not in detail view

Added tests to assert that "unified" list serializer
produces same fields as the ordinary serializer,
for unified jobs & unified JTs

Added test to check that list serializers do differ
from detail serializer except for allowed differences

Added test to check that list serializers are applied
correctly - only on list views, and that detail views,
likewise, do not use list serializers

Fix the many many bugs discovered by these new
testing mechanisms
2018-06-29 14:03:52 -04:00

56 lines
1.6 KiB
Python

import pytest
import logging
from mock import PropertyMock
from awx.api.urls import urlpatterns as api_patterns
# Django
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern
@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 = []
@pytest.fixture()
def all_views():
'''
returns a set of all views in the app
'''
patterns = set([])
url_views = set([])
# Add recursive URL patterns
unprocessed = set(api_patterns)
while unprocessed:
to_process = unprocessed.copy()
unprocessed = set([])
for pattern in to_process:
if hasattr(pattern, 'lookup_str') and not pattern.lookup_str.startswith('awx.api'):
continue
patterns.add(pattern)
if isinstance(pattern, RegexURLResolver):
for sub_pattern in pattern.url_patterns:
if sub_pattern not in patterns:
unprocessed.add(sub_pattern)
# Get view classes
for pattern in patterns:
if isinstance(pattern, RegexURLPattern) and hasattr(pattern.callback, 'view_class'):
url_views.add(pattern.callback.view_class)
return url_views
@pytest.fixture()
def dummy_log_record():
return logging.LogRecord(
'awx', # logger name
20, # loglevel INFO
'./awx/some/module.py', # pathname
100, # lineno
'User joe logged in', # msg
tuple(), # args,
None # exc_info
)