Better support for dealing with packages from template defs in tests. Fixed minor issues in DAO.stg. refs #500