From 154a29f600f932a69c1fc847a5f3c59d0e8652f2 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 12 Apr 2023 23:57:00 +0300 Subject: [PATCH] Added tests, fixed arguments priority --- aiogram/fsm/strategy.py | 2 +- tests/test_fsm/test_strategy.py | 38 ++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/aiogram/fsm/strategy.py b/aiogram/fsm/strategy.py index 8620261f..28dddeb9 100644 --- a/aiogram/fsm/strategy.py +++ b/aiogram/fsm/strategy.py @@ -20,5 +20,5 @@ def apply_strategy( if strategy == FSMStrategy.GLOBAL_USER: return user_id, user_id, None if strategy == FSMStrategy.USER_IN_THREAD: - return user_id, chat_id, thread_id + return chat_id, user_id, thread_id return chat_id, user_id, None diff --git a/tests/test_fsm/test_strategy.py b/tests/test_fsm/test_strategy.py index b00a7b98..3dab2b3d 100644 --- a/tests/test_fsm/test_strategy.py +++ b/tests/test_fsm/test_strategy.py @@ -2,19 +2,41 @@ import pytest from aiogram.fsm.strategy import FSMStrategy, apply_strategy +CHAT_ID = -42 +USER_ID = 42 +THREAD_ID = 1 + +PRIVATE = (USER_ID, USER_ID, None) +CHAT = (CHAT_ID, USER_ID, None) +THREAD = (CHAT_ID, USER_ID, THREAD_ID) + class TestStrategy: @pytest.mark.parametrize( "strategy,case,expected", [ - [FSMStrategy.USER_IN_CHAT, (-42, 42), (-42, 42)], - [FSMStrategy.CHAT, (-42, 42), (-42, -42)], - [FSMStrategy.GLOBAL_USER, (-42, 42), (42, 42)], - [FSMStrategy.USER_IN_CHAT, (42, 42), (42, 42)], - [FSMStrategy.CHAT, (42, 42), (42, 42)], - [FSMStrategy.GLOBAL_USER, (42, 42), (42, 42)], + [FSMStrategy.USER_IN_CHAT, CHAT, CHAT], + [FSMStrategy.USER_IN_CHAT, PRIVATE, PRIVATE], + [FSMStrategy.USER_IN_CHAT, THREAD, CHAT], + [FSMStrategy.CHAT, CHAT, (CHAT_ID, CHAT_ID, None)], + [FSMStrategy.CHAT, PRIVATE, (USER_ID, USER_ID, None)], + [FSMStrategy.CHAT, THREAD, (CHAT_ID, CHAT_ID, None)], + [FSMStrategy.GLOBAL_USER, CHAT, PRIVATE], + [FSMStrategy.GLOBAL_USER, PRIVATE, PRIVATE], + [FSMStrategy.GLOBAL_USER, THREAD, PRIVATE], + [FSMStrategy.USER_IN_THREAD, CHAT, CHAT], + [FSMStrategy.USER_IN_THREAD, PRIVATE, PRIVATE], + [FSMStrategy.USER_IN_THREAD, THREAD, THREAD], ], ) def test_strategy(self, strategy, case, expected): - chat_id, user_id = case - assert apply_strategy(chat_id=chat_id, user_id=user_id, strategy=strategy) == expected + chat_id, user_id, thread_id = case + assert ( + apply_strategy( + chat_id=chat_id, + user_id=user_id, + thread_id=thread_id, + strategy=strategy, + ) + == expected + )