From 97e09629ea1c7b500f5ee65bdf57f6f66925f629 Mon Sep 17 00:00:00 2001 From: Arseney Zhiltsov Date: Fri, 23 Jul 2021 16:39:34 +0300 Subject: [PATCH] Fix BotDisabledResponse error_data validation (#153) --- botx/models/errors.py | 30 ++---------------------------- docs/changelog.md | 10 ++++++++++ pyproject.toml | 2 +- tests/test_models/test_errors.py | 5 ----- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/botx/models/errors.py b/botx/models/errors.py index 38f40605..d9b259b1 100644 --- a/botx/models/errors.py +++ b/botx/models/errors.py @@ -1,8 +1,6 @@ """Definition of errors in processing request from BotX API.""" -from typing import Any, Dict, List, Union - -from pydantic import validator +from typing import List from botx.models.base import BotXBaseModel @@ -21,30 +19,6 @@ class BotDisabledResponse(BotXBaseModel): reason: str = "bot_disabled" #: data about occurred error that should include `status_message` field in json. - error_data: Union[Dict[str, Any], BotDisabledErrorData] + error_data: BotDisabledErrorData errors: List[str] = [] - - @validator("error_data", always=True, each_item=True) - def status_message_in_error_data( - cls, - error_data: Dict[str, Any], # noqa: N805 - ) -> Union[BotDisabledErrorData, Dict[str, Any]]: - """Check that value contains `status_message` key or field. - - Arguments: - error_data: value that should be checked. - - Returns: - Built payload for response. - - Raises: - ValueError: raised if error_data does not contain status_message. - """ - if set(error_data.keys()) == {"status_message"}: - return BotDisabledErrorData(status_message=error_data["status_message"]) - - if "status_message" not in error_data: - raise ValueError("status_message key required in error_data") - - return error_data diff --git a/docs/changelog.md b/docs/changelog.md index 9477aa55..25423e35 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,13 @@ +## 0.21.0 (Jul 23, 2021) + +Tested on BotX 1.42.0-rc4 + +### Fixed + +* Remove `Dict[str, Any]` from type of `error_data` field of `BotDisabledResponse`, + now it can only be `BotDisabledErrorData`. + + ## 0.20.4 (Jul 23, 2021) Tested on BotX 1.42.0-rc4 diff --git a/pyproject.toml b/pyproject.toml index 13b727a6..b2c22c2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "botx" -version = "0.20.4" +version = "0.21.0" description = "A little python framework for building bots for eXpress" license = "MIT" authors = [ diff --git a/tests/test_models/test_errors.py b/tests/test_models/test_errors.py index 304b3a44..cdadeaf7 100644 --- a/tests/test_models/test_errors.py +++ b/tests/test_models/test_errors.py @@ -14,8 +14,3 @@ def test_doing_nothing_when_passed_error_data_model(): error_data=BotDisabledErrorData(status_message="test"), ) assert response.error_data.status_message == "test" - - -def test_do_not_changing_right_shape(): - extra_data = {"status_message": "test", "extra": True} - assert BotDisabledResponse(error_data=extra_data).error_data == extra_data