Made a bunch more edits up until [17418]

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17428 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2012-02-03 20:45:45 +00:00
parent 00227b6529
commit 6ecadcbdd2
11 changed files with 67 additions and 69 deletions

View File

@ -80,10 +80,7 @@ class Sitemap(object):
except Site.DoesNotExist: except Site.DoesNotExist:
pass pass
if site is None: if site is None:
raise ImproperlyConfigured("In order to use Sitemaps " raise ImproperlyConfigured("To use sitemaps, either enable the sites framework or pass a Site/RequestSite object in your view.")
"you must either use the sites framework "
"or pass in a Site or RequestSite object "
"in your view code.")
domain = site.domain domain = site.domain
urls = [] urls = []

View File

@ -411,15 +411,14 @@ class SimpleTestCase(ut2.TestCase):
def assertHTMLEqual(self, html1, html2, msg=None): def assertHTMLEqual(self, html1, html2, msg=None):
""" """
Asserts that two html snippets are semantically the same, Asserts that two HTML snippets are semantically the same.
e.g. whitespace in most cases is ignored, attribute ordering is not Whitespace in most cases is ignored, and attribute ordering is not
significant. The passed in arguments must be valid HTML. significant. The passed-in arguments must be valid HTML.
""" """
dom1 = assert_and_parse_html(self, html1, msg, dom1 = assert_and_parse_html(self, html1, msg,
u'First argument is not valid html:') u'First argument is not valid HTML:')
dom2 = assert_and_parse_html(self, html2, msg, dom2 = assert_and_parse_html(self, html2, msg,
u'Second argument is not valid html:') u'Second argument is not valid HTML:')
if dom1 != dom2: if dom1 != dom2:
standardMsg = '%s != %s' % ( standardMsg = '%s != %s' % (
@ -433,9 +432,9 @@ class SimpleTestCase(ut2.TestCase):
def assertHTMLNotEqual(self, html1, html2, msg=None): def assertHTMLNotEqual(self, html1, html2, msg=None):
"""Asserts that two HTML snippets are not semantically equivalent.""" """Asserts that two HTML snippets are not semantically equivalent."""
dom1 = assert_and_parse_html(self, html1, msg, dom1 = assert_and_parse_html(self, html1, msg,
u'First argument is not valid html:') u'First argument is not valid HTML:')
dom2 = assert_and_parse_html(self, html2, msg, dom2 = assert_and_parse_html(self, html2, msg,
u'Second argument is not valid html:') u'Second argument is not valid HTML:')
if dom1 == dom2: if dom1 == dom2:
standardMsg = '%s == %s' % ( standardMsg = '%s == %s' % (
@ -625,9 +624,9 @@ class TransactionTestCase(SimpleTestCase):
content = response.content content = response.content
if html: if html:
content = assert_and_parse_html(self, content, None, content = assert_and_parse_html(self, content, None,
u"Response's content is not valid html:") u"Response's content is not valid HTML:")
text = assert_and_parse_html(self, text, None, text = assert_and_parse_html(self, text, None,
u"Second argument is not valid html:") u"Second argument is not valid HTML:")
real_count = content.count(text) real_count = content.count(text)
if count is not None: if count is not None:
self.assertEqual(real_count, count, self.assertEqual(real_count, count,
@ -661,9 +660,9 @@ class TransactionTestCase(SimpleTestCase):
content = response.content content = response.content
if html: if html:
content = assert_and_parse_html(self, content, None, content = assert_and_parse_html(self, content, None,
u'Response\'s content is no valid html:') u'Response\'s content is not valid HTML:')
text = assert_and_parse_html(self, text, None, text = assert_and_parse_html(self, text, None,
u'Second argument is no valid html:') u'Second argument is not valid HTML:')
self.assertEqual(content.count(text), 0, self.assertEqual(content.count(text), 0,
msg_prefix + "Response should not contain '%s'" % text) msg_prefix + "Response should not contain '%s'" % text)
@ -721,7 +720,7 @@ class TransactionTestCase(SimpleTestCase):
def assertTemplateUsed(self, response=None, template_name=None, msg_prefix=''): def assertTemplateUsed(self, response=None, template_name=None, msg_prefix=''):
""" """
Asserts that the template with the provided name was used in rendering Asserts that the template with the provided name was used in rendering
the response. Also useable as context manager. the response. Also usable as context manager.
""" """
if response is None and template_name is None: if response is None and template_name is None:
raise TypeError(u'response and/or template_name argument must be provided') raise TypeError(u'response and/or template_name argument must be provided')
@ -729,7 +728,7 @@ class TransactionTestCase(SimpleTestCase):
if msg_prefix: if msg_prefix:
msg_prefix += ": " msg_prefix += ": "
# use assertTemplateUsed as context manager # Use assertTemplateUsed as context manager.
if not hasattr(response, 'templates') or (response is None and template_name): if not hasattr(response, 'templates') or (response is None and template_name):
if response: if response:
template_name = response template_name = response
@ -748,7 +747,7 @@ class TransactionTestCase(SimpleTestCase):
def assertTemplateNotUsed(self, response=None, template_name=None, msg_prefix=''): def assertTemplateNotUsed(self, response=None, template_name=None, msg_prefix=''):
""" """
Asserts that the template with the provided name was NOT used in Asserts that the template with the provided name was NOT used in
rendering the response. Also useable as context manager. rendering the response. Also usable as context manager.
""" """
if response is None and template_name is None: if response is None and template_name is None:
raise TypeError(u'response and/or template_name argument must be provided') raise TypeError(u'response and/or template_name argument must be provided')
@ -756,7 +755,7 @@ class TransactionTestCase(SimpleTestCase):
if msg_prefix: if msg_prefix:
msg_prefix += ": " msg_prefix += ": "
# use assertTemplateUsed as context manager # Use assertTemplateUsed as context manager.
if not hasattr(response, 'templates') or (response is None and template_name): if not hasattr(response, 'templates') or (response is None and template_name):
if response: if response:
template_name = response template_name = response

View File

@ -365,7 +365,7 @@ special: It's just a normal view.
You normally won't have to bother with writing 404 views. If you don't set You normally won't have to bother with writing 404 views. If you don't set
``handler404``, the built-in view :func:`django.views.defaults.page_not_found` ``handler404``, the built-in view :func:`django.views.defaults.page_not_found`
is used by default. In this case, you still have one obligation: To create a is used by default. In this case, you still have one obligation: create a
``404.html`` template in the root of your template directory. The default 404 ``404.html`` template in the root of your template directory. The default 404
view will use that template for all 404 errors. If :setting:`DEBUG` is set to view will use that template for all 404 errors. If :setting:`DEBUG` is set to
``False`` (in your settings module) and if you didn't create a ``404.html`` ``False`` (in your settings module) and if you didn't create a ``404.html``

View File

@ -310,7 +310,7 @@ index will reflect that.
.. versionadded:: 1.4 .. versionadded:: 1.4
If you are not using the vanilla sitemap view -- for example, if it is wrapped If you're not using the vanilla sitemap view -- for example, if it's wrapped
with a caching decorator -- you must name your sitemap view and pass with a caching decorator -- you must name your sitemap view and pass
``sitemap_url_name`` to the index view:: ``sitemap_url_name`` to the index view::

View File

@ -1002,7 +1002,7 @@ For example::
.. versionadded:: 1.4 .. versionadded:: 1.4
As with the :djadmin:`startapp` command, the ``--template`` option lets you As with the :djadmin:`startapp` command, the ``--template`` option lets you
specify a directory, file path, or URL of a custom project template. See the specify a directory, file path or URL of a custom project template. See the
:djadmin:`startapp` documentation for details of supported project template :djadmin:`startapp` documentation for details of supported project template
formats. formats.

View File

@ -96,17 +96,21 @@ browsers).
It is suggested to place this first in the middleware list, so that the It is suggested to place this first in the middleware list, so that the
compression of the response content is the last thing that happens. compression of the response content is the last thing that happens.
It will not compress content bodies less than 200 bytes long, when the It will NOT compress content if any of the following are true:
``Content-Encoding`` header is already set, or when the browser does not send
an ``Accept-Encoding`` header containing ``gzip``.
Content will also not be compressed when the browser is Internet Explorer and * The content body is less than 200 bytes long.
the ``Content-Type`` header contains ``javascript`` or starts with anything
other than ``text/``. This is done to overcome a bug present in early versions
of Internet Explorer which caused decompression not to be performed on certain
content types.
GZip compression can be applied to individual views using the * The response has already set the ``Content-Encoding`` header.
* The request (the browser) hasn't sent an ``Accept-Encoding`` header
containing ``gzip``.
* The request is from Internet Explorer and the ``Content-Type`` header
contains ``javascript`` or starts with anything other than ``text/``.
We do this to avoid a bug in early versions of IE that caused decompression
not to be performed on certain content types.
You can apply GZip compression to individual views using the
:func:`~django.views.decorators.http.gzip_page()` decorator. :func:`~django.views.decorators.http.gzip_page()` decorator.
Conditional GET middleware Conditional GET middleware

View File

@ -2232,7 +2232,7 @@ This template tag works on links prefixed with ``http://``, ``https://``, or
It also supports domain-only links ending in one of the original top level It also supports domain-only links ending in one of the original top level
domains (``.com``, ``.edu``, ``.gov``, ``.int``, ``.mil``, ``.net``, and domains (``.com``, ``.edu``, ``.gov``, ``.int``, ``.mil``, ``.net``, and
``.org``). For example, ``djangoproject.com`` gets converted too. ``.org``). For example, ``djangoproject.com`` gets converted.
.. versionchanged:: 1.4 .. versionchanged:: 1.4
@ -2240,7 +2240,7 @@ Until Django 1.4, only the ``.com``, ``.net`` and ``.org`` suffixes were
supported for domain-only links. supported for domain-only links.
Links can have trailing punctuation (periods, commas, close-parens) and leading Links can have trailing punctuation (periods, commas, close-parens) and leading
punctuation (opening parens) and ``urlize`` will still do the right thing. punctuation (opening parens), and ``urlize`` will still do the right thing.
Links generated by ``urlize`` have a ``rel="nofollow"`` attribute added Links generated by ``urlize`` have a ``rel="nofollow"`` attribute added
to them. to them.

View File

@ -480,15 +480,15 @@ HTML comparisons in tests
The :class:`~django.test.testcase.TestCase` base class now has some helpers to The :class:`~django.test.testcase.TestCase` base class now has some helpers to
compare HTML without tripping over irrelevant differences in whitespace, compare HTML without tripping over irrelevant differences in whitespace,
argument quoting and ordering, and closing of self-closing tags. HTML can argument quoting/ordering and closing of self-closing tags. You can either
either be compared directly with the new compare HTML directly with the new
:meth:`~django.test.testcase.TestCase.assertHTMLEqual` and :meth:`~django.test.testcase.TestCase.assertHTMLEqual` and
:meth:`~django.test.testcase.TestCase.assertHTMLNotEqual` assertions, or use :meth:`~django.test.testcase.TestCase.assertHTMLNotEqual` assertions, or use
the ``html=True`` flag with the ``html=True`` flag with
:meth:`~django.test.testcase.TestCase.assertContains` and :meth:`~django.test.testcase.TestCase.assertContains` and
:meth:`~django.test.testcase.TestCase.assertNotContains` to test if the test :meth:`~django.test.testcase.TestCase.assertNotContains` to test whether the
client's response contains a given HTML fragment. See the :ref:`assertion client's response contains a given HTML fragment. See the :ref:`assertion
documentation<assertions>` for more information. documentation<assertions>` for more.
Minor features Minor features
~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
@ -571,11 +571,11 @@ Django 1.4 also includes several smaller improvements worth noting:
* The MySQL database backend can now make use of the savepoint feature * The MySQL database backend can now make use of the savepoint feature
implemented by MySQL version 5.0.3 or newer with the InnoDB storage engine. implemented by MySQL version 5.0.3 or newer with the InnoDB storage engine.
* It is now possible to pass initial values to the model forms that are part of * It's now possible to pass initial values to the model forms that are part of
both model formsets and inline model formset as returned from factory both model formsets and inline model formsets as returned from factory
functions ``modelformset_factory`` and ``inlineformset_factory`` respectively functions ``modelformset_factory`` and ``inlineformset_factory`` respectively
just like with regular formsets. However, initial values only apply to extra just like with regular formsets. However, initial values only apply to extra
forms i.e. those which are not bound to an existing model instance. forms, i.e. those which are not bound to an existing model instance.
* The sitemaps framework can now handle HTTPS links using the new * The sitemaps framework can now handle HTTPS links using the new
:attr:`Sitemap.protocol <django.contrib.sitemaps.Sitemap.protocol>` class :attr:`Sitemap.protocol <django.contrib.sitemaps.Sitemap.protocol>` class
@ -800,8 +800,8 @@ to pysqlite). ``DatabaseWrapper`` however preserves the previous behavior by
disabling thread-sharing by default, so this does not affect any existing disabling thread-sharing by default, so this does not affect any existing
code that purely relies on the ORM or on ``DatabaseWrapper.cursor()``. code that purely relies on the ORM or on ``DatabaseWrapper.cursor()``.
Finally, while it is now possible to pass connections between threads, Django Finally, while it's now possible to pass connections between threads, Django
does not make any effort to synchronize access to the underlying backend. doesn't make any effort to synchronize access to the underlying backend.
Concurrency behavior is defined by the underlying backend implementation. Concurrency behavior is defined by the underlying backend implementation.
Check their documentation for details. Check their documentation for details.
@ -964,9 +964,9 @@ wild, because they would confuse browsers too.
``assertTemplateUsed`` and ``assertTemplateNotUsed`` as context manager ``assertTemplateUsed`` and ``assertTemplateNotUsed`` as context manager
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is now possible to check whether a template was used or not in a block of It's now possible to check whether a template was used within a block of
code with the :meth:`~django.test.testcase.TestCase.assertTemplateUsed` and code with :meth:`~django.test.testcase.TestCase.assertTemplateUsed` and
:meth:`~django.test.testcase.TestCase.assertTemplateNotUsed` assertions. They :meth:`~django.test.testcase.TestCase.assertTemplateNotUsed`. And they
can be used as a context manager:: can be used as a context manager::
with self.assertTemplateUsed('index.html'): with self.assertTemplateUsed('index.html'):
@ -974,18 +974,18 @@ can be used as a context manager::
with self.assertTemplateNotUsed('base.html'): with self.assertTemplateNotUsed('base.html'):
render_to_string('index.html') render_to_string('index.html')
See the :ref:`assertion documentation<assertions>` for more information. See the :ref:`assertion documentation<assertions>` for more.
Database connections after running the test suite Database connections after running the test suite
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The default test runner now does not restore the database connections after the The default test runner no longer restores the database connections after
tests' execution any more. This prevents the production database from being tests' execution. This prevents the production database from being exposed to
exposed to potential threads that would still be running and attempting to potential threads that would still be running and attempting to create new
create new connections. connections.
If your code relied on connections to the production database being created If your code relied on connections to the production database being created
after the tests' execution, then you may restore the previous behavior by after tests' execution, then you can restore the previous behavior by
subclassing ``DjangoTestRunner`` and overriding its ``teardown_databases()`` subclassing ``DjangoTestRunner`` and overriding its ``teardown_databases()``
method. method.

View File

@ -622,11 +622,11 @@ Providing initial values
.. versionadded:: 1.4 .. versionadded:: 1.4
As with regular formsets, it is possible to :ref:`specify initial data As with regular formsets, it's possible to :ref:`specify initial data
<formsets-initial-data>` for forms in the formset by specifying an ``initial`` <formsets-initial-data>` for forms in the formset by specifying an ``initial``
parameter when instantiating the model formset class returned by parameter when instantiating the model formset class returned by
``modelformset_factory``. However, with model formsets the initial values only ``modelformset_factory``. However, with model formsets, the initial values only
apply to extra forms, those which are not bound to an existing object instance. apply to extra forms, those that aren't bound to an existing object instance.
.. _saving-objects-in-the-formset: .. _saving-objects-in-the-formset:

View File

@ -1593,11 +1593,10 @@ your test suite.
.. versionadded:: 1.4 .. versionadded:: 1.4
You can also use this as a context manager. The code that is executed You can use this as a context manager, like this::
under the with statement is then observed instead of a response::
# This is necessary in Python 2.5 to enable the with statement, in 2.6 # This is necessary in Python 2.5 to enable the with statement.
# and up it is no longer necessary. # In 2.6 and up, it's not necessary.
from __future__ import with_statement from __future__ import with_statement
with self.assertTemplateUsed('index.html'): with self.assertTemplateUsed('index.html'):
@ -1680,14 +1679,14 @@ your test suite.
is based on HTML semantics. The comparison takes following things into is based on HTML semantics. The comparison takes following things into
account: account:
* Whitespace before and after HTML tags is ignored * Whitespace before and after HTML tags is ignored.
* All types of whitespace are considered equivalent * All types of whitespace are considered equivalent.
* All open tags are closed implicitly, i.e. when a surrounding tag is * All open tags are closed implicitly, e.g. when a surrounding tag is
closed or the HTML document ends closed or the HTML document ends.
* Empty tags are equivalent to their self-closing version * Empty tags are equivalent to their self-closing version.
* The ordering of attributes of an HTML element is not significant * The ordering of attributes of an HTML element is not significant.
* Attributes without an argument are equal to attributes that equal in * Attributes without an argument are equal to attributes that equal in
name and value (see the examples) name and value (see the examples).
The following examples are valid tests and don't raise any The following examples are valid tests and don't raise any
``AssertionError``:: ``AssertionError``::
@ -1714,7 +1713,6 @@ your test suite.
``html1`` and ``html2`` must be valid HTML. An ``AssertionError`` will be ``html1`` and ``html2`` must be valid HTML. An ``AssertionError`` will be
raised if one of them cannot be parsed. raised if one of them cannot be parsed.
.. _topics-testing-email: .. _topics-testing-email:
Email services Email services

View File

@ -357,7 +357,7 @@ class HTMLEqualTests(TestCase):
<p> This is a valid paragraph <p> This is a valid paragraph
<!-- browsers would close the p tag here --> <!-- browsers would close the p tag here -->
<div> this is a div AFTER the p</div> <div> this is a div AFTER the p</div>
</p> <!-- this is invalid html parsing however it should make no </p> <!-- this is invalid HTML parsing, but it should make no
difference in most cases --> difference in most cases -->
</body> </body>
</html>""") </html>""")