Commit 92053acb authored by Tim Graham's avatar Tim Graham
Browse files

Fixed E128 flake8 warnings in tests/.

parent df8d8d42
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh

[flake8]
exclude = build,.git,./django/utils/lru_cache.py,./django/utils/six.py,./django/conf/app_template/*,./django/dispatch/weakref_backports.py,./tests/.env,./xmlrunner,tests/view_tests/tests/py3_test_debug.py,tests/template_tests/annotated_tag_function.py
ignore = E128,W601
ignore = W601
max-line-length = 119

[isort]
+1 −2
Original line number Diff line number Diff line
@@ -12,8 +12,7 @@ site.register(User, UserAdmin)

class CustomPaginator(Paginator):
    def __init__(self, queryset, page_size, orphans=0, allow_empty_first_page=True):
        super(CustomPaginator, self).__init__(queryset, 5, orphans=2,
            allow_empty_first_page=allow_empty_first_page)
        super(CustomPaginator, self).__init__(queryset, 5, orphans=2, allow_empty_first_page=allow_empty_first_page)


class EventAdmin(admin.ModelAdmin):
+5 −10
Original line number Diff line number Diff line
@@ -130,8 +130,7 @@ class ChangeListTests(TestCase):
            '<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
            '<td class="field-parent nowrap">-</td></tr></tbody>' % link
        )
        self.assertNotEqual(table_output.find(row_html), -1,
            'Failed to find expected row element: %s' % table_output)
        self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

    def test_result_list_set_empty_value_display_on_admin_site(self):
        """
@@ -152,8 +151,7 @@ class ChangeListTests(TestCase):
            '<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
            '<td class="field-parent nowrap">???</td></tr></tbody>' % link
        )
        self.assertNotEqual(table_output.find(row_html), -1,
            'Failed to find expected row element: %s' % table_output)
        self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

    def test_result_list_set_empty_value_display_in_model_admin(self):
        """
@@ -172,8 +170,7 @@ class ChangeListTests(TestCase):
            '<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
            '<td class="field-age_display">&amp;dagger;</td><td class="field-age">-empty-</td></tr></tbody>' % link
        )
        self.assertNotEqual(table_output.find(row_html), -1,
            'Failed to find expected row element: %s' % table_output)
        self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

    def test_result_list_html(self):
        """
@@ -194,8 +191,7 @@ class ChangeListTests(TestCase):
            '<tbody><tr class="row1"><th class="field-name"><a href="%s">name</a></th>'
            '<td class="field-parent nowrap">Parent object</td></tr></tbody>' % link
        )
        self.assertNotEqual(table_output.find(row_html), -1,
            'Failed to find expected row element: %s' % table_output)
        self.assertNotEqual(table_output.find(row_html), -1, 'Failed to find expected row element: %s' % table_output)

    def test_result_list_editable_html(self):
        """
@@ -894,8 +890,7 @@ class SeleniumTests(AdminSeleniumTestCase):
        Ensure that the status line for selected rows gets updated correctly (#22038)
        """
        self.admin_login(username='super', password='secret')
        self.selenium.get('%s%s' % (self.live_server_url,
                                    reverse('admin:auth_user_changelist')))
        self.selenium.get(self.live_server_url + reverse('admin:auth_user_changelist'))

        form_id = '#changelist-form'

+13 −17
Original line number Diff line number Diff line
@@ -73,15 +73,16 @@ class AdminCustomUrlsTest(TestCase):
        """
        # Should get the change_view for model instance with PK 'add', not show
        # the add_view
        url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label,
                args=(quote('add'),))
        url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label, args=(quote('add'),))
        response = self.client.get(url)
        self.assertContains(response, 'Change action')

        # Should correctly get the change_view for the model instance with the
        # funny-looking PK (the one with a 'path/to/html/document.html' value)
        url = reverse('admin_custom_urls:%s_action_change' % Action._meta.app_label,
                args=(quote("path/to/html/document.html"),))
        url = reverse(
            'admin_custom_urls:%s_action_change' % Action._meta.app_label,
            args=(quote("path/to/html/document.html"),)
        )
        response = self.client.get(url)
        self.assertContains(response, 'Change action')
        self.assertContains(response, 'value="path/to/html/document.html"')
@@ -95,12 +96,11 @@ class AdminCustomUrlsTest(TestCase):
        """
        post_data = {'name': 'John Doe'}
        self.assertEqual(Person.objects.count(), 0)
        response = self.client.post(
            reverse('admin_custom_urls:admin_custom_urls_person_add'), post_data)
        response = self.client.post(reverse('admin_custom_urls:admin_custom_urls_person_add'), post_data)
        persons = Person.objects.all()
        self.assertEqual(len(persons), 1)
        self.assertRedirects(
            response, reverse('admin_custom_urls:admin_custom_urls_person_history', args=[persons[0].pk]))
        redirect_url = reverse('admin_custom_urls:admin_custom_urls_person_history', args=[persons[0].pk])
        self.assertRedirects(response, redirect_url)

    def test_post_save_change_redirect(self):
        """
@@ -112,11 +112,9 @@ class AdminCustomUrlsTest(TestCase):
        Person.objects.create(name='John Doe')
        self.assertEqual(Person.objects.count(), 1)
        person = Person.objects.all()[0]
        post_data = {'name': 'Jack Doe'}
        response = self.client.post(
            reverse('admin_custom_urls:admin_custom_urls_person_change', args=[person.pk]), post_data)
        self.assertRedirects(
            response, reverse('admin_custom_urls:admin_custom_urls_person_delete', args=[person.pk]))
        post_url = reverse('admin_custom_urls:admin_custom_urls_person_change', args=[person.pk])
        response = self.client.post(post_url, {'name': 'Jack Doe'})
        self.assertRedirects(response, reverse('admin_custom_urls:admin_custom_urls_person_delete', args=[person.pk]))

    def test_post_url_continue(self):
        """
@@ -125,9 +123,7 @@ class AdminCustomUrlsTest(TestCase):
        """
        post_data = {'name': 'SuperFast', '_continue': '1'}
        self.assertEqual(Car.objects.count(), 0)
        response = self.client.post(
            reverse('admin_custom_urls:admin_custom_urls_car_add'), post_data)
        response = self.client.post(reverse('admin_custom_urls:admin_custom_urls_car_add'), post_data)
        cars = Car.objects.all()
        self.assertEqual(len(cars), 1)
        self.assertRedirects(
            response, reverse('admin_custom_urls:admin_custom_urls_car_history', args=[cars[0].pk]))
        self.assertRedirects(response, reverse('admin_custom_urls:admin_custom_urls_car_history', args=[cars[0].pk]))
+28 −55
Original line number Diff line number Diff line
@@ -54,14 +54,11 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
        self.client.logout()
        response = self.client.get(reverse('django-admindocs-docroot'), follow=True)
        # Should display the login screen
        self.assertContains(response,
            '<input type="hidden" name="next" value="/admindocs/" />', html=True)
        self.assertContains(response, '<input type="hidden" name="next" value="/admindocs/" />', html=True)
        self.client.force_login(self.superuser)
        response = self.client.get(reverse('django-admindocs-docroot'))
        self.assertContains(response, '<h1>Documentation</h1>', html=True)
        self.assertContains(response,
                            '<h1 id="site-name"><a href="/admin/">Django '
                            'administration</a></h1>')
        self.assertContains(response, '<h1 id="site-name"><a href="/admin/">Django administration</a></h1>')

    def test_bookmarklets(self):
        response = self.client.get(reverse('django-admindocs-bookmarklets'))
@@ -77,16 +74,17 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):

    def test_view_index(self):
        response = self.client.get(reverse('django-admindocs-views-index'))
        self.assertContains(response,
        self.assertContains(
            response,
            '<h3><a href="/admindocs/views/django.contrib.admindocs.views.BaseAdminDocsView/">/admindocs/</a></h3>',
            html=True)
            html=True
        )
        self.assertContains(response, 'Views by namespace test')
        self.assertContains(response, 'Name: <code>test:func</code>.')

    def test_view_detail(self):
        response = self.client.get(
            reverse('django-admindocs-views-detail',
                    args=['django.contrib.admindocs.views.BaseAdminDocsView']))
        url = reverse('django-admindocs-views-detail', args=['django.contrib.admindocs.views.BaseAdminDocsView'])
        response = self.client.get(url)
        # View docstring
        self.assertContains(response, 'Base view for admindocs views.')

@@ -94,9 +92,8 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
        """
        #23601 - Ensure the view exists in the URLconf.
        """
        response = self.client.get(
            reverse('django-admindocs-views-detail',
                    args=['urlpatterns_reverse.nonimported_module.view']))
        url = reverse('django-admindocs-views-detail', args=['urlpatterns_reverse.nonimported_module.view'])
        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)
        self.assertNotIn("urlpatterns_reverse.nonimported_module", sys.modules)

@@ -109,22 +106,20 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
        )

    def test_template_detail(self):
        response = self.client.get(reverse('django-admindocs-templates',
            args=['admin_doc/template_detail.html']))
        self.assertContains(response,
            '<h1>Template: "admin_doc/template_detail.html"</h1>', html=True)
        response = self.client.get(reverse('django-admindocs-templates', args=['admin_doc/template_detail.html']))
        self.assertContains(response, '<h1>Template: "admin_doc/template_detail.html"</h1>', html=True)

    def test_missing_docutils(self):
        utils.docutils_is_available = False
        try:
            response = self.client.get(reverse('django-admindocs-docroot'))
            self.assertContains(response,
            self.assertContains(
                response,
                '<h3>The admin documentation system requires Python\'s '
                '<a href="http://docutils.sf.net/">docutils</a> library.</h3>',
                html=True)
            self.assertContains(response,
                                '<h1 id="site-name"><a href="/admin/">Django '
                                'administration</a></h1>')
                html=True
            )
            self.assertContains(response, '<h1 id="site-name"><a href="/admin/">Django administration</a></h1>')
        finally:
            utils.docutils_is_available = True

@@ -200,18 +195,12 @@ class DefaultRoleTest(AdminDocsTestCase):
        ``django.contrib.admindocs.utils.parse_rst`` should use
        ``cmsreference`` as the default role.
        """
        markup = ('<p><a class="reference external" href="/admindocs/%s">'
                  'title</a></p>\n')
        self.assertEqual(utils.parse_rst('`title`', 'model'),
                         markup % 'models/title/')
        self.assertEqual(utils.parse_rst('`title`', 'view'),
                         markup % 'views/title/')
        self.assertEqual(utils.parse_rst('`title`', 'template'),
                         markup % 'templates/title/')
        self.assertEqual(utils.parse_rst('`title`', 'filter'),
                         markup % 'filters/#title')
        self.assertEqual(utils.parse_rst('`title`', 'tag'),
                         markup % 'tags/#title')
        markup = '<p><a class="reference external" href="/admindocs/%s">title</a></p>\n'
        self.assertEqual(utils.parse_rst('`title`', 'model'), markup % 'models/title/')
        self.assertEqual(utils.parse_rst('`title`', 'view'), markup % 'views/title/')
        self.assertEqual(utils.parse_rst('`title`', 'template'), markup % 'templates/title/')
        self.assertEqual(utils.parse_rst('`title`', 'filter'), markup % 'filters/#title')
        self.assertEqual(utils.parse_rst('`title`', 'tag'), markup % 'tags/#title')

    def test_publish_parts(self):
        """
@@ -220,8 +209,7 @@ class DefaultRoleTest(AdminDocsTestCase):
        ``cmsreference``. See #6681.
        """
        import docutils
        self.assertNotEqual(docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE,
                            'cmsreference')
        self.assertNotEqual(docutils.parsers.rst.roles.DEFAULT_INTERPRETED_ROLE, 'cmsreference')
        source = 'reST, `interpreted text`, default role.'
        markup = '<p>reST, <cite>interpreted text</cite>, default role.</p>\n'
        parts = docutils.core.publish_parts(source=source, writer_name="html4css1")
@@ -286,21 +274,9 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase):
        by a method
        """
        company = Company.objects.create(name="Django")
        person = Person.objects.create(
            first_name="Human",
            last_name="User",
            company=company
        )

        self.assertEqual(
            get_return_data_type(person.get_status_count.__name__),
            'Integer'
        )

        self.assertEqual(
            get_return_data_type(person.get_groups_list.__name__),
            'List'
        )
        person = Person.objects.create(first_name="Human", last_name="User", company=company)
        self.assertEqual(get_return_data_type(person.get_status_count.__name__), 'Integer')
        self.assertEqual(get_return_data_type(person.get_groups_list.__name__), 'List')

    def test_descriptions_render_correctly(self):
        """
@@ -361,10 +337,7 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase):
        A model with ``related_name`` of `+` should not show backward relationship
        links in admin docs
        """
        response = self.client.get(
            reverse('django-admindocs-models-detail',
                    args=['admin_docs', 'family']))

        response = self.client.get(reverse('django-admindocs-models-detail', args=['admin_docs', 'family']))
        fields = response.context_data.get('fields')
        self.assertEqual(len(fields), 2)

Loading