Maybe this is duplicated too? I factored that out into a fn in https://github.com/puppetlabs/puppetdb/pull/815. Probably a good candidate for test utils (now or later when 815 gets merged).