1.6
2014

Tips for Upgrading Django
From time to time we inherit code bases running outdated versions of Django and part of our work is to get them running a stable and secure version. In the past year we've done upgrades from versions as old as 1.0 and we've learned a few lessons along the way.
2013

ShipIt Day 4: SaltStack, Front-end Exploration, and Django Core
Last week everyone at Caktus stepped away from client work for a day and a half to focus on learning and experimenting. This was our fourth ShipIt day at Caktus, our first being almost exactly a year ago. Each time we all learn a ton, not only by diving head first into something new, but also by hearing the experiences of everyone else on the team.

Skipping Test DB Creation
We are always looking for ways to make our tests run faster. That means
writing tests which don't preform I/O (DB reads/writes, disk
reads/writes) when possible. Django has a collection of TestCase
subclasses
for different use cases. The common TestCase
handles the fixture
loading and the creation the of TestClient
. It uses the database
transactions to ensure that the database state is reset for every test.
That is it wraps each test in a transaction and rolls it back once the
test is over. Any transaction management inside the test becomes a
no-op. Since [TestCase]{.title-ref}[ overrides the transaction
facilities, if you need to test the transactional behavior of a piece of
code you can instead use
]{.title-ref}[TransactionTestCase]{.title-ref}[.
]{.title-ref}[TransactionTestCase]{.title-ref}` resets the database
after the test runs by truncating all tables which is much slower than
rolling back the transaction particularly if you have a large number of
tables.

MEDIA_ROOT and Django Tests
If you’ve ever written a test for a view or model with associated
uploaded files you might have noticed a small problem with those files
hanging around after the tests are complete. Since version 1.3, Django
won’t delete the files associated with your model instances when they
are deleted. Some work-arounds for this
issue
involve writing a custom delete for your model or using a post_delete
signal handler. But even with those in place the files would not be
deleted during tests because the model instances are not explicitly
deleted at the end of the test case. Instead, Django simply rolls back
the transaction and the delete method is never called nor are the
signals fired. This can be quite an annoyance when running the tests
repeatedly and watching your MEDIA_ROOT
(or worse your S3 bucket) fill
up with garbage data. More than annoyance, this introduces something you
always want to avoid in unittests: global state.