Fix dangerous use self.app in init_app and test refactoring.