def test_single(self): el = etree.fromstring(''' <root> <altRecordID TYPE="foo">bar</altRecordID> </root> ''') self.assertEqual(get_altrecordids(el), {'foo': ['bar']})
def test_multiple_same_type(self): el = etree.fromstring(''' <root> <altRecordID TYPE="foo">first</altRecordID> <altRecordID TYPE="foo">second</altRecordID> </root> ''') self.assertEqual(get_altrecordids(el), {'foo': ['first', 'second']})
def test_none(self): el = etree.fromstring(''' <root></root> ''') self.assertEqual(get_altrecordids(el), {})
def poll(self, path, sa=None): for entry in os.listdir(path): subpath = os.path.join(path, entry) if os.path.isdir(subpath): continue entryname, entryext = os.path.splitext(entry) entryext = entryext[1:] if entryext != 'tar': continue objid = os.path.basename(entryname) if InformationPackage.objects.filter(object_identifier_value=objid).exists(): logger.debug(u'Information package with object identifier value "{}" already exists'.format(objid)) continue if not stable_path(subpath): continue xmlfile = os.path.splitext(subpath)[0] + '.xml' if sa is None: logger.info(u'No SA specified, get from submit description instead') tree = etree.parse(xmlfile) root = tree.getroot() altrecordids = get_altrecordids(root) sa_id = altrecordids['SUBMISSIONAGREEMENT'][0] logger.info(u'Found SA in submit description: {}'.format(sa_id)) sa = SubmissionAgreement.objects.get(pk=sa_id) else: logger.info(u'Using specified sa: {}'.format(sa)) sa = SubmissionAgreement.objects.get(name=sa) if sa.profile_workflow is None: logger.debug(u'No workflow profile in SA, skipping') continue if proj not in sa.profile_workflow.specification: logger.debug( 'No workflow specified in {} for current project {}, skipping'.format( sa.profile_workflow, proj ) ) continue org = Group.objects.get(name='Default') role = 'admin' responsible = GroupMember.objects.filter(roles__codename=role, group=org).get().member.django_user ip = InformationPackage.objects.create( object_identifier_value=objid, sip_objid=objid, object_path=subpath, package_type=InformationPackage.AIP, submission_agreement=sa, submission_agreement_locked=True, state='Prepared', responsible=responsible, package_mets_path=xmlfile, ) ip.create_profile_rels(p_types, responsible) org.add_object(ip) yield ip
def poll(self, path, sa=None): for entry in os.listdir(path): subpath = os.path.join(path, entry) if os.path.isdir(subpath): continue entryname, entryext = os.path.splitext(entry) entryext = entryext[1:] if entryext != 'tar': continue objid = os.path.basename(entryname) if InformationPackage.objects.filter( object_identifier_value=objid).exists(): logger.debug( u'Information package with object identifier value "{}" already exists' .format(objid)) continue if not stable_path(subpath): continue xmlfile = os.path.splitext(subpath)[0] + '.xml' if sa is None: logger.info( u'No SA specified, get from submit description instead') tree = etree.parse(xmlfile) root = tree.getroot() altrecordids = get_altrecordids(root) sa_id = altrecordids['SUBMISSIONAGREEMENT'][0] logger.info( u'Found SA in submit description: {}'.format(sa_id)) sa = SubmissionAgreement.objects.get(pk=sa_id) else: logger.info(u'Using specified sa: {}'.format(sa)) sa = SubmissionAgreement.objects.get(name=sa) if sa.profile_workflow is None: logger.debug(u'No workflow profile in SA, skipping') continue if proj not in sa.profile_workflow.specification: logger.debug( 'No workflow specified in {} for current project {}, skipping' .format(sa.profile_workflow, proj)) continue org = Group.objects.get(name='Default') role = 'admin' responsible = GroupMember.objects.filter( roles__codename=role, group=org).get().member.django_user ip = InformationPackage.objects.create( object_identifier_value=objid, sip_objid=objid, object_path=subpath, package_type=InformationPackage.AIP, submission_agreement=sa, submission_agreement_locked=True, state='Prepared', responsible=responsible, package_mets_path=xmlfile, ) ip.create_profile_rels(p_types, responsible) org.add_object(ip) yield ip