Skip to content

Commit

Permalink
Merge branch 'feature/3446_oaipmh_missing_metadata_attr' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Mar 21, 2023
2 parents ec0eb57 + c066931 commit de5829c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
48 changes: 47 additions & 1 deletion doajtest/unit/test_oaipmh.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def setUp(self):
# We're going to need this a lot.
self.oai_ns = {'oai': 'http://www.openarchives.org/OAI/2.0/',
'oai_dc': 'http://www.openarchives.org/OAI/2.0/oai_dc/',
'dc': 'http://purl.org/dc/elements/1.1/'}
'dc': 'http://purl.org/dc/elements/1.1/',
'xsi' : 'http://www.w3.org/2001/XMLSchema-instance'}

def test_01_oai_ListMetadataFormats(self):
""" Check we get the correct response from the OAI endpoint ListMetdataFormats request"""
Expand Down Expand Up @@ -397,3 +398,48 @@ def test_10_subjects(self):

# Check we have the correct journal
assert records[0].xpath('//dc:title', namespaces=self.oai_ns)[0].text == j_public.bibjson().title


def test_11_oai_dc_attr(self):
"""test if the OAI-PMH article feed returns record with correct attributes in oai_dc element"""
article_source = ArticleFixtureFactory.make_article_source(eissn='1234-1234', pissn='5678-5678,', in_doaj=True)
a_private = models.Article(**article_source)
ba = a_private.bibjson()
ba.title = "Private Article"
a_private.save(blocking=True)

time.sleep(1)

with self.app_test.test_request_context():
with self.app_test.test_client() as t_client:
resp = t_client.get(url_for('oaipmh.oaipmh', specified='article', verb='ListRecords', metadataPrefix='oai_dc'))
assert resp.status_code == 200

t = etree.fromstring(resp.data)
# find metadata element of our record
elem = t.xpath('/oai:OAI-PMH/oai:ListRecords/oai:record/oai:metadata', namespaces=self.oai_ns)
# metadata element should have only one child, "dc" with correct nsmap
oai_dc = elem[0].getchildren()
assert len(oai_dc) == 1
assert oai_dc[0].tag == "{%s}" % self.oai_ns["oai_dc"] + "dc"
assert oai_dc[0].nsmap["xsi"] == self.oai_ns["xsi"]

journal_sources = JournalFixtureFactory.make_many_journal_sources(2, in_doaj=True)
j_public = models.Journal(**journal_sources[0])
j_public.save(blocking=True)
public_id = j_public.id

with self.app_test.test_request_context():
with self.app_test.test_client() as t_client:
resp = t_client.get(
url_for('oaipmh.oaipmh', specified='article', verb='ListRecords', metadataPrefix='oai_dc'))
assert resp.status_code == 200

t = etree.fromstring(resp.data)
# find metadata element of our record
elem = t.xpath('/oai:OAI-PMH/oai:ListRecords/oai:record/oai:metadata', namespaces=self.oai_ns)
#metadata element should have only one child, "dc" with correct nsmap
oai_dc = elem[0].getchildren()
assert len(oai_dc) == 1
assert oai_dc[0].tag == "{%s}" % self.oai_ns["oai_dc"] + "dc"
assert oai_dc[0].nsmap["xsi"] == self.oai_ns["xsi"]
22 changes: 12 additions & 10 deletions portality/crosswalks/oaipmh.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class OAI_Crosswalk(object):
XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance"
XSI = "{%s}" % XSI_NAMESPACE

NSMAP = {None: PMH_NAMESPACE, "xsi": XSI_NAMESPACE}
XMLNS_NAMESPACE = "http://www.openarchives.org/OAI/2.0/"
XMLNS = "{%s}" % XMLNS_NAMESPACE

NSMAP = {None: PMH_NAMESPACE, "xsi": XSI_NAMESPACE, "xmlns": XMLNS_NAMESPACE}

def crosswalk(self, record):
raise NotImplementedError()
Expand Down Expand Up @@ -96,10 +99,10 @@ class OAI_DC_Article(OAI_DC):
def crosswalk(self, record):
bibjson = record.bibjson()

metadata = etree.Element(self.PMH + "metadata", nsmap=self.NSMAP)
oai_dc = etree.SubElement(metadata, self.OAIDC + "dc")
metadata = etree.Element(self.PMH + "metadata")
oai_dc = etree.SubElement(metadata, self.OAIDC + "dc", nsmap=self.NSMAP)
oai_dc.set(self.XSI + "schemaLocation",
"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd")
"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd")

if bibjson.title is not None:
title = etree.SubElement(oai_dc, self.DC + "title")
Expand Down Expand Up @@ -228,11 +231,10 @@ class OAI_DC_Journal(OAI_DC):
def crosswalk(self, record):
bibjson = record.bibjson()

metadata = etree.Element(self.PMH + "metadata", nsmap=self.NSMAP)
oai_dc = etree.SubElement(metadata, self.OAIDC + "dc")
metadata = etree.Element(self.PMH + "metadata")
oai_dc = etree.SubElement(metadata, self.OAIDC + "dc", nsmap=self.NSMAP)
oai_dc.set(self.XSI + "schemaLocation",
"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd")

"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd")
if bibjson.title is not None:
title = etree.SubElement(oai_dc, self.DC + "title")
set_text(title, bibjson.title)
Expand Down Expand Up @@ -313,8 +315,8 @@ class OAI_DOAJ_Article(OAI_Crosswalk):
def crosswalk(self, record):
bibjson = record.bibjson()

metadata = etree.Element(self.PMH + "metadata", nsmap=self.NSMAP)
oai_doaj_article = etree.SubElement(metadata, self.OAI_DOAJ + "doajArticle")
metadata = etree.Element(self.PMH + "metadata")
oai_doaj_article = etree.SubElement(metadata, self.OAI_DOAJ + "doajArticle", nsmap=self.NSMAP)
oai_doaj_article.set(self.XSI + "schemaLocation",
"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd http://doaj.org/features/oai_doaj/1.0/ https://doaj.org/static/doaj/doajArticles.xsd")

Expand Down

0 comments on commit de5829c

Please sign in to comment.