1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[gsoc2009-testing] Extending documentation, fixing rst formatting.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11144 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Kevin Kubasik 2009-07-01 22:26:51 +00:00
parent 0c11738415
commit b1b9d34fa5
2 changed files with 56 additions and 64 deletions

View File

@ -11,11 +11,11 @@ popular `Windmill`_ framework. Writing a windmill test
is simple, following these steps: is simple, following these steps:
.. _Windmill: http://getwindmill.com .. _Windmill: http://getwindmill.com
#. Your windmill tests must be their own module, named ``wmtests`` or ``windmilltests``. #. Your windmill tests must be their own module, named ``wmtests`` or ``windmilltests``.
#. Django must be able to run any function in the module without arguments.::
#. Django must be able to run any function in the module without arguments.
::
from windmill.conf import global_settings from windmill.conf import global_settings
ADMIN_URL = "%s/test_admin/admin" % global_settings.TEST_URL ADMIN_URL = "%s/test_admin/admin" % global_settings.TEST_URL
from windmill.authoring import WindmillTestClient from windmill.authoring import WindmillTestClient
@ -29,62 +29,30 @@ is simple, following these steps:
client.waits.forPageLoad(timeout=u'20000') client.waits.forPageLoad(timeout=u'20000')
... ...
#. Your windmill testing module must load any files other than the module loader #. Your windmill testing module must load any files other than the module loader in ``__init__.py``.::
in ``__init__.py``.
::
from primary.py import *
Your custom storage system may override any of the storage methods explained in from primary import *
:ref:`ref-files-storage`, but you **must** implement the following methods: ...
* :meth:`Storage.delete` Setup and Teardown are done differently for windmill tests, and consist of the following
* :meth:`Storage.exists` functions. :
* :meth:`Storage.listdir`
* :meth:`Storage.size`
* :meth:`Storage.url`
You'll also usually want to use hooks specifically designed for custom storage * :meth:`setup_module`
objects. These are: * :meth:`teardown_module`
``_open(name, mode='rb')`` A sample implementation, in ``__init__.py``.::
~~~~~~~~~~~~~~~~~~~~~~~~~~
**Required**. from primary import *
Called by ``Storage.open()``, this is the actual mechanism the storage class def setup_module(module):
uses to open the file. This must return a ``File`` object, though in most cases, module.property = fetch_property()
you'll want to return some subclass here that implements logic specific to the
backend storage system.
``_save(name, content)`` def teardown_module(module):
~~~~~~~~~~~~~~~~~~~~~~~~ module.property = None
Called by ``Storage.save()``. The ``name`` will already have gone through
``get_valid_name()`` and ``get_available_name()``, and the ``content`` will be a
``File`` object itself.
Should return the actual name of name of the file saved (usually the ``name``
passed in, but if the storage needs to change the file name return the new name
instead).
``get_valid_name(name)`` These methods can be included in any file with windmill tests. See `functest`_
------------------------ for more information.
Returns a filename suitable for use with the underlying storage system. The .. _functest : http://functest.pythonesque.org/
``name`` argument passed to this method is the original filename sent to the
server, after having any path information removed. Override this to customize
how non-standard characters are converted to safe filenames.
The code provided on ``Storage`` retains only alpha-numeric characters, periods
and underscores from the original filename, removing everything else.
``get_available_name(name)``
----------------------------
Returns a filename that is available in the storage mechanism, possibly taking
the provided filename into account. The ``name`` argument passed to this method
will have already cleaned to a filename valid for the storage system, according
to the ``get_valid_name()`` method described above.
The code provided on ``Storage`` simply appends underscores to the filename
until it finds one that's available in the destination directory.

View File

@ -688,6 +688,28 @@ arguments at time of construction:
and session data cleared to defaults. Subsequent requests will appear and session data cleared to defaults. Subsequent requests will appear
to come from an AnonymousUser. to come from an AnonymousUser.
Making mock requests
~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 1.1
Use the ``django.test.mocks.RequestFactory`` class to create mock requests. Usage is as follows.
::
rf = RequestFactory()
get_request = rf.get('/hello/')
post_request = rf.post('/submit/', {'foo': 'bar'})
Once you have a request object you can pass it to any view function, just as if
that view had been hooked up using a URLconf.
.. class:: RequestFactory()
There is only one method on a ``RequestFactory``.
.. method:: RequestFactory.request(path, **request)
This will return a request object with the proper environment.
Testing responses Testing responses
~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
@ -920,6 +942,8 @@ This means, instead of instantiating a ``Client`` in each test::
response = self.client.get('/customer/index/') response = self.client.get('/customer/index/')
self.failUnlessEqual(response.status_code, 200) self.failUnlessEqual(response.status_code, 200)
.. _topics-testing-fixtures: .. _topics-testing-fixtures:
Fixture loading Fixture loading