Exemple #1
0
 def test_create_from_dict(self):
     workTest = WorkRecord.createFromDict(**{
         'title': 'A Title',
         'uuid': '0000000-0000-0000-0000-00000000000'
     })
     self.assertIsInstance(workTest, WorkRecord)
     self.assertEqual(workTest.title, 'A Title')
def readFromClassify(workXML, workUUID):
    """Parse Classify XML document into a object that complies with the
    SFR data model. Accepts a single XML document and returns a WorkRecord."""
    logger.debug('Parsing Returned Work')

    work = workXML.find('.//work', namespaces=NAMESPACE)
    start = workXML.find('.//start', namespaces=NAMESPACE)

    oclcTitle = work.get('title')
    oclcNo = Identifier('oclc', work.text, 1)
    owiNo = Identifier('owi', work.get('owi'), 1)

    if OutputManager.checkRecentQueries('lookup/{}/{}/{}'.format(
        'owi', work.get('owi'), start.text
    )) is True:
        raise DataError('Work {} with OWI {} already classified'.format(
            workUUID, work.get('owi')
        ))

    measurements = []
    for measure in ['editions', 'holdings', 'eholdings']:
        measurements.append(Measurement(
            measure,
            work.get(measure),
            1,
            MEASUREMENT_TIME,
            work.text
        ))

    authors = workXML.findall('.//author', namespaces=NAMESPACE)
    authorList = list(map(parseAuthor, authors))

    editions = workXML.findall('.//edition', namespaces=NAMESPACE)
    editionList = loadEditions(editions)

    headings = workXML.findall('.//heading', namespaces=NAMESPACE)
    headingList = list(map(parseHeading, headings))

    workDict = {
        'title': oclcTitle,
        'agents': authorList,
        'instances': editionList,
        'subjects': headingList,
        'identifiers': [
            oclcNo,
            owiNo
        ],
        'measurements': measurements
    }

    instanceCount = int(work.get('editions', 0))

    return WorkRecord.createFromDict(**workDict), instanceCount, work.text