Example #1
0
    def test_read_json_extended(self):
        '''It should read in json with extended info'''

        s = (b'{'
            b'"!":"BytestagCollectionInfo",'
            b'"comment":"hello",'
            b'"files":['
                b'{'
                b'"!":"BytestagFileInfo",'
                b'"hash":"jbip9t8iC9lEz3jndkm5I2fTWV0=",'
                b'"parts":["jbip9t8iC9lEz3jndkm5I2fTWV0="]'
                b'}'
            b'],'
            b'"name":"my video",'
            b'"timestamp":123456789'
        b'}')

        info = CollectionInfo.from_bytes(s)

        self.assertIsInstance(info.file_infos[0], FileInfo)
        self.assertEqual(info.comment, 'hello')
        self.assertEqual(info.name, 'my video')
        self.assertEqual(info.timestamp, 123456789)

        result_bytes = info.to_bytes()

        self.assertEqual(s, result_bytes)
Example #2
0
    def _get_collection_type(self, path):
        cookie_len = len(CollectionInfo.SIGNATURE)

        with open(path, 'rb') as f:
            data = f.read(cookie_len)

            if CollectionInfo.is_valid_signature(data):
                return CollectionInfoTypes.BYTESTAG

            if path.endswith('.torrent'):
                f.seek(0)

                if BitTorrentInfoFile.is_valid_signature(f.read(1024)):
                    return CollectionInfoTypes.BITTORRENT
Example #3
0
    def test_read_json(self):
        '''It should read in json with basic info'''

        s = (b'{'
            b'"!":"BytestagCollectionInfo",'
            b'"files":['
                b'{'
                b'"!":"BytestagFileInfo",'
                b'"hash":"jbip9t8iC9lEz3jndkm5I2fTWV0=",'
                b'"parts":["jbip9t8iC9lEz3jndkm5I2fTWV0="]'
                b'}'
            b']'
        b'}')

        info = CollectionInfo.from_bytes(s)

        self.assertIsInstance(info.file_infos[0], FileInfo)

        result_bytes = info.to_bytes()

        self.assertEqual(s, result_bytes)