Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changes
- Remove deprecated ``Botan`` import from ``utils`` (``Botan`` is still available through ``contrib``).
- Remove deprecated ``ReplyKeyboardHide``.
- Remove deprecated ``edit_message`` argument of `bot.set_game_score``.
- Add the possibility to add objects as arguments to send_* methods.

**2017-06-18**

Expand Down
165 changes: 120 additions & 45 deletions telegram/bot.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions telegram/files/sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class MaskPosition(TelegramObject):
size, from left to right.
y_shift (:obj:`float`): Shift by Y-axis measured in heights of the mask scaled to the face
size, from top to bottom.
zoom (:obj:`float`): Mask scaling coefficient. For example, 2.0 means double size.
scale (:obj:`float`): Mask scaling coefficient. For example, 2.0 means double size.

Notes:
:attr:`type` should be one of the following: `forehead`, `eyes`, `mouth` or `chin`. You can
Expand All @@ -163,7 +163,7 @@ class MaskPosition(TelegramObject):
y_shift (:obj:`float`): Shift by Y-axis measured in heights of the mask scaled to the face
size, from top to bottom. For example, 1.0 will place the mask just below the default
mask position.
zoom (:obj:`float`): Mask scaling coefficient. For example, 2.0 means double size.
scale (:obj:`float`): Mask scaling coefficient. For example, 2.0 means double size.
"""

FOREHEAD = 'forehead'
Expand All @@ -175,11 +175,11 @@ class MaskPosition(TelegramObject):
CHIN = 'chin'
""":obj:`str`: 'chin'"""

def __init__(self, point, x_shift, y_shift, zoom, **kwargs):
def __init__(self, point, x_shift, y_shift, scale, **kwargs):
self.point = point
self.x_shift = x_shift
self.y_shift = y_shift
self.zoom = zoom
self.scale = scale

@classmethod
def de_json(cls, data, bot):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def test_send_audio_resend(self):

self.assertEqual(audio, self.audio)

@flaky(3, 1)
@timeout(10)
def test_send_audio_with_audio(self):
message = self._bot.send_audio(audio=self.audio, chat_id=self._chat_id)
audio = message.audio

self.assertEqual(audio, self.audio)

def test_audio_de_json(self):
audio = telegram.Audio.de_json(self.json_dict, self._bot)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def test_contact_de_json(self):
self.assertEqual(contact.last_name, self.last_name)
self.assertEqual(contact.user_id, self.user_id)

def test_send_contact_with_contact(self):
con = telegram.Contact.de_json(self.json_dict, self._bot)
message = self._bot.send_contact(contact=con, chat_id=self._chat_id)
contact = message.contact

self.assertEqual(contact, con)

def test_contact_to_json(self):
contact = telegram.Contact.de_json(self.json_dict, self._bot)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ def test_send_document_resend(self):

self.assertEqual(document, self.document)

@flaky(3, 1)
@timeout(10)
def test_send_document_with_document(self):
message = self._bot.send_document(document=self.document, chat_id=self._chat_id)
document = message.document

self.assertEqual(document, self.document)


def test_document_de_json(self):
document = telegram.Document.de_json(self.json_dict, self._bot)

Expand Down
17 changes: 11 additions & 6 deletions tests/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def test_send_location_explicit_args(self):
self.assertEqual(location.latitude, self.latitude)
self.assertEqual(location.longitude, self.longitude)

def test_send_location_with_location(self):
loc = telegram.Location(longitude=self.longitude, latitude=self.latitude)
message = self._bot.send_location(location=loc, chat_id=self._chat_id)
location = message.location

self.assertEqual(location, loc)

def test_location_de_json(self):
location = telegram.Location.de_json(self.json_dict, self._bot)

Expand All @@ -78,19 +85,17 @@ def test_error_send_location_empty_args(self):
json_dict['latitude'] = ''
json_dict['longitude'] = ''

self.assertRaises(telegram.TelegramError,
lambda: self._bot.sendLocation(chat_id=self._chat_id,
**json_dict))
with self.assertRaises(TypeError):
self._bot.sendLocation(chat_id=self._chat_id, **json_dict)

def test_error_location_without_required_args(self):
json_dict = self.json_dict

del (json_dict['latitude'])
del (json_dict['longitude'])

self.assertRaises(TypeError,
lambda: self._bot.sendLocation(chat_id=self._chat_id,
**json_dict))
with self.assertRaises(ValueError):
self._bot.sendLocation(chat_id=self._chat_id, **json_dict)

@flaky(3, 1)
def test_reply_location(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_official.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def check_method(h4):
ignored |= {'filename'} # Undocumented
elif name == 'setGameScore':
ignored |= {'edit_message'} # TODO: Now deprecated, so no longer in telegrams docs
elif name == 'sendContact':
ignored |= {'contact'} # Added for ease of use
elif name == 'sendLocation':
ignored |= {'location'} # Added for ease of use
elif name == 'sendVenue':
ignored |= {'venue'} # Added for ease of use

logger.debug((sig.parameters.keys(), checked, ignored,
sig.parameters.keys() - checked - ignored))
Expand Down
12 changes: 11 additions & 1 deletion tests/test_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def test_send_photo_bytesio_jpg_file(self):
@flaky(3, 1)
@timeout(10)
def test_silent_send_photo(self):
message = self._bot.sendPhoto(photo=self.photo_file, chat_id=self._chat_id, disable_notification=True)
message = self._bot.sendPhoto(photo=self.photo_file, chat_id=self._chat_id,
disable_notification=True)
thumb, photo = message.photo

self.assertIsInstance(thumb, telegram.PhotoSize)
Expand All @@ -192,6 +193,15 @@ def test_silent_send_photo(self):
self.assertIsInstance(photo.file_id, str)
self.assertNotEqual(photo.file_id, '')

@flaky(3, 1)
@timeout(10)
def test_send_photo_with_photosize(self):
message = self._bot.send_photo(photo=self.photo, chat_id=self._chat_id)
thumb, photo = message.photo

self.assertEqual(photo, self.photo)
self.assertEqual(thumb, self.thumb)

@flaky(3, 1)
@timeout(10)
def test_send_photo_resend(self):
Expand Down
15 changes: 12 additions & 3 deletions tests/test_sticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ def test_sticker_de_json(self):
self.assertEqual(sticker.emoji, self.emoji)
self.assertEqual(sticker.file_size, self.sticker.file_size)

@flaky(3, 1)
@timeout(10)
def test_send_sticker_with_sticker(self):
message = self._bot.send_sticker(sticker=self.sticker, chat_id=self._chat_id)
sticker = message.sticker

self.assertEqual(sticker, self.sticker)


def test_sticker_to_json(self):
self.assertTrue(self.is_json(self.sticker.to_json()))

Expand Down Expand Up @@ -288,13 +297,13 @@ def setUp(self):
self.point = telegram.MaskPosition.EYES
self.x_shift = -1
self.y_shift = 1
self.zoom = 2
self.scale = 2

self.json_dict = {
'point': self.point,
'x_shift': self.x_shift,
'y_shift': self.y_shift,
'zoom': self.zoom
'scale': self.scale
}

def test_mask_position_de_json(self):
Expand All @@ -303,7 +312,7 @@ def test_mask_position_de_json(self):
self.assertEqual(mask_position.point, self.point)
self.assertEqual(mask_position.x_shift, self.x_shift)
self.assertEqual(mask_position.y_shift, self.y_shift)
self.assertEqual(mask_position.zoom, self.zoom)
self.assertEqual(mask_position.scale, self.scale)

def test_mask_positiont_to_json(self):
mask_position = telegram.MaskPosition.de_json(self.json_dict, self._bot)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class VenueTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram Venue."""

def setUp(self):
self.location = telegram.Location(longitude=1., latitude=0.)
self.location = telegram.Location(longitude=-46.788279, latitude=-23.691288)
self.title = 'title'
self._address = '_address'
self.foursquare_id = 'foursquare id'
Expand All @@ -53,6 +53,13 @@ def test_venue_de_json(self):
self.assertEqual(sticker.address, self._address)
self.assertEqual(sticker.foursquare_id, self.foursquare_id)

def test_send_venue_with_venue(self):
ven = telegram.Venue.de_json(self.json_dict, self._bot)
message = self._bot.send_venue(chat_id=self._chat_id, venue=ven)
venue = message.venue

self.assertEqual(venue, ven)

def test_venue_to_json(self):
sticker = telegram.Venue.de_json(self.json_dict, self._bot)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ def test_send_video_resend(self):
self.assertEqual(video.thumb, self.video.thumb)
self.assertEqual(video.mime_type, self.video.mime_type)

@flaky(3, 1)
@timeout(10)
def test_send_video_with_video(self):
message = self._bot.send_video(video=self.video, chat_id=self._chat_id)
video = message.video

self.assertEqual(video, self.video)


def test_video_de_json(self):
video = telegram.Video.de_json(self.json_dict, self._bot)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_videonote.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ def test_send_videonote_resend(self):
self.assertEqual(videonote.thumb, self.videonote.thumb)
self.assertEqual(videonote.file_size, self.videonote.file_size)

@flaky(3, 1)
@timeout(10)
def test_send_video_note_with_video_note(self):
message = self._bot.send_video_note(video_note=self.videonote, chat_id=self._chat_id)
video_note = message.video_note

self.assertEqual(video_note, self.videonote)

def test_videonote_de_json(self):
videonote = telegram.VideoNote.de_json(self.json_dict, self._bot)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def test_send_voice_resend(self):
self.assertEqual(voice.duration, self.voice.duration)
self.assertEqual(voice.mime_type, self.voice.mime_type)

@flaky(3, 1)
@timeout(10)
def test_send_voice_with_voice(self):
message = self._bot.send_voice(voice=self.voice, chat_id=self._chat_id)
voice = message.voice

self.assertEqual(voice, self.voice)


def test_voice_de_json(self):
voice = telegram.Voice.de_json(self.json_dict, self._bot)

Expand Down