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
This commit is contained in:
adrian-turjak 2016-12-06 18:09:36 +13:00
parent d2856c9822
commit 1961ca91c3
13 changed files with 32 additions and 46 deletions

View File

@ -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(

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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):

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@ -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)

View File

@ -1 +1,2 @@
mock==1.2.0
flake8>=3.0.4

13
tox.ini
View File

@ -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