forked from LBRYCommunity/lbry-sdk
Tests for new JSON Schema system
This commit is contained in:
parent
d8d462f43c
commit
9cf1d6b710
1 changed files with 21 additions and 21 deletions
|
@ -1,14 +1,14 @@
|
|||
from lbrynet.metadata import Metadata
|
||||
from twisted.trial import unittest
|
||||
|
||||
from jsonschema import ValidationError
|
||||
|
||||
class MetadataTest(unittest.TestCase):
|
||||
def test_assertion_if_no_metadata(self):
|
||||
def test_validation_error_if_no_metadata(self):
|
||||
metadata = {}
|
||||
with self.assertRaises(AssertionError):
|
||||
with self.assertRaises(ValidationError):
|
||||
Metadata.Metadata(metadata)
|
||||
|
||||
def test_assertion_if_source_is_missing(self):
|
||||
def test_validation_error_if_source_is_missing(self):
|
||||
metadata = {
|
||||
'license': 'Oscilloscope Laboratories',
|
||||
'description': 'Four couples meet for Sunday brunch only to discover they are stuck in a house together as the world may be about to end.',
|
||||
|
@ -18,7 +18,7 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'audio/mpeg',
|
||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
||||
}
|
||||
with self.assertRaises(AssertionError):
|
||||
with self.assertRaises(ValidationError):
|
||||
Metadata.Metadata(metadata)
|
||||
|
||||
def test_metadata_works_without_fee(self):
|
||||
|
@ -36,7 +36,7 @@ class MetadataTest(unittest.TestCase):
|
|||
m = Metadata.Metadata(metadata)
|
||||
self.assertFalse('fee' in m)
|
||||
|
||||
def test_assertion_if_invalid_source(self):
|
||||
def test_validation_error_if_invalid_source(self):
|
||||
metadata = {
|
||||
'license': 'Oscilloscope Laboratories',
|
||||
'description': 'Four couples meet for Sunday brunch only to discover they are stuck in a house together as the world may be about to end.',
|
||||
|
@ -48,10 +48,10 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'audio/mpeg',
|
||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
||||
}
|
||||
with self.assertRaises(AssertionError):
|
||||
with self.assertRaises(ValidationError):
|
||||
Metadata.Metadata(metadata)
|
||||
|
||||
def test_assertion_if_missing_v001_field(self):
|
||||
def test_validation_error_if_missing_v001_field(self):
|
||||
metadata = {
|
||||
'license': 'Oscilloscope Laboratories',
|
||||
'fee': {'LBC': {'amount': 50.0, 'address': 'bRQJASJrDbFZVAvcpv3NoNWoH74LQd5JNV'}},
|
||||
|
@ -63,7 +63,7 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'audio/mpeg',
|
||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg'
|
||||
}
|
||||
with self.assertRaises(AssertionError):
|
||||
with self.assertRaises(ValidationError):
|
||||
Metadata.Metadata(metadata)
|
||||
|
||||
def test_version_is_001_if_all_fields_are_present(self):
|
||||
|
@ -78,10 +78,10 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'audio/mpeg',
|
||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
||||
}
|
||||
m = Metadata.Metadata(metadata, process_now=False)
|
||||
m = Metadata.Metadata(metadata, migrate=False)
|
||||
self.assertEquals('0.0.1', m.version)
|
||||
|
||||
def test_assertion_if_there_is_an_extra_field(self):
|
||||
def test_validation_error_if_there_is_an_extra_field(self):
|
||||
metadata = {
|
||||
'license': 'Oscilloscope Laboratories',
|
||||
'description': 'Four couples meet for Sunday brunch only to discover they are stuck in a house together as the world may be about to end.',
|
||||
|
@ -94,8 +94,8 @@ class MetadataTest(unittest.TestCase):
|
|||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
||||
'MYSTERYFIELD': '?'
|
||||
}
|
||||
with self.assertRaises(AssertionError):
|
||||
Metadata.Metadata(metadata, process_now=False)
|
||||
with self.assertRaises(ValidationError):
|
||||
Metadata.Metadata(metadata, migrate=False)
|
||||
|
||||
def test_version_is_002_if_all_fields_are_present(self):
|
||||
metadata = {
|
||||
|
@ -112,7 +112,7 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'video/mp4',
|
||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
||||
}
|
||||
m = Metadata.Metadata(metadata, process_now=False)
|
||||
m = Metadata.Metadata(metadata, migrate=False)
|
||||
self.assertEquals('0.0.2', m.version)
|
||||
|
||||
def test_version_is_003_if_all_fields_are_present(self):
|
||||
|
@ -130,7 +130,7 @@ class MetadataTest(unittest.TestCase):
|
|||
'content_type': 'video/mp4',
|
||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
||||
}
|
||||
m = Metadata.Metadata(metadata, process_now=False)
|
||||
m = Metadata.Metadata(metadata, migrate=False)
|
||||
self.assertEquals('0.0.3', m.version)
|
||||
|
||||
def test_version_claimed_is_001_but_version_is_002(self):
|
||||
|
@ -148,8 +148,8 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'video/mp4',
|
||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
||||
}
|
||||
with self.assertRaises(AssertionError):
|
||||
Metadata.Metadata(metadata, process_now=False)
|
||||
with self.assertRaises(ValidationError):
|
||||
Metadata.Metadata(metadata, migrate=False)
|
||||
|
||||
def test_version_claimed_is_002_but_version_is_003(self):
|
||||
metadata = {
|
||||
|
@ -166,8 +166,8 @@ class MetadataTest(unittest.TestCase):
|
|||
'content_type': 'video/mp4',
|
||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
||||
}
|
||||
with self.assertRaises(AssertionError):
|
||||
Metadata.Metadata(metadata, process_now=False)
|
||||
with self.assertRaises(ValidationError):
|
||||
Metadata.Metadata(metadata, migrate=False)
|
||||
|
||||
def test_version_001_ports_to_003(self):
|
||||
metadata = {
|
||||
|
@ -181,7 +181,7 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'audio/mpeg',
|
||||
'thumbnail': 'http://ia.media-imdb.com/images/M/MV5BMTQwNjYzMTQ0Ml5BMl5BanBnXkFtZTcwNDUzODM5Nw@@._V1_SY1000_CR0,0,673,1000_AL_.jpg',
|
||||
}
|
||||
m = Metadata.Metadata(metadata, process_now=True)
|
||||
m = Metadata.Metadata(metadata, migrate=True)
|
||||
self.assertEquals('0.0.3', m.version)
|
||||
|
||||
def test_version_002_ports_to_003(self):
|
||||
|
@ -199,5 +199,5 @@ class MetadataTest(unittest.TestCase):
|
|||
'content-type': 'video/mp4',
|
||||
'thumbnail': 'https://svs.gsfc.nasa.gov/vis/a010000/a012000/a012034/Combined.00_08_16_17.Still004.jpg'
|
||||
}
|
||||
m = Metadata.Metadata(metadata, process_now=True)
|
||||
m = Metadata.Metadata(metadata, migrate=True)
|
||||
self.assertEquals('0.0.3', m.version)
|
Loading…
Reference in a new issue