Factor database out of tests.py into dqtests.py