1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Refs #27392 -- Removed "Tests that", "Ensures that", etc. from test docstrings.

This commit is contained in:
za
2016-10-27 14:53:39 +07:00
committed by Tim Graham
parent 4bb70cbcc6
commit 321e94fa41
185 changed files with 1216 additions and 1528 deletions

View File

@@ -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, '''<label>Action: <select name="action" required>
@@ -3364,7 +3348,7 @@ action)</option>
self.assertNotContains(response, '<input type="checkbox" class="action-select"')
def test_model_without_action_still_has_jquery(self):
"Tests that a ModelAdmin without any actions still gets jQuery included in page"
"A ModelAdmin without any actions still gets jQuery included in page"
response = self.client.get(reverse('admin:admin_views_oldsubscriber_changelist'))
self.assertIsNone(response.context["action_form"])
self.assertContains(
@@ -3373,14 +3357,14 @@ action)</option>
)
def test_action_column_class(self):
"Tests that the checkbox column class is present in the response"
"The checkbox column class is present in the response"
response = self.client.get(reverse('admin:admin_views_subscriber_changelist'))
self.assertIsNotNone(response.context["action_form"])
self.assertContains(response, 'action-checkbox-column')
def test_multiple_actions_form(self):
"""
Test that actions come from the form whose submit button was pressed (#10618).
Actions come from the form whose submit button was pressed (#10618).
"""
action_data = {
ACTION_CHECKBOX_NAME: [1],
@@ -3501,7 +3485,7 @@ class TestCustomChangeList(TestCase):
self.assertEqual(response.status_code, 302) # redirect somewhere
# Hit the page once to get messages out of the queue message list
response = self.client.get(reverse('admin:admin_views_gadget_changelist'))
# Ensure that data is still not visible on the page
# Data is still not visible on the page
response = self.client.get(reverse('admin:admin_views_gadget_changelist'))
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, 'First Gadget')
@@ -3765,8 +3749,7 @@ class AdminCustomQuerysetTest(TestCase):
def test_history_view_custom_qs(self):
"""
Ensure that custom querysets are considered for the admin history view.
Refs #21013.
Custom querysets are considered for the admin history view.
"""
self.client.post(reverse('admin:login'), self.super_login)
FilteredManager.objects.create(pk=1)
@@ -3806,7 +3789,7 @@ class AdminInlineFileUploadTest(TestCase):
def test_inline_file_upload_edit_validation_error_post(self):
"""
Test that inline file uploads correctly display prior data (#10002).
Inline file uploads correctly display prior data (#10002).
"""
post_data = {
"name": "Test Gallery",
@@ -3936,7 +3919,7 @@ class AdminInlineTests(TestCase):
self.assertEqual(Widget.objects.all()[0].name, "Widget 1")
widget_id = Widget.objects.all()[0].id
# Check that the PK link exists on the rendered form
# The PK link exists on the rendered form
response = self.client.get(collector_url)
self.assertContains(response, 'name="widget_set-0-id"')
@@ -3968,7 +3951,7 @@ class AdminInlineTests(TestCase):
self.assertEqual(Grommet.objects.count(), 1)
self.assertEqual(Grommet.objects.all()[0].name, "Grommet 1")
# Check that the PK link exists on the rendered form
# The PK link exists on the rendered form
response = self.client.get(collector_url)
self.assertContains(response, 'name="grommet_set-0-code"')
@@ -4001,7 +3984,7 @@ class AdminInlineTests(TestCase):
self.assertEqual(DooHickey.objects.count(), 1)
self.assertEqual(DooHickey.objects.all()[0].name, "Doohickey 1")
# Check that the PK link exists on the rendered form
# The PK link exists on the rendered form
response = self.client.get(collector_url)
self.assertContains(response, 'name="doohickey_set-0-code"')
@@ -4034,7 +4017,7 @@ class AdminInlineTests(TestCase):
self.assertEqual(Whatsit.objects.count(), 1)
self.assertEqual(Whatsit.objects.all()[0].name, "Whatsit 1")
# Check that the PK link exists on the rendered form
# The PK link exists on the rendered form
response = self.client.get(collector_url)
self.assertContains(response, 'name="whatsit_set-0-index"')
@@ -4067,7 +4050,7 @@ class AdminInlineTests(TestCase):
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1")
doodad_pk = FancyDoodad.objects.all()[0].pk
# Check that the PK link exists on the rendered form
# The PK link exists on the rendered form
response = self.client.get(collector_url)
self.assertContains(response, 'name="fancydoodad_set-0-doodad_ptr"')
@@ -4090,8 +4073,9 @@ class AdminInlineTests(TestCase):
self.assertEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated")
def test_ordered_inline(self):
"""Check that an inline with an editable ordering fields is
updated correctly. Regression for #10922"""
"""
An inline with an editable ordering fields is updated correctly.
"""
# Create some objects with an initial ordering
Category.objects.create(id=1, order=1, collector=self.collector)
Category.objects.create(id=2, order=2, collector=self.collector)
@@ -4139,7 +4123,7 @@ class AdminInlineTests(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(self.collector.category_set.count(), 4)
self.assertEqual(Category.objects.get(id=1).order, 14)
self.assertEqual(Category.objects.get(id=2).order, 13)
@@ -4269,8 +4253,8 @@ class SeleniumTests(AdminSeleniumTestCase):
def test_prepopulated_fields(self):
"""
Ensure that the JavaScript-automated prepopulated fields work with the
main form and with stacked and tabular inlines.
The JavaScript-automated prepopulated fields work with the main form
and with stacked and tabular inlines.
Refs #13068, #9264, #9983, #9784.
"""
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
@@ -4382,9 +4366,8 @@ class SeleniumTests(AdminSeleniumTestCase):
def test_populate_existing_object(self):
"""
Ensure that the prepopulation works for existing objects too, as long
as the original field is empty.
Refs #19082.
The prepopulation works for existing objects too, as long as
the original field is empty (#19082).
"""
# Slugs are empty to start with.
item = MainPrepopulated.objects.create(
@@ -4422,7 +4405,7 @@ class SeleniumTests(AdminSeleniumTestCase):
def test_collapsible_fieldset(self):
"""
Test that the 'collapse' class in fieldsets definition allows to
The 'collapse' class in fieldsets definition allows to
show/hide the appropriate field section.
"""
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
@@ -4614,7 +4597,7 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
self.assertContains(response, "Unknown coolness.")
self.assertContains(response, "foo")
# Checks that multiline text in a readonly field gets <br /> tags
# Multiline text in a readonly field gets <br /> tags
self.assertContains(response, "Multiline<br />test<br />string")
self.assertContains(response, "<p>Multiline<br />html<br />content</p>", html=True)
self.assertContains(response, "InlineMultiline<br />test<br />string")
@@ -5093,8 +5076,7 @@ class CSSTest(TestCase):
@ignore_warnings(category=RemovedInDjango20Warning) # for allow_tags deprecation
def test_field_prefix_css_classes(self):
"""
Ensure that fields have a CSS class name with a 'field-' prefix.
Refs #16371.
Fields have a CSS class name with a 'field-' prefix.
"""
response = self.client.get(reverse('admin:admin_views_post_add'))
@@ -5113,9 +5095,8 @@ class CSSTest(TestCase):
def test_index_css_classes(self):
"""
Ensure that CSS class names are used for each app and model on the
admin index pages.
Refs #17050.
CSS class names are used for each app and model on the admin index
pages (#17050).
"""
# General index page
response = self.client.get(reverse('admin:index'))
@@ -5278,8 +5259,8 @@ class DateHierarchyTests(TestCase):
formats.reset_format_cache()
def assert_non_localized_year(self, response, year):
"""Ensure that the year is not localized with
USE_THOUSAND_SEPARATOR. Refs #15234.
"""
The year is not localized with USE_THOUSAND_SEPARATOR (#15234).
"""
self.assertNotContains(response, formats.number_format(year))
@@ -5299,7 +5280,7 @@ class DateHierarchyTests(TestCase):
def test_empty(self):
"""
Ensure that no date hierarchy links display with empty changelist.
No date hierarchy links display with empty changelist.
"""
response = self.client.get(
reverse('admin:admin_views_podcast_changelist'))
@@ -5309,7 +5290,7 @@ class DateHierarchyTests(TestCase):
def test_single(self):
"""
Ensure that single day-level date hierarchy appears for single object.
Single day-level date hierarchy appears for single object.
"""
DATE = datetime.date(2000, 6, 30)
Podcast.objects.create(release_date=DATE)
@@ -5320,7 +5301,7 @@ class DateHierarchyTests(TestCase):
def test_within_month(self):
"""
Ensure that day-level links appear for changelist within single month.
day-level links appear for changelist within single month.
"""
DATES = (datetime.date(2000, 6, 30),
datetime.date(2000, 6, 15),
@@ -5335,7 +5316,7 @@ class DateHierarchyTests(TestCase):
def test_within_year(self):
"""
Ensure that month-level links appear for changelist within single year.
month-level links appear for changelist within single year.
"""
DATES = (datetime.date(2000, 1, 30),
datetime.date(2000, 3, 15),
@@ -5352,7 +5333,7 @@ class DateHierarchyTests(TestCase):
def test_multiple_years(self):
"""
Ensure that year-level links appear for year-spanning changelist.
year-level links appear for year-spanning changelist.
"""
DATES = (datetime.date(2001, 1, 30),
datetime.date(2003, 3, 15),
@@ -5411,7 +5392,7 @@ class DateHierarchyTests(TestCase):
@override_settings(ROOT_URLCONF='admin_views.urls')
class AdminCustomSaveRelatedTests(TestCase):
"""
Ensure that one can easily customize the way related objects are saved.
One can easily customize the way related objects are saved.
Refs #16115.
"""
@@ -5985,7 +5966,7 @@ class AdminViewOnSiteTests(TestCase):
)
def test_check(self):
"Ensure that the view_on_site value is either a boolean or a callable"
"The view_on_site value is either a boolean or a callable"
try:
admin = CityAdmin(City, AdminSite())
CityAdmin.view_on_site = True
@@ -6007,24 +5988,24 @@ class AdminViewOnSiteTests(TestCase):
CityAdmin.view_on_site = True
def test_false(self):
"Ensure that the 'View on site' button is not displayed if view_on_site is False"
"The 'View on site' button is not displayed if view_on_site is False"
response = self.client.get(reverse('admin:admin_views_restaurant_change', args=(self.r1.pk,)))
content_type_pk = ContentType.objects.get_for_model(Restaurant).pk
self.assertNotContains(response, reverse('admin:view_on_site', args=(content_type_pk, 1)))
def test_true(self):
"Ensure that the default behavior is followed if view_on_site is True"
"The default behavior is followed if view_on_site is True"
response = self.client.get(reverse('admin:admin_views_city_change', args=(self.c1.pk,)))
content_type_pk = ContentType.objects.get_for_model(City).pk
self.assertContains(response, reverse('admin:view_on_site', args=(content_type_pk, self.c1.pk)))
def test_callable(self):
"Ensure that the right link is displayed if view_on_site is a callable"
"The right link is displayed if view_on_site is a callable"
response = self.client.get(reverse('admin:admin_views_worker_change', args=(self.w1.pk,)))
self.assertContains(response, '"/worker/%s/%s/"' % (self.w1.surname, self.w1.name))
def test_missing_get_absolute_url(self):
"Ensure None is returned if model doesn't have get_absolute_url"
"None is returned if model doesn't have get_absolute_url"
model_admin = ModelAdmin(Worker, None)
self.assertIsNone(model_admin.get_view_on_site_url(Worker()))
@@ -6056,26 +6037,26 @@ class InlineAdminViewOnSiteTest(TestCase):
self.client.force_login(self.superuser)
def test_false(self):
"Ensure that the 'View on site' button is not displayed if view_on_site is False"
"The 'View on site' button is not displayed if view_on_site is False"
response = self.client.get(reverse('admin:admin_views_state_change', args=(self.s1.pk,)))
content_type_pk = ContentType.objects.get_for_model(City).pk
self.assertNotContains(response, reverse('admin:view_on_site', args=(content_type_pk, self.c1.pk)))
def test_true(self):
"Ensure that the 'View on site' button is displayed if view_on_site is True"
"The 'View on site' button is displayed if view_on_site is True"
response = self.client.get(reverse('admin:admin_views_city_change', args=(self.c1.pk,)))
content_type_pk = ContentType.objects.get_for_model(Restaurant).pk
self.assertContains(response, reverse('admin:view_on_site', args=(content_type_pk, self.r1.pk)))
def test_callable(self):
"Ensure that the right link is displayed if view_on_site is a callable"
"The right link is displayed if view_on_site is a callable"
response = self.client.get(reverse('admin:admin_views_restaurant_change', args=(self.r1.pk,)))
self.assertContains(response, '"/worker_inline/%s/%s/"' % (self.w1.surname, self.w1.name))
@override_settings(ROOT_URLCONF='admin_views.urls')
class TestETagWithAdminView(SimpleTestCase):
# See https://code.djangoproject.com/ticket/16003
# The admin is compatible with ETags (#16003).
def test_admin(self):
with self.settings(USE_ETAGS=False):