Adds (very) basic unit tests for the database server

Gets rid of duplicate code, and pulls it into a function instead.