Adding foursquare_type field to Venue by spontanurlaub · Pull Request #1170 · python-telegram-bot/python-telegram-bot · GitHub
Skip to content
Merged
12 changes: 10 additions & 2 deletions telegram/bot.py
8 changes: 7 additions & 1 deletion telegram/files/venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,29 @@ class Venue(TelegramObject):
title (:obj:`str`): Name of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue. (For example,
"arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)

Args:
location (:class:`telegram.Location`): Venue location.
title (:obj:`str`): Name of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue.
foursquare_type (:obj:`str`, optional): Foursquare type of the venue. (For example,
"arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, location, title, address, foursquare_id=None, **kwargs):
def __init__(self, location, title, address, foursquare_id=None, foursquare_type=None,
**kwargs):
# Required
self.location = location
self.title = title
self.address = address
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type

self._id_attrs = (self.location, self.title)

Expand Down
9 changes: 9 additions & 0 deletions telegram/inline/inlinequeryresultvenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class InlineQueryResultVenue(InlineQueryResult):
title (:obj:`str`): Title of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue if known.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
Expand All @@ -50,6 +53,9 @@ class InlineQueryResultVenue(InlineQueryResult):
title (:obj:`str`): Title of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue if known.
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
Expand All @@ -68,6 +74,7 @@ def __init__(self,
title,
address,
foursquare_id=None,
foursquare_type=None,
reply_markup=None,
input_message_content=None,
thumb_url=None,
Expand All @@ -85,6 +92,8 @@ def __init__(self,
# Optional
if foursquare_id:
self.foursquare_id = foursquare_id
if foursquare_type:
self.foursquare_type = foursquare_type
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:
Expand Down
10 changes: 9 additions & 1 deletion telegram/inline/inputvenuemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,30 @@ class InputVenueMessageContent(InputMessageContent):
title (:obj:`str`): Name of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue, if known.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)

Args:
latitude (:obj:`float`): Latitude of the location in degrees.
longitude (:obj:`float`): Longitude of the location in degrees.
title (:obj:`str`): Name of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue, if known.
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, latitude, longitude, title, address, foursquare_id=None, **kwargs):
def __init__(self, latitude, longitude, title, address, foursquare_id=None,
foursquare_type=None, **kwargs):
# Required
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
7 changes: 6 additions & 1 deletion tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,19 @@ def test_send_venue(self, bot, chat_id):
latitude = -23.691288
title = 'title'
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
message = bot.send_venue(chat_id=chat_id, title=title, address=address, latitude=latitude,
longitude=longitude)
longitude=longitude, foursquare_id=foursquare_id,
foursquare_type=foursquare_type)

assert message.venue
assert message.venue.title == title
assert message.venue.address == address
assert message.venue.location.latitude == latitude
assert message.venue.location.longitude == longitude
assert message.venue.foursquare_id == foursquare_id
assert message.venue.foursquare_type == foursquare_type

@flaky(3, 1)
@pytest.mark.timeout(10)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_inlinequeryresultvenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def inline_query_result_venue():
TestInlineQueryResultVenue.title,
TestInlineQueryResultVenue.address,
foursquare_id=TestInlineQueryResultVenue.foursquare_id,
foursquare_type=TestInlineQueryResultVenue.foursquare_type,
thumb_url=TestInlineQueryResultVenue.thumb_url,
thumb_width=TestInlineQueryResultVenue.thumb_width,
thumb_height=TestInlineQueryResultVenue.thumb_height,
Expand All @@ -47,6 +48,7 @@ class TestInlineQueryResultVenue(object):
title = 'title'
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
thumb_url = 'thumb url'
thumb_width = 10
thumb_height = 15
Expand All @@ -61,6 +63,7 @@ def test_expected_values(self, inline_query_result_venue):
assert inline_query_result_venue.title == self.title
assert inline_query_result_venue.address == self.address
assert inline_query_result_venue.foursquare_id == self.foursquare_id
assert inline_query_result_venue.foursquare_type == self.foursquare_type
assert inline_query_result_venue.thumb_url == self.thumb_url
assert inline_query_result_venue.thumb_width == self.thumb_width
assert inline_query_result_venue.thumb_height == self.thumb_height
Expand All @@ -80,6 +83,8 @@ def test_to_dict(self, inline_query_result_venue):
assert inline_query_result_venue_dict['address'] == inline_query_result_venue.address
assert (inline_query_result_venue_dict['foursquare_id'] ==
inline_query_result_venue.foursquare_id)
assert (inline_query_result_venue_dict['foursquare_type'] ==
inline_query_result_venue.foursquare_type)
assert inline_query_result_venue_dict['thumb_url'] == inline_query_result_venue.thumb_url
assert (inline_query_result_venue_dict['thumb_width'] ==
inline_query_result_venue.thumb_width)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_inputvenuemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def input_venue_message_content():
TestInputVenueMessageContent.longitude,
TestInputVenueMessageContent.title,
TestInputVenueMessageContent.address,
foursquare_id=TestInputVenueMessageContent.foursquare_id)
foursquare_id=TestInputVenueMessageContent.foursquare_id,
foursquare_type=TestInputVenueMessageContent.foursquare_type)


class TestInputVenueMessageContent(object):
Expand All @@ -37,13 +38,15 @@ class TestInputVenueMessageContent(object):
title = 'title'
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'

def test_expected_values(self, input_venue_message_content):
assert input_venue_message_content.longitude == self.longitude
assert input_venue_message_content.latitude == self.latitude
assert input_venue_message_content.title == self.title
assert input_venue_message_content.address == self.address
assert input_venue_message_content.foursquare_id == self.foursquare_id
assert input_venue_message_content.foursquare_type == self.foursquare_type

def test_to_dict(self, input_venue_message_content):
input_venue_message_content_dict = input_venue_message_content.to_dict()
Expand All @@ -57,3 +60,5 @@ def test_to_dict(self, input_venue_message_content):
assert input_venue_message_content_dict['address'] == input_venue_message_content.address
assert (input_venue_message_content_dict['foursquare_id'] ==
input_venue_message_content.foursquare_id)
assert (input_venue_message_content_dict['foursquare_type'] ==
input_venue_message_content.foursquare_type)
12 changes: 9 additions & 3 deletions tests/test_venue.py