Fixing tests.

Lots of changes in this commit could go back to master as they make the
tests less dependent on data.