Move more export logic into the export module

Also split the export tests out of the normal DB tests into their own file, and
use StringIO instead of the Tempfile hack.

Part of #82