コード例 #1
0
 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)
コード例 #2
0
 def test_init__sticker(self):
     self.message_json['sticker'] = self.sticker
     message = Message(self.message_json)
     self.assertEqual(
         message.sending_kwargs,
         {'sticker': 'BQADAgAD7gAD9HsZAAFCdfFWtd5o1gI'},
     )
コード例 #3
0
 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)
コード例 #4
0
 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')
コード例 #5
0
 def test_init__document(self):
     self.message_json['document'] = {
         'file_id': 'foo',
     }
     message = Message(self.message_json)
     self.assertEqual(
         message.sending_kwargs,
         {
             'document': 'foo',
         },
     )
コード例 #6
0
 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,
         },
     )
コード例 #7
0
 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',
         },
     )
コード例 #8
0
 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',
             },
         )
コード例 #9
0
 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,
         },
     )
コード例 #10
0
 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)
コード例 #11
0
 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',
         },
     )
コード例 #12
0
 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',
         },
     )
コード例 #13
0
 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, '')
コード例 #14
0
 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)
コード例 #15
0
 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)
コード例 #16
0
 def test_init__invalid_json(self):
     with self.assertRaises(UnsupportedContentError):
         Message(self.message_json)
コード例 #17
0
 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)
コード例 #18
0
 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')
コード例 #19
0
 def test_init__invalid_voice(self, telepot):
     telepot.glance.return_value = 'voice', 'private', 31416
     with self.assertRaises(UnsupportedContentError):
         Message(self.message_json)