Skip to content

Commit

Permalink
implemented a test for #127 - Add API call to trigger ontology pull f…
Browse files Browse the repository at this point in the history
…rom remote location
  • Loading branch information
mdorf committed Jan 11, 2024
1 parent 60fee47 commit cd7ca2a
Show file tree
Hide file tree
Showing 5 changed files with 1,040 additions and 17 deletions.
22 changes: 5 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ncbo/goo.git
revision: 6db93bb3d5095a5fe0d017e572c5a04caa34ebc6
revision: db2b330fb6c5fd4ea9ee17d5b58ca997f304a340
branch: develop
specs:
goo (0.0.2)
Expand All @@ -15,7 +15,7 @@ GIT

GIT
remote: https://github.com/ncbo/ncbo_annotator.git
revision: d7ee80860a0eab9293af81083a0700d099c50263
revision: 9a037b955b1d6c3c9955250d7499afdd10d4bbd3
branch: develop
specs:
ncbo_annotator (0.0.1)
Expand All @@ -26,7 +26,7 @@ GIT

GIT
remote: https://github.com/ncbo/ncbo_cron.git
revision: 23316314217ec2e6b5cba8d66f3b8a491f53da4c
revision: a733888915a6c188e636ff605027490c381d72a0
branch: develop
specs:
ncbo_cron (0.0.1)
Expand All @@ -42,7 +42,7 @@ GIT

GIT
remote: https://github.com/ncbo/ncbo_ontology_recommender.git
revision: 003b65c5e5ce8b0736085d6825ee1b8e9548826e
revision: 41e61ddccdde09a45961b0f2bf7ad0ddb18b382e
branch: develop
specs:
ncbo_ontology_recommender (0.0.1)
Expand All @@ -53,7 +53,7 @@ GIT

GIT
remote: https://github.com/ncbo/ontologies_linked_data.git
revision: 9487c7f73e68abab097af523d42c1d2e106e614b
revision: e716a6d410883a8e59121e7d09d2c80a6f6ab1fc
branch: develop
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -165,10 +165,7 @@ GEM
google-cloud-env (2.1.0)
faraday (>= 1.0, < 3.a)
google-cloud-errors (1.3.1)
google-protobuf (3.25.2-aarch64-linux)
google-protobuf (3.25.2-arm64-darwin)
google-protobuf (3.25.2-x86_64-darwin)
google-protobuf (3.25.2-x86_64-linux)
googleapis-common-protos (1.4.0)
google-protobuf (~> 3.14)
googleapis-common-protos-types (~> 1.2)
Expand All @@ -182,18 +179,9 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
grpc (1.60.0-aarch64-linux)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.60.0-arm64-darwin)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.60.0-x86_64-darwin)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.60.0-x86_64-linux)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
haml (5.2.2)
temple (>= 0.8.0)
tilt
Expand Down
13 changes: 13 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# conig file for unit tests

# GOO_BACKEND_NAME = ENV.include?("GOO_BACKEND_NAME") ? ENV["GOO_BACKEND_NAME"] : "AG"
# GOO_HOST = ENV.include?("GOO_HOST") ? ENV["GOO_HOST"] : "localhost"
# GOO_PATH_QUERY = ENV.include?("GOO_PATH_QUERY") ? ENV["GOO_PATH_QUERY"] : "/repositories/bioportal"
# GOO_PATH_DATA = ENV.include?("GOO_PATH_DATA") ? ENV["GOO_PATH_DATA"] : "/repositories/bioportal/statements"
# GOO_PATH_UPDATE = ENV.include?("GOO_PATH_UPDATE") ? ENV["GOO_PATH_UPDATE"] : "/repositories/bioportal/statements"
# GOO_PORT = ENV.include?("GOO_PORT") ? ENV["GOO_PORT"] : 10035

GOO_BACKEND_NAME = ENV.include?("GOO_BACKEND_NAME") ? ENV["GOO_BACKEND_NAME"] : "4store"
GOO_HOST = ENV.include?("GOO_HOST") ? ENV["GOO_HOST"] : "localhost"
GOO_PATH_DATA = ENV.include?("GOO_PATH_DATA") ? ENV["GOO_PATH_DATA"] : "/data/"
GOO_PATH_QUERY = ENV.include?("GOO_PATH_QUERY") ? ENV["GOO_PATH_QUERY"] : "/sparql/"
GOO_PATH_UPDATE = ENV.include?("GOO_PATH_UPDATE") ? ENV["GOO_PATH_UPDATE"] : "/update/"
GOO_PORT = ENV.include?("GOO_PORT") ? ENV["GOO_PORT"] : 8080

MGREP_DICTIONARY_FILE = ENV.include?("MGREP_DICTIONARY_FILE") ? ENV["MGREP_DICTIONARY_FILE"] : "./test/data/dictionary.txt"
MGREP_HOST = ENV.include?("MGREP_HOST") ? ENV["MGREP_HOST"] : "localhost"


# MGREP_PORT = ENV.include?("MGREP_PORT") ? ENV["MGREP_PORT"] : 55556
MGREP_PORT = ENV.include?("MGREP_PORT") ? ENV["MGREP_PORT"] : 55555


REDIS_GOO_CACHE_HOST = ENV.include?("REDIS_GOO_CACHE_HOST") ? ENV["REDIS_GOO_CACHE_HOST"] : "localhost"
REDIS_HTTP_CACHE_HOST = ENV.include?("REDIS_HTTP_CACHE_HOST") ? ENV["REDIS_HTTP_CACHE_HOST"] : "localhost"
REDIS_PERSISTENT_HOST = ENV.include?("REDIS_PERSISTENT_HOST") ? ENV["REDIS_PERSISTENT_HOST"] : "localhost"
Expand Down
62 changes: 62 additions & 0 deletions test/controllers/test_ontologies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'webrick'
require_relative '../test_case'

class TestOntologiesController < TestCase
Expand Down Expand Up @@ -29,6 +30,8 @@ def self._set_vars
hasOntologyLanguage: "OWL",
administeredBy: ["tom"]
}
@@server_thread = nil
@@server_url = nil
end

def self._create_user
Expand Down Expand Up @@ -253,9 +256,68 @@ def test_download_acl_only
end
end

def test_on_demand_ontology_pull
ont = create_ontologies_and_submissions(ont_count: 1, submission_count: 1, process_submission: true)[2].first
ont.bring_remaining
acronym = ont.acronym
sub = ont.submissions.first
sub.bring(:pullLocation) if sub.bring?(:pullLocation)
assert_equal(nil, sub.pullLocation, msg="Pull location should be nil at this point in the test")

allowed_user = ont.administeredBy.first
allowed_user.bring(:apikey)

post "/ontologies/#{acronym}/pull?apikey=#{allowed_user.apikey}"
assert_equal(404, last_response.status, msg="This ontology is is NOT configured to be remotely pulled at this point in the test. It should return status 404")

begin
start_server
sub.pullLocation = RDF::IRI.new(@@server_url)
sub.save
LinkedData.settings.enable_security = true
post "/ontologies/#{acronym}/pull?apikey=#{allowed_user.apikey}"
assert_equal(204, last_response.status, msg="The ontology owner was unable to execute the on-demand pull")

blocked_user = User.new({
username: "blocked",
email: "[email protected]",
password: "12345"
})
blocked_user.save
post "/ontologies/#{acronym}/pull?apikey=#{blocked_user.apikey}"
assert_equal(403, last_response.status, msg="A non-authorized user was able to execute the on-demand pull")
ensure
stop_server
LinkedData.settings.enable_security = false
end
end

private

def start_server
ont_path = File.expand_path("../../data/ontology_files/BRO_v3.2.owl", __FILE__)
file = File.new(ont_path)
port = Random.rand(55000..65535) # http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic.2C_private_or_ephemeral_ports
@@server_url = "http://localhost:#{port}/"
@@server_thread = Thread.new do
server = WEBrick::HTTPServer.new(Port: port)
server.mount_proc '/' do |req, res|
contents = file.read
file.rewind
res.body = contents
end
begin
server.start
ensure
server.shutdown
end
end
end

def stop_server
Thread.kill(@@server_thread) if @@server_thread
end

def check400(response)
assert response.status >= 400
assert MultiJson.load(response.body)["errors"]
Expand Down
Loading

0 comments on commit cd7ca2a

Please sign in to comment.