Added complete tests for query insertion/getting by ID.

(I'm not sure about the test ordering that makes it work, it seems like
magic to me)