Changeset 3737
- Timestamp:
- 09/08/06 08:10:57 (2 years ago)
- Files:
-
- django/trunk/docs/testing.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/testing.txt
r3715 r3737 93 93 Like doctests, Django's unit tests use a standard library module: unittest_. 94 94 As with doctests, Django's test runner looks for any unit test cases defined 95 in ``models.py``, or in a ``tests.py`` file in your application directory. 95 in ``models.py``, or in a ``tests.py`` file stored in the application 96 directory. 96 97 97 98 An equivalent unittest test case for the above example would look like:: … … 111 112 112 113 When you `run your tests`_, the test utility will find all the test cases 113 (that is, subclasses of ``unittest.TestCase``) in ``tests.py``, automatically 114 build a test suite out of those test cases, and run that suite. 114 (that is, subclasses of ``unittest.TestCase``) in ``models.py`` and 115 ``tests.py``, automatically build a test suite out of those test cases, 116 and run that suite. 115 117 116 118 For more details about ``unittest``, see the `standard library unittest … … 198 200 199 201 The Test Client is stateful; if a cookie is returned as part of a response, 200 that cookie is provided as part of the next request . Expiry policies for these201 cookies are not followed; if you want a cookie to expire, either delete it202 manually from ``client.cookies``, or create a new Client instance (which will 203 effectively delete all cookies).202 that cookie is provided as part of the next request issued to that Client 203 instance. Expiry policies for these cookies are not followed; if you want 204 a cookie to expire, either delete it manually from ``client.cookies``, or 205 create a new Client instance (which will effectively delete all cookies). 204 206 205 207 Making requests … … 211 213 212 214 ``get(path, data={})`` 213 214 215 Make a GET request on the provided ``path``. The key-value pairs in the 215 216 data dictionary will be used to create a GET data payload. For example:: … … 223 224 224 225 ``post(path, data={})`` 225 226 226 Make a POST request on the provided ``path``. The key-value pairs in the 227 227 data dictionary will be used to create the POST data payload. This payload … … 244 244 245 245 ``login(path, username, password)`` 246 247 246 In a production site, it is likely that some views will be protected with 248 247 the @login_required URL provided by ``django.contrib.auth``. Interacting … … 308 307 self.client = Client() 309 308 def test_details(self): 309 # Issue a GET request 310 310 response = self.client.get('/customer/details/') 311 311 312 # Check that the respose is 200 OK 312 313 self.failUnlessEqual(response.status_code, 200) 314 # Check that the rendered context contains 5 customers 313 315 self.failUnlessEqual(len(response.context['customers']), 5) 314 316
