From 473ed016deab00d157a756518e3b46860a16c4ea Mon Sep 17 00:00:00 2001 From: Aaron Tan Date: Tue, 15 Nov 2016 16:32:27 -0500 Subject: [PATCH] Fix flake8 E305 errors. --- awx/api/generics.py | 1 + awx/api/views.py | 2 +- awx/conf/conf.py | 1 + awx/conf/registry.py | 1 + awx/lib/tower_display_callback/display.py | 2 ++ awx/lib/tower_display_callback/events.py | 1 + awx/main/conf.py | 1 + awx/main/management/commands/run_socketio_service.py | 1 + awx/main/models/__init__.py | 3 +++ awx/main/models/organization.py | 1 + awx/main/registrar.py | 1 + awx/main/signals.py | 2 ++ awx/main/tests/base.py | 1 + awx/main/tests/functional/api/test_organization_counts.py | 1 + awx/main/tests/functional/commands/test_cleanup_facts.py | 1 + .../tests/functional/commands/test_run_fact_cache_receiver.py | 1 + awx/main/tests/functional/conftest.py | 1 + awx/main/tests/functional/models/fact/test_get_host_fact.py | 4 ++++ awx/main/tests/manual/workflows/linear.py | 1 + awx/main/tests/manual/workflows/parallel.py | 1 + awx/main/tests/old/users.py | 1 + awx/main/tests/unit/models/test_workflow_unit.py | 1 + awx/main/tests/unit/scheduler/conftest.py | 2 ++ awx/main/tests/unit/scheduler/test_dag.py | 1 + awx/main/utils.py | 1 + awx/plugins/library/scan_files.py | 1 + awx/plugins/library/scan_packages.py | 1 + awx/plugins/library/scan_services.py | 1 + awx/settings/defaults.py | 1 + awx/sso/__init__.py | 1 + awx/sso/conf.py | 2 ++ awx/sso/views.py | 3 +++ setup.py | 1 + tools/data_generators/rbac_dummy_data_generator.py | 1 + 34 files changed, 45 insertions(+), 1 deletion(-) diff --git a/awx/api/generics.py b/awx/api/generics.py index a6b7bb12fb..6329b3fd62 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -469,6 +469,7 @@ class SubListCreateAttachDetachAPIView(SubListCreateAPIView): else: return self.attach(request, *args, **kwargs) + ''' Models for which you want the last instance to be deleted from the database when the last disassociate is called should inherit from this class. Further, diff --git a/awx/api/views.py b/awx/api/views.py index 06a249d60e..ee219894f8 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -1736,6 +1736,7 @@ class GroupList(ListCreateAPIView): serializer_class = GroupSerializer capabilities_prefetch = ['inventory.admin', 'inventory.adhoc', 'inventory.update'] + ''' Useful when you have a self-refering ManyToManyRelationship. * Tower uses a shallow (2-deep only) url pattern. For example: @@ -4013,7 +4014,6 @@ class RoleChildrenList(SubListAPIView): return Role.filter_visible_roles(self.request.user, role.children.all()) - # Create view functions for all of the class-based views to simplify inclusion # in URL patterns and reverse URL lookups, converting CamelCase names to # lowercase_with_underscore (e.g. MyView.as_view() becomes my_view). diff --git a/awx/conf/conf.py b/awx/conf/conf.py index e14e7c684c..8562bb0929 100644 --- a/awx/conf/conf.py +++ b/awx/conf/conf.py @@ -60,6 +60,7 @@ register( def _get_read_only_ansible_cow_selection_default(): return getattr(settings, 'ANSIBLE_COW_SELECTION', 'No default cow!') + register( 'READONLY_ANSIBLE_COW_SELECTION', field_class=fields.CharField, diff --git a/awx/conf/registry.py b/awx/conf/registry.py index 1babae1786..8e90f8add3 100644 --- a/awx/conf/registry.py +++ b/awx/conf/registry.py @@ -118,4 +118,5 @@ class SettingsRegistry(object): logger.warning('Unable to retrieve default value for setting "%s".', setting, exc_info=True) return field_instance + settings_registry = SettingsRegistry() diff --git a/awx/lib/tower_display_callback/display.py b/awx/lib/tower_display_callback/display.py index 5b1265201e..7f32ca9379 100644 --- a/awx/lib/tower_display_callback/display.py +++ b/awx/lib/tower_display_callback/display.py @@ -67,6 +67,7 @@ def with_verbosity(f): return f(*args, **kwargs) return wrapper + Display.verbose = with_verbosity(Display.verbose) @@ -89,4 +90,5 @@ def display_with_context(f): event_context.remove_local(uuid=None) return wrapper + Display.display = display_with_context(Display.display) diff --git a/awx/lib/tower_display_callback/events.py b/awx/lib/tower_display_callback/events.py index ad7eb6418e..009c0c8efc 100644 --- a/awx/lib/tower_display_callback/events.py +++ b/awx/lib/tower_display_callback/events.py @@ -134,4 +134,5 @@ class EventContext(object): def dump_end(self, fileobj): self.dump(fileobj, self.get_end_dict()) + event_context = EventContext() diff --git a/awx/main/conf.py b/awx/main/conf.py index 35a3d12275..70af78240a 100644 --- a/awx/main/conf.py +++ b/awx/main/conf.py @@ -88,6 +88,7 @@ def _load_default_license_from_file(): logger.warning('Could not read license from "%s".', license_file, exc_info=True) return {} + register( 'LICENSE', field_class=fields.DictField, diff --git a/awx/main/management/commands/run_socketio_service.py b/awx/main/management/commands/run_socketio_service.py index 4c233aa312..c1c49b7945 100644 --- a/awx/main/management/commands/run_socketio_service.py +++ b/awx/main/management/commands/run_socketio_service.py @@ -124,6 +124,7 @@ class SocketController(object): self.server = server return server + socketController = SocketController(SocketSessionManager()) # diff --git a/awx/main/models/__init__.py b/awx/main/models/__init__.py index f70229cf72..97297d7bcf 100644 --- a/awx/main/models/__init__.py +++ b/awx/main/models/__init__.py @@ -36,6 +36,7 @@ def _new_handle_m2m_field(self, obj, field): return _original_handle_m2m_field(self, obj, field) _PythonSerializer.handle_m2m_field = _new_handle_m2m_field + # Add custom methods to User model for permissions checks. from django.contrib.auth.models import User # noqa from awx.main.access import * # noqa @@ -58,6 +59,7 @@ def user_get_admin_of_organizations(user): def user_get_auditor_of_organizations(user): return Organization.objects.filter(auditor_role__members=user) + User.add_to_class('organizations', user_get_organizations) User.add_to_class('admin_of_organizations', user_get_admin_of_organizations) User.add_to_class('auditor_of_organizations', user_get_auditor_of_organizations) @@ -74,6 +76,7 @@ def user_is_system_auditor(user, tf): else: Role.singleton('system_auditor').members.remove(user) + User.add_to_class('is_system_auditor', user_is_system_auditor) # Import signal handlers only after models have been defined. diff --git a/awx/main/models/organization.py b/awx/main/models/organization.py index e02ad2d75c..d39c5180f8 100644 --- a/awx/main/models/organization.py +++ b/awx/main/models/organization.py @@ -191,6 +191,7 @@ class Profile(CreatedModifiedModel): default='', ) + """ Since expiration and session expiration is event driven a token could be invalidated for both reasons. Further, we only support a single reason for a diff --git a/awx/main/registrar.py b/awx/main/registrar.py index 5f0a1589a4..6d0ccfe495 100644 --- a/awx/main/registrar.py +++ b/awx/main/registrar.py @@ -39,4 +39,5 @@ class ActivityStreamRegistrar(object): m2m_attr = getattr(model, m2mfield.name) m2m_changed.disconnect(dispatch_uid=str(self.__class__) + str(m2m_attr.through) + "_associate") + activity_stream_registrar = ActivityStreamRegistrar() diff --git a/awx/main/signals.py b/awx/main/signals.py index 7a06934d27..cb2987beb7 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -200,6 +200,7 @@ def cleanup_detached_labels_on_deleted_parent(sender, instance, **kwargs): if l.is_candidate_for_detach(): l.delete() + post_save.connect(emit_update_inventory_on_created_or_deleted, sender=Host) post_delete.connect(emit_update_inventory_on_created_or_deleted, sender=Host) post_save.connect(emit_update_inventory_on_created_or_deleted, sender=Group) @@ -307,6 +308,7 @@ class ActivityStreamEnabled(threading.local): def __nonzero__(self): return bool(self.enabled and getattr(settings, 'ACTIVITY_STREAM_ENABLED', True)) + activity_stream_enabled = ActivityStreamEnabled() @contextlib.contextmanager diff --git a/awx/main/tests/base.py b/awx/main/tests/base.py index 699e9885e2..907caa7e75 100644 --- a/awx/main/tests/base.py +++ b/awx/main/tests/base.py @@ -89,6 +89,7 @@ class MockCommonlySlowTestMixin(object): mock.patch.object(generics, 'get_view_description', return_value=None).start() super(MockCommonlySlowTestMixin, self).__init__(*args, **kwargs) + ansible_version = get_ansible_version() class BaseTestMixin(MockCommonlySlowTestMixin): ''' diff --git a/awx/main/tests/functional/api/test_organization_counts.py b/awx/main/tests/functional/api/test_organization_counts.py index 0e57488fab..f20396e46b 100644 --- a/awx/main/tests/functional/api/test_organization_counts.py +++ b/awx/main/tests/functional/api/test_organization_counts.py @@ -40,6 +40,7 @@ def organization_resource_creator(organization, user): return organization return rf + COUNTS_PRIMES = { 'users': 11, 'admins': 5, diff --git a/awx/main/tests/functional/commands/test_cleanup_facts.py b/awx/main/tests/functional/commands/test_cleanup_facts.py index e67a751a42..206fe04d2e 100644 --- a/awx/main/tests/functional/commands/test_cleanup_facts.py +++ b/awx/main/tests/functional/commands/test_cleanup_facts.py @@ -35,6 +35,7 @@ def test_cleanup_granularity(fact_scans, hosts): deleted_count = cleanup_facts.cleanup(timestamp_future, granularity) assert 60 == deleted_count + ''' Delete half of the scans ''' diff --git a/awx/main/tests/functional/commands/test_run_fact_cache_receiver.py b/awx/main/tests/functional/commands/test_run_fact_cache_receiver.py index 0bb9da523d..c6b00ef048 100644 --- a/awx/main/tests/functional/commands/test_run_fact_cache_receiver.py +++ b/awx/main/tests/functional/commands/test_run_fact_cache_receiver.py @@ -57,6 +57,7 @@ def test_process_fact_message_services(fact_msg_services): check_process_fact_message_module(fact_returned, fact_msg_services, 'services') + ''' We pickypack our fact sending onto the Ansible fact interface. The interface is . Where facts is a json blob of all the facts. diff --git a/awx/main/tests/functional/conftest.py b/awx/main/tests/functional/conftest.py index d81cc49538..9d7b913069 100644 --- a/awx/main/tests/functional/conftest.py +++ b/awx/main/tests/functional/conftest.py @@ -51,6 +51,7 @@ def disable_signals(): mocked = mock.patch('django.dispatch.Signal.send', autospec=True) mocked.start() + ''' FIXME: Not sure how "far" just setting the BROKER_URL will get us. We may need to incluence CELERY's configuration like we do in the old unit tests (see base.py) diff --git a/awx/main/tests/functional/models/fact/test_get_host_fact.py b/awx/main/tests/functional/models/fact/test_get_host_fact.py index 2569417496..4e74615b45 100644 --- a/awx/main/tests/functional/models/fact/test_get_host_fact.py +++ b/awx/main/tests/functional/models/fact/test_get_host_fact.py @@ -20,6 +20,7 @@ def test_newest_scan_exact(hosts, fact_scans): assert fact_found == fact_known + ''' Show me the most recent state of the sytem at any point of time. or, said differently @@ -48,6 +49,7 @@ def test_newest_scan_less_than(hosts, fact_scans): assert fact_found == fact_known + ''' Tests query Fact that is in the middle of the fact scan timeline, but not an exact timestamp. ''' @@ -69,6 +71,7 @@ def test_query_middle_of_timeline(hosts, fact_scans): assert fact_found == fact_known + ''' Query time less than any fact scan. Should return None ''' @@ -83,6 +86,7 @@ def test_query_result_empty(hosts, fact_scans): assert fact_found is None + ''' Query by fact module other than 'ansible' ''' diff --git a/awx/main/tests/manual/workflows/linear.py b/awx/main/tests/manual/workflows/linear.py index ebb2c99b45..4a8801de88 100755 --- a/awx/main/tests/manual/workflows/linear.py +++ b/awx/main/tests/manual/workflows/linear.py @@ -36,5 +36,6 @@ def do_init(): jt_never= JobTemplate.objects.get(id=7) do_init_workflow(jt_success, jt_fail, jt_never) + if __name__ == "__main__": do_init() diff --git a/awx/main/tests/manual/workflows/parallel.py b/awx/main/tests/manual/workflows/parallel.py index 303554d793..766ddc6d0c 100755 --- a/awx/main/tests/manual/workflows/parallel.py +++ b/awx/main/tests/manual/workflows/parallel.py @@ -41,5 +41,6 @@ def do_init(): jt_parallel.append(JobTemplate.objects.get(id=18)) do_init_workflow(jt_success, jt_fail, jt_never, jt_parallel) + if __name__ == "__main__": do_init() diff --git a/awx/main/tests/old/users.py b/awx/main/tests/old/users.py index 7d95fe7604..73ceafd840 100644 --- a/awx/main/tests/old/users.py +++ b/awx/main/tests/old/users.py @@ -74,6 +74,7 @@ class AuthTokenLimitTest(BaseTest): response = self.get(user_me_url, expect=401, auth=auth_token1) self.assertEqual(AuthToken.reason_long('limit_reached'), response['detail']) + ''' Ensure ips from the X-Forwarded-For get honored and used in auth tokens ''' diff --git a/awx/main/tests/unit/models/test_workflow_unit.py b/awx/main/tests/unit/models/test_workflow_unit.py index add8379727..709668ddcf 100644 --- a/awx/main/tests/unit/models/test_workflow_unit.py +++ b/awx/main/tests/unit/models/test_workflow_unit.py @@ -105,6 +105,7 @@ def jt_ask(job_template_factory): def project_unit(): return Project(name='example-proj') + example_prompts = dict(job_type='check', job_tags='quack', limit='duck', skip_tags='oink') @pytest.fixture diff --git a/awx/main/tests/unit/scheduler/conftest.py b/awx/main/tests/unit/scheduler/conftest.py index 42f2b59cd3..8bbba71c46 100644 --- a/awx/main/tests/unit/scheduler/conftest.py +++ b/awx/main/tests/unit/scheduler/conftest.py @@ -185,6 +185,7 @@ def successful_inventory_update(epoch, inventory_update_factory): inventory_update['status'] = 'successful' return inventory_update + ''' Job ''' @@ -219,6 +220,7 @@ def running_job(job_factory): job['status'] = 'running' return job + ''' Inventory id -> [InventorySourceDict, ...] ''' diff --git a/awx/main/tests/unit/scheduler/test_dag.py b/awx/main/tests/unit/scheduler/test_dag.py index ab1e45c3d8..3aad7e9b27 100644 --- a/awx/main/tests/unit/scheduler/test_dag.py +++ b/awx/main/tests/unit/scheduler/test_dag.py @@ -48,6 +48,7 @@ def dag_simple_edge_labels(): return dag + ''' class TestSimpleDAG(object): def test_get_root_nodes(self, dag_root): diff --git a/awx/main/utils.py b/awx/main/utils.py index 4178bea0d2..d03ee3b0d4 100644 --- a/awx/main/utils.py +++ b/awx/main/utils.py @@ -662,6 +662,7 @@ def getattrd(obj, name, default=NoDefaultProvided): return default raise + current_apps = apps def set_current_apps(apps): global current_apps diff --git a/awx/plugins/library/scan_files.py b/awx/plugins/library/scan_files.py index cd07954b48..64c52c65bd 100644 --- a/awx/plugins/library/scan_files.py +++ b/awx/plugins/library/scan_files.py @@ -161,4 +161,5 @@ def main(): results = dict(ansible_facts=dict(files=files)) module.exit_json(**results) + main() diff --git a/awx/plugins/library/scan_packages.py b/awx/plugins/library/scan_packages.py index ee091db39f..3b94fb75ab 100755 --- a/awx/plugins/library/scan_packages.py +++ b/awx/plugins/library/scan_packages.py @@ -85,4 +85,5 @@ def main(): results = dict(skipped=True, msg="Unsupported Distribution") module.exit_json(**results) + main() diff --git a/awx/plugins/library/scan_services.py b/awx/plugins/library/scan_services.py index 1632ffab39..778cdcc058 100644 --- a/awx/plugins/library/scan_services.py +++ b/awx/plugins/library/scan_services.py @@ -190,4 +190,5 @@ def main(): results['msg'] = "WARNING: Could not find status for all services. Sometimes this is due to insufficient privileges." module.exit_json(**results) + main() diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index a15c4121d4..4dc7791324 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -37,6 +37,7 @@ def is_testing(argv=None): def IS_TESTING(argv=None): return is_testing(argv) + DEBUG = True TEMPLATE_DEBUG = DEBUG SQL_DEBUG = DEBUG diff --git a/awx/sso/__init__.py b/awx/sso/__init__.py index dd505d105d..c7ec0d9321 100644 --- a/awx/sso/__init__.py +++ b/awx/sso/__init__.py @@ -18,6 +18,7 @@ def xmlsec_initialize(*args, **kwargs): original_xmlsec_initialize(*args, **kwargs) xmlsec_initialized = True + dm.xmlsec.binding.initialize = xmlsec_initialize diff --git a/awx/sso/conf.py b/awx/sso/conf.py index 45f75b35af..533067a91c 100644 --- a/awx/sso/conf.py +++ b/awx/sso/conf.py @@ -23,6 +23,7 @@ class SocialAuthCallbackURL(object): path = reverse('social:complete', args=(self.provider,)) return urlparse.urljoin(settings.TOWER_URL_BASE, path) + SOCIAL_AUTH_ORGANIZATION_MAP_HELP_TEXT = _('''\ Mapping to organization admins/users from social auth accounts. This setting controls which users are placed into which Tower organizations based on @@ -799,6 +800,7 @@ register( def get_saml_metadata_url(): return urlparse.urljoin(settings.TOWER_URL_BASE, reverse('sso:saml_metadata')) + register( 'SOCIAL_AUTH_SAML_CALLBACK_URL', field_class=fields.CharField, diff --git a/awx/sso/views.py b/awx/sso/views.py index 962b89943e..512caa0e75 100644 --- a/awx/sso/views.py +++ b/awx/sso/views.py @@ -33,6 +33,7 @@ class BaseRedirectView(RedirectView): else: return url + sso_error = BaseRedirectView.as_view() sso_inactive = BaseRedirectView.as_view() @@ -67,6 +68,7 @@ class CompleteView(BaseRedirectView): response.set_cookie('current_user', current_user) return response + sso_complete = CompleteView.as_view() @@ -86,4 +88,5 @@ class MetadataView(View): else: return HttpResponse(content=str(errors), content_type='text/plain') + saml_metadata = MetadataView.as_view() diff --git a/setup.py b/setup.py index 2cf997a1a6..78dde7b8ec 100755 --- a/setup.py +++ b/setup.py @@ -77,6 +77,7 @@ def proc_data_files(data_files): ##################################################################### + setup( name='ansible-tower', version=__version__.split("-")[0], # FIXME: Should keep full version here? diff --git a/tools/data_generators/rbac_dummy_data_generator.py b/tools/data_generators/rbac_dummy_data_generator.py index f9e583c3a3..06f4880750 100755 --- a/tools/data_generators/rbac_dummy_data_generator.py +++ b/tools/data_generators/rbac_dummy_data_generator.py @@ -101,6 +101,7 @@ def spread(n, m): ret[0] += n return ret + ids = defaultdict(lambda: 0)