def test_source_should_encode_full(self): source = Source('the_source', 'The Source') source.author = 'The Author' source.publisher = 'The Publisher' source.date = Date(2000, 1, 1) source.contained_by = Source('the_containing_source', 'The Containing Source') source.links.add( Link('https://example.com/the-person', 'The Person Online')) source.contains.append( Source('the_contained_source', 'The Contained Source')) source.citations.append( Citation('the_citation', Source('the_source', 'The Source'))) expected = { '$schema': '/schema.json#/definitions/source', '@context': { 'name': 'https://schema.org/name', }, '@type': 'https://schema.org/Thing', 'id': 'the_source', 'name': 'The Source', 'author': 'The Author', 'publisher': 'The Publisher', 'contains': [ '/source/the_contained_source/index.json', ], 'citations': [ '/citation/the_citation/index.json', ], 'containedBy': '/source/the_containing_source/index.json', 'date': { 'year': 2000, 'month': 1, 'day': 1, }, 'links': [ { 'url': 'https://example.com/the-person', 'label': 'The Person Online', }, ], } self.assert_encodes(expected, source, 'source')
def _parse_source(ancestry: _IntermediateAncestry, element: Element) -> None: handle = _xpath1(element, './@handle') source = Source(_xpath1(element, './@id'), _xpath1(element, './ns:stitle').text) repository_source_handle = _xpath1(element, './ns:reporef/@hlink') if repository_source_handle is not None: source.contained_by = ancestry.sources[repository_source_handle] # Parse the author. sauthor_element = _xpath1(element, './ns:sauthor') if sauthor_element is not None: source.author = sauthor_element.text # Parse the publication info. spubinfo_element = _xpath1(element, './ns:spubinfo') if spubinfo_element is not None: source.publisher = spubinfo_element.text _parse_objref(ancestry, source, element) _parse_attribute_privacy(source, element) ancestry.sources[handle] = source
def test_author(self) -> None: sut = Source() self.assertIsNone(sut.author) author = 'Me' sut.author = author self.assertEquals(author, sut.author)