diff --git a/prospector-more.yml b/prospector-more.yml index d5280bf0e5a..955a768dbfb 100644 --- a/prospector-more.yml +++ b/prospector-more.yml @@ -3,7 +3,6 @@ inherits: prospector strictness: medium ignore-paths: - - api/ - cdn/ - comments/ - core/ diff --git a/readthedocs/api/base.py b/readthedocs/api/base.py index 1459f4a5d6b..76f82f14f2d 100644 --- a/readthedocs/api/base.py +++ b/readthedocs/api/base.py @@ -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 @@ -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 @@ -27,6 +27,9 @@ class ProjectResource(ModelResource, SearchMixin): + + """API resource for Project model.""" + users = fields.ToManyField('readthedocs.api.base.UserResource', 'users') class Meta(object): @@ -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): @@ -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: @@ -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): @@ -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) @@ -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() diff --git a/readthedocs/api/client.py b/readthedocs/api/client.py index 5f083dd9fcf..117395b52e1 100644 --- a/readthedocs/api/client.py +++ b/readthedocs/api/client.py @@ -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 @@ -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") diff --git a/readthedocs/api/utils.py b/readthedocs/api/utils.py index 160ad2fee8f..7a75c5dab36 100644 --- a/readthedocs/api/utils.py +++ b/readthedocs/api/utils.py @@ -1,3 +1,4 @@ +"""Utility classes for api module""" import logging from django.core.paginator import Paginator, InvalidPage @@ -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) @@ -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) @@ -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) @@ -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``.