Skip to content

Commit 97e0962

Browse files
authored
Fix BotDisabledResponse error_data validation (#153)
1 parent 98b495a commit 97e0962

File tree

4 files changed

+13
-34
lines changed

4 files changed

+13
-34
lines changed

botx/models/errors.py

+2-28
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Definition of errors in processing request from BotX API."""
22

3-
from typing import Any, Dict, List, Union
4-
5-
from pydantic import validator
3+
from typing import List
64

75
from botx.models.base import BotXBaseModel
86

@@ -21,30 +19,6 @@ class BotDisabledResponse(BotXBaseModel):
2119
reason: str = "bot_disabled"
2220

2321
#: data about occurred error that should include `status_message` field in json.
24-
error_data: Union[Dict[str, Any], BotDisabledErrorData]
22+
error_data: BotDisabledErrorData
2523

2624
errors: List[str] = []
27-
28-
@validator("error_data", always=True, each_item=True)
29-
def status_message_in_error_data(
30-
cls,
31-
error_data: Dict[str, Any], # noqa: N805
32-
) -> Union[BotDisabledErrorData, Dict[str, Any]]:
33-
"""Check that value contains `status_message` key or field.
34-
35-
Arguments:
36-
error_data: value that should be checked.
37-
38-
Returns:
39-
Built payload for response.
40-
41-
Raises:
42-
ValueError: raised if error_data does not contain status_message.
43-
"""
44-
if set(error_data.keys()) == {"status_message"}:
45-
return BotDisabledErrorData(status_message=error_data["status_message"])
46-
47-
if "status_message" not in error_data:
48-
raise ValueError("status_message key required in error_data")
49-
50-
return error_data

docs/changelog.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.21.0 (Jul 23, 2021)
2+
3+
Tested on BotX 1.42.0-rc4
4+
5+
### Fixed
6+
7+
* Remove `Dict[str, Any]` from type of `error_data` field of `BotDisabledResponse`,
8+
now it can only be `BotDisabledErrorData`.
9+
10+
111
## 0.20.4 (Jul 23, 2021)
212

313
Tested on BotX 1.42.0-rc4

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "botx"
3-
version = "0.20.4"
3+
version = "0.21.0"
44
description = "A little python framework for building bots for eXpress"
55
license = "MIT"
66
authors = [

tests/test_models/test_errors.py

-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@ def test_doing_nothing_when_passed_error_data_model():
1414
error_data=BotDisabledErrorData(status_message="test"),
1515
)
1616
assert response.error_data.status_message == "test"
17-
18-
19-
def test_do_not_changing_right_shape():
20-
extra_data = {"status_message": "test", "extra": True}
21-
assert BotDisabledResponse(error_data=extra_data).error_data == extra_data

0 commit comments

Comments
 (0)