def test_sticker_2020_11_08(self):
        # HotCherry, the waving one.
        file_id_4_22 = FileId.from_file_id('CAADAgADBQADwDZPE_lqX5qCa011FgQ')
        self.assertEqual(file_id_4_22.type_id, file_id_4_22.TYPE_STICKER,
                         'type is sticker')
        self.assertEqual(4, file_id_4_22.version)
        self.assertEqual(22, file_id_4_22.sub_version)
        self.assertEqual(1391391008142393349, file_id_4_22.id)
        self.assertEqual(8452530284324154105, file_id_4_22.access_hash)

        file_id_4_27 = FileId.from_file_id(
            'CAACAgIAAxkBAAIC1F9CrovDlZGS5umOiP0HdbMIxVhsAAIFAAPANk8T-WpfmoJrTXUbBA'
        )  # (4,27)
        self.assertEqual(file_id_4_27.type_id, file_id_4_27.TYPE_STICKER,
                         'type is sticker')
        self.assertEqual(4, file_id_4_27.version)
        self.assertEqual(27, file_id_4_27.sub_version)
        self.assertEqual(1391391008142393349, file_id_4_27.id)
        self.assertEqual(8452530284324154105, file_id_4_27.access_hash)

        file_id_4_30 = FileId.from_file_id(
            'CAACAgIAAxkBAAIE31-nVcM1Bkj0e5shlg_MIYsrRdDFAAIFAAPANk8T-WpfmoJrTXUeBA'
        )  # (4,30)
        self.assertEqual(file_id_4_30.type_id, file_id_4_30.TYPE_STICKER,
                         'type is sticker')
        self.assertEqual(4, file_id_4_30.version)
        self.assertEqual(30, file_id_4_30.sub_version)
        self.assertEqual(1391391008142393349, file_id_4_30.id)
        self.assertEqual(8452530284324154105, file_id_4_30.access_hash)
Beispiel #2
0
 def test_sticker(self):
     file_id_old = FileId.from_file_id('CAADAQADegAD997LEUiQZafDlhIeAg')
     file_id_new = FileId.from_file_id(
         'CAACAgEAAx0CVgtngQACAuFfU1GY9wiRG7A7jlIBbP2yvAostAACegAD997LEUiQZafDlhIeGwQ'
     )
     expected = 'AgADegAD997LEQ'
     self.assertEqual(expected,
                      FileUniqueId.from_file_id(file_id_old).to_unique_id(),
                      'Old style file ID.')
     self.assertEqual(expected,
                      FileUniqueId.from_file_id(file_id_new).to_unique_id(),
                      'Old style file ID.')
 def test_photo_a_v2_0(self):
     file_id = FileId.from_file_id(
         'AgADAgADRaoxG64rCUlfm3fj3nihW3PHUQ8ABLefjdP8kuxqa7ABAAEC')
     self.assertEqual(FileId.TYPE_PHOTO, file_id.type_id)
     self.assertIsInstance(file_id, PhotoFileId)
     self.assertEqual(2, file_id.version)
     self.assertEqual(0, file_id.sub_version)
 def test_user_ids(self):
     #https://getstickers.me/sticker/test4458pack/CAADAgAD1AkAAgKLowABByoNoHLboHEC/
     test_data = {
         'BQADAgAD3AkAAgKLowABKlAd1pemg-gC':
         None,
         'BQADAgAD7QkAAgKLowABuLSCK5e9BY0C':
         None,
         'CAADAgAD0gkAAgKLowAB_uE0vZEqv4oC':
         10717954,
         'CAACAgIAAxkBAAIEVF9Do80olppb0490gLH2I1cszuoMAALcCQACAoujAAEqUB3Wl6aD6BsE':
         10717954,
         'CAADAgAD1AkAAgKLowABByoNoHLboHEC':
         10717954,
         'CAACAgIAAxkBAAIEWl9EYjGyD-ToGsSWHMIz19CYxsYWAAK7CgACAoujAAHTPCFEqkdBoxsE':
         10717954,
     }
     for file_id, expected_owner_id in test_data.items():
         obj = FileId.from_file_id(file_id)
         self.assertIsInstance(obj, FileId, msg=f'file_id = {file_id!r}')
         self.assertIsInstance(obj,
                               DocumentFileId,
                               msg=f'file_id = {file_id!r}')
         self.assertIn(obj.type_id, [5, 8], msg=f'file_id = {file_id!r}')
         self.assertEqual('document',
                          obj.type_generic,
                          msg=f'file_id = {file_id!r}')
         self.assertIn(obj.type_detailed, ['document', 'sticker'],
                       msg=f'file_id = {file_id!r}')
         self.assertEqual(expected_owner_id,
                          obj.owner_id,
                          msg=f'file_id = {file_id!r}')
 def test_photo_a_v4_22(self):
     # same as AgADAgADRaoxG64rCUlfm3fj3nihW3PHUQ8ABLefjdP8kuxqa7ABAAEC
     file_id = FileId.from_file_id(
         'AgADAgADRaoxG64rCUlfm3fj3nihW3PHUQ8ABAEAAwIAA3gAA2uwAQABFgQ')
     self.assertEqual(FileId.TYPE_PHOTO, file_id.type_id)
     self.assertIsInstance(file_id, PhotoFileId)
     self.assertEqual(4, file_id.version)
     self.assertEqual(22, file_id.sub_version)
 def test_v4_post2020(self):
     file_id = FileId.from_file_id(
         'CAACAgQAAxkBAAIC4l9CWDGzVUcDejU0TETLWbOdfsCoAALDAAOYWaoN_rEGs9NF6ocbBA'
     )
     self.assertEqual(file_id.type_id, file_id.TYPE_STICKER,
                      'type is sticker')
     self.assertEqual('document', file_id.type_generic)
     self.assertEqual(file_id.type_detailed, 'sticker', 'type is sticker')
 def test_photo_a_v4_27(self):
     # same as AgADAgADRaoxG64rCUlfm3fj3nihW3PHUQ8ABLefjdP8kuxqa7ABAAEC
     file_id = FileId.from_file_id(
         'AgACAgIAAxkBAAIBp19C0Fkv9R4D-TriZLzK7vBUw-DrAAJFqjEbrisJSV-bd-PeeKFbc8dRDwAEAQADAgADbQADbbABAAEbBA'
     )
     self.assertEqual(FileId.TYPE_PHOTO, file_id.type_id)
     self.assertIsInstance(file_id, PhotoFileId)
     self.assertEqual(4, file_id.version)
     self.assertEqual(27, file_id.sub_version)
 def test_photo_a_v4_30(self):
     # same as AgADAgADRaoxG64rCUlfm3fj3nihW3PHUQ8ABLefjdP8kuxqa7ABAAEC
     file_id = FileId.from_file_id(
         'AgACAgIAAxkBAAIE3V-nVPRnkcGnCW8Vd53VQgouUt60AAJFqjEbrisJSV-bd-PeeKFbc8dRDwAEAQADAgADeAADa7ABAAEeBA'
     )
     self.assertEqual(FileId.TYPE_PHOTO, file_id.type_id)
     self.assertIsInstance(file_id, PhotoFileId)
     self.assertEqual(4, file_id.version)
     self.assertEqual(30, file_id.sub_version)
Beispiel #9
0
 def test_a_bunch_of_file_ids(self):
     file_ids = [
         'CAADBAADwwADmFmqDf6xBrPTReqHFgQ',
         'CAACAgQAAxkBAAIC4l9CWDGzVUcDejU0TETLWbOdfsCoAALDAAOYWaoN_rEGs9NF6ocbBA',
         'CAADBAADwwADmFmqDf6xBrPTReqHAg'
     ]
     for file_id in file_ids:
         with self.subTest(f'file_id: {file_id}'):
             file = FileId.from_file_id(file_id)
             self.assertEqual(
                 'AgADwwADmFmqDQ',
                 FileUniqueId.from_file_id(file).to_unique_id())
    def test_to_unique(self):
        given_file_id = 'CAACAgIAAxkBAAIEol9yQhBqFnT4HXldAh31a-hYXuDIAAIECwACAoujAAFFn1sl9AABHbkbBA'
        expected_unique_id = 'AgADBAsAAgKLowAB'

        file_id = FileId.from_file_id(given_file_id)
        self.assertEqual(8, file_id.type_id)
        self.assertEqual(46033261910035204, file_id.id)

        unique_id = FileUniqueId.from_file_id(file_id)
        self.assertEqual(2, unique_id.type_id)
        self.assertEqual(46033261910035204, unique_id.id)
        self.assertEqual(None, unique_id.volume_id)
        self.assertEqual(None, unique_id.local_id)
        self.assertEqual(None, unique_id.url)
        unique_id_str = unique_id.to_unique_id()

        self.assertEqual(expected_unique_id, unique_id_str)
 def test_user_ids_from_file(self):
     users = {}
     fails = 0
     successes = 0
     FILE = '/Users/luckydonald/Downloads/Telegram/tblsticker.csv.txt'
     import os
     if not os.path.exists(FILE):
         self.skipTest('There\'s no file with stickers to test with.')
     # end if
     with open('/Users/luckydonald/Downloads/Telegram/tblsticker.csv.txt'
               ) as f:
         for line in f:
             file_id, _ = line.split(',', 1)
             if file_id == 'id':
                 # header line
                 continue
             # end if
             try:
                 obj = FileId.from_file_id(file_id)
                 successes += 1
             except:
                 fails += 1
                 continue
             # end try
             owner_id = obj.owner_id
             if owner_id not in users:
                 users[owner_id] = []
             # end if
             users[owner_id].append(file_id)
         # end for
     # end with
     with open('/Users/luckydonald/Downloads/Telegram/tblsticker.json',
               'w') as f:
         f.write(repr(users))
     # end with
     # print(users)
     print(len(users))
     print(successes)
     print(fails)
 def test_03(self):
     file_id = FileId.from_file_id('BQADBAADdggAAuIf-FAgXs_aELTd4wI')
Beispiel #13
0
    def test_send_sticker(self):
        original_file_id = 'CAACAgIAAx0EUh03EAADDl-oWPT0MOIQZ93aktaAu8hU8rPEAAK2BgACAoujAAFGAUWZ6DSbtR4E'
        try:
            from pytgbot import Bot
        except ImportError:
            return self.fail('pytgbot dependency missing')
        # end try

        if not API_KEY:
            return self.fail('API_KEY not set')
        # end if
        if not CHAT_ID:
            return self.fail('CHAT_ID not set')
        # end if

        bot = Bot(API_KEY)

        msg = bot.send_sticker(chat_id=CHAT_ID, sticker=original_file_id)
        print(msg)

        sticker_file = FileId.from_file_id(msg.sticker.file_id)
        sticker_file_unique_id = FileUniqueId.from_file_id(
            msg.sticker.file_id).to_unique_id()
        self.assertEqual(msg.sticker.file_unique_id, sticker_file_unique_id)
        self.assertEqual(FileId.TYPE_STICKER, sticker_file.type_id)
        self.assertEqual('sticker', sticker_file.type_detailed)
        self.assertEqual('document', sticker_file.type_generic)
        self.assertEqual(sticker_file.version, FileId.MAX_VERSION[0],
                         'sticker should be supported max (sub_)version')
        self.assertEqual(sticker_file.sub_version, FileId.MAX_VERSION[1],
                         'sticker should be supported max (sub_)version')
        self.assertEqual(46033261910034102, sticker_file.id)
        self.assertEqual(-5360632757845950138, sticker_file.access_hash)
        self.assertEqual(2, sticker_file.dc_id)
        # self.assertEqual(b64decode('BFIdNxAAAAAOX6hY9PQw4hBn3dqS1oC7yFTys8Q='), sticker_file.file_reference)

        thumb_file = FileId.from_file_id(msg.sticker.thumb.file_id)
        # 'AAMCAgADGQMAAQHUiF-oKLkvxChbEROPTTw6Aagft9bPAAK2BgACAoujAAFGAUWZ6DSbtUufgioABAEAB20AAwpQAAIeBA'
        thumb_file_unique_id = FileUniqueId.from_file_id(
            thumb_file).to_unique_id()
        self.assertEqual(msg.sticker.thumb.file_unique_id,
                         thumb_file_unique_id)
        self.assertEqual(FileId.TYPE_THUMBNAIL, thumb_file.type_id)
        self.assertEqual('thumbnail', thumb_file.type_detailed)
        self.assertEqual('photo', thumb_file.type_generic)
        self.assertEqual(sticker_file.version, thumb_file.version)
        self.assertEqual(sticker_file.sub_version, thumb_file.sub_version)
        self.assertEqual(sticker_file.id, thumb_file.id)
        self.assertEqual(sticker_file.access_hash, thumb_file.access_hash)
        self.assertEqual(sticker_file.dc_id, thumb_file.dc_id)
        self.assertEqual(sticker_file.file_reference,
                         thumb_file.file_reference)
        # PhotosizeSource
        self.assertIsInstance(thumb_file.photosize,
                              PhotoFileId.PhotosizeSource)
        self.assertEqual(20490, thumb_file.photosize.location_local_id)
        self.assertEqual(713203531, thumb_file.photosize.volume_id)
        self.assertEqual(PhotoFileId.PHOTOSIZE_SOURCE_THUMBNAIL,
                         thumb_file.photosize.type_id)
        # PhotosizeSourceThumbnail
        self.assertIsInstance(thumb_file.photosize,
                              PhotoFileId.PhotosizeSourceThumbnail)
        self.assertEqual(b'm', thumb_file.photosize.thumbnail_type)
        self.assertEqual(FileId.TYPE_THUMBNAIL, thumb_file.photosize.file_type)
 def test_02(self):
     file_id = FileId.from_file_id('BQADBAADwgQAArWB8VA7hTVCyclc2QI')
    def test_sticker_starlight_filly(self):
        file_unique_id_decoded = rle_decode(base64url_decode('AgADwwADmFmqDQ'))
        type_id = struct.unpack("<i", file_unique_id_decoded[0:4])[0]
        self.assertEqual(2, type_id)
        media_id = struct.unpack("<q", file_unique_id_decoded[-8:])[0]
        # sticker(pack: Story_pony_love)
        file_id_4_22 = FileId.from_file_id('CAADBAADwwADmFmqDf6xBrPTReqHFgQ')
        self.assertEqual(file_id_4_22.type_id, FileId.TYPE_STICKER,
                         'type is sticker')
        self.assertEqual(4, file_id_4_22.version)
        self.assertEqual(22, file_id_4_22.sub_version)
        self.assertIsInstance(file_id_4_22, DocumentFileId)
        self.assertEqual(media_id, file_id_4_22.id)

        file_id_4_27 = FileId.from_file_id(
            'CAACAgQAAxkBAAIC4l9CWDGzVUcDejU0TETLWbOdfsCoAALDAAOYWaoN_rEGs9NF6ocbBA'
        )  # (4,27)
        self.assertEqual(file_id_4_27.type_id, FileId.TYPE_STICKER,
                         'type is sticker')
        self.assertEqual(4, file_id_4_27.version)
        self.assertEqual(27, file_id_4_27.sub_version)
        self.assertIsInstance(file_id_4_27, DocumentFileId)
        self.assertEqual(media_id, file_id_4_27.id)

        self.assertEqual(file_id_4_22.type_id,
                         file_id_4_27.type_id,
                         msg='4.22->4.27: type_id')
        self.assertEqual(file_id_4_22.type_generic,
                         file_id_4_27.type_generic,
                         msg='4.22->4.27: type_generic')
        self.assertEqual(file_id_4_22.type_detailed,
                         file_id_4_27.type_detailed,
                         msg='4.22->4.27: type_detailed')
        self.assertEqual(file_id_4_22.dc_id,
                         file_id_4_27.dc_id,
                         msg='4.22->4.27: dc_id')
        self.assertEqual(file_id_4_22.id,
                         file_id_4_27.id,
                         msg='4.22->4.27: id')
        self.assertEqual(file_id_4_22.access_hash,
                         file_id_4_27.access_hash,
                         msg='4.22->4.27: access_hash')
        self.assertEqual(file_id_4_22.owner_id,
                         file_id_4_27.owner_id,
                         msg='4.22->4.27: owner_id')

        file_id_4_30 = FileId.from_file_id(
            'CAACAgQAAxkBAAIE4V-nVmlwWzNxKeRGZYjG0m7UWm0IAALDAAOYWaoN_rEGs9NF6oceBA'
        )  # (4,30)
        self.assertEqual(file_id_4_30.type_id, FileId.TYPE_STICKER,
                         'type is sticker')
        self.assertEqual(4, file_id_4_30.version)
        self.assertEqual(30, file_id_4_30.sub_version)
        self.assertIsInstance(file_id_4_30, DocumentFileId)
        self.assertEqual(media_id, file_id_4_30.id)

        self.assertEqual(file_id_4_22.type_id,
                         file_id_4_30.type_id,
                         msg='4.22->4.30: type_id')
        self.assertEqual(file_id_4_22.type_generic,
                         file_id_4_30.type_generic,
                         msg='4.22->4.30: type_generic')
        self.assertEqual(file_id_4_22.type_detailed,
                         file_id_4_30.type_detailed,
                         msg='4.22->4.30: type_detailed')
        self.assertEqual(file_id_4_22.dc_id,
                         file_id_4_30.dc_id,
                         msg='4.22->4.30: dc_id')
        self.assertEqual(file_id_4_22.id,
                         file_id_4_30.id,
                         msg='4.22->4.30: id')
        self.assertEqual(file_id_4_22.access_hash,
                         file_id_4_30.access_hash,
                         msg='4.22->4.30: access_hash')
        self.assertEqual(file_id_4_22.owner_id,
                         file_id_4_30.owner_id,
                         msg='4.22->4.30: owner_id')
 def test_06(self):
     file_id = FileId.from_file_id(
         'DQACAgEAAxkBAAEDwpNfQqMoig8g_nGkspL1ZGZ0mIQwYQACdgAD7HrwRIhNNhRczBGAGwQ'
     )
    def test_other_impl(self):
        false = False
        true = True
        null = None

        test_data = {
            'CAADBAADwwADmFmqDf6xBrPTReqHFgQ': {
                "version": 4,
                "subVersion": 22,
                "typeId": 8,
                "dc_id": 4,
                "hasReference": false,
                "hasWebLocation": false,
                "type": "sticker",
                "id": 984697977903775939,
                "access_hash": -8653026958495010306
            },
            'CAACAgQAAxkBAAIC4l9CWDGzVUcDejU0TETLWbOdfsCoAALDAAOYWaoN_rEGs9NF6ocbBA':
            {
                "version": 4,
                "subVersion": 27,
                "typeId": 8,
                "dc_id": 4,
                "hasReference": true,
                "hasWebLocation": false,
                "type": "sticker",
                "fileReference":
                "01000002e25f425831b35547037a35344c44cb59b39d7ec0a8",
                "id": 984697977903775939,
                "access_hash": -8653026958495010306
            },
            'CAADBAADwwADmFmqDf6xBrPTReqHAg': {
                "version": 2,
                "subVersion": 0,
                "typeId": 8,
                "dc_id": 4,
                "hasReference": false,
                "hasWebLocation": false,
                "type": "sticker",
                "id": 984697977903775939,
                "access_hash": -8653026958495010306
            },
            'CAADAgAD8wkAAgKLowABpAz7kZfM7jcC': {
                "version": 2,
                "subVersion": 0,
                "typeId": 8,
                "dc_id": 2,
                "hasReference": false,
                "hasWebLocation": false,
                "type": "sticker",
                "id": 46033261910034931,
                "access_hash": 4030383667904449700
            },
            'CAACAgIAAxkBAAIBGV9DozZKicI-6IkNYlzxMUPaNnwBAALzCQACAoujAAGkDPuRl8zuNxsE':
            {
                "version": 4,
                "subVersion": 27,
                "typeId": 8,
                "dc_id": 2,
                "hasReference": true,
                "hasWebLocation": false,
                "type": "sticker",
                "fileReference":
                "01000001195f43a3364a89c23ee8890d625cf13143da367c01",
                "id": 46033261910034931,
                "access_hash": 4030383667904449700
            },
            'BQADAgAD3AkAAgKLowABKlAd1pemg-gC': {
                "version": 2,
                "subVersion": 0,
                "typeId": 5,
                "dc_id": 2,
                "hasReference": false,
                "hasWebLocation": false,
                "type": "document",
                "id": 46033261910034908,
                "access_hash": -1692325863898656726
            },
            'CAACAgIAAxkBAAIEVF9Do80olppb0490gLH2I1cszuoMAALcCQACAoujAAEqUB3Wl6aD6BsE':
            {
                "version": 4,
                "subVersion": 27,
                "typeId": 8,
                "dc_id": 2,
                "hasReference": true,
                "hasWebLocation": false,
                "type": "sticker",
                "fileReference":
                "01000004545f43a3cd28969a5bd38f7480b1f623572cceea0c",
                "id": 46033261910034908,
                "access_hash": -1692325863898656726
            },
            'CAADAgADIwYAAmpiTwttSWWW_Tc0aQI': {
                "version": 2,
                "subVersion": 0,
                "typeId": 8,
                "dc_id": 2,
                "hasReference": false,
                "hasWebLocation": false,
                "type": "sticker",
                "id": 814978264983406115,
                "access_hash": 7580745635060861293
            },
            'CAACAgIAAxkBAAIEVl9DpKV6azEUxxqd204SZQzixxO0AAIjBgACamJPC21JZZb9NzRpGwQ':
            {
                "version": 4,
                "subVersion": 27,
                "typeId": 8,
                "dc_id": 2,
                "hasReference": true,
                "hasWebLocation": false,
                "type": "sticker",
                "fileReference":
                "01000004565f43a4a57a6b3114c71a9ddb4e12650ce2c713b4",
                "id": 814978264983406115,
                "access_hash": 7580745635060861293
            },
        }
        for file_id, expected in test_data.items():
            obj = FileId.from_file_id(file_id)
            self.assertIsInstance(obj, FileId, msg=f'file_id = {file_id!r}')
            self.assertIsInstance(obj,
                                  DocumentFileId,
                                  msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('version'),
                             obj.version,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('subVersion'),
                             obj.sub_version,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('typeId'),
                             obj.type_id,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('type'),
                             obj.type_detailed,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('dc_id'),
                             obj.dc_id,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('hasReference'),
                             obj.has_reference,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('hasWebLocation'),
                             obj.has_web_location,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('id'),
                             obj.id,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(expected.pop('access_hash', None),
                             obj.access_hash,
                             msg=f'file_id = {file_id!r}')
            self.assertEqual(
                to_binary(expected.pop('fileReference', b'')),
                encode((obj.file_reference if obj.file_reference else b''),
                       'hex'),
                msg=f'file_id = {file_id!r}')
            self.assertEqual(
                {},
                expected,
                msg=f'file_id = {file_id!r} - array shall be empty now.')
 def test_11(self):
     file_id = FileId.from_file_id(
         'AgADAQADP7UxG8teKQICXFeh7eXaDtYD3ikABER9JkFQSzXqS6oAAgI')
 def test_08(self):
     file_id = FileId.from_file_id('CQADBAAD-AADc7jIUkFI8kwZnWFDAg')
 def test_12(self):
     file_id = FileId.from_file_id('CAADBAAD2AADfDCoCh1TJEHYmiHfAg')
     self.assertEqual(file_id.type_id, file_id.TYPE_STICKER,
                      'type is sticker')
 def test_v4_before2020(self):
     file_id = FileId.from_file_id('CAADBAADwwADmFmqDf6xBrPTReqHFgQ')
     self.assertEqual(file_id.type_id, file_id.TYPE_STICKER,
                      'type is sticker')
     self.assertEqual('document', file_id.type_generic)
     self.assertEqual(file_id.type_detailed, 'sticker', 'type is sticker')
 def test_13(self):
     file_id = FileId.from_file_id('BAADBAADAgADpCP6CbTQbvd25YqQAg')
 def test_04(self):
     file_id = FileId.from_file_id('AwADBAADcwMAAhE1WFMeQwq5P_t28gI')
 def test_10(self):
     file_id = FileId.from_file_id(
         'AgADBAADmK8xG5B8CVLPkd0jIGgFvmsRHxsABOpZnaBmJdfAI2wFAAEC')
 def test_05(self):
     file_id = FileId.from_file_id('DQADAQADdgAD7HrwRIhNNhRczBGAAg')
 def test_01(self):
     file_id = FileId.from_file_id(
         'AgADBAAD_a4xG5EpaFJ9trmvgJ_jKUAtoBoABDqqHjBWUjhBIgkBAAEC')
 def test_07(self):
     file_id = FileId.from_file_id('CgADBAADIaEAAqobZAfVqgLO2giGbAI')
 def test_sticker_2018_nov(self):
     file_id = FileId.from_file_id('CAADAgAD8wkAAgKLowABpAz7kZfM7jcC'
                                   )  # test4458pack, the bigger Test one.
     self.assertEqual(file_id.type_id, file_id.TYPE_STICKER,
                      'type is sticker')
     self.assertEqual(2, file_id.version)
 def test_09(self):
     file_id = FileId.from_file_id(
         'AgADBAADb6kxGzVD2VJxFZJnnojLocawuxkABCpho4S-bEPOrboCAAEC')
Beispiel #30
0
    def test_get_chat_picture_supergroup(self):
        try:
            from pytgbot import Bot
        except ImportError:
            return self.fail('pytgbot dependency missing')
        # end try

        if not API_KEY:
            return self.fail('API_KEY not set')
        # end if
        if not SUPERGROUP_ID:
            return self.fail('SUPERGROUP_ID not set')
        # end if

        bot = Bot(API_KEY)

        chat = bot.get_chat(chat_id=SUPERGROUP_ID)
        print(repr(chat))
        if not chat.photo:
            return self.skipTest('Test chat has no picture')
        # end if

        # big picture

        big_file = FileId.from_file_id(
            chat.photo.big_file_id
        )  # 'AQADAgATqfDdly4AAwMAA4siCOX_____AAhKowIAAR4E'

        big_file_unique_id = FileUniqueId.from_file_id(
            chat.photo.big_file_id).to_unique_id()
        self.assertEqual(chat.photo.big_file_unique_id, big_file_unique_id)

        self.assertEqual(FileId.TYPE_PROFILE_PHOTO, big_file.type_id)
        self.assertEqual('profile picture', big_file.type_detailed)
        self.assertEqual('photo', big_file.type_generic)
        self.assertEqual(big_file.version, FileId.MAX_VERSION[0],
                         'sticker should be supported max (sub_)version')
        self.assertEqual(big_file.sub_version, FileId.MAX_VERSION[1],
                         'sticker should be supported max (sub_)version')
        self.assertEqual(0, big_file.id)
        self.assertEqual(0, big_file.access_hash)
        self.assertEqual(False, big_file.has_reference)
        self.assertEqual(False, big_file.has_web_location)

        self.assertIsInstance(big_file.photosize, PhotoFileId.PhotosizeSource)
        # self.assertEqual(200116400297, big_file.photosize.volume_id)
        # self.assertEqual(172874, big_file.photosize.location_local_id)

        self.assertEqual(PhotoFileId.PHOTOSIZE_SOURCE_DIALOGPHOTO_BIG,
                         big_file.photosize.type_id)
        self.assertIsInstance(big_file.photosize,
                              PhotoFileId.PhotosizeSourceDialogPhotoBig)
        self.assertEqual(SUPERGROUP_ID, big_file.photosize.dialog_id)
        self.assertNotEqual(0, big_file.photosize.dialog_access_hash)

        # small picture

        small_file = FileId.from_file_id(
            chat.photo.small_file_id
        )  # 'AQADAgATqfDdly4AAwIAA4siCOX_____AAhIowIAAR4E'
        small_file_unique_id = FileUniqueId.from_file_id(
            chat.photo.small_file_id).to_unique_id()
        self.assertEqual(chat.photo.small_file_unique_id, small_file_unique_id)

        self.assertEqual(FileId.TYPE_PROFILE_PHOTO, small_file.type_id)
        self.assertEqual(big_file.type_detailed, small_file.type_detailed)
        self.assertEqual(big_file.type_generic, small_file.type_generic)
        self.assertEqual(big_file.version, small_file.version)
        self.assertEqual(big_file.sub_version, small_file.sub_version)
        self.assertEqual(big_file.id, small_file.id)
        self.assertEqual(big_file.access_hash, small_file.access_hash)
        self.assertEqual(big_file.has_reference, small_file.has_reference)
        self.assertEqual(big_file.has_web_location,
                         small_file.has_web_location)

        self.assertIsInstance(small_file.photosize,
                              PhotoFileId.PhotosizeSource)
        self.assertEqual(big_file.photosize.volume_id,
                         small_file.photosize.volume_id)
        # self.assertEqual(172872, small_file.photosize.location_local_id)

        self.assertEqual(PhotoFileId.PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL,
                         small_file.photosize.type_id)
        self.assertIsInstance(small_file.photosize,
                              PhotoFileId.PhotosizeSourceDialogPhotoSmall)
        self.assertEqual(SUPERGROUP_ID, small_file.photosize.dialog_id)
        self.assertEqual(big_file.photosize.dialog_access_hash,
                         small_file.photosize.dialog_access_hash)