示例#1
0
    def test_holdings(self):
        # title data
        titlexml = os.path.join(os.path.dirname(openoni.core.__file__), 
            'test-data', 'title.xml')

        # holdings data
        holdingsxml = os.path.join(os.path.dirname(openoni.core.__file__), 
            'test-data', 'holdings.xml')

        # first need to load the titles so we can link against them
        title_loader = TitleLoader()
        title_loader.load_file(titlexml)

        # now load the holdings from the same file
        holding_loader = HoldingLoader()
        holding_loader.load_file(holdingsxml)
        
        # fetch the title and see that holdings are attached
        t = Title.objects.get(lccn='sn83030846')
        holdings = list(t.holdings.all())
        self.assertEqual(len(holdings), 10)
        h = holdings[1]
        self.assertEqual(h.institution.name, 'Colgate Univ')
        self.assertEqual(h.type, 'Original')
        self.assertEqual(h.description, '<1876:5:18> <1884:1:10> <1885:9:3>')
        self.assertEqual(h.description_as_list(), [u'<1876:5:18>', u'<1884:1:10>', u'<1885:9:3>'])
        self.assertEqual(str(h.last_updated), '01/1992')
示例#2
0
    def handle(self, holdings_source=default_location, *args, **options):
        
        if not os.path.exists(holdings_source): 
            _logger.error("There is no valid holdings source folder defined.")
            set_holdings = ['To load holdings - Add a folder called "holdings"',
            'to the bib directory that is set in settings',
            'or pass the location of holdings as an arguement to the loader.',]
            _logger.error(' '.join(set_holdings))
            return

        # First we want to make sure that our material types are up to date
        material_types = models.MaterialType.objects.all()
        [m.delete() for m in material_types]
        management.call_command('loaddata', 'material_types.json')
       
        holding_loader = HoldingLoader()
        holding_loader.main(holdings_source)