Add a fixed test command, make monkeypatching safer.

- Restore the 'test' command which falls back to the previous app's command, whatever that is.
- Apply test monkeypatches only when running our test command, and only when using a DB backend which requires it.
- This fixes the behavior of the --settings flag in manage.py, which was broken by the previous
  method of monkeypatching.