def setUp(self): self.app = Application() self.app.route("/", TestController) self.app.route("/<action>/", TestController) self.app.route("/options/", TestProxyController) self.app.route("/reflection/<action>/", ReflectionController) self.app.route("/reflection/<action>/<arg>/", ReflectionController) self.test_app = TestApp(self.app)
def unauth(cls, app: Application, request: Request, **kwargs) -> bool: """ Выполняет деаутентификацию @param request: Запрос пользователя @type request: Request @param kwargs: Параметры окружения @return: Результат выполнения авторизации @rtype : bool """ request.response.set_cookie("token", "", path="/", expires=datetime.now() - timedelta(seconds=30*60)) app.redirect(cls.root)
class ControllerTestsFixture(unittest.TestCase): def setUp(self): self.app = Application() self.app.route("/", TestController) self.app.route("/<action>/", TestController) self.app.route("/options/", TestProxyController) self.app.route("/reflection/<action>/", ReflectionController) self.app.route("/reflection/<action>/<arg>/", ReflectionController) self.test_app = TestApp(self.app) def get_query(self, url, data=None): return self.test_app.get(url, data if data else None).body.decode("utf-8") def post_query(self, url, data=None): return self.test_app.post(url, data if data else {}, xhr=True).body.decode() def get_headers_from_get_query(self, url): return self.test_app.get(url).headers
def user_initialization_hook_static(cls, app: Application, request: Request, auto_register=None): """ Стандартный алгоритм аутентификации :param app: Экземпляр приложения :param request: Запрос пользователя :return: Аккаунт пользователя """ if request.path in [ "{}auth/login".format(cls.root), "{}auth/auth".format(cls.root), "{}auth/change_password".format(cls.root), ]: return None try: a = cls.auth_service().authentificate_by_request(request) return a except (NoDataForAuth, IncorrectToken): if auto_register: return cls.new_default_account(request, auto_register=auto_register) else: app.redirect("{}auth/login/".format(cls.root))
""" PRIVATE API """ from envi import Application from controllers import DefaultPrivateController application = Application() application.route("/<action>/", DefaultPrivateController)
""" Микро-сервис для обработки изображений """ from envi import Application from controllers import Controller application = Application() application.route("/<action>/", Controller) application.route("/v1/<action>/", Controller)
from envi import Application from controllers import RoutesController application = Application() application.route("/<action>/", RoutesController) # latest version of the controller application.route("/v1/<action>/", RoutesController) # specific version of the controller
""" Микро-сервис для аутентификации """ from envi import Application as EnviApplication from controllers import AuthController application = EnviApplication() application.route("/<action>/", AuthController) application.route("/v1/<action>/", AuthController)
""" PUBLIC API """ from envi import Application from controllers import DefaultPublicController application = Application() application.route("/<action>/", DefaultPublicController)
def setUp(self): app = Application() app.route("/", JsonRpcController) self.test_app = TestApp(app)