def test_add_figure(): schema = load_schema('hep') subschema = schema['properties']['figures'] builder = LiteratureBuilder('test') builder.add_figure( 'key', caption='caption', label='label', material='publication', source='source', url='url', ) expected = [ { 'caption': 'caption', 'key': 'key', 'label': 'label', 'material': 'publication', 'source': 'source', 'url': 'url', }, ] result = builder.record assert validate(result['figures'], subschema) is None assert expected == result['figures'] for key in subschema['items']['properties'].keys(): assert key in result['figures'][0]
def test_add_figure_inspire_next(): schema = load_schema('hep') subschema = schema['properties']['figures'] builder = LiteratureBuilder('test') builder.add_figure( 'key', caption='caption', label='label', material='publication', source='source', url='url', description='description', original_url='http://www.example.com/original_url' ) expected = [ { 'caption': 'caption', 'key': 'key', 'label': 'label', 'material': 'publication', 'source': 'source', 'url': 'url', 'original_url': 'http://www.example.com/original_url' }, ] result = builder.record assert validate(result['figures'], subschema) is None assert expected == result['figures']
def test_add_figure_fails_on_duplicated_key(): builder = LiteratureBuilder('test') builder.add_figure( 'key', caption='caption', label='label', material='publication', source='source', url='url', description='description', filename='filename', original_ur='original_url' ) with pytest.raises(ValueError): builder.add_figure( 'key', caption='caption', label='label', material='publication', source='source', url='url', description='description', filename='filename', original_ur='original_url' )
def test_add_figure_fails_on_non_file_api_relative_url(): schema = load_schema('hep') subschema = schema['properties']['figures'] builder = LiteratureBuilder('test') with pytest.raises(ValidationError): builder.add_figure( 'key', caption='caption', label='label', material='publication', source='source', url='/not/api/url/for/files', description='description', original_url='http://www.example.com/original_url' ) result = builder.record validate(result['figures'], subschema)
def test_add_figure_fails_on_duplicated_key(): builder = LiteratureBuilder('test') builder.add_figure( 'key', caption='caption', label='label', material='publication', source='source', url='url', ) with pytest.raises(ValueError): builder.add_figure( 'key', caption='caption', label='label', material='publication', source='source', url='url', )