Skip to content

Commit 3f351d5

Browse files
committed
Improve test coverage
1 parent 786235f commit 3f351d5

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/test_file_id.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
import pytest
20+
1921
from pyrogram.file_id import FileId, FileUniqueId, FileType, FileUniqueType
2022

2123

@@ -155,3 +157,38 @@ def test_chat_photo():
155157
check_unique(channel_photo_small_unique, FileUniqueType.PHOTO)
156158
check(channel_photo_big, FileType.CHAT_PHOTO)
157159
check_unique(channel_photo_big_unique, FileUniqueType.PHOTO)
160+
161+
162+
def test_old_file_id():
163+
old = "BQADBAADQNKSZqjl5DcROGn_eu5JtgAEAgAEAg"
164+
check(old, FileType.DOCUMENT)
165+
166+
167+
def test_unknown_file_type():
168+
unknown = "RQACAgIAAx0CAAGgr9AAAgmPX7b4UxbjNoFEO_L0I4s6wrXNJA8AAgQAA4GkuUm9FFvIaOhXWR4E"
169+
170+
with pytest.raises(ValueError, match=r"Unknown file_type \d+ of file_id \w+"):
171+
check(unknown, FileType.DOCUMENT)
172+
173+
174+
def test_unknown_thumbnail_source():
175+
unknown = "AAMCAgADHQIAAaCv0AACCY9ftvhTFuM2gUQ78vQjizrCtc0kDwACBAADgaS5Sb0UW8ho6FdZIH3qihAAA6QBAAIeBA"
176+
177+
with pytest.raises(ValueError, match=r"Unknown thumbnail_source \d+ of file_id \w+"):
178+
check(unknown, FileType.THUMBNAIL)
179+
180+
181+
def test_stringify_file_id():
182+
file_id = "BQACAgIAAx0CAAGgr9AAAgmPX7b4UxbjNoFEO_L0I4s6wrXNJA8AAgQAA4GkuUm9FFvIaOhXWR4E"
183+
string = "{'major': 4, 'minor': 30, 'file_type': <FileType.DOCUMENT: 5>, 'dc_id': 2, " \
184+
"'file_reference': b'\\x02\\x00\\xa0\\xaf\\xd0\\x00\\x00\\t\\x8f_\\xb6\\xf8S\\x16\\xe36\\x81D;\\xf2\\xf4#\\x8b:\\xc2\\xb5\\xcd$\\x0f', " \
185+
"'media_id': 5312458109417947140, 'access_hash': 6437869729085068477}"
186+
187+
assert str(FileId.decode(file_id)) == string
188+
189+
190+
def test_stringify_file_unique_id():
191+
file_unique_id = "AgADBAADgaS5SQ"
192+
string = "{'file_unique_type': <FileUniqueType.DOCUMENT: 2>, 'media_id': 5312458109417947140}"
193+
194+
assert str(FileUniqueId.decode(file_unique_id)) == string

0 commit comments

Comments
 (0)