Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy in OAI-PMH #2200

Merged
merged 7 commits into from
Mar 21, 2023
49 changes: 47 additions & 2 deletions 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 @@ -343,4 +344,48 @@ def test_09_article(self):
assert len(r) == 1

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

def test_10_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")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richard-jones I am unsure about the schemaLocation that should be added here. Could you help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me, I think


Expand Down