https://github.com/seporaitis/django-tutorial-tests
Django tutorial application with a few more tests.
https://github.com/seporaitis/django-tutorial-tests
django django-test django-tutorial-application python3
Last synced: 10 months ago
JSON representation
Django tutorial application with a few more tests.
- Host: GitHub
- URL: https://github.com/seporaitis/django-tutorial-tests
- Owner: seporaitis
- Created: 2017-06-22T21:04:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-24T22:10:20.000Z (over 8 years ago)
- Last Synced: 2025-03-23T20:11:37.585Z (11 months ago)
- Topics: django, django-test, django-tutorial-application, python3
- Language: Python
- Size: 27.3 KB
- Stars: 5
- Watchers: 0
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Django Test Tutorial
[](https://travis-ci.org/seporaitis/django-tutorial-tests/builds)
## What is this?
This is the standard Django tutorial application with some extra
tests.
## Why is it here?
High level: provide examples of testing Django views, especially GET &
POST requests, using Django test `Client` and Django `RequestFactory`.
The top-level difference between the two is that `Client` creates and
runs the request starting at low-level HTTP, to middleware, to view,
and returns the response object with the context, used to render
template.
On the other hand, `RequestFactory` returns request object that can be
then used to test view function as a black-box, with exactly known
inputs, testing for specific outputs.
Although both have their purpose, request factory based tests are much
faster than client, as can be observed by cloning this repository and
running `tox`:
``` shell
$ tox -- polls.tests.test_views_with_request_factory
... output ...
Ran 9 tests in 0.030s
```
``` shell
$ tox -- polls.tests.test_views_with_client
... output ...
Ran 10 tests in 0.205s
```
## Tests
* using `Client`: [polls/tests/test_views_with_client.py](https://github.com/seporaitis/django-tutorial-tests/blob/master/polls/tests/test_views_with_client.py)
* using `RequestFactory`: [polls/tests/test_views_with_request_factory.py](https://github.com/seporaitis/django-tutorial-tests/blob/master/polls/tests/test_views_with_request_factory.py)
## More reading:
* [Django test `Client`](https://docs.djangoproject.com/en/dev/topics/testing/tools/)
* [Django `RequestFactory`](https://docs.djangoproject.com/en/1.11/topics/testing/advanced/#the-request-factory)