Refine tests.

Using python `mock`