Skip to content

Commit fb28e4d

Browse files
committed
Add file_id.py tests
1 parent 301a13e commit fb28e4d

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

tests/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

tests/test_file_id.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from pyrogram.file_id import FileId, FileUniqueId, FileType, FileUniqueType
20+
21+
22+
def check(file_id: str, expected_file_type: FileType):
23+
decoded = FileId.decode(file_id)
24+
25+
assert decoded.file_type == expected_file_type
26+
assert decoded.encode() == file_id
27+
28+
29+
def check_unique(file_unique_id: str, expected_file_unique_type: FileUniqueType):
30+
decoded = FileUniqueId.decode(file_unique_id)
31+
32+
assert decoded.file_unique_type == expected_file_unique_type
33+
assert decoded.encode() == file_unique_id
34+
35+
36+
def test_audio():
37+
audio = "CQACAgIAAx0CAAGgr9AAAgmQX7b4XPBstC1fFUuJBooHTHFd7HMAAgUAA4GkuUnVOGG5P196yR4E"
38+
audio_unique = "AgADBQADgaS5SQ"
39+
audio_thumb = "AAMCAgADHQIAAaCv0AACCZBftvhc8Gy0LV8VS4kGigdMcV3scwACBQADgaS5SdU4Ybk_X3rJIH3qihAAAwEAB20AA_OeAQABHgQ"
40+
audio_thumb_unique = "AQADIH3qihAAA_OeAQAB"
41+
42+
check(audio, FileType.AUDIO)
43+
check_unique(audio_unique, FileUniqueType.DOCUMENT)
44+
check(audio_thumb, FileType.THUMBNAIL)
45+
check_unique(audio_thumb_unique, FileUniqueType.PHOTO)
46+
47+
48+
def test_video():
49+
video = "BAACAgIAAx0CAAGgr9AAAgmRX7b4Xv9f-4BK5VR_5ppIOF6UIp0AAgYAA4GkuUmhnZz2xC37wR4E"
50+
video_unique = "AgADBgADgaS5SQ"
51+
video_thumb = "AAMCAgADHQIAAaCv0AACCZFftvhe_1_7gErlVH_mmkg4XpQinQACBgADgaS5SaGdnPbELfvBIH3qihAAAwEAB20AA_WeAQABHgQ"
52+
video_thumb_unique = "AQADIH3qihAAA_WeAQAB"
53+
54+
check(video, FileType.VIDEO)
55+
check_unique(video_unique, FileUniqueType.DOCUMENT)
56+
check(video_thumb, FileType.THUMBNAIL)
57+
check_unique(video_thumb_unique, FileUniqueType.PHOTO)
58+
59+
60+
def test_document():
61+
document = "BQACAgIAAx0CAAGgr9AAAgmPX7b4UxbjNoFEO_L0I4s6wrXNJA8AAgQAA4GkuUm9FFvIaOhXWR4E"
62+
document_unique = "AgADBAADgaS5SQ"
63+
document_thumb = "AAMCAgADHQIAAaCv0AACCY9ftvhTFuM2gUQ78vQjizrCtc0kDwACBAADgaS5Sb0UW8ho6FdZIH3qihAAAwEAB3MAA_GeAQABHgQ"
64+
document_thumb_unique = "AQADIH3qihAAA_GeAQAB"
65+
66+
check(document, FileType.DOCUMENT)
67+
check_unique(document_unique, FileUniqueType.DOCUMENT)
68+
check(document_thumb, FileType.THUMBNAIL)
69+
check_unique(document_thumb_unique, FileUniqueType.PHOTO)
70+
71+
72+
def test_animation():
73+
animation = "CgACAgIAAx0CAAGgr9AAAgmSX7b4Y2g8_QW2XFd49iUmRnHOyG8AAgcAA4GkuUnry9gWDzF_5R4E"
74+
animation_unique = "AgADBwADgaS5SQ"
75+
76+
check(animation, FileType.ANIMATION)
77+
check_unique(animation_unique, FileUniqueType.DOCUMENT)
78+
79+
80+
def test_voice():
81+
voice = "AwACAgIAAx0CAAGgr9AAAgmUX7b4c1KQyHVwzffxC2EnSYWsMAQAAgkAA4GkuUlsZUZ4_I97AR4E"
82+
voice_unique = "AgADCQADgaS5SQ"
83+
84+
check(voice, FileType.VOICE)
85+
check_unique(voice_unique, FileUniqueType.DOCUMENT)
86+
87+
88+
def test_video_note():
89+
video_note = "DQACAgIAAx0CAAGgr9AAAgmVX7b53qrRzCEO13BaLQJaYuFbdlwAAgoAA4GkuUmlqIzDy_PCsx4E"
90+
video_note_unique = "AgADCgADgaS5SQ"
91+
video_note_thumb = "AAMCAgADHQIAAaCv0AACCZVftvneqtHMIQ7XcFotAlpi4Vt2XAACCgADgaS5SaWojMPL88KzIH3qihAAAwEAB20AA_meAQABHgQ"
92+
video_note_thumb_unique = "AQADIH3qihAAA_meAQAB"
93+
94+
check(video_note, FileType.VIDEO_NOTE)
95+
check_unique(video_note_unique, FileUniqueType.DOCUMENT)
96+
check(video_note_thumb, FileType.THUMBNAIL)
97+
check_unique(video_note_thumb_unique, FileUniqueType.PHOTO)
98+
99+
100+
def test_sticker():
101+
sticker = "CAACAgEAAx0CAAGgr9AAAgmWX7b6uFeLlhXEgYrM8pIbGaQKRQ0AAswBAALjeAQAAbeooNv_tb6-HgQ"
102+
sticker_unique = "AgADzAEAAuN4BAAB"
103+
sticker_thumb = "AAMCAQADHQIAAaCv0AACCZZftvq4V4uWFcSBiszykhsZpApFDQACzAEAAuN4BAABt6ig2_-1vr5gWNkpAAQBAAdtAAM0BQACHgQ"
104+
sticker_thumb_unique = "AQADYFjZKQAENAUAAg"
105+
106+
check(sticker, FileType.STICKER)
107+
check_unique(sticker_unique, FileUniqueType.DOCUMENT)
108+
check(sticker_thumb, FileType.THUMBNAIL)
109+
check_unique(sticker_thumb_unique, FileUniqueType.PHOTO)
110+
111+
112+
def test_photo():
113+
photo_small = "AgACAgIAAx0CAAGgr9AAAgmZX7b7IPLRl8NcV3EJkzHwI1gwT-oAAq2nMRuBpLlJPJY-URZfhTkgfeqKEAADAQADAgADbQADAZ8BAAEeBA"
114+
photo_small_unique = "AQADIH3qihAAAwGfAQAB"
115+
photo_medium = "AgACAgIAAx0CAAGgr9AAAgmZX7b7IPLRl8NcV3EJkzHwI1gwT-oAAq2nMRuBpLlJPJY-URZfhTkgfeqKEAADAQADAgADeAADAp8BAAEeBA"
116+
photo_medium_unique = "AQADIH3qihAAAwKfAQAB"
117+
photo_big = "AgACAgIAAx0CAAGgr9AAAgmZX7b7IPLRl8NcV3EJkzHwI1gwT-oAAq2nMRuBpLlJPJY-URZfhTkgfeqKEAADAQADAgADeQAD_54BAAEeBA"
118+
photo_big_unique = "AQADIH3qihAAA_-eAQAB"
119+
120+
check(photo_small, FileType.PHOTO)
121+
check_unique(photo_small_unique, FileUniqueType.PHOTO)
122+
check(photo_medium, FileType.PHOTO)
123+
check_unique(photo_medium_unique, FileUniqueType.PHOTO)
124+
check(photo_big, FileType.PHOTO)
125+
check_unique(photo_big_unique, FileUniqueType.PHOTO)
126+
127+
128+
def test_chat_photo():
129+
user_photo_small = "AQADAgADrKcxGylBBQAJIH3qihAAAwIAAylBBQAF7bDHYwABnc983KcAAh4E"
130+
user_photo_small_unique = "AQADIH3qihAAA9ynAAI"
131+
user_photo_big = "AQADAgADrKcxGylBBQAJIH3qihAAAwMAAylBBQAF7bDHYwABnc983qcAAh4E"
132+
user_photo_big_unique = "AQADIH3qihAAA96nAAI"
133+
134+
chat_photo_small = "AQADAgATIH3qihAAAwIAA3t3-P______AAjhngEAAR4E"
135+
chat_photo_small_unique = "AQADIH3qihAAA-GeAQAB"
136+
chat_photo_big = "AQADAgATIH3qihAAAwMAA3t3-P______AAjjngEAAR4E"
137+
chat_photo_big_unique = "AQADIH3qihAAA-OeAQAB"
138+
139+
channel_photo_small = "AQADAgATIH3qihAAAwIAA-fFwCoX____MvARg8nvpc3RpwACHgQ"
140+
channel_photo_small_unique = "AQADIH3qihAAA9GnAAI"
141+
channel_photo_big = "AQADAgATIH3qihAAAwMAA-fFwCoX____MvARg8nvpc3TpwACHgQ"
142+
channel_photo_big_unique = "AQADIH3qihAAA9OnAAI"
143+
144+
check(user_photo_small, FileType.CHAT_PHOTO)
145+
check_unique(user_photo_small_unique, FileUniqueType.PHOTO)
146+
check(user_photo_big, FileType.CHAT_PHOTO)
147+
check_unique(user_photo_big_unique, FileUniqueType.PHOTO)
148+
149+
check(chat_photo_small, FileType.CHAT_PHOTO)
150+
check_unique(chat_photo_small_unique, FileUniqueType.PHOTO)
151+
check(chat_photo_big, FileType.CHAT_PHOTO)
152+
check_unique(chat_photo_big_unique, FileUniqueType.PHOTO)
153+
154+
check(channel_photo_small, FileType.CHAT_PHOTO)
155+
check_unique(channel_photo_small_unique, FileUniqueType.PHOTO)
156+
check(channel_photo_big, FileType.CHAT_PHOTO)
157+
check_unique(channel_photo_big_unique, FileUniqueType.PHOTO)

0 commit comments

Comments
 (0)