def test_note_should_encode_minimal(self): note = Note('the_note', 'The Note') expected = { '$schema': '/schema.json#/definitions/note', '@type': 'https://schema.org/Thing', 'id': 'the_note', 'text': 'The Note', } self.assert_encodes(expected, note, 'note')
def test_file_should_encode_full(self): with NamedTemporaryFile() as f: file = File('the_file', f.name) file.type = 'text/plain' file.notes.append(Note('The Note')) Person('the_person').files.append(file) expected = { '$schema': '/schema.json#/definitions/file', 'id': 'the_file', 'type': 'text/plain', 'entities': [ '/person/the_person/index.json', ], 'notes': [ { 'text': 'The Note', }, ], } self.assert_encodes(expected, file, 'file')
def test_file_should_encode_full(self): with NamedTemporaryFile() as f: note = Note('the_note', 'The Note') file = File('the_file', f.name) file.media_type = MediaType('text/plain') file.notes.append(note) Person('the_person').files.append(file) expected = { '$schema': '/schema.json#/definitions/file', 'id': 'the_file', 'mediaType': 'text/plain', 'resources': [ '/en/person/the_person/index.json', ], 'notes': [ '/en/note/the_note/index.json', ], 'links': [ { 'url': '/en/file/the_file/index.json', 'relationship': 'canonical', 'mediaType': 'application/json', }, { 'url': '/nl/file/the_file/index.json', 'relationship': 'alternate', 'locale': 'nl-NL', }, { 'url': '/en/file/the_file/index.html', 'relationship': 'alternate', 'mediaType': 'text/html', }, ], } self.assert_encodes(expected, file, 'file')
def test_text(self) -> None: text = 'Betty wrote this.' sut = Note('N1', text) self.assertEquals(text, sut.text)
def test_id(self) -> None: note_id = 'N1' sut = Note(note_id, 'Betty wrote this.') self.assertEquals(note_id, sut.id)
def test_text(self): text = 'Betty wrote this.' sut = Note(text) self.assertEquals(text, sut.text)
def _load_note(loader: _Loader, element: ElementTree.Element): handle = element.get('handle') note_id = element.get('id') text = _xpath1(element, './ns:text').text loader._notes[handle] = Note(note_id, text)
def _parse_note(ancestry: _IntermediateAncestry, element: Element): handle = _xpath1(element, './@handle') text = _xpath1(element, './ns:text/text()') ancestry.notes[handle] = Note(text)