Skip to content

linting for the api module #2870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion prospector-more.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ inherits: prospector
strictness: medium

ignore-paths:
- api/
- cdn/
- comments/
- core/
Expand Down
19 changes: 15 additions & 4 deletions readthedocs/api/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""API resources"""
import logging
import json
import redis

from django.contrib.auth.models import User
from django.conf import settings
from django.conf.urls import url
from django.shortcuts import get_object_or_404
from django.core.cache import cache
Expand All @@ -16,7 +16,7 @@
from tastypie.utils import dict_strip_unicode_keys, trailing_slash

from readthedocs.builds.constants import LATEST
from readthedocs.builds.models import Build, Version
from readthedocs.builds.models import Version
from readthedocs.core.utils import trigger_build
from readthedocs.projects.models import Project, ImportedFile
from readthedocs.restapi.views.footer_views import get_version_compare_data
Expand All @@ -27,6 +27,9 @@


class ProjectResource(ModelResource, SearchMixin):

"""API resource for Project model."""

users = fields.ToManyField('readthedocs.api.base.UserResource', 'users')

class Meta(object):
Expand Down Expand Up @@ -115,6 +118,9 @@ def override_urls(self):


class VersionResource(ModelResource):

"""API resource for Version model."""

project = fields.ForeignKey(ProjectResource, 'project', full=True)

class Meta(object):
Expand All @@ -133,7 +139,7 @@ def get_object_list(self, request):
self._meta.queryset = Version.objects.api(user=request.user)
return super(VersionResource, self).get_object_list(request)

def version_compare(self, request, project_slug, base=None, **kwargs):
def version_compare(self, request, project_slug, base=None, **__):
project = get_object_or_404(Project, slug=project_slug)
if base and base != LATEST:
try:
Expand Down Expand Up @@ -180,6 +186,9 @@ def override_urls(self):


class FileResource(ModelResource, SearchMixin):

"""API resource for ImportedFile model."""

project = fields.ForeignKey(ProjectResource, 'project', full=True)

class Meta(object):
Expand Down Expand Up @@ -207,7 +216,7 @@ def override_urls(self):
name="api_get_anchor"),
]

def get_anchor(self, request, **kwargs):
def get_anchor(self, request, **__):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
Expand All @@ -229,6 +238,8 @@ def get_anchor(self, request, **kwargs):

class UserResource(ModelResource):

"""Read-only API resource for User model."""

class Meta(object):
allowed_methods = ['get']
queryset = User.objects.all()
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/api/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Slumber API client"""
import logging

from slumber import API, serialize
from slumber import API
from requests import Session
from django.conf import settings

Expand All @@ -21,7 +22,7 @@ def setup_api():
'session': session,
}
if USER and PASS:
log.debug("Using slumber with user %s, pointed at %s" % (USER, API_HOST))
log.debug("Using slumber with user %s, pointed at %s", USER, API_HOST)
session.auth = (USER, PASS)
else:
log.warning("SLUMBER_USERNAME/PASSWORD settings are not set")
Expand Down
16 changes: 11 additions & 5 deletions readthedocs/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Utility classes for api module"""
import logging

from django.core.paginator import Paginator, InvalidPage
Expand Down Expand Up @@ -40,7 +41,7 @@ class Meta:
search_highlight = True
"""

def get_search(self, request, **kwargs):
def get_search(self, request):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
Expand Down Expand Up @@ -72,12 +73,14 @@ def _url_template(self, query, selected_facets):

def _search(self, request, model, facets=None, page_size=20,
highlight=True):
# pylint: disable=too-many-locals
"""
`facets`
Return a paginated list of objects for a request.

`model`
Limit the search to a particular model
`facets`
A list of facets to include with the results
`models`
Limit the search to one or more models
"""
form = FacetedSearchForm(request.GET, facets=facets or [],
models=(model,), load_all=True)
Expand Down Expand Up @@ -145,6 +148,9 @@ def error_response(self, errors, request):


class PostAuthentication(BasicAuthentication):

"""Require HTTP Basic authentication for any method other than GET."""

def is_authenticated(self, request, **kwargs):
val = super(PostAuthentication, self).is_authenticated(request,
**kwargs)
Expand All @@ -154,7 +160,7 @@ def is_authenticated(self, request, **kwargs):


class EnhancedModelResource(ModelResource):
def obj_get_list(self, request=None, *args, **kwargs):
def obj_get_list(self, request=None, *_, **kwargs):
"""
A ORM-specific implementation of ``obj_get_list``.

Expand Down