simplified the tests using some template functions
now use foreign keys to link rows appropriately
added cleanup of rows at end of test case (otherwise tests that populate and leave empty cause problems for other tests needing to delete if there are dangling referrers)