mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Change methods not using its bound instance to staticmethods
This commit is contained in:
parent
deab57c6dc
commit
25701aac4f
11 changed files with 40 additions and 20 deletions
|
|
@ -16,7 +16,8 @@ class LoggingMiddleware(BaseMiddleware):
|
|||
|
||||
super(LoggingMiddleware, self).__init__()
|
||||
|
||||
def check_timeout(self, obj):
|
||||
@staticmethod
|
||||
def check_timeout(obj):
|
||||
start = obj.conf.get('_start', None)
|
||||
if start:
|
||||
del obj.conf['_start']
|
||||
|
|
@ -248,7 +249,8 @@ class LoggingFilter(logging.Filter):
|
|||
yield 'update_type', 'pre_checkout_query'
|
||||
yield from self.process_pre_checkout_query(update.pre_checkout_query)
|
||||
|
||||
def make_prefix(self, prefix, iterable):
|
||||
@staticmethod
|
||||
def make_prefix(prefix, iterable):
|
||||
"""
|
||||
Add prefix to the label
|
||||
|
||||
|
|
|
|||
|
|
@ -385,7 +385,8 @@ class HashTag(Filter):
|
|||
or self.cashtags and set(cashtags) & set(self.cashtags):
|
||||
return {'hashtags': hashtags, 'cashtags': cashtags}
|
||||
|
||||
def _get_tags(self, text, entities):
|
||||
@staticmethod
|
||||
def _get_tags(text, entities):
|
||||
hashtags = []
|
||||
cashtags = []
|
||||
|
||||
|
|
@ -529,7 +530,8 @@ class StateFilter(BoundFilter):
|
|||
states.append(item)
|
||||
self.states = states
|
||||
|
||||
def get_target(self, obj):
|
||||
@staticmethod
|
||||
def get_target(obj):
|
||||
return getattr(getattr(obj, 'chat', None), 'id', None), getattr(getattr(obj, 'from_user', None), 'id', None)
|
||||
|
||||
async def check(self, obj):
|
||||
|
|
|
|||
|
|
@ -198,7 +198,8 @@ class BaseStorage:
|
|||
"""
|
||||
await self.reset_state(chat=chat, user=user, with_data=True)
|
||||
|
||||
def has_bucket(self):
|
||||
@staticmethod
|
||||
def has_bucket():
|
||||
return False
|
||||
|
||||
async def get_bucket(self, *,
|
||||
|
|
|
|||
|
|
@ -218,7 +218,8 @@ class WebhookRequestHandler(web.View):
|
|||
if response is not None:
|
||||
asyncio.ensure_future(response.execute_response(dispatcher.bot), loop=loop)
|
||||
|
||||
def get_response(self, results):
|
||||
@staticmethod
|
||||
def get_response(results):
|
||||
"""
|
||||
Get response object from results.
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ def invalid_token_fixture(request):
|
|||
|
||||
|
||||
class TestCheckToken:
|
||||
def test_valid(self):
|
||||
@staticmethod
|
||||
def test_valid():
|
||||
if check_token(VALID_TOKEN) is not True:
|
||||
raise AssertionError
|
||||
|
||||
def test_invalid_token(self, invalid_token):
|
||||
@staticmethod
|
||||
def test_invalid_token(invalid_token):
|
||||
with pytest.raises(ValidationError):
|
||||
check_token(invalid_token)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ from aiogram.dispatcher.filters.state import StatesGroup
|
|||
|
||||
|
||||
class TestStatesGroup:
|
||||
def test_all_childs(self):
|
||||
@staticmethod
|
||||
def test_all_childs():
|
||||
class InnerState1(StatesGroup):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ async def callback3(foo: int, **kwargs):
|
|||
|
||||
|
||||
class TestHandlerObj:
|
||||
def test_init_decorated(self):
|
||||
@staticmethod
|
||||
def test_init_decorated():
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -30,22 +30,26 @@ class Test_check_token:
|
|||
This case gonna be deleted
|
||||
"""
|
||||
|
||||
def test_ok(self, data):
|
||||
@staticmethod
|
||||
def test_ok(data):
|
||||
if check_token(data, TOKEN) is not True:
|
||||
raise AssertionError
|
||||
|
||||
def test_fail(self, data):
|
||||
@staticmethod
|
||||
def test_fail(data):
|
||||
data.pop("username")
|
||||
if check_token(data, TOKEN) is not False:
|
||||
raise AssertionError
|
||||
|
||||
|
||||
class Test_check_integrity:
|
||||
def test_ok(self, data):
|
||||
@staticmethod
|
||||
def test_ok(data):
|
||||
if check_integrity(TOKEN, data) is not True:
|
||||
raise AssertionError
|
||||
|
||||
def test_fail(self, data):
|
||||
@staticmethod
|
||||
def test_fail(data):
|
||||
data.pop("username")
|
||||
if check_integrity(TOKEN, data) is not False:
|
||||
raise AssertionError
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ from aiogram.utils.helper import Item, ListItem, OrderedHelper
|
|||
|
||||
|
||||
class TestOrderedHelper:
|
||||
def test_items_are_ordered(self):
|
||||
@staticmethod
|
||||
def test_items_are_ordered():
|
||||
class Helper(OrderedHelper):
|
||||
A = Item()
|
||||
D = Item()
|
||||
|
|
@ -12,7 +13,8 @@ class TestOrderedHelper:
|
|||
if Helper.all() != ["A", "D", "C", "B"]:
|
||||
raise AssertionError
|
||||
|
||||
def test_list_items_are_ordered(self):
|
||||
@staticmethod
|
||||
def test_list_items_are_ordered():
|
||||
class Helper(OrderedHelper):
|
||||
A = ListItem()
|
||||
D = ListItem()
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ from aiogram.utils import markdown
|
|||
|
||||
|
||||
class TestMarkdownEscape:
|
||||
def test_equality_sign_is_escaped(self):
|
||||
@staticmethod
|
||||
def test_equality_sign_is_escaped():
|
||||
if markdown.escape_md(r"e = mc2") != r"e \= mc2":
|
||||
raise AssertionError
|
||||
|
||||
def test_pre_escaped(self):
|
||||
@staticmethod
|
||||
def test_pre_escaped():
|
||||
if markdown.escape_md(r"hello\.") != r"hello\\\.":
|
||||
raise AssertionError
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ from aiogram.utils import text_decorations
|
|||
|
||||
|
||||
class TestTextDecorations:
|
||||
def test_unparse_entities_normal_text(self):
|
||||
@staticmethod
|
||||
def test_unparse_entities_normal_text():
|
||||
if (
|
||||
text_decorations.markdown_decoration.unparse(
|
||||
"hi i'm bold and italic and still bold",
|
||||
|
|
@ -18,7 +19,8 @@ class TestTextDecorations:
|
|||
):
|
||||
raise AssertionError
|
||||
|
||||
def test_unparse_entities_emoji_text(self):
|
||||
@staticmethod
|
||||
def test_unparse_entities_emoji_text():
|
||||
"""
|
||||
emoji is encoded as two chars in json
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue