mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-01-10 20:12:52 +01:00
add location attribute #272
This commit is contained in:
parent
5aab4525c2
commit
0e0611767a
2 changed files with 15 additions and 2 deletions
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
"""This module contains a object that represents a Telegram InlineQuery"""
|
"""This module contains a object that represents a Telegram InlineQuery"""
|
||||||
|
|
||||||
from telegram import TelegramObject, User
|
from telegram import TelegramObject, User, Location
|
||||||
|
|
||||||
|
|
||||||
class InlineQuery(TelegramObject):
|
class InlineQuery(TelegramObject):
|
||||||
|
@ -39,6 +39,10 @@ class InlineQuery(TelegramObject):
|
||||||
from_user (:class:`telegram.User`):
|
from_user (:class:`telegram.User`):
|
||||||
query (str):
|
query (str):
|
||||||
offset (str):
|
offset (str):
|
||||||
|
**kwargs: Arbitrary keyword arguments.
|
||||||
|
|
||||||
|
Keyword Args:
|
||||||
|
location (optional[:class:`telegram.Location`]):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
|
@ -53,6 +57,9 @@ class InlineQuery(TelegramObject):
|
||||||
self.query = query
|
self.query = query
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
|
|
||||||
|
# Optional
|
||||||
|
self.location = kwargs.get('location')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def de_json(data):
|
def de_json(data):
|
||||||
"""
|
"""
|
||||||
|
@ -68,6 +75,7 @@ class InlineQuery(TelegramObject):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data['from_user'] = User.de_json(data.get('from'))
|
data['from_user'] = User.de_json(data.get('from'))
|
||||||
|
data['location'] = Location.de_json(data.get('location'))
|
||||||
|
|
||||||
return InlineQuery(**data)
|
return InlineQuery(**data)
|
||||||
|
|
||||||
|
|
|
@ -37,17 +37,20 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
user = telegram.User(1, 'First name')
|
user = telegram.User(1, 'First name')
|
||||||
|
location = telegram.Location(8.8, 53.1)
|
||||||
|
|
||||||
self.id = 'id'
|
self.id = 'id'
|
||||||
self.from_user = user
|
self.from_user = user
|
||||||
self.query = 'query text'
|
self.query = 'query text'
|
||||||
self.offset = 'offset'
|
self.offset = 'offset'
|
||||||
|
self.location = location
|
||||||
|
|
||||||
self.json_dict = {
|
self.json_dict = {
|
||||||
'id': self.id,
|
'id': self.id,
|
||||||
'from': self.from_user.to_dict(),
|
'from': self.from_user.to_dict(),
|
||||||
'query': self.query,
|
'query': self.query,
|
||||||
'offset': self.offset
|
'offset': self.offset,
|
||||||
|
'location': self.location.to_dict()
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_inlinequery_de_json(self):
|
def test_inlinequery_de_json(self):
|
||||||
|
@ -56,6 +59,8 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
||||||
self.assertEqual(inlinequery.id, self.id)
|
self.assertEqual(inlinequery.id, self.id)
|
||||||
self.assertDictEqual(inlinequery.from_user.to_dict(),
|
self.assertDictEqual(inlinequery.from_user.to_dict(),
|
||||||
self.from_user.to_dict())
|
self.from_user.to_dict())
|
||||||
|
self.assertDictEqual(inlinequery.location.to_dict(),
|
||||||
|
self.location.to_dict())
|
||||||
self.assertEqual(inlinequery.query, self.query)
|
self.assertEqual(inlinequery.query, self.query)
|
||||||
self.assertEqual(inlinequery.offset, self.offset)
|
self.assertEqual(inlinequery.offset, self.offset)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue