Exemple #1
0
class TestDaoistProcessing(unittest.TestCase):

    def setUp(self):
        self.daoist = Daoist('shunk', 'test/fixtures/Shunk_handles_FAKE.csv',
            'test/fixtures/Shunk_ead_FAKE.xml', 'test_dir')
        self.daoist.load_handles()
        self.daoist.load_ead()
        self.test_node = self.daoist.src_root.xpath('//ead:c02[@id="ref18"]',
            namespaces=self.daoist.src_nsmap)[0]
        self.handle = {
            'title': 'Yves Klein, first experiments with "Living Brushes," ' +
                'Robert Godet\'s apartment, 9 rue Le-Regrattier, Île ' +
                'Saint-Louis, Paris',
            'handle': 'http://hdl.handle.net/10020/2014r20e0012'
        }

    def test_check_for_dupe(self):
        namespaces = self.daoist.src_nsmap
        self.duped_testnode = self.daoist.src_root.xpath('//ead:c02[@id="ref12"]', namespaces =namespaces)[0]
        handle = {'title': 'Allan Kaprow artwork, unidentified', 'handle': 'http://hdl.handle.net/10020/2014r20e0002'}
        dupecheck = self.daoist.check_for_dupe(self.duped_testnode, namespaces, handle)
        self.assertEqual(dupecheck, True)

        dupecheck = self.daoist.check_for_dupe(self.test_node, namespaces, self.handle)
        self.assertEqual(dupecheck, False)

    def test_get_title(self):
        title = self.daoist.get_title(self.test_node)
        self.assertEqual(title,
            "Yves Klein, first experiments with Living Brushes, Robert " +
            "Godet's apartment, 9 rue Le-Regrattier, Île Saint-Louis, Paris")

    def test_add_dao(self):
        self.daoist.add_dao(self.test_node, self.handle)
        children = self.test_node.getchildren()
        self.assertEqual(len(children), 4)

        dao_hits = self.test_node.xpath(
            'ead:dao[@ns2:href="http://hdl.handle.net/10020/2014r20e0012"]',
            namespaces=self.daoist.src_nsmap)
        self.assertEqual(len(dao_hits), 1)

    def test_find_position(self):
        pos = self.daoist.find_position(self.test_node)
        self.assertEqual(pos, 1)

        self.test_node2 = self.daoist.src_root.xpath('//ead:c02[@id="ref20"]',
            namespaces=self.daoist.src_nsmap)[0]
        pos = self.daoist.find_position(self.test_node2)
        self.assertEqual(pos, 2)

        self.test_node3 = self.daoist.src_root.xpath('//ead:c02[@id="ref24"]',
            namespaces=self.daoist.src_nsmap)[0]
        pos = self.daoist.find_position(self.test_node3)
        self.assertEqual(pos, 2)

    def test_process(self):
        totals = self.daoist.process()
        self.assertTrue(os.path.exists('test_dir'))
        ts = self.daoist.timestamp
        self.assertTrue(os.path.exists('test_dir/shunk_%s_ead_dao.xml' % ts))
        self.assertEqual(totals, [1064, 2, 1, 4]) #I added 4 duplicates.
        shutil.rmtree(self.daoist.target_dir, ignore_errors=True)
        self.assertFalse(os.path.exists(self.daoist.target_dir))