Skip to content
Snippets Groups Projects
Commit 89b10ae9 authored by Sophie Servan (DESY)'s avatar Sophie Servan (DESY)
Browse files

Add tests for oai-pmh endpoints

parent 6e319a57
No related branches found
No related tags found
1 merge request!18Add tests for oai-pmh endpoints
Pipeline #350700 passed
image: ruby:3.0
stages:
- test
- build
variables:
......@@ -8,11 +9,17 @@ variables:
before_script:
- gem install bundler jekyll --no-document
- bundle install
test:
stage: test
script:
- bundle exec ruby scripts/check_oai_pmh.rb
allow_failure: true
build:
stage: build
script:
- bundle install
- bundle exec jekyll build
artifacts:
paths:
......
......@@ -2,3 +2,11 @@ source "https://rubygems.org"
# add jekyll as a dependency
gem "jekyll"
# add dependencies for HTTP requests
gem "httparty"
# add dependencies to work with yaml and xml files
gem "yaml"
gem "nokogiri"
......@@ -13,6 +13,9 @@ GEM
forwardable-extended (2.6.0)
google-protobuf (3.23.3-x86_64-linux)
http_parser.rb (0.8.0)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jekyll (4.3.2)
......@@ -44,9 +47,14 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
mini_mime (1.1.5)
multi_xml (0.6.0)
nokogiri (1.16.2-x86_64-linux)
racc (~> 1.4)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (5.0.1)
racc (1.7.3)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
......@@ -61,12 +69,16 @@ GEM
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.4.2)
webrick (1.8.1)
yaml (0.3.0)
PLATFORMS
x86_64-linux
DEPENDENCIES
httparty
jekyll
nokogiri
yaml
BUNDLED WITH
2.4.15
......@@ -249,9 +249,9 @@
odr:
link: https://rodare.hzdr.de/
oai-pmh-endpoint:
link: https://www.hzdr.de/publications/OAI-PMH?verb=Identify
link: https://rodare.hzdr.de/oai2d?verb=Identify
status: Active
last-check: 2024-02-07
last-check: 2024-02-19
## ILL ##
- short-name: ILL
......
# check_oai_pmh.rb
require 'httparty'
require 'nokogiri'
require 'yaml'
def check_oai_pmh_endpoint(endpoint_url)
begin
response = HTTParty.head(endpoint_url)
if response.success?
response = HTTParty.get(endpoint_url)
if !(response.body.nil? || response.body.empty?)
xml_response = Nokogiri::XML(response.body)
oai_pmh_tag = xml_response.at_xpath('//*[name()="OAI-PMH"]')
if oai_pmh_tag
puts "Endpoint is functional. OAI-PMH tag found in response."
return "Active"
else
puts "Endpoint does not contain OAI-PMH tag."
return "Error"
end
else
puts "Endpoint returned an empty body."
return "Error"
end
else
puts "Endpoint returned HTTP status code #{response.code}."
return "Error"
end
rescue StandardError => e
puts "Error occurred while accessing endpoint: #{e.message}"
return "Error"
end
end
up_to_date = true
facilities = YAML.safe_load(File.read('_data/facilities.yml'), permitted_classes: [Date])
facilities.each do |facility|
odr = facility['odr']
if odr && odr.key?('oai-pmh-endpoint')
oai_pmh_endpoint = odr['oai-pmh-endpoint']['link']
if oai_pmh_endpoint
expected_status = odr['oai-pmh-endpoint']['status']
puts "Checking OAI-PMH endpoint for #{facility['short-name']}: #{oai_pmh_endpoint}"
endpoint_status = check_oai_pmh_endpoint(oai_pmh_endpoint)
status_match = expected_status == endpoint_status
puts "Error: Expected status '#{expected_status}' for #{facility['short-name']} OAI-PMH endpoint, but found status '#{endpoint_status}'." unless status_match
up_to_date &= status_match
end
end
end
exit(1) unless up_to_date
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment