示例#1
0
 def test_read_write_states(self):    
     doc = BioDesDoc().from_xml(self.create_element())
     doc.add_or_update_state(type='floruit', frm="1900", to="1910", place='Zohar', place_id='1')
     state = doc.get_state(type='floruit')
     self.assertEqual(state.get('from'), '1900')
     self.assertEqual(state.get('to'), '1910')
     self.assertEqual(state.get('type'), 'floruit')
     self.assertEqual(state.find('place').text, 'Zohar')
     self.assertEqual(state.find('place').get('key'), '1')
     doc.add_or_update_state(type='floruit', place_id='', place='')
     self.assertEqual(state.find('place').get('key'), '')       
     states = doc.get_states(type='floruit')
     self.assertEqual(states, [state])
     
     doc.add_state(type='occupation', idno="1")
     self.assertEqual(len(states), 1)
     doc.add_state(type='occupation', idno="2")
     doc.add_state(type='occupation', idno="3")
     states = doc.get_states(type='occupation')
     self.assertEqual(len(states), 3)
     doc.remove_state(type='occupation', idx=1)
     states = doc.get_states(type='occupation')
     self.assertEqual(len(states), 2)
     self.assertEqual([s.get('idno') for s in states], ['1', '3'])
     
     #remove states by index number
     states = doc.get_states()
     some_state = states[1]
     some_index = some_state.getparent().index(some_state)
     doc.remove_state(idx= some_index)
     self.assertEqual(len(states)-1, len(doc.get_states()))
示例#2
0
    def test_create_some_samples(self, **args):
        #create a very simple file
        kw = {
            'url_biografie':'http://www.gerbrandy.com/bio',
            'url_publisher':'http://www.gerbrandy.com',
            'naam_publisher':'Website van Jelle',
            'titel_biografie':'Bio van Jelle',
            'naam':'Jelle Gerbrandy',
        }

        doc = BioDesDoc()
        doc.from_args(**kw)
        doc.to_file('biodes10_minimal.xml')

        #the most complex case includes everyting
        kw = {
            'bioport_id':'biodesid',   
            'url_biografie':'http://url_van_de_biografie',
            'url_publisher':'http://url_van_de_publisher',
            'titel_biografie':'titel van de biografie',
            'naam_publisher':'naam van depublisher',
#            'naam':'naam',
            'auteur':'auteur',
    #        'beroep':'beroep',
            'prepositie':'prepositie',
            'voornaam':'voornaam',
            'intrapositie':'intrapositie', 
            'geslachtsnaam': 'geslachtsnaam',
            'postpositie':'postpositie',
            'laatst_veranderd':'2009-11-11',   
            'publicatiedatum':'2009-11-11',
            'geboortedatum':'2009-11-11',
            'geboortedatum_tekst':'2009-11-11 in tekst',
            'geboorteplaats':'geboorteplaats',
            'sterfdatum':'2011-11-11',
            'sterfdatum_tekst':'sterfdatum_tekst',
            'sterfplaats':'sterfplaats',
            'geslacht':'1',
            'illustraties':['http://illustratie1.jpg', 'http://illustratie2.jpg'],
            'namen':['Naam1', ('mr.', 'Jan', 'van', 'Voorbeeld', 'Esq.')], 
            'namen_en':['John'],
            'tekst':'tekst van de biografie kan <em>Markup</em> <p>bevatten</p>', 
        }
        doc.from_args(**kw)
        doc._add_event(
            type='marriage',
            when='1901-12-12',
            text='getrouwd met marietje',
        )
        doc.add_state(
            type='occupation',
            frm='1940', 
            to='1960',
            text='schilder',
            )
        doc.add_state(
            type='residence',
            frm='1940', 
            to='1960',
            text='Amsterdam',
            )

        doc.add_state(
            type='claim_to_fame',
            text='Superbekende persoon!',
            )

        doc.add_state(
            type='occupation',
            frm='1940', 
            to='1960',
            text='schilder',
            place="Amsterdam",
            )
    
        doc.to_file('biodes10_maximal.xml')