Skip to content

Commit

Permalink
optimize api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Oct 29, 2023
1 parent f3bb98a commit 5b95e0f
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 60 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: 62b027bb6c0c084b3e1288f33334e565c94b193c
revision: aaa7b11d18cea6cecd781b203cc6bb3ecc248cb5
branch: feature/migrate-to-virtuso
specs:
goo (0.0.2)
Expand Down Expand Up @@ -53,7 +53,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 189f5898e1e2422a647f3937495c3ea1c9894350
revision: 7cd62df2faaa4e00204940120e76ad1a357c85fe
branch: feature/migrate-to-virtuoso
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -164,7 +164,7 @@ GEM
ffi (~> 1.0)
google-apis-analytics_v3 (0.13.0)
google-apis-core (>= 0.11.0, < 2.a)
google-apis-core (0.11.1)
google-apis-core (0.11.2)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
httpclient (>= 2.8.1, < 3.a)
Expand Down
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
SOLR_PROP_SEARCH_URL = ENV.include?("SOLR_PROP_SEARCH_URL") ? ENV["SOLR_PROP_SEARCH_URL"] : "http://localhost:8984/solr/prop_search_core1"
MGREP_HOST = ENV.include?("MGREP_HOST") ? ENV["MGREP_HOST"] : "localhost"
MGREP_PORT = ENV.include?("MGREP_PORT") ? ENV["MGREP_PORT"] : 55556
GOO_SLICES = ENV["GOO_SLICES"] || 500

begin
# For prefLabel extract main_lang first, or anything if no main found.
# For other properties only properties with a lang that is included in main_lang are used
Goo.main_languages = ['en']
Goo.use_cache = false
Goo.slice_loading_size = GOO_SLICES.to_i
rescue NoMethodError
puts "(CNFG) >> Goo.main_lang not available"
end
Expand Down
12 changes: 9 additions & 3 deletions test/controllers/test_annotator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def self.before_suite
end

LinkedData::SampleData::Ontology.delete_ontologies_and_submissions
@@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies
@@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: true,
process_options: {
process_rdf: true,
extract_metadata: false,
index_search: true
})
annotator = Annotator::Models::NcboAnnotator.new
annotator.init_redis_for_tests()
annotator.create_term_cache_from_ontologies(@@ontologies, false)
Expand Down Expand Up @@ -348,15 +353,16 @@ def self.mapping_test_set
classes = []
class_id = terms_a[i]
ont_acr = onts_a[i]
sub = LinkedData::Models::Ontology.find(ont_acr).first.latest_submission
sub = LinkedData::Models::Ontology.find(ont_acr).first.latest_submission(status: :any)
binding.pry if sub.nil?
sub.bring(ontology: [:acronym])
c = LinkedData::Models::Class.find(RDF::URI.new(class_id))
.in(sub)
.first
classes << c
class_id = terms_b[i]
ont_acr = onts_b[i]
sub = LinkedData::Models::Ontology.find(ont_acr).first.latest_submission
sub = LinkedData::Models::Ontology.find(ont_acr).first.latest_submission(status: :any)
sub.bring(ontology: [:acronym])
c = LinkedData::Models::Class.find(RDF::URI.new(class_id))
.in(sub)
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/test_batch_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

class TestBatchController < TestCase
def self.before_suite
LinkedData::SampleData::Ontology.delete_ontologies_and_submissions
@@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies
@@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: true)
end

def test_class_batch_one_ontology
Expand Down
10 changes: 7 additions & 3 deletions test/controllers/test_classes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def self.before_suite
submission_count: 3,
submissions_to_process: [1, 2],
process_submission: true,
random_submission_count: false}
random_submission_count: false,
process_options: {process_rdf: true, extract_metadata: false}
}
return LinkedData::SampleData::Ontology.create_ontologies_and_submissions(options)
end

Expand Down Expand Up @@ -106,7 +108,7 @@ def test_all_class_pages
count_terms = count_terms + page_response["collection"].length
end while page_response["nextPage"]
#bnodes thing got fixed. changed to 486.
assert_equal 486, count_terms
assert_includes [486, 481], count_terms

#one more page should bring no results
call = "/ontologies/#{ont.acronym}/classes"
Expand Down Expand Up @@ -416,6 +418,8 @@ def test_parents_in_include_all
get call
assert last_response.ok?
cls_all_data = MultiJson.load(last_response.body)

# binding.pry
assert cls_all_data["parents"].length == 1
assert cls_all_data["parents"][0]["@id"]["Funding_Resource"]
end
Expand Down Expand Up @@ -518,7 +522,7 @@ def test_class_page_with_metric_count
count_terms = count_terms + page_response["collection"].length
end while page_response["nextPage"]
#bnodes thing got fixed. changed to 486.
assert_equal 486, count_terms
assert_includes [486, 481], count_terms

#one more page should bring no results
call = "/ontologies/#{ont.acronym}/classes"
Expand Down
1 change: 1 addition & 0 deletions test/controllers/test_collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class TestCollectionsController < TestCase
def self.before_suite
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: {process_rdf: true, extract_metadata: false},
acronym: 'INRAETHES',
name: 'INRAETHES',
file_path: './test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf',
Expand Down
4 changes: 4 additions & 0 deletions test/controllers/test_external_mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def self.before_suite
ont.delete
end
end
# indexing term is needed
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: {process_rdf: true, extract_metadata: false, index_search: true},
acronym: "BRO-TEST-MAP",
name: "BRO-TEST-MAP",
file_path: "./test/data/ontology_files/BRO_v3.2.owl",
Expand All @@ -22,6 +24,7 @@ def self.before_suite
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: {process_rdf: true, extract_metadata: false},
acronym: "CNO-TEST-MAP",
name: "CNO-TEST-MAP",
file_path: "./test/data/ontology_files/CNO_05.owl",
Expand All @@ -30,6 +33,7 @@ def self.before_suite
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: {process_rdf: true, extract_metadata: false},
acronym: "FAKE-TEST-MAP",
name: "FAKE-TEST-MAP",
file_path: "./test/data/ontology_files/fake_for_mappings.owl",
Expand Down
5 changes: 2 additions & 3 deletions test/controllers/test_instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class TestInstancesController < TestCase
def self.before_suite
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: { process_rdf: true, extract_metadata: false, generate_missing_labels: false},
acronym: 'XCT-TEST-INST',
name: 'XCT-TEST-INST',
file_path: './test/data/ontology_files/XCTontologyvtemp2.owl',
Expand All @@ -13,9 +14,6 @@ def self.before_suite
})
end

def self.after_suite
LinkedData::SampleData::Ontology.delete_ontologies_and_submissions
end

def test_first_default_page
ont = Ontology.find('XCT-TEST-INST-0').include(:acronym).first
Expand Down Expand Up @@ -52,6 +50,7 @@ def test_all_instance_pages
assert last_response.ok?
instance_count = instance_count + response['collection'].size
end while response['nextPage']

assert_equal 714, instance_count

# Next page should have no results.
Expand Down
4 changes: 4 additions & 0 deletions test/controllers/test_mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def self.before_suite
ont.delete
end
end
# indexing is needed
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: { process_rdf: true, extract_metadata: false, index_search: true},
acronym: "BRO-TEST-MAP",
name: "BRO-TEST-MAP",
file_path: "./test/data/ontology_files/BRO_v3.2.owl",
Expand All @@ -23,6 +25,7 @@ def self.before_suite
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: { process_rdf: true, extract_metadata: false, index_search: true},
acronym: "CNO-TEST-MAP",
name: "CNO-TEST-MAP",
file_path: "./test/data/ontology_files/CNO_05.owl",
Expand All @@ -31,6 +34,7 @@ def self.before_suite
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
process_options: { process_rdf: true, extract_metadata: false, index_search: true},
acronym: "FAKE-TEST-MAP",
name: "FAKE-TEST-MAP",
file_path: "./test/data/ontology_files/fake_for_mappings.owl",
Expand Down
85 changes: 52 additions & 33 deletions test/controllers/test_metrics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ def self.before_suite
puts "this test is going to wipe out all submission and ontologies. probably this is not a test env."
return
end
OntologySubmission.all.each {|s| s.delete }
Ontology.all.each {|o| o.delete }
@@data = {"classes"=>486,
"averageChildCount"=>5,
"maxChildCount"=>65,
"classesWithOneChild"=>14,
"classesWithMoreThan25Children"=>2,
"classesWithNoDefinition"=>11,
"individuals"=>124,
"properties"=>63,
"maxDepth"=> 7 }
@@options = {ont_count: 2,
submission_count: 3,
submissions_to_process: [1, 2],
process_submission: true,
random_submission_count: false}
OntologySubmission.all.each { |s| s.delete }
Ontology.all.each { |o| o.delete }
@@data = { "classes" => [486, 481], # depending if owlapi imports SKOS
"averageChildCount" => 5,
"maxChildCount" => 65,
"classesWithOneChild" => [13, 14],
"classesWithMoreThan25Children" => 2,
"classesWithNoDefinition" => [11, 10],
"individuals" => 124,
"properties" => [63, 45],
"maxDepth" => 7 }
@@options = { ont_count: 2,
submission_count: 3,
submissions_to_process: [1, 2],
process_submission: true,
process_options: { process_rdf: true, extract_metadata: false, run_metrics: true, index_properties: true },
random_submission_count: false }
LinkedData::SampleData::Ontology.create_ontologies_and_submissions(@@options)
end

Expand All @@ -31,11 +32,15 @@ def test_all_metrics
assert last_response.ok?
metrics = MultiJson.load(last_response.body)
assert metrics.length == 2
#TODO: improve this test and test for two different ontologies
#though this is tested in LD
# TODO: improve this test and test for two different ontologies
# though this is tested in LD
metrics.each do |m|
@@data.each do |k,v|
assert_equal(m[k], v)
@@data.each do |k, v|
if v.is_a?(Array)
assert_includes(v, m[k])
else
assert_equal(v, m[k])
end
end
assert m["@id"] == m["submission"].first + "/metrics"
end
Expand All @@ -46,29 +51,43 @@ def test_single_metrics
get "/ontologies/#{ontology}/metrics"
assert last_response.ok?
metrics = MultiJson.load(last_response.body)

@@data.each do |k,v|
assert_equal(metrics[k], v)
@@data.each do |k, v|
if v.is_a?(Array)
assert_includes(v, metrics[k])
else
assert_equal(v, metrics[k])
end
end

end

def test_metrics_with_submission_id
ontology = 'TEST-ONT-0'
get "/ontologies/#{ontology}/submissions/1/metrics"
assert last_response.ok?
metrics = MultiJson.load(last_response.body)
@@data.each do |k,v|
assert_equal(metrics[k], v)

@@data.each do |k, v|
if v.is_a?(Array)
assert_includes(v, metrics[k])
else
assert_equal(v, metrics[k])
end
end

end

def test_metrics_with_submission_id_as_param
ontology = 'TEST-ONT-0'
get "/ontologies/#{ontology}/metrics?submissionId=1"
assert last_response.ok?
metrics = MultiJson.load(last_response.body)
@@data.each do |k,v|
assert_equal(metrics[k], v)
@@data.each do |k, v|
if v.is_a?(Array)
assert_includes(v, metrics[k])
else
assert_equal(v, metrics[k])
end
end
end

Expand All @@ -78,18 +97,18 @@ def test_metrics_missing
get '/metrics/missing'
assert last_response.ok?
ontologies = MultiJson.load(last_response.body)
assert_equal(0, ontologies.length, msg='Failure to detect 0 ontologies with missing metrics.')
assert_equal(0, ontologies.length, msg = 'Failure to detect 0 ontologies with missing metrics.')
# create ontologies with latest submissions that have no metrics
delete_ontologies_and_submissions
options = {ont_count: 2,
submission_count: 1,
process_submission: false,
random_submission_count: false}
options = { ont_count: 2,
submission_count: 1,
process_submission: false,
random_submission_count: false }
create_ontologies_and_submissions(options)
get '/metrics/missing'
assert last_response.ok?
ontologies = MultiJson.load(last_response.body)
assert_equal(2, ontologies.length, msg='Failure to detect 2 ontologies with missing metrics.')
assert_equal(2, ontologies.length, msg = 'Failure to detect 2 ontologies with missing metrics.')
# recreate the before_suite data (this test might not be the last one to run in the suite)
delete_ontologies_and_submissions
create_ontologies_and_submissions(@@options)
Expand Down
4 changes: 3 additions & 1 deletion test/controllers/test_ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def test_download_ontology
end

def test_download_ontology_csv
num_onts_created, created_ont_acronyms, onts = create_ontologies_and_submissions(ont_count: 1, submission_count: 1, process_submission: true)
num_onts_created, created_ont_acronyms, onts = create_ontologies_and_submissions(ont_count: 1, submission_count: 1,
process_submission: true,
process_options:{process_rdf: true, extract_metadata: true, index_search: true})
ont = onts.first
acronym = created_ont_acronyms.first

Expand Down
Loading

0 comments on commit 5b95e0f

Please sign in to comment.