diff --git a/docs/internals/contributing/writing-code/coding-style.txt b/docs/internals/contributing/writing-code/coding-style.txt index 39f49f10e6..7b7712919b 100644 --- a/docs/internals/contributing/writing-code/coding-style.txt +++ b/docs/internals/contributing/writing-code/coding-style.txt @@ -53,6 +53,19 @@ Python style (``six.assertRaisesRegex()`` as long as we support Python 2) only if you need to use regular expression matching. +* In test docstrings, state the expected behavior that each test demonstrates. + Don't include preambles such as "Tests that" or "Ensures that". + + Reserve ticket references for obscure issues where the ticket has additional + details that can't be easily described in docstrings or comments. Include the + ticket number at the end of a sentence like this:: + + def test_foo(): + """ + A test docstring looks like this (#123456). + """ + ... + .. _coding-style-imports: Imports diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py index 7d477a16d2..c501770761 100644 --- a/tests/admin_changelist/tests.py +++ b/tests/admin_changelist/tests.py @@ -134,7 +134,7 @@ class ChangeListTests(TestCase): def test_result_list_set_empty_value_display_on_admin_site(self): """ - Test that empty value display can be set on AdminSite + Empty value display can be set on AdminSite. """ new_child = Child.objects.create(name='name', parent=None) request = self.factory.get('/child/') @@ -155,7 +155,7 @@ class ChangeListTests(TestCase): def test_result_list_set_empty_value_display_in_model_admin(self): """ - Test that empty value display can be set in ModelAdmin or individual fields. + Empty value display can be set in ModelAdmin or individual fields. """ new_child = Child.objects.create(name='name', parent=None) request = self.factory.get('/child/') @@ -174,8 +174,8 @@ class ChangeListTests(TestCase): def test_result_list_html(self): """ - Verifies that inclusion tag result_list generates a table when with - default ModelAdmin settings. + Inclusion tag result_list generates a table when with default + ModelAdmin settings. """ new_parent = Parent.objects.create(name='parent') new_child = Child.objects.create(name='name', parent=new_parent) @@ -672,10 +672,9 @@ class ChangeListTests(TestCase): def test_deterministic_order_for_unordered_model(self): """ - Ensure that the primary key is systematically used in the ordering of - the changelist's results to guarantee a deterministic order, even - when the Model doesn't have any default ordering defined. - Refs #17198. + The primary key is used in the ordering of the changelist's results to + guarantee a deterministic order, even when the model doesn't have any + default ordering defined (#17198). """ superuser = self._create_superuser('superuser') @@ -717,10 +716,9 @@ class ChangeListTests(TestCase): def test_deterministic_order_for_model_ordered_by_its_manager(self): """ - Ensure that the primary key is systematically used in the ordering of - the changelist's results to guarantee a deterministic order, even - when the Model has a manager that defines a default ordering. - Refs #17198. + The primary key is used in the ordering of the changelist's results to + guarantee a deterministic order, even when the model has a manager that + defines a default ordering (#17198). """ superuser = self._create_superuser('superuser') @@ -887,7 +885,7 @@ class SeleniumTests(AdminSeleniumTestCase): def test_add_row_selection(self): """ - Ensure that the status line for selected rows gets updated correctly (#22038) + The status line for selected rows gets updated correctly (#22038). """ self.admin_login(username='super', password='secret') self.selenium.get(self.live_server_url + reverse('admin:auth_user_changelist')) diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py index 2cf7f66d9d..fa1bcc1518 100644 --- a/tests/admin_checks/tests.py +++ b/tests/admin_checks/tests.py @@ -165,16 +165,15 @@ class SystemChecksTestCase(SimpleTestCase): def test_custom_get_form_with_fieldsets(self): """ - Ensure that the fieldsets checks are skipped when the ModelAdmin.get_form() method + The fieldsets checks are skipped when the ModelAdmin.get_form() method is overridden. - Refs #19445. """ errors = ValidFormFieldsets(Song, AdminSite()).check() self.assertEqual(errors, []) def test_fieldsets_fields_non_tuple(self): """ - Tests for a tuple/list for the first fieldset's fields. + The first fieldset's fields must be a list/tuple. """ class NotATupleAdmin(admin.ModelAdmin): list_display = ["pk", "title"] @@ -197,7 +196,7 @@ class SystemChecksTestCase(SimpleTestCase): def test_nonfirst_fieldset(self): """ - Tests for a tuple/list for the second fieldset's fields. + The second fieldset's fields must be a list/tuple. """ class NotATupleAdmin(admin.ModelAdmin): fieldsets = [ @@ -309,7 +308,7 @@ class SystemChecksTestCase(SimpleTestCase): def test_generic_inline_model_admin_non_generic_model(self): """ - Ensure that a model without a GenericForeignKey raises problems if it's included + A model without a GenericForeignKey raises problems if it's included in an GenericInlineModelAdmin definition. """ class BookInline(GenericStackedInline): diff --git a/tests/admin_custom_urls/tests.py b/tests/admin_custom_urls/tests.py index 11a0375ae2..319e6f6653 100644 --- a/tests/admin_custom_urls/tests.py +++ b/tests/admin_custom_urls/tests.py @@ -68,9 +68,6 @@ class AdminCustomUrlsTest(TestCase): self.assertContains(response, 'Action added through a popup') def test_admin_URLs_no_clash(self): - """ - Test that some admin URLs work correctly. - """ # 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'),)) @@ -89,10 +86,8 @@ class AdminCustomUrlsTest(TestCase): def test_post_save_add_redirect(self): """ - Ensures that ModelAdmin.response_post_save_add() controls the - redirection after the 'Save' button has been pressed when adding a - new object. - Refs 8001, 18310, 19505. + ModelAdmin.response_post_save_add() controls the redirection after + the 'Save' button has been pressed when adding a new object. """ post_data = {'name': 'John Doe'} self.assertEqual(Person.objects.count(), 0) @@ -104,10 +99,8 @@ class AdminCustomUrlsTest(TestCase): def test_post_save_change_redirect(self): """ - Ensures that ModelAdmin.response_post_save_change() controls the - redirection after the 'Save' button has been pressed when editing an - existing object. - Refs 8001, 18310, 19505. + ModelAdmin.response_post_save_change() controls the redirection after + the 'Save' button has been pressed when editing an existing object. """ Person.objects.create(name='John Doe') self.assertEqual(Person.objects.count(), 1) @@ -118,8 +111,8 @@ class AdminCustomUrlsTest(TestCase): def test_post_url_continue(self): """ - Ensures that the ModelAdmin.response_add()'s parameter `post_url_continue` - controls the redirection after an object has been created. + The ModelAdmin.response_add()'s parameter `post_url_continue` controls + the redirection after an object has been created. """ post_data = {'name': 'SuperFast', '_continue': '1'} self.assertEqual(Car.objects.count(), 0) diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py index 940bb3ce8c..e2da7ec59e 100644 --- a/tests/admin_filters/tests.py +++ b/tests/admin_filters/tests.py @@ -891,7 +891,7 @@ class ListFiltersTests(TestCase): def test_filter_with_failing_queryset(self): """ - Ensure that when a filter's queryset method fails, it fails loudly and + When a filter's queryset method fails, it fails loudly and the corresponding exception doesn't get swallowed (#17828). """ modeladmin = DecadeFilterBookAdminWithFailingQueryset(Book, site) @@ -941,8 +941,8 @@ class ListFiltersTests(TestCase): def test_parameter_ends_with__in__or__isnull(self): """ - Ensure that a SimpleListFilter's parameter name is not mistaken for a - model field if it ends with '__isnull' or '__in' (#17091). + A SimpleListFilter's parameter name is not mistaken for a model field + if it ends with '__isnull' or '__in' (#17091). """ # When it ends with '__in' ----------------------------------------- modeladmin = DecadeFilterBookAdminParameterEndsWith__In(Book, site) diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py index 5871f16a3b..2716d2abdb 100644 --- a/tests/admin_inlines/tests.py +++ b/tests/admin_inlines/tests.py @@ -107,8 +107,8 @@ class TestInline(TestDataMixin, TestCase): def test_tabular_non_field_errors(self): """ - Ensure that non_field_errors are displayed correctly, including the - right value for colspan. Refs #13510. + non_field_errors are displayed correctly, including the correct value + for colspan. """ data = { 'title_set-TOTAL_FORMS': 1, @@ -153,9 +153,8 @@ class TestInline(TestDataMixin, TestCase): def test_help_text(self): """ - Ensure that the inlines' model field help texts are displayed when - using both the stacked and tabular layouts. - Ref #8190. + The inlines' model field help texts are displayed when using both the + stacked and tabular layouts. """ response = self.client.get(reverse('admin:admin_inlines_holder4_add')) self.assertContains(response, '
Awesome stacked help text is awesome.
', 4) @@ -191,8 +190,7 @@ class TestInline(TestDataMixin, TestCase): def test_non_related_name_inline(self): """ - Ensure that multiple inlines with related_name='+' have correct form - prefixes. Bug #16838. + Multiple inlines with related_name='+' have correct form prefixes. """ response = self.client.get(reverse('admin:admin_inlines_capofamiglia_add')) self.assertContains(response, '', html=True) @@ -221,8 +219,8 @@ class TestInline(TestDataMixin, TestCase): @override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) def test_localize_pk_shortcut(self): """ - Ensure that the "View on Site" link is correct for locales that use - thousand separators + The "View on Site" link is correct for locales that use thousand + separators. """ holder = Holder.objects.create(pk=123456789, dummy=42) inner = Inner.objects.create(pk=987654321, holder=holder, dummy=42, readonly='') @@ -232,8 +230,8 @@ class TestInline(TestDataMixin, TestCase): def test_custom_pk_shortcut(self): """ - Ensure that the "View on Site" link is correct for models with a - custom primary key field. Bug #18433. + The "View on Site" link is correct for models with a custom primary key + field. """ parent = ParentModelWithCustomPk.objects.create(my_own_pk="foo", name="Foo") child1 = ChildModel1.objects.create(my_own_pk="bar", name="Bar", parent=parent) @@ -246,8 +244,7 @@ class TestInline(TestDataMixin, TestCase): def test_create_inlines_on_inherited_model(self): """ - Ensure that an object can be created with inlines when it inherits - another class. Bug #19524. + An object can be created with inlines when it inherits another class. """ data = { 'name': 'Martian', @@ -285,7 +282,7 @@ class TestInline(TestDataMixin, TestCase): def test_min_num(self): """ - Ensure that min_num and extra determine number of forms. + min_num and extra determine number of forms. """ class MinNumInline(TabularInline): model = BinaryTree @@ -309,9 +306,6 @@ class TestInline(TestDataMixin, TestCase): self.assertContains(response, total_forms) def test_custom_min_num(self): - """ - Ensure that get_min_num is called and used correctly. - """ bt_head = BinaryTree.objects.create(name="Tree Head") BinaryTree.objects.create(name="First Child", parent=bt_head) @@ -741,8 +735,7 @@ class SeleniumTests(AdminSeleniumTestCase): def test_add_stackeds(self): """ - Ensure that the "Add another XXX" link correctly adds items to the - stacked formset. + The "Add another XXX" link correctly adds items to the stacked formset. """ self.admin_login(username='super', password='secret') self.selenium.get(self.live_server_url + reverse('admin:admin_inlines_holder4_add')) @@ -781,14 +774,12 @@ class SeleniumTests(AdminSeleniumTestCase): def test_add_inlines(self): """ - Ensure that the "Add another XXX" link correctly adds items to the - inline form. + The "Add another XXX" link correctly adds items to the inline form. """ self.admin_login(username='super', password='secret') self.selenium.get(self.live_server_url + reverse('admin:admin_inlines_profilecollection_add')) - # Check that there's only one inline to start with and that it has the - # correct ID. + # There's only one inline to start with and it has the correct ID. self.assertEqual(len(self.selenium.find_elements_by_css_selector( '.dynamic-profile_set')), 1) self.assertEqual(self.selenium.find_elements_by_css_selector( @@ -802,8 +793,8 @@ class SeleniumTests(AdminSeleniumTestCase): # Add an inline self.selenium.find_element_by_link_text('Add another Profile').click() - # Check that the inline has been added, that it has the right id, and - # that it contains the right fields. + # The inline has been added, it has the right id, and it contains the + # correct fields. self.assertEqual(len(self.selenium.find_elements_by_css_selector('.dynamic-profile_set')), 2) self.assertEqual(self.selenium.find_elements_by_css_selector( '.dynamic-profile_set')[1].get_attribute('id'), 'profile_set-1') @@ -833,7 +824,7 @@ class SeleniumTests(AdminSeleniumTestCase): self.selenium.find_element_by_xpath('//input[@value="Save"]').click() self.wait_page_loaded() - # Check that the objects have been created in the database + # The objects have been created in the database self.assertEqual(ProfileCollection.objects.all().count(), 1) self.assertEqual(Profile.objects.all().count(), 3) @@ -864,7 +855,7 @@ class SeleniumTests(AdminSeleniumTestCase): 'form#profilecollection_form tr.dynamic-profile_set#profile_set-1 td.delete a').click() self.selenium.find_element_by_css_selector( 'form#profilecollection_form tr.dynamic-profile_set#profile_set-2 td.delete a').click() - # Verify that they're gone and that the IDs have been re-sequenced + # The rows are gone and the IDs have been re-sequenced self.assertEqual(len(self.selenium.find_elements_by_css_selector( '#profile_set-group table tr.dynamic-profile_set')), 3) self.assertEqual(len(self.selenium.find_elements_by_css_selector( diff --git a/tests/admin_ordering/tests.py b/tests/admin_ordering/tests.py index 6e19accc21..44d7beb368 100644 --- a/tests/admin_ordering/tests.py +++ b/tests/admin_ordering/tests.py @@ -156,7 +156,7 @@ class TestRelatedFieldsAdminOrdering(TestCase): self.check_ordering_of_field_choices([self.b1, self.b2]) def test_custom_queryset_still_wins(self): - """Test that custom queryset has still precedence (#21405)""" + """Custom queryset has still precedence (#21405)""" class SongAdmin(admin.ModelAdmin): # Exclude one of the two Bands from the querysets def formfield_for_foreignkey(self, db_field, request, **kwargs): diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 329263db0a..656736be82 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -1428,8 +1428,8 @@ class ManageTestserver(AdminScriptTestCase): ########################################################################## # COMMAND PROCESSING TESTS -# Check that user-space commands are correctly handled - in particular, -# that arguments to the commands are correctly parsed and processed. +# user-space commands are correctly handled - in particular, arguments to +# the commands are correctly parsed and processed. ########################################################################## class CommandTypes(AdminScriptTestCase): @@ -1671,7 +1671,7 @@ class CommandTypes(AdminScriptTestCase): def test_run_from_argv_non_ascii_error(self): """ - Test that non-ASCII message of CommandError does not raise any + Non-ASCII message of CommandError does not raise any UnicodeDecodeError in run_from_argv. """ def raise_command_error(*args, **kwargs): diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py index 2e72f5a05d..966a1f11f2 100644 --- a/tests/admin_utils/tests.py +++ b/tests/admin_utils/tests.py @@ -72,7 +72,7 @@ class NestedObjectsTests(TestCase): def test_on_delete_do_nothing(self): """ - Check that the nested collector doesn't query for DO_NOTHING objects. + The nested collector doesn't query for DO_NOTHING objects. """ n = NestedObjects(using=DEFAULT_DB_ALIAS) objs = [Event.objects.create()] @@ -83,9 +83,9 @@ class NestedObjectsTests(TestCase): def test_relation_on_abstract(self): """ - #21846 -- Check that `NestedObjects.collect()` doesn't trip - (AttributeError) on the special notation for relations on abstract - models (related_name that contains %(app_label)s and/or %(class)s). + NestedObjects.collect() doesn't trip (AttributeError) on the special + notation for relations on abstract models (related_name that contains + %(app_label)s and/or %(class)s) (#21846). """ n = NestedObjects(using=DEFAULT_DB_ALIAS) Car.objects.create() diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index be38a14b03..2aa042c386 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -108,7 +108,6 @@ class ArticleAdmin(admin.ModelAdmin): ) def changelist_view(self, request): - "Test that extra_context works" return super(ArticleAdmin, self).changelist_view( request, extra_context={ 'extra_var': 'Hello!' @@ -163,7 +162,6 @@ class CustomArticleAdmin(admin.ModelAdmin): delete_selected_confirmation_template = 'custom_admin/delete_selected_confirmation.html' def changelist_view(self, request): - "Test that extra_context works" return super(CustomArticleAdmin, self).changelist_view( request, extra_context={ 'extra_var': 'Hello!' diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 0eae2e467a..0643448984 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -213,8 +213,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase): def test_admin_static_template_tag(self): """ - Test that admin_static.static is pointing to the collectstatic version - (as django.contrib.collectstatic is in installed apps). + admin_static.static points to the collectstatic version + (as django.contrib.collectstatic is in INSTALLED_APPS). """ old_url = staticfiles_storage.base_url staticfiles_storage.base_url = '/test/' @@ -486,8 +486,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase): self.assertContentBefore(response, link1, link2) def test_multiple_sort_same_field(self): - # Check that we get the columns we expect if we have two columns - # that correspond to the same ordering field + # The changelist displays the correct columns if two columns correspond + # to the same ordering field. dt = datetime.datetime.now() p1 = Podcast.objects.create(name="A", release_date=dt) p2 = Podcast.objects.create(name="B", release_date=dt - datetime.timedelta(10)) @@ -517,9 +517,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase): def test_sort_indicators_admin_order(self): """ - Ensures that the admin shows default sort indicators for all - kinds of 'ordering' fields: field names, method on the model - admin and model itself, and other callables. See #17252. + The admin shows default sort indicators for all kinds of 'ordering' + fields: field names, method on the model admin and model itself, and + other callables. See #17252. """ models = [(AdminOrderedField, 'adminorderedfield'), (AdminOrderedModelMethod, 'adminorderedmodelmethod'), @@ -857,9 +857,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase): def test_change_view_with_show_delete_extra_context(self): """ - Ensured that the 'show_delete' context variable in the admin's change - view actually controls the display of the delete button. - Refs #10057. + The 'show_delete' context variable in the admin's change view controls + the display of the delete button. """ instance = UndeletableObject.objects.create(name='foo') response = self.client.get(reverse('admin:admin_views_undeletableobject_change', args=(instance.pk,))) @@ -867,11 +866,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase): def test_allows_attributeerror_to_bubble_up(self): """ - Ensure that AttributeErrors are allowed to bubble when raised inside - a change list view. - - Requires a model to be created so there's something to be displayed - + AttributeErrors are allowed to bubble when raised inside a change list + view. Requires a model to be created so there's something to display. Refs: #16655, #18593, and #18747 """ Simple.objects.create() @@ -881,9 +877,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase): def test_changelist_with_no_change_url(self): """ ModelAdmin.changelist_view shouldn't result in a NoReverseMatch if url - for change_view is removed from get_urls - - Regression test for #20934 + for change_view is removed from get_urls (#20934). """ UnchangeableObject.objects.create() response = self.client.get(reverse('admin:admin_views_unchangeableobject_changelist')) @@ -977,7 +971,7 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): def test_extended_bodyclass_template_change_form(self): """ - Ensure that the admin/change_form.html template uses block.super in the + The admin/change_form.html template uses block.super in the bodyclass block. """ response = self.client.get(reverse('admin:admin_views_section_add')) @@ -997,15 +991,14 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): def test_extended_bodyclass_template_index(self): """ - Ensure that the admin/index.html template uses block.super in the - bodyclass block. + The admin/index.html template uses block.super in the bodyclass block. """ response = self.client.get(reverse('admin:index')) self.assertContains(response, 'bodyclass_consistency_check ') def test_extended_bodyclass_change_list(self): """ - Ensure that the admin/change_list.html' template uses block.super + The admin/change_list.html' template uses block.super in the bodyclass block. """ response = self.client.get(reverse('admin:admin_views_article_changelist')) @@ -1013,7 +1006,7 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): def test_extended_bodyclass_template_login(self): """ - Ensure that the admin/login.html template uses block.super in the + The admin/login.html template uses block.super in the bodyclass block. """ self.client.logout() @@ -1022,7 +1015,7 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): def test_extended_bodyclass_template_delete_confirmation(self): """ - Ensure that the admin/delete_confirmation.html template uses + The admin/delete_confirmation.html template uses block.super in the bodyclass block. """ group = Group.objects.create(name="foogroup") @@ -1031,7 +1024,7 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): def test_extended_bodyclass_template_delete_selected_confirmation(self): """ - Ensure that the admin/delete_selected_confirmation.html template uses + The admin/delete_selected_confirmation.html template uses block.super in bodyclass block. """ group = Group.objects.create(name="foogroup") @@ -1047,8 +1040,7 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase): def test_filter_with_custom_template(self): """ - Ensure that one can use a custom template to render an admin filter. - Refs #17515. + A custom template can be used to render an admin filter. """ response = self.client.get(reverse('admin:admin_views_color2_changelist')) self.assertTemplateUsed(response, 'custom_filter_template.html') @@ -1078,7 +1070,7 @@ class AdminViewFormUrlTest(TestCase): def test_change_form_URL_has_correct_value(self): """ - Tests whether change_view has form_url in response.context + change_view has form_url in response.context """ response = self.client.get( reverse('admin:admin_views_section_change', args=(self.s1.pk,), current_app=self.current_app) @@ -1088,10 +1080,8 @@ class AdminViewFormUrlTest(TestCase): def test_initial_data_can_be_overridden(self): """ - Tests that the behavior for setting initial - form data can be overridden in the ModelAdmin class. - - Usually, the initial value is set via the GET params. + The behavior for setting initial form data can be overridden in the + ModelAdmin class. Usually, the initial value is set via the GET params. """ response = self.client.get( reverse('admin:admin_views_restaurant_add', current_app=self.current_app), @@ -1115,9 +1105,7 @@ class AdminJavaScriptTest(TestCase): def test_js_minified_only_if_debug_is_false(self): """ - Ensure that the minified versions of the JS files are only used when - DEBUG is False. - Refs #17521. + The minified versions of the JS files are only used when DEBUG is False. """ with override_settings(DEBUG=False): response = self.client.get(reverse('admin:admin_views_section_add')) @@ -1157,7 +1145,7 @@ class SaveAsTests(TestCase): self.client.force_login(self.superuser) def test_save_as_duplication(self): - """Ensure save as actually creates a new person""" + """'save as' creates a new person""" post_data = {'_saveasnew': '', 'name': 'John M', 'gender': 1, 'age': 42} response = self.client.post(reverse('admin:admin_views_person_change', args=(self.per1.pk,)), post_data) self.assertEqual(len(Person.objects.filter(name='John M')), 1) @@ -1179,7 +1167,7 @@ class SaveAsTests(TestCase): def test_save_as_new_with_validation_errors(self): """ - Ensure that when you click "Save as new" and have a validation error, + When you click "Save as new" and have a validation error, you only see the "Save as new" button and not the other save buttons, and that only the "Save as" button is visible. """ @@ -1609,7 +1597,7 @@ class AdminViewPermissionsTest(TestCase): self.assertEqual(mail.outbox[0].subject, 'Greetings from a created object') self.client.get(reverse('admin:logout')) - # Check that the addition was logged correctly + # The addition was logged correctly addition_log = LogEntry.objects.all()[0] new_article = Article.objects.last() article_ct = ContentType.objects.get_for_model(Article) @@ -1968,7 +1956,7 @@ class AdminViewPermissionsTest(TestCase): def test_has_module_permission(self): """ - Ensure that has_module_permission() returns True for all users who + has_module_permission() returns True for all users who have any permission for that module (add, change, or delete), so that the module is displayed on the admin index page. """ @@ -1997,9 +1985,8 @@ class AdminViewPermissionsTest(TestCase): def test_overriding_has_module_permission(self): """ - Ensure that overriding has_module_permission() has the desired effect. - In this case, it always returns False, so the module should not be - displayed on the admin index page for any users. + If has_module_permission() always returns False, the module shouldn't + be displayed on the admin index page for any users. """ articles = Article._meta.verbose_name_plural.title() sections = Section._meta.verbose_name_plural.title() @@ -2438,9 +2425,6 @@ class SecureViewTests(TestCase): """ def test_secure_view_shows_login_if_not_logged_in(self): - """ - Ensure that we see the admin login form. - """ secure_url = reverse('secure_view') response = self.client.get(secure_url) self.assertRedirects(response, '%s?next=%s' % (reverse('admin:login'), secure_url)) @@ -2450,7 +2434,7 @@ class SecureViewTests(TestCase): def test_staff_member_required_decorator_works_with_argument(self): """ - Ensure that staff_member_required decorator works with an argument + Staff_member_required decorator works with an argument (redirect_field_name). """ secure_url = '/test_admin/admin/secure-view2/' @@ -2518,7 +2502,7 @@ class AdminViewUnicodeTest(TestCase): def test_unicode_delete(self): """ - Ensure that the delete_view handles non-ASCII characters + The delete_view handles non-ASCII characters """ delete_dict = {'post': 'yes'} delete_url = reverse('admin:admin_views_book_delete', args=(self.b1.pk,)) @@ -2664,9 +2648,10 @@ class AdminViewListEditable(TestCase): self.assertIs(Person.objects.get(name="John Mauchly").alive, False) def test_non_field_errors(self): - ''' Ensure that non field errors are displayed for each of the - forms in the changelist's formset. Refs #13126. - ''' + """ + Non-field errors are displayed for each of the forms in the + changelist's formset. + """ fd1 = FoodDelivery.objects.create(reference='123', driver='bill', restaurant='thai') fd2 = FoodDelivery.objects.create(reference='456', driver='bill', restaurant='india') fd3 = FoodDelivery.objects.create(reference='789', driver='bill', restaurant='pizza') @@ -2747,7 +2732,7 @@ class AdminViewListEditable(TestCase): "form-0-alive": "1", "form-0-gender": "2", - # Ensure that the form processing understands this as a list_editable "Save" + # The form processing understands this as a list_editable "Save" # and not an action "Go". "_save": "Save", } @@ -2802,7 +2787,7 @@ class AdminViewListEditable(TestCase): "form-3-id": "4", "form-3-collector": "1", - # Ensure that the form processing understands this as a list_editable "Save" + # The form processing understands this as a list_editable "Save" # and not an action "Go". "_save": "Save", } @@ -2810,7 +2795,7 @@ class AdminViewListEditable(TestCase): # Successful post will redirect self.assertEqual(response.status_code, 302) - # Check that the order values have been applied to the right objects + # The order values have been applied to the right objects self.assertEqual(Category.objects.get(id=1).order, 14) self.assertEqual(Category.objects.get(id=2).order, 13) self.assertEqual(Category.objects.get(id=3).order, 1) @@ -2818,8 +2803,7 @@ class AdminViewListEditable(TestCase): def test_list_editable_pagination(self): """ - Ensure that pagination works for list_editable items. - Refs #16819. + Pagination works for list_editable items. """ UnorderedObject.objects.create(id=1, name='Unordered object #1') UnorderedObject.objects.create(id=2, name='Unordered object #2') @@ -2897,11 +2881,10 @@ class AdminViewListEditable(TestCase): self.assertEqual(response.context['cl'].list_editable, ()) def test_pk_hidden_fields(self): - """ Ensure that hidden pk fields aren't displayed in the table body and - that their corresponding human-readable value is displayed instead. - Note that the hidden pk fields are in fact be displayed but - separately (not in the table), and only once. - Refs #12475. + """ + hidden pk fields aren't displayed in the table body and their + corresponding human-readable value is displayed instead. The hidden pk + fields are displayed but separately (not in the table) and only once. """ story1 = Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...') story2 = Story.objects.create( @@ -2991,15 +2974,15 @@ class AdminSearchTest(TestCase): self.client.force_login(self.superuser) def test_search_on_sibling_models(self): - "Check that a search that mentions sibling models" + "A search that mentions sibling models" response = self.client.get(reverse('admin:admin_views_recommendation_changelist') + '?q=bar') # confirm the search returned 1 object self.assertContains(response, "\n1 recommendation\n") def test_with_fk_to_field(self): """ - Ensure that the to_field GET parameter is preserved when a search - is performed. Refs #10918. + The to_field GET parameter is preserved when a search is performed. + Refs #10918. """ response = self.client.get(reverse('admin:auth_user_changelist') + '?q=joe&%s=id' % TO_FIELD_VAR) self.assertContains(response, "\n1 user\n") @@ -3082,7 +3065,9 @@ class AdminInheritedInlinesTest(TestCase): self.client.force_login(self.superuser) def test_inline(self): - "Ensure that inline models which inherit from a common parent are correctly handled by admin." + """ + Inline models which inherit from a common parent are correctly handled. + """ foo_user = "foo username" bar_user = "bar username" @@ -3300,8 +3285,8 @@ class AdminActionsTest(TestCase): def test_default_redirect(self): """ - Test that actions which don't return an HttpResponse are redirected to - the same page, retaining the querystring (which may contain changelist + Actions which don't return an HttpResponse are redirected to the same + page, retaining the querystring (which may contain changelist information). """ action_data = { @@ -3338,8 +3323,7 @@ class AdminActionsTest(TestCase): def test_actions_ordering(self): """ - Ensure that actions are ordered as expected. - Refs #15964. + Actions are ordered as expected. """ response = self.client.get(reverse('admin:admin_views_externalsubscriber_changelist')) self.assertContains(response, '''