Unit tests for the Survey save override method
Recall in the previous chapter that we ultimately implemented four individual tests of the Survey
save override function:
A straightforward test of the added capability, which verifies that if
closes
is not specified when aSurvey
is created, it is auto-set to a week afteropens
A test that verifies that this auto-set operation is not performed if
closes
is explicitly specified during creationA test that verifies that
closes
is only auto-set if its value is missing during initial creation, not while saving an existing instanceA test that verifies that the
save
override function does not introduce an unexpected exception in the error case where neitheropens
norcloses
is specified during creation
To implement these as unit tests instead of doctests, create a TestCase
within the suvery/tests.py
file, replacing the sample SimpleTest
. Within the new TestCase
class, define each individual test as a separate test method in that TestCase
, like so:
import...