def test_init__message_with_reply(self, telepot): telepot.glance.return_value = 'text', 'private', 31416 self.message_json['text'] = 'foo' message = Message(self.message_json) self.assertFalse(message.is_reply) self.message_json['reply_to_message'] = None message = Message(self.message_json) self.assertTrue(message.is_reply)
def test_init__sticker(self): self.message_json['sticker'] = self.sticker message = Message(self.message_json) self.assertEqual( message.sending_kwargs, {'sticker': 'BQADAgAD7gAD9HsZAAFCdfFWtd5o1gI'}, )
def test_init__invalid_location(self, telepot): self.message_json['location'] = { 'latitude': 'foo', } telepot.glance.return_value = 'location', 'private', 31416 with self.assertRaises(UnsupportedContentError): Message(self.message_json)
def test_init__text(self): self.message_json['text'] = 'foo' message = Message(self.message_json) self.assertEqual( message.sending_kwargs, {'text': 'foo'}, ) self.assertEqual(message.text, 'foo')
def test_init__document(self): self.message_json['document'] = { 'file_id': 'foo', } message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'document': 'foo', }, )
def test_init__voice(self): self.message_json['voice'] = { 'file_id': 'foo', } message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'voice': 'foo', 'duration': None, }, )
def test_init__location(self): self.message_json['location'] = { 'latitude': 'foo', 'longitude': 'bar', } message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'latitude': 'foo', 'longitude': 'bar', }, )
def test_init__photo_with_caption(self): self.message_json['photo'] = [ {'file_id': 'foo'}, {'file_id': 'bar'}, ] self.message_json['caption'] = 'baz' message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'caption': 'baz', 'photo': 'foo', }, )
def test_init__audio(self): self.message_json['audio'] = { 'file_id': 'foo', } message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'audio': 'foo', 'duration': None, 'performer': None, 'title': None, }, )
def test_init__photo(self): self.message_json['photo'] = [ {'file_id': 'foo'}, {'file_id': 'bar'}, ] message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'caption': None, 'photo': 'foo', }, ) self.assertEqual(message.text, None)
def test_init__video_with_info(self): self.message_json['video'] = { 'duration': 85, 'file_id': 'foo', } self.message_json['caption'] = 'Pink Floyd' message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'video': 'foo', 'duration': 85, 'caption': 'Pink Floyd', }, )
def test_init__audio_with_info(self): self.message_json['audio'] = { 'duration': 85, 'file_id': 'foo', 'performer': 'Pink Floyd', 'title': 'Another Brick In The Wall Part 3', } message = Message(self.message_json) self.assertEqual( message.sending_kwargs, { 'audio': 'foo', 'duration': 85, 'performer': 'Pink Floyd', 'title': 'Another Brick In The Wall Part 3', }, )
def test_init__command_without_args(self, telepot): telepot.glance.return_value = 'text', 'private', 31416 self.message_json['text'] = '/start' message = Message(self.message_json) self.assertEqual(message.command, 'start') self.assertEqual(message.command_args, '')
def test_init__text_without_command_has_empty_comand_field(self, telepot): telepot.glance.return_value = 'text', 'private', 31416 self.message_json['text'] = 'foo' message = Message(self.message_json) self.assertEqual(message.command, None) self.assertEqual(message.command_args, None)
def test_init__unknown_content_type(self, telepot): telepot.glance.return_value = 'foo_content_type', 'private', 31416 with self.assertRaises(UnsupportedContentError): Message(self.message_json)
def test_init__invalid_json(self): with self.assertRaises(UnsupportedContentError): Message(self.message_json)
def test_init__message_with_forward(self, telepot): telepot.glance.return_value = 'text', 'private', 31416 self.message_json['forward_from'] = None with self.assertRaises(UnsupportedContentError): Message(self.message_json)
def test_init__command_with_underscore(self, telepot): telepot.glance.return_value = 'text', 'private', 31416 self.message_json['text'] = '/begin_chat here' message = Message(self.message_json) self.assertEqual(message.command, 'begin_chat') self.assertEqual(message.command_args, 'here')
def test_init__invalid_voice(self, telepot): telepot.glance.return_value = 'voice', 'private', 31416 with self.assertRaises(UnsupportedContentError): Message(self.message_json)