Add new testing to test.py and Refactory query method