Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed May 8, 2024
1 parent 129bacc commit 9ce795c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/oaipmh/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def getRecord(self, root, metadata_dict, verb, identifier, metadata_prefix):

metadata_element.append(metadata_xml)

return etree.tostring(metadata_element, pretty_print=True, encoding='unicode')
return etree.tostring(root, pretty_print=True, encoding='unicode')

def identify(self, root, verb):
self.addRequestElement(root, verb)
Expand Down
33 changes: 18 additions & 15 deletions app/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,15 +768,17 @@ def test_oai(self):

root = etree.fromstring(res.data)

namespace_dc = {'dc': 'http://purl.org/dc/elements/1.1/'}
namespace_oaipmh = {'oaipmh': 'http://www.openarchives.org/OAI/2.0/'}
namespace_datacite = {'datacite': 'http://datacite.org/schema/kernel-4'}

self.assertEqual(root.find(".//dc:title", namespace_dc).text, "Deploy a VM")
self.assertEqual(root.find(".//dc:creator", namespace_dc).text, "Miguel Caballer")
self.assertEqual(root.find(".//dc:date", namespace_dc).text, "2020-09-08")
namespaces = {'ns0': 'http://www.openarchives.org/OAI/2.0/',
'dc': 'http://purl.org/dc/elements/1.1/',
'oaipmh': 'http://www.openarchives.org/OAI/2.0/',
'datacite': 'http://datacite.org/schema/kernel-4'}

self.assertEqual(root.find(".//dc:title", namespaces).text, "Deploy a VM")
self.assertEqual(root.find(".//dc:creator", namespaces).text, "Miguel Caballer")
self.assertEqual(root.find(".//dc:date", namespaces).text, "2020-09-08")
self.assertEqual(root.find(".//ns0:identifier", namespaces).text,
"https://github.com/grycap/tosca/blob/main/templates/simple-node-disk.yml")
# self.assertIsNotNone(root.find(".//dc:type", namespace_dc))
# self.assertIsNotNone(root.find(".//dc:identifier", namespace_dc))
# self.assertIsNotNone(root.find(".//dc:rights", namespace_dc))

# Test ListIdentifiers
Expand All @@ -785,7 +787,7 @@ def test_oai(self):

root = etree.fromstring(res.data)

self.assertEqual(root.find(".//oaipmh:identifier", namespace_oaipmh).text,
self.assertEqual(root.find(".//oaipmh:identifier", namespaces).text,
"https://github.com/grycap/tosca/blob/main/templates/simple-node-disk.yml")

# Test ListRecords oai_dc
Expand All @@ -794,11 +796,12 @@ def test_oai(self):

root = etree.fromstring(res.data)

self.assertEqual(root.find(".//dc:title", namespace_dc).text, "Deploy a VM")
self.assertEqual(root.find(".//dc:creator", namespace_dc).text, "Miguel Caballer")
self.assertEqual(root.find(".//dc:date", namespace_dc).text, "2020-09-08")
self.assertEqual(root.find(".//dc:title", namespaces).text, "Deploy a VM")
self.assertEqual(root.find(".//dc:creator", namespaces).text, "Miguel Caballer")
self.assertEqual(root.find(".//dc:date", namespaces).text, "2020-09-08")
self.assertEqual(root.find(".//ns0:identifier", namespaces).text,
"https://github.com/grycap/tosca/blob/main/templates/simple-node-disk.yml")
# self.assertIsNotNone(root.find(".//dc:type", namespace_dc))
# self.assertIsNotNone(root.find(".//dc:identifier", namespace_dc))
# self.assertIsNotNone(root.find(".//dc:rights", namespace_dc))

# Test ListRecords oai_openaire
Expand All @@ -807,15 +810,15 @@ def test_oai(self):

root = etree.fromstring(res.data)

self.assertEqual(root.find(".//datacite:creatorName", namespace_datacite).text, "Miguel Caballer")
self.assertEqual(root.find(".//datacite:creatorName", namespaces).text, "Miguel Caballer")

# Test ListMetadataFormats
res = self.client.get('/oai?verb=ListMetadataFormats')
self.assertEqual(200, res.status_code)

root = etree.fromstring(res.data)

prefixes = root.findall(".//oaipmh:metadataPrefix", namespace_oaipmh)
prefixes = root.findall(".//oaipmh:metadataPrefix", namespaces)
prefixes_text = [prefix.text for prefix in prefixes]

self.assertIn('oai_dc', prefixes_text)
Expand Down

0 comments on commit 9ce795c

Please sign in to comment.