@@ -32,101 +32,41 @@ class FileTest(BaseTest, unittest.TestCase):
3232 """This object represents Tests for Telegram File."""
3333
3434 def setUp (self ):
35- self .audio_file_id = 'BQADAQADDwADHyP1B6PSPq2HjX8kAg'
36- self .document_file_id = 'BQADAQADpAADHyP1B04ipZxJTe2BAg'
37- self .sticker_file_id = 'BQADAQADHAADyIsGAAFZfq1bphjqlgI'
38- self .video_file_id = 'BAADAQADXwADHyP1BwJFTcmY2RYCAg'
39- self .voice_file_id = 'AwADAQADTgADHyP1B_mbw34svXPHAg'
40-
4135 self .json_dict = {
42- 'file_id' : self . audio_file_id ,
36+ 'file_id' : "NOTVALIDDONTMATTER" ,
4337 'file_path' :
4438 'https://api.telegram.org/file/bot133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0/document/file_3' ,
4539 'file_size' : 28232
4640 }
4741
48- def test_get_and_download_file_audio (self ):
49- newFile = self ._bot .getFile (self .audio_file_id )
50-
51- self .assertEqual (newFile .file_size , 28232 )
52- self .assertEqual (newFile .file_id , self .audio_file_id )
53- self .assertTrue (newFile .file_path .startswith ('https://' ))
54-
55- newFile .download ('telegram.mp3' )
56-
57- self .assertTrue (os .path .isfile ('telegram.mp3' ))
58-
59- def test_get_and_download_file_document (self ):
60- newFile = self ._bot .getFile (self .document_file_id )
61-
62- self .assertEqual (newFile .file_size , 12948 )
63- self .assertEqual (newFile .file_id , self .document_file_id )
64- self .assertTrue (newFile .file_path .startswith ('https://' ))
65-
66- newFile .download ('telegram.png' )
67-
68- self .assertTrue (os .path .isfile ('telegram.png' ))
69-
70- def test_get_and_download_file_sticker (self ):
71- newFile = self ._bot .getFile (self .sticker_file_id )
72-
73- self .assertEqual (newFile .file_size , 39518 )
74- self .assertEqual (newFile .file_id , self .sticker_file_id )
75- self .assertTrue (newFile .file_path .startswith ('https://' ))
76-
77- newFile .download ('telegram.webp' )
78-
79- self .assertTrue (os .path .isfile ('telegram.webp' ))
80-
81- def test_get_and_download_file_video (self ):
82- newFile = self ._bot .getFile (self .video_file_id )
83-
84- self .assertEqual (newFile .file_size , 326534 )
85- self .assertEqual (newFile .file_id , self .video_file_id )
86- self .assertTrue (newFile .file_path .startswith ('https://' ))
87-
88- newFile .download ('telegram.mp4' )
89-
90- self .assertTrue (os .path .isfile ('telegram.mp4' ))
91-
92- def test_get_and_download_file_voice (self ):
93- newFile = self ._bot .getFile (self .voice_file_id )
94-
95- self .assertEqual (newFile .file_size , 9199 )
96- self .assertEqual (newFile .file_id , self .voice_file_id )
97- self .assertTrue (newFile .file_path .startswith ('https://' ))
98-
99- newFile .download ('telegram.ogg' )
100-
101- self .assertTrue (os .path .isfile ('telegram.ogg' ))
102-
10342 def test_file_de_json (self ):
104- newFile = telegram .File .de_json (self .json_dict , self ._bot )
43+ new_file = telegram .File .de_json (self .json_dict , self ._bot )
10544
106- self .assertEqual (newFile .file_id , self .json_dict ['file_id' ])
107- self .assertEqual (newFile .file_path , self .json_dict ['file_path' ])
108- self .assertEqual (newFile .file_size , self .json_dict ['file_size' ])
45+ self .assertEqual (new_file .file_id , self .json_dict ['file_id' ])
46+ self .assertEqual (new_file .file_path , self .json_dict ['file_path' ])
47+ self .assertEqual (new_file .file_size , self .json_dict ['file_size' ])
10948
11049 def test_file_to_json (self ):
111- newFile = telegram .File .de_json (self .json_dict , self ._bot )
50+ new_file = telegram .File .de_json (self .json_dict , self ._bot )
11251
113- self .assertTrue (self .is_json (newFile .to_json ()))
52+ self .assertTrue (self .is_json (new_file .to_json ()))
11453
11554 def test_file_to_dict (self ):
116- newFile = telegram .File .de_json (self .json_dict , self ._bot )
55+ new_file = telegram .File .de_json (self .json_dict , self ._bot ). to_dict ( )
11756
118- self .assertTrue (self .is_dict (newFile . to_dict () ))
119- self .assertEqual (newFile ['file_id' ], self .json_dict ['file_id' ])
120- self .assertEqual (newFile ['file_path' ], self .json_dict ['file_path' ])
121- self .assertEqual (newFile ['file_size' ], self .json_dict ['file_size' ])
57+ self .assertTrue (self .is_dict (new_file ))
58+ self .assertEqual (new_file ['file_id' ], self .json_dict ['file_id' ])
59+ self .assertEqual (new_file ['file_path' ], self .json_dict ['file_path' ])
60+ self .assertEqual (new_file ['file_size' ], self .json_dict ['file_size' ])
12261
12362 def test_error_get_empty_file_id (self ):
12463 json_dict = self .json_dict
12564 json_dict ['file_id' ] = ''
12665 del (json_dict ['file_path' ])
12766 del (json_dict ['file_size' ])
12867
129- self .assertRaises (telegram .TelegramError , lambda : self ._bot .getFile (** json_dict ))
68+ with self .assertRaises (telegram .TelegramError ):
69+ self ._bot .getFile (** json_dict )
13070
13171 def test_error_file_without_required_args (self ):
13272 json_dict = self .json_dict
@@ -135,14 +75,16 @@ def test_error_file_without_required_args(self):
13575 del (json_dict ['file_path' ])
13676 del (json_dict ['file_size' ])
13777
138- self .assertRaises (TypeError , lambda : self ._bot .getFile (** json_dict ))
78+ with self .assertRaises (TypeError ):
79+ self ._bot .getFile (** json_dict )
80+
13981
14082 def test_equality (self ):
141- a = telegram .File (self . audio_file_id , self ._bot )
142- b = telegram .File (self . audio_file_id , self ._bot )
143- c = telegram .File (self . audio_file_id , None )
144- d = telegram .File (self . document_file_id , self ._bot )
145- e = telegram .Voice (self . audio_file_id , 0 )
83+ a = telegram .File ("DOESNTMATTER" , self ._bot )
84+ b = telegram .File ("DOESNTMATTER" , self ._bot )
85+ c = telegram .File ("DOESNTMATTER" , None )
86+ d = telegram .File ("DOESNTMATTER2" , self ._bot )
87+ e = telegram .Voice ("DOESNTMATTER" , 0 )
14688
14789 self .assertEqual (a , b )
14890 self .assertEqual (hash (a ), hash (b ))
0 commit comments