-
-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added get_url() method for Message object and shifted_id property for…
… Chat object (#585) * Added get_url() method for Message object and shifted_id property for Chat object * Added missing closing bracket to shifted_id description * Added basic groups to skipped pattern, simplified code * Return None instead of raising TypeError, removed redundant f-string * Change get_url typing to Optional[str] * Better shifted_id method * get_url tests added * Added whitespace (E226) * Code format with black * Parametrized test
- Loading branch information
1 parent
53da500
commit 32bc051
Showing
3 changed files
with
86 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import datetime | ||
from typing import Optional | ||
|
||
import pytest | ||
from aiogram.types import Chat, Message | ||
|
||
from tests.mocked_bot import MockedBot | ||
|
||
|
||
class TestGetMessageUrl: | ||
@pytest.mark.parametrize( | ||
"chat_type,chat_id,chat_username,force_private,expected_result", | ||
[ | ||
["private", 123456, "username", False, None], | ||
["group", -123456, "username", False, None], | ||
["supergroup", -1001234567890, None, False, "https://t.me/c/1234567890/10"], | ||
["supergroup", -1001234567890, None, True, "https://t.me/c/1234567890/10"], | ||
["supergroup", -1001234567890, "username", False, "https://t.me/username/10"], | ||
["supergroup", -1001234567890, "username", True, "https://t.me/c/1234567890/10"], | ||
["channel", -1001234567890, None, False, "https://t.me/c/1234567890/10"], | ||
["channel", -1001234567890, None, True, "https://t.me/c/1234567890/10"], | ||
["channel", -1001234567890, "username", False, "https://t.me/username/10"], | ||
["channel", -1001234567890, "username", True, "https://t.me/c/1234567890/10"], | ||
# 2 extra cases: 9-digit ID and 11-digit ID (without "-100") | ||
["supergroup", -100123456789, None, True, "https://t.me/c/123456789/10"], | ||
["supergroup", -10012345678901, None, True, "https://t.me/c/12345678901/10"], | ||
], | ||
) | ||
def test_method( | ||
self, | ||
bot: MockedBot, | ||
chat_type: str, | ||
chat_id: int, | ||
chat_username: Optional[str], | ||
force_private: bool, | ||
expected_result: Optional[str], | ||
): | ||
|
||
fake_chat = Chat(id=chat_id, username=chat_username, type=chat_type) | ||
fake_message_id = 10 | ||
fake_message = Message( | ||
message_id=fake_message_id, | ||
date=datetime.datetime.now(), | ||
text="test", | ||
chat=fake_chat, | ||
) | ||
|
||
if expected_result is None: | ||
assert fake_message.get_url(force_private=force_private) is None | ||
else: | ||
assert fake_message.get_url(force_private=force_private) == expected_result |