~netlandish/django-wiki

9c993c4bde6d3a3611e5733843c749cfecf30a55 — Benjamin Bach 4 years ago 3843e51
Lint flake8 failures, including a bug where .format was mistaken for .join
M setup.cfg => setup.cfg +6 -2
@@ 2,8 2,12 @@
universal = 0

[flake8]
ignore = E501 W503 W504
max-line-length = 160
# ignore = E501 W503 W504

# black style
max-line-length = 120
extend-ignore = E203

max-complexity = 10
exclude = .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg,*/*migrations,testproject


M src/wiki/decorators.py => src/wiki/decorators.py +3 -3
@@ 35,10 35,10 @@ def response_forbidden(request, article, urlpath, read_denied=False):


# TODO: This decorator is too complex (C901)
def get_article(
def get_article(  # noqa: max-complexity=23
    func=None,
    can_read=True,
    can_write=False,  # noqa: max-complexity=13
    can_write=False,
    deleted_contents=False,
    not_locked=False,
    can_delete=False,


@@ 88,7 88,7 @@ def get_article(
                    path = "/".join(pathlist[:-1])
                    parent = models.URLPath.get_by_path(path)
                    return HttpResponseRedirect(
                        reverse("wiki:create", kwargs={"path": parent.path,})
                        reverse("wiki:create", kwargs={"path": parent.path})
                        + "?slug=%s" % pathlist[-1].lower()
                    )
                except models.URLPath.DoesNotExist:

M src/wiki/plugins/editsection/views.py => src/wiki/plugins/editsection/views.py +3 -3
@@ 132,7 132,7 @@ class EditSection(EditView):
                request.session["editsection_content"] = self.orig_section
            else:
                messages.error(
                    request, " ".format(ERROR_SECTION_CHANGED, ERROR_TRY_AGAIN)
                    request, "{} {}".format(ERROR_SECTION_CHANGED, ERROR_TRY_AGAIN)
                )
                return self._redirect_to_article()
        else:


@@ 158,7 158,7 @@ class EditSection(EditView):
            if self.orig_section != text[location[0] : location[1]]:
                messages.warning(
                    self.request,
                    " ".format(
                    "{} {} {}".format(
                        ERROR_SECTION_CHANGED, ERROR_SECTION_UNSAVED, ERROR_TRY_AGAIN
                    ),
                )


@@ 174,7 174,7 @@ class EditSection(EditView):
            )
            self.article.save()
            messages.error(
                self.request, " ".format(ERROR_ARTICLE_CHANGED, ERROR_TRY_AGAIN)
                self.request, "{} {}".format(ERROR_ARTICLE_CHANGED, ERROR_TRY_AGAIN)
            )

        return self._redirect_to_article()

M src/wiki/plugins/images/models.py => src/wiki/plugins/images/models.py +1 -1
@@ 117,7 117,7 @@ class ImageRevision(RevisionPluginRevision):
            return gettext("Current revision not set!!")


def on_image_revision_delete(instance, *args, **kwargs):
def on_image_revision_delete(instance, *args, **kwargs):  # noqa: max-complexity=11
    if not instance.image:
        return


M src/wiki/plugins/images/views.py => src/wiki/plugins/images/views.py +1 -1
@@ 196,7 196,7 @@ class RevisionAddView(ArticleMixin, FormView):
        messages.info(
            self.request,
            _("%(file)s has been saved.")
            % {"file": self.image.current_revision.imagerevision.get_filename(),},
            % {"file": self.image.current_revision.imagerevision.get_filename()},
        )
        if self.urlpath:
            return redirect("wiki:edit", path=self.urlpath.path)

M src/wiki/plugins/macros/mdx/toc.py => src/wiki/plugins/macros/mdx/toc.py +0 -2
@@ 1,5 1,3 @@
import re

from markdown.extensions.toc import slugify
from markdown.extensions.toc import TocExtension
from markdown.extensions.toc import TocTreeprocessor

M testproject/testproject/urls.py => testproject/testproject/urls.py +1 -1
@@ 32,7 32,7 @@ if settings.DEBUG:
            # For django versions before 2.0:
            # url(r'^__debug__/', include(debug_toolbar.urls)),
        ] + urlpatterns
    except ImportError as ie:
    except ImportError:
        pass

urlpatterns += [

M tests/core/test_views.py => tests/core/test_views.py +8 -10
@@ 34,9 34,7 @@ class RootArticleViewTestsBase(FuncBaseMixin):
        """
        self.get_url("wiki:root")
        self.assertUrlsEqual(resolve_url("wiki:root_create"))
        self.fill(
            {"#id_content": "test heading h1\n====\n", "#id_title": "Wiki Test",}
        )
        self.fill({"#id_content": "test heading h1\n====\n", "#id_title": "Wiki Test"})
        self.submit('button[name="save_changes"]')
        self.assertUrlsEqual("/")
        self.assertTextPresent("test heading h1")


@@ 630,7 628,7 @@ class SourceViewTests(
):
    def test_template_used(self):
        response = self.client.get(
            reverse("wiki:source", kwargs={"article_id": self.root_article.pk,})
            reverse("wiki:source", kwargs={"article_id": self.root_article.pk})
        )
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, template_name="wiki/source.html")


@@ 639,13 637,13 @@ class SourceViewTests(
        # everybody can see the source of an article
        self.client.logout()
        response = self.client.get(
            reverse("wiki:source", kwargs={"article_id": self.root_article.pk,})
            reverse("wiki:source", kwargs={"article_id": self.root_article.pk})
        )
        self.assertEqual(response.status_code, 200)

    def test_content(self):
        response = self.client.get(
            reverse("wiki:source", kwargs={"article_id": self.root_article.pk,})
            reverse("wiki:source", kwargs={"article_id": self.root_article.pk})
        )
        self.assertIn("Source of ", str(response.content))
        self.assertEqual(response.context["selected_tab"], "source")


@@ 656,13 654,13 @@ class HistoryViewTests(
):
    def test_can_read_permission(self):
        response = self.client.get(
            reverse("wiki:history", kwargs={"article_id": self.root_article.pk,})
            reverse("wiki:history", kwargs={"article_id": self.root_article.pk})
        )
        self.assertEqual(response.status_code, 200)

    def test_content(self):
        response = self.client.get(
            reverse("wiki:history", kwargs={"article_id": self.root_article.pk,})
            reverse("wiki:history", kwargs={"article_id": self.root_article.pk})
        )
        self.assertContains(response, "History:")
        self.assertEqual(response.context["selected_tab"], "history")


@@ 701,7 699,7 @@ class SettingsViewTests(
        group = CustomGroup.objects.create()
        response = self.client.post(
            resolve_url("wiki:settings", article_id=self.root_article.pk) + "?f=form0",
            {"group": group.pk, "owner_username": SUPERUSER1_USERNAME,},
            {"group": group.pk, "owner_username": SUPERUSER1_USERNAME},
            follow=True,
        )
        self.root_article.refresh_from_db()


@@ 767,6 765,6 @@ class SettingsViewTests(

    def test_content(self):
        response = self.client.get(
            reverse("wiki:settings", kwargs={"article_id": self.root_article.pk,})
            reverse("wiki:settings", kwargs={"article_id": self.root_article.pk})
        )
        self.assertEqual(response.context["selected_tab"], "settings")

M tests/plugins/attachments/test_views.py => tests/plugins/attachments/test_views.py +10 -10
@@ 41,7 41,7 @@ class AttachmentTests(
        filestream = self._createTxtFilestream(self.test_data)
        response = self.client.post(
            url,
            {"description": self.test_description, "file": filestream, "save": "1",},
            {"description": self.test_description, "file": filestream, "save": "1"},
        )
        self.assertRedirects(response, url)



@@ 70,7 70,7 @@ class AttachmentTests(
        data = "This is a plain text file"
        filestream = self._createTxtFilestream(data)
        self.client.post(
            url, {"description": "My file", "file": filestream, "save": "1",}
            url, {"description": "My file", "file": filestream, "save": "1"}
        )
        attachment = self.article.shared_plugins_set.all()[0].attachment



@@ 87,7 87,7 @@ class AttachmentTests(
        replacement_data = data + " And this is my edit"
        replacement_filestream = self._createTxtFilestream(replacement_data)
        self.client.post(
            url, {"description": "Replacement upload", "file": replacement_filestream,}
            url, {"description": "Replacement upload", "file": replacement_filestream}
        )
        attachment = self.article.shared_plugins_set.all()[0].attachment
        # Revision count should be two


@@ 142,28 142,28 @@ class AttachmentTests(
    def test_render(self):
        output = self.get_article("[attachment:1]")
        expected = (
            '<span class="attachment"><a href=".*attachments/download/1/"'
            ' title="Click to download test\.txt">\s*test\.txt\s*</a>'
            r'<span class="attachment"><a href=".*attachments/download/1/"'
            r' title="Click to download test\.txt">\s*test\.txt\s*</a>'
        )
        self.assertRegexpMatches(output, expected)

    def test_render_missing(self):
        output = self.get_article("[attachment:2]")
        expected = '<span class="attachment attachment-deleted">\s*Attachment with ID #2 is deleted.\s*</span>'
        expected = r'<span class="attachment attachment-deleted">\s*Attachment with ID #2 is deleted.\s*</span>'
        self.assertRegexpMatches(output, expected)

    def test_render_title(self):
        output = self.get_article('[attachment:1 title:"Test title"]')
        expected = (
            '<span class="attachment"><a href=".*attachments/download/1/"'
            ' title="Click to download test\.txt">\s*Test title\s*</a>'
            r'<span class="attachment"><a href=".*attachments/download/1/"'
            r' title="Click to download test\.txt">\s*Test title\s*</a>'
        )
        self.assertRegexpMatches(output, expected)

    def test_render_title_size(self):
        output = self.get_article('[attachment:1 title:"Test title 2" size]')
        expected = (
            '<span class="attachment"><a href=".*attachments/download/1/"'
            ' title="Click to download test\.txt">\s*Test title 2 \[25[^b]bytes\]\s*</a>'
            r'<span class="attachment"><a href=".*attachments/download/1/"'
            r' title="Click to download test\.txt">\s*Test title 2 \[25[^b]bytes\]\s*</a>'
        )
        self.assertRegexpMatches(output, expected)

M tests/plugins/notifications/test_forms.py => tests/plugins/notifications/test_forms.py +1 -2
@@ 1,5 1,4 @@
from django.test import TestCase
from django_nyt.forms import SettingsForm
from wiki.plugins.notifications.forms import SettingsFormSet

from tests.base import RequireSuperuserMixin


@@ 7,4 6,4 @@ from tests.base import RequireSuperuserMixin

class SettingsFormTests(RequireSuperuserMixin, TestCase):
    def test_formset(self):
        formset = SettingsFormSet(user=self.superuser1)
        SettingsFormSet(user=self.superuser1)

M tests/testdata/urls.py => tests/testdata/urls.py +1 -1
@@ 15,7 15,7 @@ if settings.DEBUG:
        re_path(
            r"^media/(?P<path>.*)$",
            "django.views.static.serve",
            {"document_root": settings.MEDIA_ROOT,},
            {"document_root": settings.MEDIA_ROOT},
        ),
    ]