Fix database metadata functions and add a unit test
Add test cases for templates