2016-07-27 19:05:29 +02:00
|
|
|
import mock
|
|
|
|
from lbrynet.core import LBRYMetadata
|
|
|
|
|
|
|
|
from twisted.trial import unittest
|
|
|
|
|
|
|
|
|
|
|
|
class LBRYFeeFormatTest(unittest.TestCase):
|
|
|
|
def test_fee_created_with_correct_inputs(self):
|
|
|
|
fee_dict = {
|
|
|
|
'USD': {
|
2016-07-28 08:30:37 +02:00
|
|
|
'amount': 10.0,
|
|
|
|
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
2016-07-27 19:05:29 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-28 08:19:45 +02:00
|
|
|
fee = LBRYMetadata.LBRYFeeValidator(fee_dict)
|
2016-07-28 08:30:37 +02:00
|
|
|
self.assertEqual(10.0, fee['USD']['amount'])
|
2016-07-27 19:05:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
class LBRYFeeTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.patcher = mock.patch('time.time')
|
|
|
|
self.time = self.patcher.start()
|
|
|
|
self.time.return_value = 0
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.time.stop()
|
|
|
|
|
|
|
|
def test_fee_converts_to_lbc(self):
|
|
|
|
fee_dict = {
|
|
|
|
'USD': {
|
2016-07-28 08:30:37 +02:00
|
|
|
'amount': 10.0,
|
|
|
|
'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
2016-07-27 19:05:29 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-28 08:30:37 +02:00
|
|
|
rates = {'BTCLBC': {'spot': 3.0, 'ts': 2}, 'USDBTC': {'spot': 2.0, 'ts': 3}}
|
2016-07-27 19:05:29 +02:00
|
|
|
fee = LBRYMetadata.LBRYFee(fee_dict, rates, 0)
|
2016-07-28 08:30:37 +02:00
|
|
|
self.assertEqual(60.0, fee.to_lbc())
|
2016-07-27 19:05:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MetadataTest(unittest.TestCase):
|
|
|
|
def test_assertion_if_source_is_missing(self):
|
|
|
|
metadata = {}
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
LBRYMetadata.Metadata(metadata)
|
|
|
|
|
|
|
|
def test_assertion_if_invalid_source(self):
|
|
|
|
metadata = {
|
|
|
|
'sources': {'garbage': None}
|
|
|
|
}
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
LBRYMetadata.Metadata(metadata)
|
|
|
|
|
|
|
|
def test_assertion_if_missing_v001_field(self):
|
|
|
|
metadata = {
|
|
|
|
'sources': [],
|
|
|
|
}
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
LBRYMetadata.Metadata(metadata)
|
|
|
|
|
|
|
|
def test_version_is_001_if_all_fields_are_present(self):
|
|
|
|
metadata = {
|
|
|
|
'sources': [],
|
|
|
|
'title': None,
|
|
|
|
'description': None,
|
|
|
|
'author': None,
|
|
|
|
'language': None,
|
|
|
|
'license': None,
|
|
|
|
'content-type': None,
|
|
|
|
}
|
|
|
|
m = LBRYMetadata.Metadata(metadata)
|
2016-07-28 08:19:45 +02:00
|
|
|
self.assertEquals('0.0.1', m.meta_version)
|
2016-07-27 19:05:29 +02:00
|
|
|
|
|
|
|
def test_assertion_if_there_is_an_extra_field(self):
|
|
|
|
metadata = {
|
|
|
|
'sources': [],
|
|
|
|
'title': None,
|
|
|
|
'description': None,
|
|
|
|
'author': None,
|
|
|
|
'language': None,
|
|
|
|
'license': None,
|
|
|
|
'content-type': None,
|
|
|
|
'extra': None
|
|
|
|
}
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
LBRYMetadata.Metadata(metadata)
|
|
|
|
|
|
|
|
def test_version_is_002_if_all_fields_are_present(self):
|
|
|
|
metadata = {
|
|
|
|
'sources': [],
|
|
|
|
'title': None,
|
|
|
|
'description': None,
|
|
|
|
'author': None,
|
|
|
|
'language': None,
|
|
|
|
'license': None,
|
|
|
|
'content-type': None,
|
|
|
|
'nsfw': None,
|
|
|
|
'ver': None
|
|
|
|
}
|
|
|
|
m = LBRYMetadata.Metadata(metadata)
|
2016-07-28 08:19:45 +02:00
|
|
|
self.assertEquals('0.0.2', m.meta_version)
|
2016-07-27 19:05:29 +02:00
|
|
|
|
|
|
|
|