forked from python-telegram-bot/python-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_inputmedia.py
More file actions
140 lines (117 loc) · 5.59 KB
/
test_inputmedia.py
File metadata and controls
140 lines (117 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2018
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
import pytest
from flaky import flaky
from telegram import InputMediaVideo, InputMediaPhoto, Message
from .test_video import video, video_file
from .test_photo import _photo, photo_file, photo, thumb
@pytest.fixture(scope='class')
def input_media_video():
return InputMediaVideo(media=TestInputMediaVideo.media,
caption=TestInputMediaVideo.caption,
width=TestInputMediaVideo.width,
height=TestInputMediaVideo.height,
duration=TestInputMediaVideo.duration)
@pytest.fixture(scope='class')
def input_media_photo():
return InputMediaPhoto(media=TestInputMediaPhoto.media,
caption=TestInputMediaPhoto.caption)
class TestInputMediaVideo(object):
type = "video"
media = "NOTAREALFILEID"
caption = "My Caption"
width = 3
height = 4
duration = 5
def test_expected_values(self, input_media_video):
assert input_media_video.type == self.type
assert input_media_video.media == self.media
assert input_media_video.caption == self.caption
assert input_media_video.width == self.width
assert input_media_video.height == self.height
assert input_media_video.duration == self.duration
def test_to_dict(self, input_media_video):
input_media_video_dict = input_media_video.to_dict()
assert input_media_video_dict['type'] == input_media_video.type
assert input_media_video_dict['media'] == input_media_video.media
assert input_media_video_dict['caption'] == input_media_video.caption
assert input_media_video_dict['width'] == input_media_video.width
assert input_media_video_dict['height'] == input_media_video.height
assert input_media_video_dict['duration'] == input_media_video.duration
def test_with_video(self, video):
# fixture found in test_video
input_media_video = InputMediaVideo(video, caption="test 3")
assert input_media_video.type == self.type
assert input_media_video.media == video.file_id
assert input_media_video.width == video.width
assert input_media_video.height == video.height
assert input_media_video.duration == video.duration
assert input_media_video.caption == "test 3"
def test_error_with_file(self, video_file):
# fixture found in test_video
with pytest.raises(ValueError, match="file_id, url or Video"):
InputMediaVideo(video_file)
class TestInputMediaPhoto(object):
type = "photo"
media = "NOTAREALFILEID"
caption = "My Caption"
def test_expected_values(self, input_media_photo):
assert input_media_photo.type == self.type
assert input_media_photo.media == self.media
assert input_media_photo.caption == self.caption
def test_to_dict(self, input_media_photo):
input_media_photo_dict = input_media_photo.to_dict()
assert input_media_photo_dict['type'] == input_media_photo.type
assert input_media_photo_dict['media'] == input_media_photo.media
assert input_media_photo_dict['caption'] == input_media_photo.caption
def test_with_photo(self, photo):
# fixture found in test_photo
imp = InputMediaPhoto(photo, caption="test 2")
assert imp.type == self.type
assert imp.media == photo.file_id
assert imp.caption == "test 2"
def test_error_with_file(self, photo_file):
# fixture found in test_photo
with pytest.raises(ValueError, match="file_id, url or PhotoSize"):
InputMediaPhoto(photo_file)
@pytest.fixture(scope='function')
def media_group(photo, thumb):
return [InputMediaPhoto(photo), InputMediaPhoto(thumb)]
class TestSendMediaGroup(object):
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_send_media_group_photo(self, bot, chat_id, media_group):
messages = bot.send_media_group(chat_id, media_group)
assert isinstance(messages, list)
assert len(messages) == 2
assert all([isinstance(mes, Message) for mes in messages])
assert all([mes.media_group_id == messages[0].media_group_id for mes in messages])
@flaky(3, 1)
@pytest.mark.timeout(10)
def test_send_media_group_all_args(self, bot, chat_id, media_group):
m1 = bot.send_message(chat_id, text="test")
messages = bot.send_media_group(chat_id, media_group, disable_notification=True,
reply_to_message_id=m1.message_id)
assert isinstance(messages, list)
assert len(messages) == 2
assert all([isinstance(mes, Message) for mes in messages])
assert all([mes.media_group_id == messages[0].media_group_id for mes in messages])
@pytest.mark.skip(reason="Needs a rework to send new files")
def test_send_media_group_new_files(self):
pass