mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-02-16 18:31:45 +01:00
Add tests for InputContactMessageContent InputLocationMessageContent InputTextMessageContent InputVenueMessageContent
This commit is contained in:
parent
ca1fff25f7
commit
4b173bfd52
6 changed files with 395 additions and 18 deletions
|
@ -21,24 +21,6 @@
|
||||||
|
|
||||||
from telegram.error import InvalidToken
|
from telegram.error import InvalidToken
|
||||||
|
|
||||||
try:
|
|
||||||
type(basestring)
|
|
||||||
except NameError:
|
|
||||||
basestring = str
|
|
||||||
|
|
||||||
|
|
||||||
def validate_string(arg, name):
|
|
||||||
"""
|
|
||||||
Validate a string argument. Raises a ValueError if `arg` is neither an
|
|
||||||
instance of basestring (Python 2) or str (Python 3) nor None.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
arg (basestring): The value to be tested
|
|
||||||
name (str): The name of the argument, for the error message
|
|
||||||
"""
|
|
||||||
if not isinstance(arg, basestring) and arg is not None:
|
|
||||||
raise ValueError(name + ' is not a string')
|
|
||||||
|
|
||||||
|
|
||||||
def validate_token(token):
|
def validate_token(token):
|
||||||
"""a very basic validation on token"""
|
"""a very basic validation on token"""
|
||||||
|
|
86
tests/test_inputcontactmessagecontent.py
Normal file
86
tests/test_inputcontactmessagecontent.py
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
|
# Copyright (C) 2015-2016
|
||||||
|
# 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/].
|
||||||
|
|
||||||
|
"""This module contains a object that represents Tests for Telegram
|
||||||
|
InputContactMessageContent"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info[0:2] == (2, 6):
|
||||||
|
import unittest2 as unittest
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
sys.path.append('.')
|
||||||
|
|
||||||
|
import telegram
|
||||||
|
from tests.base import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class InputContactMessageContentTest(BaseTest, unittest.TestCase):
|
||||||
|
"""This object represents Tests for Telegram InputContactMessageContent."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.phone_number = 'phone number'
|
||||||
|
self.first_name = 'first name'
|
||||||
|
self.last_name = 'last name'
|
||||||
|
|
||||||
|
self.json_dict = {
|
||||||
|
'first_name': self.first_name,
|
||||||
|
'phone_number': self.phone_number,
|
||||||
|
'last_name': self.last_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_icmc_de_json(self):
|
||||||
|
icmc = telegram.InputContactMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertEqual(icmc.first_name, self.first_name)
|
||||||
|
self.assertEqual(icmc.phone_number, self.phone_number)
|
||||||
|
self.assertEqual(icmc.last_name, self.last_name)
|
||||||
|
|
||||||
|
def test_icmc_de_json_factory(self):
|
||||||
|
icmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(isinstance(icmc, telegram.InputContactMessageContent))
|
||||||
|
|
||||||
|
def test_icmc_de_json_factory_without_required_args(self):
|
||||||
|
json_dict = self.json_dict
|
||||||
|
|
||||||
|
del (json_dict['phone_number'])
|
||||||
|
del (json_dict['first_name'])
|
||||||
|
|
||||||
|
icmc = telegram.InputMessageContent.de_json(json_dict)
|
||||||
|
|
||||||
|
self.assertFalse(icmc)
|
||||||
|
|
||||||
|
def test_icmc_to_json(self):
|
||||||
|
icmc = telegram.InputContactMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(self.is_json(icmc.to_json()))
|
||||||
|
|
||||||
|
def test_icmc_to_dict(self):
|
||||||
|
icmc = telegram.InputContactMessageContent.de_json(
|
||||||
|
self.json_dict).to_dict()
|
||||||
|
|
||||||
|
self.assertTrue(self.is_dict(icmc))
|
||||||
|
self.assertDictEqual(self.json_dict, icmc)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
83
tests/test_inputlocationmessagecontent.py
Normal file
83
tests/test_inputlocationmessagecontent.py
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
|
# Copyright (C) 2015-2016
|
||||||
|
# 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/].
|
||||||
|
|
||||||
|
"""This module contains a object that represents Tests for Telegram
|
||||||
|
InputLocationMessageContent"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info[0:2] == (2, 6):
|
||||||
|
import unittest2 as unittest
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
sys.path.append('.')
|
||||||
|
|
||||||
|
import telegram
|
||||||
|
from tests.base import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class InputLocationMessageContentTest(BaseTest, unittest.TestCase):
|
||||||
|
"""This object represents Tests for Telegram InputLocationMessageContent."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.latitude = 1.
|
||||||
|
self.longitude = 2.
|
||||||
|
|
||||||
|
self.json_dict = {
|
||||||
|
'longitude': self.longitude,
|
||||||
|
'latitude': self.latitude,
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_ilmc_de_json(self):
|
||||||
|
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertEqual(ilmc.longitude, self.longitude)
|
||||||
|
self.assertEqual(ilmc.latitude, self.latitude)
|
||||||
|
|
||||||
|
def test_ilmc_de_json_factory(self):
|
||||||
|
ilmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(isinstance(ilmc, telegram.InputLocationMessageContent))
|
||||||
|
|
||||||
|
def test_ilmc_de_json_factory_without_required_args(self):
|
||||||
|
json_dict = self.json_dict
|
||||||
|
|
||||||
|
del (json_dict['longitude'])
|
||||||
|
del (json_dict['latitude'])
|
||||||
|
|
||||||
|
ilmc = telegram.InputMessageContent.de_json(json_dict)
|
||||||
|
|
||||||
|
self.assertFalse(ilmc)
|
||||||
|
|
||||||
|
def test_ilmc_to_json(self):
|
||||||
|
ilmc = telegram.InputLocationMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(self.is_json(ilmc.to_json()))
|
||||||
|
|
||||||
|
def test_ilmc_to_dict(self):
|
||||||
|
ilmc = telegram.InputLocationMessageContent.de_json(
|
||||||
|
self.json_dict).to_dict()
|
||||||
|
|
||||||
|
self.assertTrue(self.is_dict(ilmc))
|
||||||
|
self.assertDictEqual(self.json_dict, ilmc)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
46
tests/test_inputmessagecontent.py
Normal file
46
tests/test_inputmessagecontent.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
|
# Copyright (C) 2015-2016
|
||||||
|
# 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/].
|
||||||
|
|
||||||
|
"""This module contains a object that represents Tests for Telegram
|
||||||
|
InputMessageContent"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info[0:2] == (2, 6):
|
||||||
|
import unittest2 as unittest
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
sys.path.append('.')
|
||||||
|
|
||||||
|
import telegram
|
||||||
|
from tests.base import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class InputMessageContentTest(BaseTest, unittest.TestCase):
|
||||||
|
"""This object represents Tests for Telegram InputMessageContent."""
|
||||||
|
|
||||||
|
def test_imc_de_json(self):
|
||||||
|
imc = telegram.InputMessageContent.de_json(None)
|
||||||
|
|
||||||
|
self.assertFalse(imc)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
86
tests/test_inputtextmessagecontent.py
Normal file
86
tests/test_inputtextmessagecontent.py
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
|
# Copyright (C) 2015-2016
|
||||||
|
# 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/].
|
||||||
|
|
||||||
|
"""This module contains a object that represents Tests for Telegram
|
||||||
|
InputTextMessageContent"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info[0:2] == (2, 6):
|
||||||
|
import unittest2 as unittest
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
sys.path.append('.')
|
||||||
|
|
||||||
|
import telegram
|
||||||
|
from tests.base import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class InputTextMessageContentTest(BaseTest, unittest.TestCase):
|
||||||
|
"""This object represents Tests for Telegram InputTextMessageContent."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.message_text = '*message text*'
|
||||||
|
self.parse_mode = telegram.ParseMode.MARKDOWN
|
||||||
|
self.disable_web_page_preview = True
|
||||||
|
|
||||||
|
self.json_dict = {
|
||||||
|
'parse_mode': self.parse_mode,
|
||||||
|
'message_text': self.message_text,
|
||||||
|
'disable_web_page_preview': self.disable_web_page_preview,
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_itmc_de_json(self):
|
||||||
|
itmc = telegram.InputTextMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertEqual(itmc.parse_mode, self.parse_mode)
|
||||||
|
self.assertEqual(itmc.message_text, self.message_text)
|
||||||
|
self.assertEqual(itmc.disable_web_page_preview,
|
||||||
|
self.disable_web_page_preview)
|
||||||
|
|
||||||
|
def test_itmc_de_json_factory(self):
|
||||||
|
itmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(isinstance(itmc, telegram.InputTextMessageContent))
|
||||||
|
|
||||||
|
def test_itmc_de_json_factory_without_required_args(self):
|
||||||
|
json_dict = self.json_dict
|
||||||
|
|
||||||
|
del (json_dict['message_text'])
|
||||||
|
|
||||||
|
itmc = telegram.InputMessageContent.de_json(json_dict)
|
||||||
|
|
||||||
|
self.assertFalse(itmc)
|
||||||
|
|
||||||
|
def test_itmc_to_json(self):
|
||||||
|
itmc = telegram.InputTextMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(self.is_json(itmc.to_json()))
|
||||||
|
|
||||||
|
def test_itmc_to_dict(self):
|
||||||
|
itmc = telegram.InputTextMessageContent.de_json(
|
||||||
|
self.json_dict).to_dict()
|
||||||
|
|
||||||
|
self.assertTrue(self.is_dict(itmc))
|
||||||
|
self.assertDictEqual(self.json_dict, itmc)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
94
tests/test_inputvenuemessagecontent.py
Normal file
94
tests/test_inputvenuemessagecontent.py
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# A library that provides a Python interface to the Telegram Bot API
|
||||||
|
# Copyright (C) 2015-2016
|
||||||
|
# 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/].
|
||||||
|
|
||||||
|
"""This module contains a object that represents Tests for Telegram
|
||||||
|
InputVenueMessageContent"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info[0:2] == (2, 6):
|
||||||
|
import unittest2 as unittest
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
sys.path.append('.')
|
||||||
|
|
||||||
|
import telegram
|
||||||
|
from tests.base import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
class InputVenueMessageContentTest(BaseTest, unittest.TestCase):
|
||||||
|
"""This object represents Tests for Telegram InputVenueMessageContent."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.latitude = 1.
|
||||||
|
self.longitude = 2.
|
||||||
|
self.title = 'title'
|
||||||
|
self._address = 'address' # nose binds self.address for testing
|
||||||
|
self.foursquare_id = 'foursquare id'
|
||||||
|
|
||||||
|
self.json_dict = {
|
||||||
|
'longitude': self.longitude,
|
||||||
|
'latitude': self.latitude,
|
||||||
|
'title': self.title,
|
||||||
|
'address': self._address,
|
||||||
|
'foursquare_id': self.foursquare_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_ivmc_de_json(self):
|
||||||
|
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertEqual(ivmc.longitude, self.longitude)
|
||||||
|
self.assertEqual(ivmc.latitude, self.latitude)
|
||||||
|
self.assertEqual(ivmc.title, self.title)
|
||||||
|
self.assertEqual(ivmc.address, self._address)
|
||||||
|
self.assertEqual(ivmc.foursquare_id, self.foursquare_id)
|
||||||
|
|
||||||
|
def test_ivmc_de_json_factory(self):
|
||||||
|
ivmc = telegram.InputMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(isinstance(ivmc, telegram.InputVenueMessageContent))
|
||||||
|
|
||||||
|
def test_ivmc_de_json_factory_without_required_args(self):
|
||||||
|
json_dict = self.json_dict
|
||||||
|
|
||||||
|
del (json_dict['longitude'])
|
||||||
|
del (json_dict['latitude'])
|
||||||
|
del (json_dict['title'])
|
||||||
|
del (json_dict['address'])
|
||||||
|
|
||||||
|
ivmc = telegram.InputMessageContent.de_json(json_dict)
|
||||||
|
|
||||||
|
self.assertFalse(ivmc)
|
||||||
|
|
||||||
|
def test_ivmc_to_json(self):
|
||||||
|
ivmc = telegram.InputVenueMessageContent.de_json(self.json_dict)
|
||||||
|
|
||||||
|
self.assertTrue(self.is_json(ivmc.to_json()))
|
||||||
|
|
||||||
|
def test_ivmc_to_dict(self):
|
||||||
|
ivmc = telegram.InputVenueMessageContent.de_json(
|
||||||
|
self.json_dict).to_dict()
|
||||||
|
|
||||||
|
self.assertTrue(self.is_dict(ivmc))
|
||||||
|
self.assertDictEqual(self.json_dict, ivmc)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Add table
Reference in a new issue