-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7f87f5
commit c5e44c9
Showing
8 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from dataclasses import dataclass | ||
from typing import Any, Dict, Literal, Optional | ||
|
||
from pydantic import Field | ||
|
||
from pybotx.models.api_base import VerifiedPayloadBaseModel | ||
from pybotx.models.base_command import ( | ||
BaseBotAPIContext, | ||
BotAPIBaseCommand, | ||
BotAPIBaseSystemEventPayload, | ||
BotCommandBase, | ||
) | ||
from pybotx.models.bot_account import BotAccount | ||
from pybotx.models.enums import BotAPISystemEventTypes | ||
|
||
|
||
@dataclass | ||
class EventEdit(BotCommandBase): | ||
"""Event `system:event_edit`. | ||
Attributes: | ||
body: updated message body. | ||
""" | ||
|
||
body: Optional[str] | ||
|
||
|
||
class BotAPIEventEditData(VerifiedPayloadBaseModel): | ||
body: Optional[str] | ||
|
||
|
||
class BotAPIEventEditPayload(BotAPIBaseSystemEventPayload): | ||
body: Literal[BotAPISystemEventTypes.EVENT_EDIT] | ||
data: BotAPIEventEditData | ||
|
||
|
||
class BotAPIEventEdit(BotAPIBaseCommand): | ||
payload: BotAPIEventEditPayload = Field(..., alias="command") | ||
sender: BaseBotAPIContext = Field(..., alias="from") | ||
|
||
def to_domain(self, raw_command: Dict[str, Any]) -> EventEdit: | ||
return EventEdit( | ||
bot=BotAccount( | ||
id=self.bot_id, | ||
host=self.sender.host, | ||
), | ||
raw_command=raw_command, | ||
body=self.payload.data.body, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pybotx" | ||
version = "0.61.2" | ||
version = "0.61.3" | ||
description = "A python library for interacting with eXpress BotX API" | ||
authors = [ | ||
"Sidnev Nikolay <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
import pytest | ||
|
||
from pybotx import ( | ||
Bot, | ||
BotAccount, | ||
BotAccountWithSecret, | ||
EventEdit, | ||
HandlerCollector, | ||
lifespan_wrapper, | ||
) | ||
|
||
pytestmark = [ | ||
pytest.mark.asyncio, | ||
pytest.mark.mock_authorization, | ||
pytest.mark.usefixtures("respx_mock"), | ||
] | ||
|
||
|
||
async def test__event_edit__succeed( | ||
bot_account: BotAccountWithSecret, | ||
) -> None: | ||
# - Arrange - | ||
payload = { | ||
"sync_id": "a465f0f3-1354-491c-8f11-f400164295cb", | ||
"command": { | ||
"body": "system:event_edit", | ||
"data": {"body": "Edited"}, | ||
"command_type": "system", | ||
"metadata": {}, | ||
}, | ||
"async_files": [], | ||
"attachments": [], | ||
"entities": [], | ||
"from": { | ||
"user_huid": None, | ||
"group_chat_id": None, | ||
"ad_login": None, | ||
"ad_domain": None, | ||
"username": None, | ||
"chat_type": None, | ||
"manufacturer": None, | ||
"device": None, | ||
"device_software": None, | ||
"device_meta": {}, | ||
"platform": None, | ||
"platform_package_id": None, | ||
"is_admin": None, | ||
"is_creator": None, | ||
"app_version": None, | ||
"locale": "en", | ||
"host": "cts.example.com", | ||
}, | ||
"bot_id": "24348246-6791-4ac0-9d86-b948cd6a0e46", | ||
"proto_version": 4, | ||
"source_sync_id": None, | ||
} | ||
|
||
collector = HandlerCollector() | ||
event_edit: Optional[EventEdit] = None | ||
|
||
@collector.event_edit | ||
async def event_edit_handler(event: EventEdit, bot: Bot) -> None: | ||
nonlocal event_edit | ||
event_edit = event | ||
# Drop `raw_command` from asserting | ||
event_edit.raw_command = None | ||
|
||
built_bot = Bot(collectors=[collector], bot_accounts=[bot_account]) | ||
|
||
# - Act - | ||
async with lifespan_wrapper(built_bot) as bot: | ||
bot.async_execute_raw_bot_command(payload) | ||
|
||
# - Assert - | ||
assert event_edit == EventEdit( | ||
bot=BotAccount( | ||
id=UUID("24348246-6791-4ac0-9d86-b948cd6a0e46"), | ||
host="cts.example.com", | ||
), | ||
raw_command=None, | ||
body="Edited", | ||
) |