From 1961ca91c303605f3556aca15cec0ab93c2d586d Mon Sep 17 00:00:00 2001 From: adrian-turjak Date: Tue, 6 Dec 2016 18:09:36 +1300 Subject: [PATCH] Adding pep8 tests * also fixing test posargs to allow single test running * fixing up random pep8 failures * removing empty or unused test modules Change-Id: I59bb2fedeeac2b8eeb45740d16768fec59fb3e4b --- stacktask/actions/models.py | 11 ++++++----- stacktask/actions/tenant_setup/models.py | 19 ++++++++----------- stacktask/api/tests.py | 15 --------------- stacktask/api/v1/models.py | 1 + stacktask/api/v1/openstack.py | 3 +-- stacktask/api/v1/tests/__init__.py | 1 - stacktask/api/v1/utils.py | 2 +- stacktask/api/v1/views.py | 2 +- .../notifications/request_tracker/tests.py | 3 --- stacktask/notifications/tests.py | 3 --- stacktask/settings.py | 4 ++-- test-requirements.txt | 1 + tox.ini | 13 +++++++++++-- 13 files changed, 32 insertions(+), 46 deletions(-) delete mode 100644 stacktask/api/tests.py delete mode 100644 stacktask/notifications/request_tracker/tests.py delete mode 100644 stacktask/notifications/tests.py diff --git a/stacktask/actions/models.py b/stacktask/actions/models.py index 6ee2c90..621f594 100644 --- a/stacktask/actions/models.py +++ b/stacktask/actions/models.py @@ -148,7 +148,7 @@ class BaseAction(object): self.logger.info("(%s) - %s" % (timezone.now(), note)) note = "%s - (%s)" % (note, timezone.now()) self.action.task.add_action_note( - unicode(self), note) + str(self), note) def pre_approve(self): return self._pre_approve() @@ -168,7 +168,7 @@ class BaseAction(object): def _submit(self, token_data): raise NotImplementedError - def __unicode__(self): + def __str__(self): return self.__class__.__name__ @@ -435,7 +435,7 @@ class NewUserAction(UserNameAction, ProjectMixin, UserMixin): self._validate_domain_id() and self._validate_project_id() and self._validate_targer_user() - ) + ) self.action.save() def _pre_approve(self): @@ -933,7 +933,7 @@ class ResetUserPasswordAction(UserNameAction, UserMixin): self._validate_domain_name() and self._validate_username_exists() and self._validate_user_roles() - ) + ) self.action.save() def _pre_approve(self): @@ -1020,7 +1020,7 @@ class EditUserRolesAction(UserIdAction, ProjectMixin, UserMixin): self._validate_project_id() and self._validate_target_user() and self._validate_user_roles() - ) + ) self.action.save() def _pre_approve(self): @@ -1090,6 +1090,7 @@ def register_action_class(action_class, serializer_class): data[action_class.__name__] = (action_class, serializer_class) settings.ACTION_CLASSES.update(data) + # Register each action model register_action_class(NewUserAction, serializers.NewUserSerializer) register_action_class( diff --git a/stacktask/actions/tenant_setup/models.py b/stacktask/actions/tenant_setup/models.py index 3518491..41a5c63 100644 --- a/stacktask/actions/tenant_setup/models.py +++ b/stacktask/actions/tenant_setup/models.py @@ -72,7 +72,7 @@ class NewDefaultNetworkAction(BaseAction, ProjectMixin): self._validate_project_id() and self._validate_defaults() and self._validate_keystone_user() - ) + ) self.action.save() def _create_network(self): @@ -195,7 +195,7 @@ class NewProjectDefaultNetworkAction(NewDefaultNetworkAction): self.action.valid = ( self._validate_region() and self._validate_defaults() - ) + ) self.action.save() def _validate(self): @@ -203,7 +203,7 @@ class NewProjectDefaultNetworkAction(NewDefaultNetworkAction): self._validate_region() and self._validate_project_id() and self._validate_defaults() - ) + ) self.action.save() def _pre_approve(self): @@ -257,7 +257,7 @@ class AddDefaultUsersToProjectAction(BaseAction, ProjectMixin, UserMixin): self.action.valid = ( self._validate_users() and self._validate_project_id() - ) + ) self.action.save() def _pre_approve(self): @@ -295,9 +295,7 @@ class SetProjectQuotaAction(BaseAction): class ServiceQuotaFunctor(object): def __call__(self, project_id, values): - self.client.quotas.update( - project_id, - **values) + self.client.quotas.update(project_id, **values) class ServiceQuotaCinderFunctor(ServiceQuotaFunctor): def __init__(self, region_name): @@ -318,9 +316,7 @@ class SetProjectQuotaAction(BaseAction): body = { 'quota': values } - self.client.update_quota( - project_id, - body) + self.client.update_quota(project_id, body) _quota_updaters = { 'cinder': ServiceQuotaCinderFunctor, @@ -386,7 +382,8 @@ class SetProjectQuotaAction(BaseAction): # functor for the service+region service_functor = updater_class(region_name) service_functor(self.project_id, values) - self.add_note("Project quota for region %s set to %s" % ( + self.add_note( + "Project quota for region %s set to %s" % ( region_name, quota_size)) self.action.state = "completed" diff --git a/stacktask/api/tests.py b/stacktask/api/tests.py deleted file mode 100644 index 5c954a0..0000000 --- a/stacktask/api/tests.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (C) 2015 Catalyst IT Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from stacktask.api.v1 import tests diff --git a/stacktask/api/v1/models.py b/stacktask/api/v1/models.py index 55b06d7..9a40eaf 100644 --- a/stacktask/api/v1/models.py +++ b/stacktask/api/v1/models.py @@ -25,6 +25,7 @@ def register_taskview_class(url, taskview_class): 'url': url} settings.TASKVIEW_CLASSES.update(data) + register_taskview_class(r'^actions/CreateProject/?$', tasks.CreateProject) register_taskview_class(r'^actions/InviteUser/?$', tasks.InviteUser) register_taskview_class(r'^actions/ResetPassword/?$', tasks.ResetPassword) diff --git a/stacktask/api/v1/openstack.py b/stacktask/api/v1/openstack.py index fffa0da..f14bf4a 100644 --- a/stacktask/api/v1/openstack.py +++ b/stacktask/api/v1/openstack.py @@ -204,8 +204,7 @@ class UserRoles(tasks.TaskView): request.data['user_id'] = user_id self.logger.info("(%s) - New EditUser %s request." % ( - timezone.now(), request.method - )) + timezone.now(), request.method)) processed, status = self.process_actions(request) errors = processed.get('errors', None) diff --git a/stacktask/api/v1/tests/__init__.py b/stacktask/api/v1/tests/__init__.py index 4330ba9..7f4ac3b 100644 --- a/stacktask/api/v1/tests/__init__.py +++ b/stacktask/api/v1/tests/__init__.py @@ -239,7 +239,6 @@ class FakeManager(object): global temp_cache return temp_cache['domains'].get(domain_id, None) - def get_region(self, region_id): global temp_cache return temp_cache['regions'].get(region_id, None) diff --git a/stacktask/api/v1/utils.py b/stacktask/api/v1/utils.py index 53992d0..084e704 100644 --- a/stacktask/api/v1/utils.py +++ b/stacktask/api/v1/utils.py @@ -65,7 +65,7 @@ def send_email(task, email_conf, token=None): email = act.get_email() if email: emails.add(email) - actions[unicode(act)] = act + actions[str(act)] = act if not emails: return diff --git a/stacktask/api/v1/views.py b/stacktask/api/v1/views.py index b159cf1..d678f8e 100644 --- a/stacktask/api/v1/views.py +++ b/stacktask/api/v1/views.py @@ -654,7 +654,7 @@ class TokenDetail(APIViewWithLogger): if field not in required_fields: required_fields.append(field) - return Response({'actions': [unicode(act) for act in actions], + return Response({'actions': [str(act) for act in actions], 'required_fields': required_fields}) def post(self, request, id, format=None): diff --git a/stacktask/notifications/request_tracker/tests.py b/stacktask/notifications/request_tracker/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/stacktask/notifications/request_tracker/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/stacktask/notifications/tests.py b/stacktask/notifications/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/stacktask/notifications/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/stacktask/settings.py b/stacktask/settings.py index 9909ce2..86c0d1c 100644 --- a/stacktask/settings.py +++ b/stacktask/settings.py @@ -100,8 +100,8 @@ if 'test' in sys.argv: else: config_file = "/etc/stacktask/conf.yaml" if not os.path.isfile(config_file): - print ("%s does not exist. Reverting to default config file." % - config_file) + print("%s does not exist. Reverting to default config file." % + config_file) config_file = "conf/conf.yaml" with open(config_file) as f: CONFIG = yaml.load(f) diff --git a/test-requirements.txt b/test-requirements.txt index feb26b9..3b79276 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,2 @@ mock==1.2.0 +flake8>=3.0.4 diff --git a/tox.ini b/tox.ini index 3554c7b..439824f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,19 @@ [tox] -envlist = py27 +envlist = py27,pep8 skipsdist = True [testenv] usedevelop = True deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt -commands = stacktask-api test stacktask {posargs} +commands = stacktask-api test {posargs} setenv = VIRTUAL_ENV={envdir} + +[testenv:pep8] +commands = flake8 + +[flake8] +ignore = D100,D101,D102,D103,D104,D105,D200,D203,D202,D204,D205,D208,D400,D401 +show-source = true +builtins = _ +exclude=.venv,venv,.env,env,.git,.tox,dist,doc,*lib/python*,*egg,stacktask/api/migrations/*,stacktask/actions/migrations