mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
"Add get_mounted_bot function and improve model comparison in tests"
In this commit, a new function `get_mounted_bot` was added to `context_controller.py` that returns the bot mounted in context. This function was needed to bypass the limitation in pydantic BaseModel's properties, which neither support computed fields nor serialization/validation. Various tests were also updated to compare models using `model_dump_json()` method rather than comparing the models directly. This change provides more accurate comparisons by considering default values in the models. Further, the dispatcher was adjusted to enforce update re-mounting if the mounted bot differs from the current update. This allows shortcuts to be used in the bot's current instance and ensures the correct propagation of the context to all the nested objects and attributes of Updates.
This commit is contained in:
parent
31c11c31e0
commit
74e00a30b1
4 changed files with 31 additions and 7 deletions
|
|
@ -460,7 +460,9 @@ class TestDispatcher:
|
|||
|
||||
@observer()
|
||||
async def my_handler(event: Any, **kwargs: Any):
|
||||
assert event == getattr(update, event_type)
|
||||
assert event.model_dump(exclude_defaults=True) == getattr(
|
||||
update, event_type
|
||||
).model_dump(exclude_defaults=True)
|
||||
if has_chat:
|
||||
assert kwargs["event_chat"]
|
||||
if has_user:
|
||||
|
|
@ -469,7 +471,9 @@ class TestDispatcher:
|
|||
|
||||
result = await router.feed_update(bot, update, test="PASS")
|
||||
assert isinstance(result, dict)
|
||||
assert result["event_update"] == update
|
||||
assert result["event_update"].model_dump(exclude_defaults=True) == update.model_dump(
|
||||
exclude_defaults=True
|
||||
)
|
||||
assert result["event_router"] == router
|
||||
assert result["test"] == "PASS"
|
||||
|
||||
|
|
@ -532,7 +536,9 @@ class TestDispatcher:
|
|||
)
|
||||
result = await dp.feed_update(bot, update, test="PASS")
|
||||
assert isinstance(result, dict)
|
||||
assert result["event_update"] == update
|
||||
assert result["event_update"].model_dump(exclude_defaults=True) == update.model_dump(
|
||||
exclude_defaults=True
|
||||
)
|
||||
assert result["event_router"] == router1
|
||||
assert result["test"] == "PASS"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue