2016-07-20 19:00:34 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-11-07 21:15:05 +01:00
|
|
|
from lbrynet import utils
|
2016-07-26 16:34:00 +02:00
|
|
|
|
|
|
|
from twisted.trial import unittest
|
|
|
|
|
|
|
|
|
|
|
|
class CompareVersionTest(unittest.TestCase):
|
|
|
|
def test_compare_versions_isnot_lexographic(self):
|
|
|
|
self.assertTrue(utils.version_is_greater_than('0.3.10', '0.3.6'))
|
|
|
|
|
|
|
|
def test_same_versions_return_false(self):
|
|
|
|
self.assertFalse(utils.version_is_greater_than('1.3.9', '1.3.9'))
|
|
|
|
|
|
|
|
def test_same_release_is_greater_then_beta(self):
|
|
|
|
self.assertTrue(utils.version_is_greater_than('1.3.9', '1.3.9b1'))
|
|
|
|
|
|
|
|
def test_version_can_have_four_parts(self):
|
|
|
|
self.assertTrue(utils.version_is_greater_than('1.3.9.1', '1.3.9'))
|
2016-07-20 19:00:34 +02:00
|
|
|
|
2016-11-19 23:58:40 +01:00
|
|
|
def test_release_is_greater_than_rc(self):
|
|
|
|
self.assertTrue(utils.version_is_greater_than('1.3.9', '1.3.9rc0'))
|
|
|
|
|
2016-07-20 19:00:34 +02:00
|
|
|
|
|
|
|
class ObfuscationTest(unittest.TestCase):
|
|
|
|
def test_deobfuscation_reverses_obfuscation(self):
|
2018-10-18 23:53:16 +02:00
|
|
|
plain = "my_test_string"
|
|
|
|
obf = utils.obfuscate(plain.encode())
|
2016-07-20 19:00:34 +02:00
|
|
|
self.assertEqual(plain, utils.deobfuscate(obf))
|
|
|
|
|
|
|
|
def test_can_use_unicode(self):
|
2018-10-18 23:53:16 +02:00
|
|
|
plain = '☃'
|
|
|
|
obf = utils.obfuscate(plain.encode())
|
2016-07-20 19:00:34 +02:00
|
|
|
self.assertEqual(plain, utils.deobfuscate(obf))
|
2018-02-04 05:08:15 +01:00
|
|
|
|
|
|
|
|
2018-02-06 07:16:10 +01:00
|
|
|
class SdHashTests(unittest.TestCase):
|
2018-02-04 05:08:15 +01:00
|
|
|
|
2018-02-06 07:16:10 +01:00
|
|
|
def test_none_in_none_out(self):
|
|
|
|
self.assertIsNone(utils.get_sd_hash(None))
|
2018-02-04 05:08:15 +01:00
|
|
|
|
2018-02-06 07:16:10 +01:00
|
|
|
def test_ordinary_dict(self):
|
|
|
|
claim = {
|
|
|
|
"claim": {
|
|
|
|
"value": {
|
|
|
|
"stream": {
|
|
|
|
"source": {
|
|
|
|
"source": "0123456789ABCDEF"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-04 05:08:15 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-06 07:16:10 +01:00
|
|
|
self.assertEqual("0123456789ABCDEF", utils.get_sd_hash(claim))
|
2018-02-04 05:08:15 +01:00
|
|
|
|
2018-02-06 07:16:10 +01:00
|
|
|
def test_old_shape_fails(self):
|
|
|
|
claim = {
|
|
|
|
"stream": {
|
|
|
|
"source": {
|
|
|
|
"source": "0123456789ABCDEF"
|
|
|
|
}
|
2018-02-04 05:08:15 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-06 07:16:10 +01:00
|
|
|
self.assertIsNone(utils.get_sd_hash(claim))
|