Skip to content

Commit fca64f5

Browse files
committed
Move photo tests from test_bot to test_photo
1 parent c92ebc4 commit fca64f5

File tree

2 files changed

+47
-73
lines changed

2 files changed

+47
-73
lines changed

tests/test_bot.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -121,78 +121,6 @@ def testForwardMessage(self):
121121
self.assertEqual(message.forward_from.username, 'leandrotoledo')
122122
self.assertTrue(isinstance(message.forward_date, datetime))
123123

124-
@flaky(3, 1)
125-
@timeout(10)
126-
def testSendPhoto(self):
127-
message = self._bot.sendPhoto(
128-
photo=open('tests/data/telegram.png', 'rb'),
129-
caption='testSendPhoto',
130-
chat_id=self._chat_id)
131-
132-
self.assertTrue(self.is_json(message.to_json()))
133-
self.assertEqual(message.photo[0].file_size, 1451)
134-
self.assertEqual(message.caption, 'testSendPhoto')
135-
136-
@flaky(3, 1)
137-
@timeout(10)
138-
def testSilentSendPhoto(self):
139-
message = self._bot.sendPhoto(
140-
photo=open('tests/data/telegram.png', 'rb'),
141-
caption='testSendPhoto',
142-
chat_id=self._chat_id,
143-
disable_notification=True)
144-
145-
self.assertTrue(self.is_json(message.to_json()))
146-
self.assertEqual(message.photo[0].file_size, 1451)
147-
self.assertEqual(message.caption, 'testSendPhoto')
148-
149-
@flaky(3, 1)
150-
@timeout(10)
151-
def testResendPhoto(self):
152-
message = self._bot.sendPhoto(
153-
photo='AgADAQAD1y0yGx8j9Qf8f_m3CKeS6Iy95y8ABI1ggfVJ4-UvwJcAAgI', chat_id=self._chat_id)
154-
155-
self.assertTrue(self.is_json(message.to_json()))
156-
self.assertEqual(message.photo[0].file_id,
157-
'AgADAQAD1y0yGx8j9Qf8f_m3CKeS6Iy95y8ABI1ggfVJ4-UvwJcAAgI')
158-
159-
@flaky(3, 1)
160-
@timeout(10)
161-
def testSendJPGURLPhoto(self):
162-
message = self._bot.sendPhoto(
163-
photo='http://dummyimage.com/600x400/000/fff.jpg&text=telegram', chat_id=self._chat_id)
164-
165-
self.assertTrue(self.is_json(message.to_json()))
166-
self.assertEqual(message.photo[0].file_size, 813)
167-
168-
@flaky(3, 1)
169-
@timeout(10)
170-
def testSendPNGURLPhoto(self):
171-
message = self._bot.sendPhoto(
172-
photo='http://dummyimage.com/600x400/000/fff.png&text=telegram', chat_id=self._chat_id)
173-
174-
self.assertTrue(self.is_json(message.to_json()))
175-
self.assertEqual(message.photo[0].file_size, 670)
176-
177-
@flaky(3, 1)
178-
@timeout(10)
179-
def testSendGIFURLPhoto(self):
180-
message = self._bot.sendPhoto(
181-
photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram', chat_id=self._chat_id)
182-
183-
self.assertTrue(self.is_json(message.to_json()))
184-
self.assertEqual(message.photo[0].file_size, 670)
185-
186-
@flaky(3, 1)
187-
@timeout(10)
188-
def testSendBufferedReaderPhoto(self):
189-
photo = open('tests/data/telegram.png', 'rb')
190-
br_photo = io.BufferedReader(io.BytesIO(photo.read()))
191-
message = self._bot.sendPhoto(photo=br_photo, chat_id=self._chat_id)
192-
193-
self.assertTrue(self.is_json(message.to_json()))
194-
self.assertEqual(message.photo[0].file_size, 1451)
195-
196124
@flaky(3, 1)
197125
@timeout(10)
198126
def testSendGame(self):

tests/test_photo.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_expected_values(self):
7474

7575
@flaky(3, 1)
7676
@timeout(10)
77-
def test_sendphotoo_all_args(self):
77+
def test_sendphoto_all_args(self):
7878
message = self._bot.sendPhoto(self._chat_id, self.photo_file, caption=self.caption, disable_notification=False)
7979
thumb, photo = message.photo
8080

@@ -115,6 +115,38 @@ def test_send_photo_url_jpg_file(self):
115115
self.assertEqual(photo.height, self.photo.height)
116116
self.assertEqual(photo.file_size, self.photo.file_size)
117117

118+
@flaky(3, 1)
119+
@timeout(10)
120+
def test_send_photo_url_png_file(self):
121+
message = self._bot.sendPhoto(
122+
photo='http://dummyimage.com/600x400/000/fff.png&text=telegram', chat_id=self._chat_id)
123+
124+
thumb, photo = message.photo
125+
126+
self.assertIsInstance(thumb, telegram.PhotoSize)
127+
self.assertIsInstance(thumb.file_id, str)
128+
self.assertNotEqual(thumb.file_id, '')
129+
130+
self.assertIsInstance(photo, telegram.PhotoSize)
131+
self.assertIsInstance(photo.file_id, str)
132+
self.assertNotEqual(photo.file_id, '')
133+
134+
@flaky(3, 1)
135+
@timeout(10)
136+
def test_send_photo_url_gif_file(self):
137+
message = self._bot.sendPhoto(
138+
photo='http://dummyimage.com/600x400/000/fff.gif&text=telegram', chat_id=self._chat_id)
139+
140+
thumb, photo = message.photo
141+
142+
self.assertIsInstance(thumb, telegram.PhotoSize)
143+
self.assertIsInstance(thumb.file_id, str)
144+
self.assertNotEqual(thumb.file_id, '')
145+
146+
self.assertIsInstance(photo, telegram.PhotoSize)
147+
self.assertIsInstance(photo.file_id, str)
148+
self.assertNotEqual(photo.file_id, '')
149+
118150
@flaky(3, 1)
119151
@timeout(10)
120152
def test_send_photo_bytesio_jpg_file(self):
@@ -141,6 +173,20 @@ def test_send_photo_bytesio_jpg_file(self):
141173
self.assertEqual(photo.height, 1080)
142174
self.assertEqual(photo.file_size, 30907)
143175

176+
@flaky(3, 1)
177+
@timeout(10)
178+
def test_silent_send_photo(self):
179+
message = self._bot.sendPhoto(photo=self.photo_file, chat_id=self._chat_id, disable_notification=True)
180+
thumb, photo = message.photo
181+
182+
self.assertIsInstance(thumb, telegram.PhotoSize)
183+
self.assertIsInstance(thumb.file_id, str)
184+
self.assertNotEqual(thumb.file_id, '')
185+
186+
self.assertIsInstance(photo, telegram.PhotoSize)
187+
self.assertIsInstance(photo.file_id, str)
188+
self.assertNotEqual(photo.file_id, '')
189+
144190
@flaky(3, 1)
145191
@timeout(10)
146192
def test_send_photo_resend(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy