def testDesrialize(self): badInfohash = str2bin("GEh/o8rtTLB1wZJzFcSZSS4u9qo=") dto = MetadataDTO(test_perm_id, badInfohash) dto.description = u"Sample Description" dto.sign(test_keypair) serialized = dto.serialize() newDto = MDUtil.deserialize(serialized) self.assertEquals(dto, newDto)
def testDesrialize(self): badInfohash = str2bin("GEh/o8rtTLB1wZJzFcSZSS4u9qo=") dto = MetadataDTO(test_perm_id, badInfohash) dto.description = u"Sample Description" dto.sign(test_keypair) serialized = dto.serialize() newDto = MDUtil.deserialize(serialized) self.assertEquals(dto, newDto)
def testSerialize(self): badInfohash = str2bin("GEh/o8rtTLB1wZJzFcSZSS4u9qo=") dto = MetadataDTO(test_perm_id, badInfohash) dto.description = u"Sample Description" dto.sign(test_keypair) serialized = dto.serialize() self.assertEquals(7, len(serialized)) signature = serialized[6] self.assertEquals(dto.signature, signature)
def testSerialize(self): badInfohash = str2bin("GEh/o8rtTLB1wZJzFcSZSS4u9qo=") dto = MetadataDTO(test_perm_id, badInfohash) dto.description = u"Sample Description" dto.sign(test_keypair) serialized = dto.serialize() self.assertEquals(7, len(serialized)) signature = serialized[6] self.assertEquals(dto.signature, signature)
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_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]))