| 429 | | .. _testing django applications: ../testing/ |
|---|
| | 430 | .. _testing Django applications: ../testing/ |
|---|
| | 431 | |
|---|
| | 432 | testserver [fixture fixture ...] |
|---|
| | 433 | -------------------------------- |
|---|
| | 434 | |
|---|
| | 435 | **New in Django development version** |
|---|
| | 436 | |
|---|
| | 437 | Runs a Django development server (as in ``runserver``) using data from the |
|---|
| | 438 | given fixture(s). |
|---|
| | 439 | |
|---|
| | 440 | For example, this command:: |
|---|
| | 441 | |
|---|
| | 442 | django-admin.py testserver mydata.json |
|---|
| | 443 | |
|---|
| | 444 | ...would perform the following steps: |
|---|
| | 445 | |
|---|
| | 446 | 1. Create a test database, as described in `testing Django applications`_. |
|---|
| | 447 | 2. Populate the test database with fixture data from the given fixtures. |
|---|
| | 448 | (For more on fixtures, see the documentation for ``loaddata`` above.) |
|---|
| | 449 | 3. Runs the Django development server (as in ``runserver``), pointed at |
|---|
| | 450 | this newly created test database instead of your production database. |
|---|
| | 451 | |
|---|
| | 452 | This is useful in a number of ways: |
|---|
| | 453 | |
|---|
| | 454 | * When you're writing `unit tests`_ of how your views act with certain |
|---|
| | 455 | fixture data, you can use ``testserver`` to interact with the views in |
|---|
| | 456 | a Web browser, manually. |
|---|
| | 457 | |
|---|
| | 458 | * Let's say you're developing your Django application and have a "pristine" |
|---|
| | 459 | copy of a database that you'd like to interact with. You can dump your |
|---|
| | 460 | database to a fixture (using the ``dumpdata`` command, explained above), |
|---|
| | 461 | then use ``testserver`` to run your Web application with that data. With |
|---|
| | 462 | this arrangement, you have the flexibility of messing up your data |
|---|
| | 463 | in any way, knowing that whatever data changes you're making are only |
|---|
| | 464 | being made to a test database. |
|---|
| | 465 | |
|---|
| | 466 | Note that this server can only run on the default port on localhost; it does |
|---|
| | 467 | not yet accept a ``host`` or ``port`` parameter. |
|---|
| | 468 | |
|---|
| | 469 | .. _unit tests: ../testing/ |
|---|