class MessageTests(unittest.TestCase): DECODE_FILE = os.path.join(DECODING_FILES_PATH, 'message.json') def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) self.api = TelegramAPy(TELEGRAM_TOKEN) @unittest.skipIf(not SEND_MESSAGES, 'Sending messages skipped') def test_simple_message(self): """Does it send messages correctly?""" msg = self.api.sendMessage(TEST_CHAT_ID, "test_simple_message") self.assertIsInstance(msg, Message) @unittest.skipIf(not SEND_MESSAGES, 'Sending messages skipped') def test_markdown_message(self): """Does it send messages with markdown correctly?""" msg = self.api.sendMessage(TEST_CHAT_ID, "*test_markdown_message*", parse_mode=TelegramAPy.MARKDOWN_MODE) self.assertIsInstance(msg, Message) def test_message_decode(self): with open(MessageTests.DECODE_FILE) as json_file: j = json.load(json_file) obj = Message.decode(j) self.assertEqual(obj.message_id, j[Message.FIELD_MESSAGEID]) self.assertEqual(obj.text, j[Message.FIELD_TEXT]) self.assertIsInstance(obj.date, datetime.datetime) self.assertIsInstance(obj.from_, User) self.assertIsInstance(obj.chat, Chat) self.assertIsInstance(obj.forward_from, User) self.assertIsInstance(obj.reply_to_message, Message)
class GeneralTests(unittest.TestCase): def __init__(self, *args, **kwargs): super(GeneralTests, self).__init__(*args, **kwargs) self.api = TelegramAPy(TELEGRAM_TOKEN) def test_token(self): """Does work with correct token?""" self.api.getMe() def test_invalid_token(self): """Does raise exception with invalid token?""" with self.assertRaises(InvalidTokenException): TelegramAPy("wrongtoken") def test_wrong_token(self): """Does raise exception with invalid token?""" w_api = TelegramAPy("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") with self.assertRaises(TelegramException): w_api.getMe()
class UpdatesTests(unittest.TestCase): DECODE_FILE = os.path.join(DECODING_FILES_PATH, 'update.json') def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) self.api = TelegramAPy(TELEGRAM_TOKEN) def test_get_updates(self): upds = self.api.getUpdates() if upds: for upd in upds: self.assertIsInstance(upd, Update) else: self.skip("No updates recieved.") def test_update_decode(self): with open(UpdatesTests.DECODE_FILE) as json_file: j = json.load(json_file) obj = Update.decode(j) self.assertEqual(obj.update_id, j[Update.FIELD_UPDATEID]) self.assertIsInstance(obj.message, Message)
class UpdatesTests(unittest.TestCase): DECODE_FILE = os.path.join(DECODING_FILES_PATH, "update.json") def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) self.api = TelegramAPy(TELEGRAM_TOKEN) def test_get_updates(self): upds = self.api.getUpdates() if upds: for upd in upds: self.assertIsInstance(upd, Update) else: self.skip("No updates recieved.") def test_update_decode(self): with open(UpdatesTests.DECODE_FILE) as json_file: j = json.load(json_file) obj = Update.decode(j) self.assertEqual(obj.update_id, j[Update.FIELD_UPDATEID]) self.assertIsInstance(obj.message, Message)
def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs) self.api = TelegramAPy(TELEGRAM_TOKEN)
def test_wrong_token(self): """Does raise exception with invalid token?""" w_api = TelegramAPy("123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11") with self.assertRaises(TelegramException): w_api.getMe()
def test_invalid_token(self): """Does raise exception with invalid token?""" with self.assertRaises(InvalidTokenException): TelegramAPy("wrongtoken")
def __init__(self, *args, **kwargs): super(GeneralTests, self).__init__(*args, **kwargs) self.api = TelegramAPy(TELEGRAM_TOKEN)