Tutorial by Examples

This assumes that you have read the documentation about starting a new Django project. Let us assume that the main app in your project is named td (short for test driven). To create your first test, create a file named test_view.py and copy paste the following content into it. from django.test impo...
Assuming a class from django.db import models class Author(models.Model): name = models.CharField(max_length=50) def __str__(self): return self.name def get_absolute_url(self): return reverse('view_author', args=[str(self.id)]) class Book(models.Mo...
tl;dr : Create a base class that defines two user objects (say user and another_user). Create your other models and define three Client instances. self.client : Representing user logged in browser self.another_client : Representing another_user 's client self.unlogged_client : Representing unlo...
Django uses special database settings when testing so that tests can use the database normally but by default run on an empty database. Database changes in one test will not be seen by another. For example, both of the following tests will pass: from django.test import TestCase from myapp.models...
It is possible to limit the tests executed by manage.py test by specifying which modules should be discovered by the test runner: # Run only tests for the app names "app1" $ python manage.py test app1 # If you split the tests file into a module with several tests files for an app $ p...

Page 1 of 1