Test case for build_query