def test_tag(self):
        rsrc = Mock(spec=spotlight.DBpediaResource)

        # TEI
        # (doesn't actually matter what type of resource)
        self.assertEqual('name', self.tei_annotater.get_tag(rsrc))

        # EAD
        # - person
        rsrc.is_person = True
        self.assertEqual('persname', self.ead_annotater.get_tag(rsrc))
        # - corporate/organization
        rsrc.is_person = False
        rsrc.is_org = True
        self.assertEqual('corpname', self.ead_annotater.get_tag(rsrc))
        # - geographical/place name
        rsrc.is_org = False
        rsrc.is_place = True
        self.assertEqual('geogname', self.ead_annotater.get_tag(rsrc))

        # set current node to inherit namespace
        self.tei_annotater.current_node = self.tei.node
        self.ead_annotater.current_node = self.ead.node
        self.assertEqual('{%s}name' % TEI_NAMESPACE,
                         self.tei_annotater.get_tag(rsrc))
        self.assertEqual('{%s}geogname' % EAD_NAMESPACE,
                         self.ead_annotater.get_tag(rsrc))
    def test_attributes(self):
        rsrc = Mock(spec=spotlight.DBpediaResource)
        rsrc.uri = 'http://dbpedia.org/resource/TestResource'

        # TEI
        # - person
        rsrc.is_person = True
        attr = self.tei_annotater.get_attributes(rsrc)
        self.assertEqual(rsrc.uri, attr['ref'])
        self.assertEqual('person', attr['type'])
        # - corporate/organization
        rsrc.is_person = False
        rsrc.is_org = True
        self.assertEqual('org',
                         self.tei_annotater.get_attributes(rsrc)['type'])
        # - geographical/place name
        rsrc.is_org = False
        rsrc.is_place = True
        self.assertEqual('place',
                         self.tei_annotater.get_attributes(rsrc)['type'])

        # EAD
        # assume no viaf/geonames for now (viaf/geonames TODO)
        rsrc.viafid = None
        rsrc.viaf_uri = None
        rsrc.geonames_id = None
        self.assertEqual({'source': 'dbpedia',
                          'authfilenumber': 'TestResource'},
                         self.ead_annotater.get_attributes(rsrc))
    def test_is_insertable(self):
        rsrc = Mock(spec=spotlight.DBpediaResource)
        rsrc.uri = 'http://dbpedia.org/resource/TestResource'
        rsrc.is_person = False
        rsrc.is_place = False
        rsrc.is_org = False

        # EAD & tag could not be determined
        self.assertFalse(self.ead_annotater.is_insertable(rsrc, 'test'))

        # TEI and type attribute not set
        self.assertFalse(self.tei_annotater.is_insertable(rsrc, 'test'))

        # known type - should be ok for either
        rsrc.is_org = True
        self.assertTrue(self.ead_annotater.is_insertable(rsrc, 'test'))
        self.assertTrue(self.tei_annotater.is_insertable(rsrc, 'test'))