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

    def setUp(self):
        self.daoist = Daoist('shulman',
            'test/fixtures/Shulman_SeriesII_handles.csv',
            'test/fixtures/Shulman_SeriesI-III.xml', 'test_ead.xml', 2)
        self.daoist.load_handles()
        self.daoist.load_ead()
        self.find = finders.shulman
        self.handle = {
            'title': 'Job 2892: Solomon R. Guggenheim Museum (New York, N.Y.), 1959',
            'handle': 'http://hdl.handle.net/10020/2004r10_job2892'
        }
        self.bad_handle = {
            'title': 'not a real handle',
            'handle': 'http://hdl.handle.net/10020/2014r20e00xx'
        }
        self.test_node = self.daoist.src_root.xpath('//ead:c03[@id="ref6695"]',
            namespaces=self.daoist.src_nsmap)[0]

    def test_finder(self):
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.handle, 2)
        self.assertEqual(len(hits), 1)
        self.assertEqual(self.test_node.text, hits[0].text)
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.bad_handle, 2)
        self.assertEqual(len(hits), 0)
Exemple #2
0
class TestShunkFinder(unittest.TestCase):

    def setUp(self):
        self.daoist = Daoist('shunk', 'test/fixtures/Shunk_handles.csv',
            'test/fixtures/Shunk_ead.xml', 'test_ead.xml')
        self.daoist.load_handles()
        self.daoist.load_ead()
        self.find = finders.shunk
        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'
        }
        self.bad_handle = {
            'title': 'not a real handle',
            'handle': 'http://hdl.handle.net/10020/2014r20e00xx'
        }
        self.test_node = self.daoist.src_root.xpath('//ead:c02[@id="ref18"]',
            namespaces=self.daoist.src_nsmap)[0]

    def test_finder(self):
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.handle)
        self.assertEqual(len(hits), 1)
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.bad_handle)
        self.assertEqual(len(hits), 0)
Exemple #3
0
 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'
     }
Exemple #4
0
 def setUp(self):
     self.daoist = Daoist('clark_duveen', 'test/fixtures/ClarkDuveen_handles.csv',
         'test/fixtures/clark_duveen_ead.xml', 'test_ead.xml', by_id=True)
     self.daoist.load_handles()
     self.daoist.load_ead()
     self.find = finders.by_id
     self.handle = {
         'handle': 'http://hdl.handle.net/10020/2007d1_d0045'
     }
     self.bad_handle = {
         'handle': 'http://hdl.handle.net/10020/2007d1_d00xx'
     }
     self.test_node = self.daoist.src_root.xpath('//ead:c03[@id="aspace_ref162_gsw"]',
         namespaces=self.daoist.src_nsmap)[0]
Exemple #5
0
class TestDuveenFinder(unittest.TestCase):

    def setUp(self):
        self.daoist = Daoist('duveen', 'test/fixtures/duveen.csv',
            'test/fixtures/duveen_ead.xml', 'test_ead.xml')
        self.daoist.load_handles()
        self.daoist.load_ead()
        self.find = finders.duveen
        self.handle = {
            'title': 'TV film,',
            'handle': 'http://hdl.handle.net/10020/960015b413f008'
        }
        self.bad_handle = {
            'title': 'not a real handle',
            'handle': 'http://hdl.handle.net/10020/960015b999f999'
        }
        self.test_node = self.daoist.src_root.xpath('//ead:c05[@id="ref19737"]',
            namespaces=self.daoist.src_nsmap)[0]

    def test_finder(self):
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.handle)
        self.assertEqual(len(hits), 1)
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.bad_handle)
        self.assertEqual(len(hits), 0)

    def test_ranged_values(self):
        handle = {
            'title': 'Invoices, June 1, 1936-May 31, 1937, cont.',
            'handle': 'http://hdl.handle.net/10020/960015b139f006'
        }
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap, handle)
        self.assertEqual(len(hits), 1)
        test_node = self.daoist.src_root.xpath('ead:archdesc/ead:dsc/ead:c01/ead:c02/ead:c03/ead:c04[@id="ref592"]',
            namespaces=self.daoist.src_nsmap)[0]
        self.assertEqual(test_node.text, hits[0].text)
Exemple #6
0
class TestDaoistInit(unittest.TestCase):

    def setUp(self):
        self.daoist = Daoist('shunk', 'test/fixtures/Shunk_handles.csv',
            'test/fixtures/Shunk_ead.xml', 'test_ead')

    def test_load_handles(self):
        self.daoist.load_handles()
        handle_list = self.daoist.handles
        self.assertEqual(len(handle_list), 1069)
        self.assertEqual(handle_list[0]['title'],
            'Harry Shunk street photography, "tuileries," Paris')
        self.assertEqual(handle_list[0]['handle'],
            'http://hdl.handle.net/10020/2014r20e0001')

    def test_load_ead(self):
        self.daoist.load_ead()
        self.assertEqual(self.daoist.src_root.tag,
            '{urn:isbn:1-931666-22-9}ead')

    def test_series_error(self):
        with self.assertRaises(SeriesError):
            self.daoist = Daoist('shulman', 'test/fixtures/Shulman_handles.csv',
                'test/fixtures/Shulman_SeriesI-III.xml', 'test_ead')
Exemple #7
0
class TestByIdFinder(unittest.TestCase):

    def setUp(self):
        self.daoist = Daoist('clark_duveen', 'test/fixtures/ClarkDuveen_handles.csv',
            'test/fixtures/clark_duveen_ead.xml', 'test_ead.xml', by_id=True)
        self.daoist.load_handles()
        self.daoist.load_ead()
        self.find = finders.by_id
        self.handle = {
            'handle': 'http://hdl.handle.net/10020/2007d1_d0045'
        }
        self.bad_handle = {
            'handle': 'http://hdl.handle.net/10020/2007d1_d00xx'
        }
        self.test_node = self.daoist.src_root.xpath('//ead:c03[@id="aspace_ref162_gsw"]',
            namespaces=self.daoist.src_nsmap)[0]

    def test_finder(self):
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.handle)
        self.assertEqual(len(hits), 1)
        hits = self.find(self.daoist.src_root, self.daoist.src_nsmap,
            self.bad_handle)
        self.assertEqual(len(hits), 0)
Exemple #8
0
 def setUp(self):
     self.daoist = Daoist('duveen', 'test/fixtures/duveen.csv',
         'test/fixtures/duveen_ead.xml', 'test_ead.xml')
     self.daoist.load_handles()
     self.daoist.load_ead()
     self.find = finders.duveen
     self.handle = {
         'title': 'TV film,',
         'handle': 'http://hdl.handle.net/10020/960015b413f008'
     }
     self.bad_handle = {
         'title': 'not a real handle',
         'handle': 'http://hdl.handle.net/10020/960015b999f999'
     }
     self.test_node = self.daoist.src_root.xpath('//ead:c05[@id="ref19737"]',
         namespaces=self.daoist.src_nsmap)[0]
Exemple #9
0
 def setUp(self):
     self.daoist = Daoist('shulman',
         'test/fixtures/Shulman_SeriesII_handles.csv',
         'test/fixtures/Shulman_SeriesI-III.xml', 'test_ead.xml', 2)
     self.daoist.load_handles()
     self.daoist.load_ead()
     self.find = finders.shulman
     self.handle = {
         'title': 'Job 2892: Solomon R. Guggenheim Museum (New York, N.Y.), 1959',
         'handle': 'http://hdl.handle.net/10020/2004r10_job2892'
     }
     self.bad_handle = {
         'title': 'not a real handle',
         'handle': 'http://hdl.handle.net/10020/2014r20e00xx'
     }
     self.test_node = self.daoist.src_root.xpath('//ead:c03[@id="ref6695"]',
         namespaces=self.daoist.src_nsmap)[0]
Exemple #10
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))
Exemple #11
0
 def test_series_error(self):
     with self.assertRaises(SeriesError):
         self.daoist = Daoist('shulman', 'test/fixtures/Shulman_handles.csv',
             'test/fixtures/Shulman_SeriesI-III.xml', 'test_ead')
Exemple #12
0
 def setUp(self):
     self.daoist = Daoist('shunk', 'test/fixtures/Shunk_handles.csv',
         'test/fixtures/Shunk_ead.xml', 'test_ead')