diff --git a/adjutant/actions/v1/projects.py b/adjutant/actions/v1/projects.py index 4f5d8e3..a767154 100644 --- a/adjutant/actions/v1/projects.py +++ b/adjutant/actions/v1/projects.py @@ -109,10 +109,9 @@ class NewProjectAction(BaseAction, ProjectMixin, UserMixin): # put user_id into action cache: self.action.task.cache['user_id'] = user.id self.set_cache('user_id', user.id) - self.add_note(("Existing user '%s' attached to project %s" + - " with roles: %s") - % (user.name, project_id, - default_roles)) + self.add_note( + "Existing user '%s' attached to project %s with roles: %s" + % (user.name, project_id, default_roles)) def _submit(self, token_data): """ @@ -221,9 +220,9 @@ class NewProjectWithUserAction(UserNameAction, ProjectMixin, UserMixin): self.add_note("Project already created.") else: self.action.valid = ( - self._validate_domain_id() and - self._validate_parent_project() and - self._validate_project_absent()) + self._validate_domain_id() + and self._validate_parent_project() + and self._validate_project_absent()) self.action.save() if not self.valid: @@ -302,10 +301,9 @@ class NewProjectWithUserAction(UserNameAction, ProjectMixin, UserMixin): raise self.set_cache('roles_granted', True) - self.add_note(("Existing user '%s' setup on project %s" + - " with roles: %s") - % (self.username, project_id, - default_roles)) + self.add_note( + "Existing user '%s' setup on project %s with roles: %s" + % (self.username, project_id, default_roles)) elif self.action.state == "disabled": user_id = self.get_cache('user_id') if not user_id: @@ -349,10 +347,9 @@ class NewProjectWithUserAction(UserNameAction, ProjectMixin, UserMixin): raise self.set_cache('roles_granted', True) - self.add_note(("Existing user '%s' setup on project %s" + - " with roles: %s") - % (self.username, project_id, - default_roles)) + self.add_note( + "Existing user '%s' setup on project %s with roles: %s" + % (self.username, project_id, default_roles)) def _submit(self, token_data): """ diff --git a/adjutant/actions/v1/tests/test_resource_actions.py b/adjutant/actions/v1/tests/test_resource_actions.py index 3b02f8f..5f0e393 100644 --- a/adjutant/actions/v1/tests/test_resource_actions.py +++ b/adjutant/actions/v1/tests/test_resource_actions.py @@ -31,8 +31,7 @@ from adjutant.common.tests.fake_clients import ( @mock.patch('adjutant.common.user_store.IdentityManager', FakeManager) @mock.patch( - 'adjutant.actions.v1.resources.' + - 'openstack_clients.get_neutronclient', + 'adjutant.actions.v1.resources.openstack_clients.get_neutronclient', get_fake_neutron) @mock.patch( 'adjutant.common.openstack_clients.get_neutronclient', diff --git a/adjutant/actions/v1/users.py b/adjutant/actions/v1/users.py index 396d3f8..5b8a34d 100644 --- a/adjutant/actions/v1/users.py +++ b/adjutant/actions/v1/users.py @@ -54,7 +54,7 @@ class NewUserAction(UserNameAction, ProjectMixin, UserMixin): return True if user.email != self.email: self.add_note( - 'Found matching username, but email did not match.' + + 'Found matching username, but email did not match. ' 'Reporting as invalid.') return False diff --git a/adjutant/api/v1/openstack.py b/adjutant/api/v1/openstack.py index f519812..bd8d018 100644 --- a/adjutant/api/v1/openstack.py +++ b/adjutant/api/v1/openstack.py @@ -200,7 +200,7 @@ class UserDetail(tasks.TaskView): if user: return Response( {'errors': [ - 'Revoking keystone users not implemented. ' + + 'Revoking keystone users not implemented. ' 'Try removing all roles instead.']}, status=501) project_tasks = models.Task.objects.filter( diff --git a/adjutant/api/v1/tasks.py b/adjutant/api/v1/tasks.py index 53c08e2..7d1addc 100644 --- a/adjutant/api/v1/tasks.py +++ b/adjutant/api/v1/tasks.py @@ -52,8 +52,8 @@ class TaskView(APIViewWithLogger): self.task_type, settings.DEFAULT_TASK_SETTINGS) actions = ( - class_conf.get('default_actions', []) or - self.default_actions[:]) + class_conf.get('default_actions', []) + or self.default_actions[:]) actions += class_conf.get('additional_actions', []) @@ -72,8 +72,8 @@ class TaskView(APIViewWithLogger): action_serializer_list = [] action_names = ( - class_conf.get('default_actions', []) or - self.default_actions[:]) + class_conf.get('default_actions', []) + or self.default_actions[:]) action_names += class_conf.get('additional_actions', []) # instantiate all action serializers and check validity @@ -369,8 +369,8 @@ class InviteUser(TaskView): self.logger.info("(%s) - New AttachUser request." % timezone.now()) # Default project_id to the keystone user's project - if ('project_id' not in request.data or - request.data['project_id'] is None): + if ('project_id' not in request.data + or request.data['project_id'] is None): request.data['project_id'] = request.keystone_user['project_id'] processed, status = self.process_actions(request) @@ -454,8 +454,8 @@ class EditUser(TaskView): self.task_type, settings.DEFAULT_TASK_SETTINGS) action_names = ( - class_conf.get('default_actions', []) or - self.default_actions[:]) + class_conf.get('default_actions', []) + or self.default_actions[:]) action_names += class_conf.get('additional_actions', []) role_blacklist = class_conf.get('role_blacklist', []) diff --git a/adjutant/api/v1/tests/test_api_admin.py b/adjutant/api/v1/tests/test_api_admin.py index a44fb91..301d03c 100644 --- a/adjutant/api/v1/tests/test_api_admin.py +++ b/adjutant/api/v1/tests/test_api_admin.py @@ -1548,7 +1548,7 @@ class AdminAPITests(APITestCase): self.assertEqual( response.json()['errors'], - ["Error: Something went wrong on the server. " + + ["Error: Something went wrong on the server. " "It will be looked into shortly."]) new_task = Task.objects.all()[0] @@ -1558,6 +1558,6 @@ class AdminAPITests(APITestCase): self.assertEqual( new_notification.notes, {'errors': [ - "Error: KeyError('Forced key error.') while updating task. " + + "Error: KeyError('Forced key error.') while updating task. " "See task itself for details."]}) self.assertEqual(new_notification.task, new_task) diff --git a/adjutant/api/v1/tests/test_api_taskview.py b/adjutant/api/v1/tests/test_api_taskview.py index 033a9c1..b4cb39a 100644 --- a/adjutant/api/v1/tests/test_api_taskview.py +++ b/adjutant/api/v1/tests/test_api_taskview.py @@ -352,7 +352,7 @@ class TaskViewTests(AdjutantAPITestCase): self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.json(), - {'errors': ['Cannot approve an invalid task. ' + + {'errors': ['Cannot approve an invalid task. ' 'Update data and rerun pre_approve.']}) def test_new_project_existing_user(self): @@ -1394,8 +1394,8 @@ class TaskViewTests(AdjutantAPITestCase): class_conf = settings.TASK_SETTINGS.get( CreateProject.task_type, settings.DEFAULT_TASK_SETTINGS) expected_action_names = ( - class_conf.get('default_actions', []) or - CreateProject.default_actions[:]) + class_conf.get('default_actions', []) + or CreateProject.default_actions[:]) expected_action_names += class_conf.get('additional_actions', []) actions = new_task.actions @@ -1420,7 +1420,7 @@ class TaskViewTests(AdjutantAPITestCase): self.assertEqual( response.json(), - {'errors': ["Error: Something went wrong on the server. " + + {'errors': ["Error: Something went wrong on the server. " "It will be looked into shortly."]}) new_task = Task.objects.all()[0] @@ -1430,6 +1430,6 @@ class TaskViewTests(AdjutantAPITestCase): self.assertEqual( new_notification.notes, {'errors': [ - "Error: KeyError('Forced key error.') while setting up " + + "Error: KeyError('Forced key error.') while setting up " "task. See task itself for details."]}) self.assertEqual(new_notification.task, new_task) diff --git a/adjutant/api/v1/utils.py b/adjutant/api/v1/utils.py index fd68898..3d9b50c 100644 --- a/adjutant/api/v1/utils.py +++ b/adjutant/api/v1/utils.py @@ -74,8 +74,8 @@ def send_stage_email(task, email_conf, token=None): if len(emails) > 1: notes = { 'errors': - (("Error: Unable to send update, more than one email for" + - " task: %s") % task.uuid) + ("Error: Unable to send update, more than one email for task: %s" + % task.uuid) } create_notification(task, notes, error=True) return @@ -231,8 +231,8 @@ def parse_filters(func, *args, **kwargs): except (ValueError, AttributeError): return Response( {'errors': [ - ("Filters incorrectly formatted. Required format: " + - "{'filters': {'fieldname': { 'operation': 'value'}}") + "Filters incorrectly formatted. Required format: " + "{'filters': {'fieldname': { 'operation': 'value'}}" ]}, status=400 ) diff --git a/adjutant/api/v1/views.py b/adjutant/api/v1/views.py index 0727bec..3960122 100644 --- a/adjutant/api/v1/views.py +++ b/adjutant/api/v1/views.py @@ -50,15 +50,15 @@ class APIViewWithLogger(APIView): timezone.now(), e, trace)) notes = { 'errors': - [("Error: %s(%s) %s. See task " + - "itself for details.") % (type(e).__name__, e, error_text)] + ["Error: %s(%s) %s. See task itself for details." + % (type(e).__name__, e, error_text)] } create_notification(task, notes, error=True) response_dict = { 'errors': - ["Error: Something went wrong on the " + - "server. It will be looked into shortly."] + ["Error: Something went wrong on the server. " + "It will be looked into shortly."] } if return_response: return Response(response_dict, status=500) @@ -396,7 +396,7 @@ class TaskDetail(APIViewWithLogger): if not valid: return Response( {'errors': - ['Cannot approve an invalid task. ' + + ['Cannot approve an invalid task. ' 'Update data and rerun pre_approve.']}, status=400) @@ -689,8 +689,8 @@ class TokenDetail(APIViewWithLogger): except KeyError: errors[field] = ["This field is required.", ] except TypeError: - errors = ["Improperly formated json. " + - "Should be a key-value object.", ] + errors = ["Improperly formated json. " + "Should be a key-value object."] break if errors: diff --git a/adjutant/common/quota.py b/adjutant/common/quota.py index db2a39a..1ab6542 100644 --- a/adjutant/common/quota.py +++ b/adjutant/common/quota.py @@ -201,8 +201,8 @@ class QuotaManager(object): self._quota_updaters[service] self.project_id = project_id - self.size_diff_threshold = (size_difference_threshold or - self.default_size_diff_threshold) + self.size_diff_threshold = (size_difference_threshold + or self.default_size_diff_threshold) def get_current_region_quota(self, region_id): current_quota = {} diff --git a/adjutant/common/tests/fake_clients.py b/adjutant/common/tests/fake_clients.py index 3a57b56..faace53 100644 --- a/adjutant/common/tests/fake_clients.py +++ b/adjutant/common/tests/fake_clients.py @@ -186,8 +186,8 @@ class FakeManager(object): domain = self._domain_from_id(domain) global identity_cache for user in identity_cache['users'].values(): - if (user.name.lower() == name.lower() and - user.domain_id == domain.id): + if (user.name.lower() == name.lower() + and user.domain_id == domain.id): return user return None @@ -291,8 +291,8 @@ class FakeManager(object): roles = [] for assignment in identity_cache['role_assignments']: - if (assignment.user['id'] == user.id and - assignment.scope['project']['id'] == project.id): + if (assignment.user['id'] == user.id + and assignment.scope['project']['id'] == project.id): if (assignment.scope.get('OS-INHERIT:inherited_to') and not inherited) or ( @@ -364,8 +364,8 @@ class FakeManager(object): domain = self._domain_from_id(domain) global identity_cache for project in identity_cache['projects'].values(): - if (project.name.lower() == project_name.lower() and - project.domain_id == domain.id): + if (project.name.lower() == project_name.lower() + and project.domain_id == domain.id): return project return None diff --git a/tox.ini b/tox.ini index 8017bb3..1c78555 100644 --- a/tox.ini +++ b/tox.ini @@ -45,7 +45,7 @@ commands = [flake8] -ignore = D100,D101,D102,D103,D104,D105,D200,D203,D202,D204,D205,D208,D400,D401 +ignore = D100,D101,D102,D103,D104,D105,D200,D203,D202,D204,D205,D208,D400,D401,W503 show-source = true builtins = _ exclude=.venv,venv,.env,env,.git,.tox,dist,doc,*lib/python*,*egg,adjutant/api/migrations/*,adjutant/actions/migrations