Skip to content

Commit

Permalink
Fix multiple pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Jul 25, 2018
1 parent 749e0f6 commit 20d5df7
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 51 deletions.
22 changes: 11 additions & 11 deletions tcms/core/admin.py
Expand Up @@ -27,10 +27,12 @@ def delete_view(self, request, object_id, extra_context=None):
return HttpResponseRedirect(reverse('admin:sites_site_change', args=[settings.SITE_ID]))


class UniqueEmailForm:
class MyUserChangeForm(UserChangeForm):
"""
Enforces unique user emails.
"""
email = forms.EmailField(required=True)

def clean_email(self):
qs = User.objects.filter(email=self.cleaned_data['email'])
if self.instance:
Expand All @@ -41,8 +43,8 @@ def clean_email(self):
return self.cleaned_data['email']


class MyUserChangeForm(UniqueEmailForm, UserChangeForm):
email = forms.EmailField(required=True)
def _modifying_myself(request, object_id):
return request.user.pk == int(object_id)


class KiwiUserAdmin(UserAdmin):
Expand All @@ -53,22 +55,20 @@ class KiwiUserAdmin(UserAdmin):
# even when adding users via admin panel
form = MyUserChangeForm

def change_view(self, request, object_id, extra_context=None):
def change_view(self, request, object_id, form_url='', extra_context=None):
if request.user.is_superuser:
return super().change_view(request, object_id, extra_context)
return super().change_view(request, object_id, form_url, extra_context)

# object history view link to admin_user_change so we redirect
# object history view links to admin_user_change so we redirect
# to the user profile instead
user = User.objects.get(pk=object_id)
return HttpResponseRedirect(reverse('tcms-profile', args=[user.username]))

def _modifying_myself(self, request, object_id):
return request.user.pk == int(object_id)

@admin.options.csrf_protect_m
def delete_view(self, request, object_id, extra_context=None):
# if trying to delete another user go directly to parent
if not self._modifying_myself(request, object_id):
if not _modifying_myself(request, object_id):
return super().delete_view(request, object_id, extra_context)

# else allow deletion of the user own account
Expand All @@ -83,7 +83,7 @@ def delete_view(self, request, object_id, extra_context=None):
def response_delete(self, request, obj_display, obj_id):
result = super().response_delete(request, obj_display, obj_id)

if not self._modifying_myself(request, obj_id):
if not _modifying_myself(request, obj_id):
return result

# user doesn't exist anymore so go to the index page
Expand All @@ -93,7 +93,7 @@ def response_delete(self, request, obj_display, obj_id):
def has_delete_permission(self, request, obj=None):
# allow to delete yourself without having 'delete' permission
# explicitly assigned
if self._modifying_myself(request, getattr(obj, 'pk', 0)):
if _modifying_myself(request, getattr(obj, 'pk', 0)):
return True

return super().has_delete_permission(request, obj)
Expand Down
12 changes: 6 additions & 6 deletions tcms/core/ajax.py
Expand Up @@ -45,7 +45,7 @@ def info(request):
return HttpResponse(serializers.serialize('json', info_type(), fields=('name', 'value')))


class _InfoObjects(object):
class _InfoObjects:

def __init__(self, request, product_id=None):
self.request = request
Expand Down Expand Up @@ -124,7 +124,7 @@ def tags(request):
return render(request, template_name, context_data)


class _TagObjects(object):
class _TagObjects:
""" Used for getting the chosen object(TestPlan, TestCase or TestRun) from the database """

def __init__(self, request):
Expand Down Expand Up @@ -153,7 +153,7 @@ def run(self):
return 'run/get_tag.html', TestRun.objects.get(pk=self.object_pk)


class _TagActions(object):
class _TagActions:
""" Used for performing the 'add' and 'remove' actions on a given tag """

def __init__(self, obj, tag_name):
Expand All @@ -177,7 +177,7 @@ def remove(self):
self.obj.remove_tag(tag)


class _TagCounter(object): # pylint: disable=too-few-public-methods
class _TagCounter: # pylint: disable=too-few-public-methods
""" Used for counting the number of times a tag is assigned to TestRun/TestCase/TestPlan """

def __init__(self, key, test_tags):
Expand Down Expand Up @@ -342,8 +342,8 @@ def clean_bug_form(request):

if request.GET.get('a') not in ('add', 'remove'):
return (None, 'Actions only allow "add" and "remove".')
else:
data['action'] = request.GET.get('a')

data['action'] = request.GET.get('a')
data['bz_external_track'] = True if request.GET.get('bz_external_track',
False) else False

Expand Down
2 changes: 1 addition & 1 deletion tcms/core/contrib/comments/utils.py
Expand Up @@ -26,7 +26,7 @@ def add_comment(request, data):
object_pk = data.get("object_pk")

model = apps.get_model(*ctype.split(".", 1))
target = model._default_manager.get(pk=object_pk)
target = model.objects.get(pk=object_pk)

# Construct the comment form
form = django_comments.get_form()(target, data=data)
Expand Down
10 changes: 4 additions & 6 deletions tcms/core/contrib/comments/views.py
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-

import json

from django.conf import settings
from django.contrib.auth.decorators import permission_required
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse, JsonResponse
from django.http import JsonResponse
from django.views.decorators.http import require_POST

import django_comments as comments
Expand All @@ -19,7 +17,7 @@ def post(request):

# Fill out some initial data fields from an authenticated user, if present
data = request.POST.copy()
form, target = add_comment(request, data)
_form, _target = add_comment(request, data)

return JsonResponse({'rc': 0})

Expand All @@ -40,7 +38,7 @@ def delete(request):
if not comments_s:
if request.is_ajax():
ajax_response = {'rc': 1, 'response': 'Object does not exist.'}
return HttpResponse(json.dumps(ajax_response))
return JsonResponse(ajax_response)

raise ObjectDoesNotExist()

Expand All @@ -62,4 +60,4 @@ def delete(request):
request=request,
)

return HttpResponse(json.dumps(ajax_response))
return JsonResponse(ajax_response)
2 changes: 1 addition & 1 deletion tcms/core/db.py
Expand Up @@ -6,7 +6,7 @@

# TODO: redesign GroupByResult, major goal is to distiguish level node and
# value node.
class GroupByResult(object):
class GroupByResult:
"""Group By result
This object can be used as a normal dict object with less support of stock
Expand Down
2 changes: 1 addition & 1 deletion tcms/core/history.py
Expand Up @@ -98,7 +98,7 @@ class ReadOnlyHistoryAdmin(SimpleHistoryAdmin):
"""
history_list_display = ['Diff']

def Diff(self, obj):
def Diff(self, obj): # pylint: disable=invalid-name
return safe('<pre>%s</pre>' % obj.history_change_reason)

def get_readonly_fields(self, request, obj=None):
Expand Down
6 changes: 4 additions & 2 deletions tcms/core/models/__init__.py
Expand Up @@ -19,10 +19,12 @@ class Meta:
abstract = True

@classmethod
def to_xmlrpc(cls, query={}):
def to_xmlrpc(cls, query=None):
"""
Convert the query set for XMLRPC
"""
if query is None:
query = {}
serializer = XMLRPCSerializer(queryset=cls.objects.filter(**query))
return serializer.serialize_queryset()

Expand All @@ -44,7 +46,7 @@ def clean(self):

for field in self._meta.fields:
# TODO: hardcode 'notes' here
if not (field.name is 'notes') and isinstance(field, strip_types):
if not (field.name == 'notes') and isinstance(field, strip_types):
value = getattr(self, field.name)
if value:
setattr(self, field.name,
Expand Down
2 changes: 1 addition & 1 deletion tcms/core/models/base.py
Expand Up @@ -4,7 +4,7 @@
from tcms.core.utils import request_host_link


class UrlMixin(object):
class UrlMixin:
"""Mixin class for getting full URL"""

def get_full_url(self):
Expand Down
6 changes: 3 additions & 3 deletions tcms/core/utils/__init__.py
Expand Up @@ -68,7 +68,7 @@ def clean_request(request, keys=None):
for key in keys:
key = str(key)
if request_contents.get(key):
if key == 'order_by' or key == 'from_plan':
if key in ('order_by', 'from_plan'):
continue

value = request.GET[key]
Expand All @@ -79,7 +79,7 @@ def clean_request(request, keys=None):
return cleaned_request


class QuerySetIterationProxy(object):
class QuerySetIterationProxy:
"""Iterate a series of object and its associated objects at once
This iteration proxy applies to this kind of structure especially.
Expand Down Expand Up @@ -135,7 +135,7 @@ def __next__(self):
return next_one


class DataTableResult(object):
class DataTableResult:
"""Paginate and order queryset for rendering DataTable response"""

def __init__(self, request_data, queryset, column_names):
Expand Down
4 changes: 2 additions & 2 deletions tcms/issuetracker/types.py
Expand Up @@ -20,7 +20,7 @@
from tcms.issuetracker import github_integration


class IssueTrackerType(object):
class IssueTrackerType:
"""
Represents actions which can be performed with issue trackers.
This is a common interface for all issue trackers that Kiwi TCMS
Expand Down Expand Up @@ -97,7 +97,7 @@ def all_issues_link(self, _ids):
:return: - None if not suported or string representing the URL
"""
return None
pass


class Bugzilla(IssueTrackerType):
Expand Down
12 changes: 6 additions & 6 deletions tcms/report/data.py
Expand Up @@ -47,7 +47,7 @@ def do_nothing(value):
return value


class ProductBuildReportData(object):
class ProductBuildReportData:
"""Report data by builds of a Product"""

def finished_runs_count(self, product_id):
Expand Down Expand Up @@ -112,7 +112,7 @@ def total_runs_count(product_id, finished=False):
return builds


class ProductComponentReportData(object):
class ProductComponentReportData:

def failed_case_runs_count(self, product_id):
return self.total_cases(
Expand Down Expand Up @@ -171,7 +171,7 @@ def total_cases(product_id, condition=None):
return total


class ProductVersionReportData(object):
class ProductVersionReportData:
"""Report data by versions of a Product"""

def finished_case_runs_subtotal(self, product_id):
Expand Down Expand Up @@ -286,7 +286,7 @@ def case_runs_status_subtotal(product_id, version_id):
return subtotal


class CustomReportData(object):
class CustomReportData:
"""Data for custom report
In this data class, a major task is to construct INNER JOINS dynamically
Expand Down Expand Up @@ -548,7 +548,7 @@ def get_case_runs_comments(build_ids, status_ids):
return case_run_comments


class TestingReportBaseData(object):
class TestingReportBaseData:
"""Base data of various testing report"""
# filter criteria is against TestCaseRun
report_criteria = {
Expand Down Expand Up @@ -1288,7 +1288,7 @@ def walk_status_matrix_section(status_matrix_section):
yield _build, run, status_subtotal


class TestingReportCaseRunsData(object):
class TestingReportCaseRunsData:
"""Data of case runs from testing report
Case runs will be search by following criteria,
Expand Down
2 changes: 1 addition & 1 deletion tcms/search/query.py
Expand Up @@ -5,7 +5,7 @@
from tcms.testruns.models import TestRun


class SmartDjangoQuery(object):
class SmartDjangoQuery:
"""
Class mainly wraps the look-up rules and priorities\n
of fields that should be applied on Django queryset.\n
Expand Down
2 changes: 1 addition & 1 deletion tcms/testcases/actions.py
Expand Up @@ -12,7 +12,7 @@
__all__ = ('CategoryActions', 'ComponentActions')


class BaseActions(object):
class BaseActions:
"""Base class for all Actions"""

def __init__(self, request):
Expand Down
2 changes: 1 addition & 1 deletion tcms/testcases/models.py
Expand Up @@ -38,7 +38,7 @@ def serialize(cls):
return {}


class PlainText(object):
class PlainText:
"""Contains plain text converted from four text"""

def __init__(self, action, setup, effect, breakdown):
Expand Down
4 changes: 2 additions & 2 deletions tcms/testcases/views.py
Expand Up @@ -206,7 +206,7 @@ def new(request, template_name='case/new.html'):
if form.is_valid():
tc = create_testcase(request, form, tp)

class ReturnActions(object):
class ReturnActions:
def __init__(self, case, plan):
self.__all__ = ('_addanother', '_continue', '_returntocase', '_returntoplan')
self.case = case
Expand Down Expand Up @@ -1500,7 +1500,7 @@ def bug(request, case_id, template_name='case/get_bug.html'):
# FIXME: Rewrite these codes for Ajax.Request
tc = get_object_or_404(TestCase, case_id=case_id)

class CaseBugActions(object):
class CaseBugActions:
__all__ = ['get_form', 'render', 'add', 'remove']

def __init__(self, request, case, template_name):
Expand Down
2 changes: 1 addition & 1 deletion tcms/testplans/forms.py
Expand Up @@ -17,7 +17,7 @@
MIMETYPE_OPENDOCUMENT = 'application/vnd.oasis.opendocument.text'


class UploadedFile(object): # pylint: disable=too-few-public-methods
class UploadedFile: # pylint: disable=too-few-public-methods
"""Base class for all classes representing a concrete uploaded file"""

def __init__(self, uploaded_file):
Expand Down
2 changes: 1 addition & 1 deletion tcms/testruns/data.py
Expand Up @@ -27,7 +27,7 @@ def get_run_bug_ids(run_id):
).distinct().filter(case_run__run=run_id)


class TestCaseRunDataMixin(object):
class TestCaseRunDataMixin:
"""Data for test case runs"""

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions tcms/testruns/views.py
Expand Up @@ -750,7 +750,7 @@ def get_context_data(self, **kwargs):
def bug(request, case_run_id, template_name='run/execute_case_run.html'):
"""Process the bugs for case runs."""

class CaseRunBugActions(object):
class CaseRunBugActions:

def __init__(self, request, case_run, template_name):
self.request = request
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def env_value(request):
"""Run environment property edit function"""
test_runs = TestRun.objects.filter(run_id__in=request.GET.getlist('run_id'))

class RunEnvActions(object):
class RunEnvActions:
def __init__(self, request, test_runs):
self.__all__ = ['add', 'remove', 'change']
self.ajax_response = {'rc': 0, 'response': 'ok'}
Expand Down

0 comments on commit 20d5df7

Please sign in to comment.