Refactor some unit tests in termeh.api.test