Skip to content

Commit

Permalink
Merge pull request #546 from grycap/egi_brand_v2
Browse files Browse the repository at this point in the history
Egi brand v2
  • Loading branch information
micafer authored May 16, 2024
2 parents 9c7b779 + c6fcd3d commit ae28782
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
35 changes: 12 additions & 23 deletions app/oaipmh/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,48 +572,37 @@ def processRequest(self, request, metadata_dict):
'resumptionToken': 0,
}

if not request.args.get('verb'):
verb = request.values.get('verb')

if not verb:
self.addError(root, Errors.badVerb())
return etree.tostring(root, pretty_print=True, encoding='unicode')

response_xml = None
parsed_url = urlparse(request.url)
query_parameters = parsed_url.query.split('&')

for param in query_parameters:
key = param.split('=')[0]
for key in list(request.values.keys()):
if key in attributes_dict:
attributes_dict[key] += 1
# Check for duplicate attributes
if attributes_dict[key] > 1:
self.addError(root, Errors.badArgument())
return etree.tostring(root, pretty_print=True, encoding='unicode')

# Check for unknown attributes
unknown_attributes = [param.split('=')[0] for param in query_parameters
if param.split('=')[0] not in attributes_dict]
unknown_attributes = [key for key in list(request.values.keys()) if key not in attributes_dict]

if unknown_attributes:
self.addError(root, Errors.badArgument())
response_xml = etree.tostring(root, pretty_print=True, encoding='unicode')

return response_xml

if request.method == 'GET':
verb = request.args.get('verb')
metadata_prefix = request.args.get('metadataPrefix')
identifier = request.args.get('identifier')
from_date = request.args.get('from')
until_date = request.args.get('until')
set_spec = request.args.get('set')
resumption_token = request.args.get('resumptionToken')
else:
verb = request.form.get('verb')
metadata_prefix = request.form.get('metadataPrefix')
identifier = request.form.get('identifier')
from_date = request.form.get('from')
until_date = request.form.get('until')
set_spec = request.form.get('set')
resumption_token = request.form.get('resumptionToken')
metadata_prefix = request.values.get('metadataPrefix')
identifier = request.values.get('identifier')
from_date = request.values.get('from')
until_date = request.values.get('until')
set_spec = request.values.get('set')
resumption_token = request.values.get('resumptionToken')

# Create a dictionary mapping verbs to functions
verb_handlers = {
Expand Down
7 changes: 5 additions & 2 deletions app/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,12 @@ def test_oai(self):
self.assertEqual(root.find(".//oaipmh:granularity", namespace).text, "YYYY-MM-DD")
self.assertEqual(root.find(".//oaipmh:adminEmail", namespace).text, "[email protected]")

# Test Identify
res = self.client.post('/oai?verb=Identify')
# Test Identify Post with body params
res = self.client.post('/oai', headers={'Content-Type': 'application/x-www-form-urlencoded'},
data="verb=Identify")
self.assertEqual(200, res.status_code)
root = etree.fromstring(res.data)
self.assertEqual(root.find(".//oaipmh:repositoryName", namespace).text, "IM Dashboard")

# Test GetRecord
tosca_id = "https://github.com/grycap/tosca/blob/main/templates/simple-node-disk.yml"
Expand Down

0 comments on commit ae28782

Please sign in to comment.