def build_credentials(cls, request: Request): """ Метод для создания экземпляра класса Credentials на основе предоставленного объекта Request :param request: :return: """ credentials = Credentials() credentials.email = request.get("email").lower() if request.get("email", None) else None credentials.phone = normalize_phone_number(request.get("phone")) if request.get("phone", False) else None credentials.token_name = request.get("token_name", "") credentials.token = request.get("%stoken" % credentials.token_name, None) credentials.password = request.get("password", None) credentials.vk_id = request.get("vk_id", None) return credentials
def build_credentials(cls, request: Request): """ Метод для создания экземпляра класса Credentials на основе предоставленного объекта Request :param request: :return: """ credentials = Credentials() credentials.email = request.get("email").lower() if request.get( "email", None) else None credentials.phone = normalize_phone_number( request.get("phone")) if request.get("phone", False) else None credentials.token_name = request.get("token_name", "") credentials.token = request.get("%stoken" % credentials.token_name, None) credentials.password = request.get("password", None) credentials.vk_id = request.get("vk_id", None) return credentials
def test_auth_by_domain_specific_token(self): self.email_credentials.token_name = "test" auth_result = self.service.authenticate(self.email_credentials) self.assertTrue(isinstance(auth_result, dict)) self.assertEqual(1, auth_result["authentication"]["id"]) self.assertEqual(32, len(auth_result["authentication"]["testtoken"])) token = auth_result["authentication"]["testtoken"] new_credentials = Credentials() new_credentials.token = token new_credentials.token_name = "test" auth_result = self.service.authenticate(new_credentials) self.assertTrue(isinstance(auth_result, dict)) self.assertEqual(1, auth_result["authentication"]["id"]) self.assertEqual(32, len(auth_result["authentication"]["testtoken"])) # При авторизации по токену, токен не меняется: auth_result = self.service.authenticate(new_credentials) self.assertTrue(isinstance(auth_result, dict)) self.assertEqual(1, auth_result["authentication"]["id"]) self.assertEqual(token, auth_result["authentication"]["testtoken"])