def test_packDataWithSubs(self): badInfohash = str2bin("GEh/o8rtTLB1wZJzFcSZSS4u9qo=") dto = MetadataDTO(test_perm_id, badInfohash) subtitles = [ SubtitleInfo(lang, path) for lang, path in self._srtSubs.iteritems() ] for sub in subtitles: sub.computeChecksum() dto.addSubtitle(sub) packed = dto._packData() decoded = bdecode(packed) self.assertTrue(len(decoded) == 6) decodedChannelId = decoded[0] decodedInfohash = decoded[1] decodedDescription = decoded[2] decodedTimestamp = decoded[3] decodedBitmask = decoded[4] checksums = decoded[5] expectedMask = \ LanguagesProvider.getLanguagesInstance().langCodesToMask(self._srtSubs.keys()) binaryExpexted = pack("!L", expectedMask) self.assertEquals(dto.channel, decodedChannelId) self.assertEquals(dto.infohash, decodedInfohash) self.assertEquals(dto.description, decodedDescription) self.assertAlmostEquals(dto.timestamp, decodedTimestamp) self.assertEquals(binaryExpexted, decodedBitmask) self.assertEquals(3, len(checksums)) subs = dto.getAllSubtitles() i = 0 for key in sorted(subs.iterkeys()): self.assertEquals(subs[key].checksum, checksums[i]) i += 1
def test_packData(self): badInfohash = str2bin("GEh/o8rtTLB1wZJzFcSZSS4u9qo=") dto = MetadataDTO(test_perm_id, badInfohash) dto.description = u"Sample Description\u041f" bla = dto._packData() decoded = bdecode(bla) self.assertTrue(len(decoded) == 6) decodedChannelId = decoded[0] decodedInfohash = decoded[1] decodedDescription = decoded[2].decode("utf-8") decodedTimestamp = decoded[3] bin_decodedBitmask = decoded[4] decodedBitmask, = unpack("!L", bin_decodedBitmask) self.assertEquals(dto.channel, decodedChannelId) self.assertEquals(dto.infohash, decodedInfohash) self.assertEquals(dto.description, decodedDescription) self.assertAlmostEquals(dto.timestamp, decodedTimestamp) self.assertEquals(0, decodedBitmask) self.assertEquals(0, len(decoded[5]))
def test_packDataWithSubs(self): badInfohash = str2bin("GEh/o8rtTLB1wZJzFcSZSS4u9qo=") dto = MetadataDTO(test_perm_id, badInfohash) subtitles = [SubtitleInfo(lang,path) for lang,path in self._srtSubs.iteritems()] for sub in subtitles : sub.computeChecksum() dto.addSubtitle(sub) packed = dto._packData() decoded = bdecode(packed) self.assertTrue(len(decoded) == 6) decodedChannelId = decoded[0] decodedInfohash = decoded[1] decodedDescription = decoded[2] decodedTimestamp = decoded[3] decodedBitmask = decoded[4] checksums = decoded[5] expectedMask = \ LanguagesProvider.getLanguagesInstance().langCodesToMask(self._srtSubs.keys()) binaryExpexted = pack("!L", expectedMask) self.assertEquals(dto.channel, decodedChannelId) self.assertEquals(dto.infohash, decodedInfohash) self.assertEquals(dto.description,decodedDescription) self.assertAlmostEquals(dto.timestamp,decodedTimestamp) self.assertEquals(binaryExpexted,decodedBitmask) self.assertEquals(3,len(checksums)) subs = dto.getAllSubtitles() i=0 for key in sorted(subs.iterkeys()): self.assertEquals(subs[key].checksum, checksums[i]) i += 1