# Make updates and copy to container # docker cp service-tests.rb service-tests:/home/ist/service-tests/service-tests.rb # even if container is stopped ! require 'minitest/autorun' require 'rest-client' require 'nokogiri' require 'csv' class WebServiceTests < Minitest::Test def get_models require '../lazar/lib/lazar.rb' $models = OpenTox::Model::Validation.all $r_model = $models.select{|m| m if m.model.name == "LOAEL (training_log10)"}[0].id.to_s $c_model = $models.select{|m| m if m.model.name == "Mutagenicity (kazius)"}[0].id.to_s end def test_virtuoso puts "\nhttps://virtuoso.in-silico.ch" assert_raises RestClient::NotFound do response = RestClient.get "https://virtuoso.in-silico.ch" end end def test_insilico_website puts "\nhttps://in-silico.ch" response = RestClient.get "https://in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) value = xml.at('li.active').text.strip assert_equal "Software and services", value end def test_predictive_toxicology puts "\nhttps://predictive-toxicology.org/" response = RestClient.get "https://predictive-toxicology.org/" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) value = xml.at('title').text assert_equal "Predictive Toxicology", value end def test_lazar_batch puts "\nhttps://lazar-batch.in-silico.ch" require '../batch-login.rb' assert_raises RestClient::Unauthorized do response = RestClient.get "https://lazar-batch.in-silico.ch" end assert_raises RestClient::Unauthorized do response = RestClient::Request.execute method: :get, url: "https://lazar-batch.in-silico.ch", user: $user+"f", password: $passwd end assert_raises RestClient::Unauthorized do response = RestClient::Request.execute method: :get, url: "https://lazar-batch.in-silico.ch", user: $user, password: $passwd+"f" end response = RestClient::Request.execute method: :get, url: "https://lazar-batch.in-silico.ch", user: $user, password: $passwd xml = Nokogiri::HTML.parse(response.body) assert_match xml.at('h1').text.gsub(/\n/,"").strip, "lazar toxicity predictions" # batch get_models response = RestClient::Request.execute method: :post, url: "https://lazar-batch.in-silico.ch/predict", user: $user, password: $passwd, payload: { multipart: true, fileselect: File.new('./test.csv', 'rb'), selection: {$r_model => ""} } assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) value = xml.css('h5').text assert_equal "Lowest observed adverse effect level (LOAEL) (Rat)", value value = xml.at_css('a#detailsbutton_0').text.strip assert_equal "Details", value end def test_dump puts "\nhttps://dump.in-silico.ch" response = RestClient.get "https://dump.in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) dumpsize = xml.at('pre').text.split.last.to_i response = RestClient.get "https://dump.in-silico.ch/dump.tar.gz" assert_equal response.body.size.to_i, dumpsize end def test_lazar puts "\nhttps://lazar.in-silico.ch" get_models response = RestClient.get "https://lazar.in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) assert_match xml.at('h1').text.gsub(/\n/,"").strip, "lazar toxicity predictions" puts "\npredict regression: https://lazar.in-silico.ch/predict" # regression response = RestClient.post "https://lazar.in-silico.ch/predict", {identifier: "O=[N+]([O-])c1ccccc1", selection: {$r_model=>""}} xml = Nokogiri::HTML.parse(response.body) value = xml.css('td')[1].css('p')[2].text.split[1].to_f assert value.between?(0.06,0.09) puts "\npredict classification: https://lazar.in-silico.ch/predict" # classification response = RestClient.post "https://lazar.in-silico.ch/predict", {identifier: "O=[N+]([O-])c1ccccc1", selection: {$c_model=>""}} xml = Nokogiri::HTML.parse(response.body) value = xml.css('td')[1].css('p')[4].text.split.last assert_equal "mutagenic", value # regression puts "\nmodel details regression: https://lazar.in-silico.ch/predict/modeldetails/#{$r_model}" response = RestClient.get "https://lazar.in-silico.ch/predict/modeldetails/#{$r_model}" xml = Nokogiri::HTML.parse(response.body) puts "check metadata\n" links = xml.css('a') assert_equal "https://github.com/opentox/loael-paper/blob/revision/data/training_log10.csv", links[0].children.text.strip assert_equal "training_log10", links[1].children.text.strip assert_equal "Algorithm::Similarity.tanimoto", links[2].children.text.strip assert_equal "Algorithm::Caret.rf", links[3].children.text.strip text = xml.css('div.panel-body')[0] a,b = text.children[4].text.strip.split("\n") assert_equal "Type:", a.strip assert_equal "Regression", b.strip a,b = text.children[6].text.strip.split("\n") assert_equal "Training compounds:", a.strip assert_equal "671", b.strip text = xml.css('div.panel-body')[1] a,b,c = text.children[8].text.strip.split assert_equal "Descriptors:", a.strip assert_equal "fingerprint,", b.strip assert_equal "MP2D", c.strip # classification puts "\nmodel details classification: https://lazar.in-silico.ch/predict/modeldetails/#{$c_model}" response = RestClient.get "https://lazar.in-silico.ch/predict/modeldetails/#{$c_model}" xml = Nokogiri::HTML.parse(response.body) puts "check metadata\n" links = xml.css('a') assert_equal "http://cheminformatics.org/datasets/", links[0].children.text.strip assert_equal "kazius", links[1].children.text.strip assert_equal "Algorithm::Similarity.tanimoto", links[2].children.text.strip assert_equal "Algorithm::Classification.weighted_majority_vote", links[3].children.text.strip text = xml.css('div.panel-body')[0] a,b = text.children[4].text.strip.split("\n") assert_equal "Type:", a.strip assert_equal "Classification", b.strip a,b = text.children[6].text.strip.split("\n") assert_equal "Training compounds:", a.strip assert_equal "4069", b.strip text = xml.css('div.panel-body')[1] a,b,c = text.children[8].text.strip.split assert_equal "Descriptors:", a.strip assert_equal "fingerprint,", b.strip assert_equal "MP2D", c.strip end def test_nano_lazar puts "\nhttps://nano-lazar.in-silico.ch" response = RestClient.get "https://nano-lazar.in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) assert_match xml.at('h1').text.gsub(/\n/,"").strip, "nano-lazar toxicity predictions" params = {example_coating_0: "N-(2-Mercaptopropionyl)glycine", example_core: "Au", example_id: "5878a6097b6c9b003a862710", example_pc: "{}", input_coating_0: "N-(2-Mercaptopropionyl)glycine", input_core: "Au", prediction_model: "5878aa1d7b6c9b003a8629b1", type: "fingerprint" } puts "\npredict example: https://nano-lazar.in-silico.ch/predict" response = RestClient.post "https://nano-lazar.in-silico.ch/predict", params xml = Nokogiri::HTML.parse(response.body) value = xml.css('tbody').css('tr')[1].css('td')[0].css('a').text.gsub(/\n/,"").strip assert_equal value, "G15.AC" end def test_aop puts "\nhttps://aop.in-silico.ch" response = RestClient.get "https://aop.in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) assert_match xml.at('h1').text.gsub(/\n/,"").strip, "PubChem read across" puts "\nhttps://aop.in-silico.ch/cid/31703" response = RestClient.get "https://aop.in-silico.ch/cid/31703" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) value = xml.at('th').text.split.first.strip assert_equal "(7~{S},9~{S})-7-[(2~{R},4~{S},5~{S},6~{S})-4-amino-5-hydroxy-6-methyloxan-2-yl]oxy-6,9,11-trihydroxy-9-(2-hydroxyacetyl)-4-methoxy-8,10-dihydro-7~{H}-tetracene-5,12-dione", value end def test_dg2_Elena puts "\nhttps://dg2.in-silico.ch" response = RestClient.get "https://dg2.in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) batch_file_id = xml.search("label")[4].attributes["for"].value.gsub(/existing|\[|\]/,"") batch_file_name = xml.search("label")[4].text.strip assert_match xml.at('h1').text.gsub(/\n/,"").strip, "lazar toxicity predictions" puts "\nsingle prediction Mazzatorta: https://dg2.in-silico.ch/predict" response = RestClient.post "https://dg2.in-silico.ch/predict", {identifier: "O=[N+]([O-])c1ccccc1", selection: {"Mazzatorta"=>""}} xml = Nokogiri::HTML.parse(response.body) value = xml.css('td')[1].css('p')[0].text.split[1].to_f assert value, 0.384 puts "\nsingle prediction lazar LOAEL: https://dg2.in-silico.ch/predict" response = RestClient.post "https://dg2.in-silico.ch/predict", {identifier: "O=[N+]([O-])c1ccccc1", selection: {"5ba4e38b5e110b01688fa0ca"=>""}} xml = Nokogiri::HTML.parse(response.body) value = xml.css('td')[1].css('p')[2].text.split[1].to_f assert value, 0.0807 puts "\nbatch prediction with first dataset in existing list\n" response = RestClient.post "https://dg2.in-silico.ch/predict", {existing: {batch_file_id=>""}, selection: {"5ba4e38b5e110b01688fa0ca"=>""}} assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) title = xml.search("h3").text assert_equal title, "Batch Prediction Results:RHC_input" sleep 3 href = xml.search("a#downbutton_0")[0]["href"] puts "\ndownload csv batch results\n" response = RestClient.get href csv = CSV.new(response.body) header = csv.first ["ID", "Original ID", "Input", "Endpoint"].each do |h| assert_includes header, h end puts "\nmodel details lazar LOAEL: https://dg2.in-silico.ch/predict/modeldetails/5ba4e38b5e110b01688fa0ca" response = RestClient.get "https://dg2.in-silico.ch/predict/modeldetails/5ba4e38b5e110b01688fa0ca" xml = Nokogiri::HTML.parse(response.body) puts "check metadata\n" links = xml.css('a') assert_equal "https://github.com/opentox/loael-paper/blob/revision/data/training_log10.csv", links[0].children.text.strip assert_equal "training_log10", links[1].children.text.strip assert_equal "Algorithm::Similarity.tanimoto", links[2].children.text.strip assert_equal "Algorithm::Caret.rf", links[3].children.text.strip text = xml.css('div.panel-body')[0] a,b = text.children[4].text.strip.split("\n") assert_equal "Type:", a.strip assert_equal "Regression", b.strip a,b = text.children[6].text.strip.split("\n") assert_equal "Training compounds:", a.strip assert_equal "671", b.strip text = xml.css('div.panel-body')[1] a,b,c = text.children[8].text.strip.split assert_equal "Descriptors:", a.strip assert_equal "fingerprint,", b.strip assert_equal "MP2D", c.strip end def test_dg3_Elena puts "\nhttps://dg3.in-silico.ch" response = RestClient.get "https://dg3.in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) assert_match xml.at('h1').text.gsub(/\n/,"").strip, "lazar toxicity predictions" end def test_test1_Elena puts "\nhttps://test1.in-silico.ch" response = RestClient.get "https://test1.in-silico.ch" assert_equal response.code, 200 xml = Nokogiri::HTML.parse(response.body) assert_match xml.at('h1').text.gsub(/\n/,"").strip, "Nestec Toxicity Predictions" end #def test_git_server #TODO Net::HTTPBadResponse: wrong status line: "SSH-2.0-OpenSSH_7.8" # response = RestClient.get "https://git.in-silico.ch" #end def test_server_invalid_cert puts "\ninvalid cert test4" assert_raises RestClient::SSLCertificateNotVerified do response = RestClient.get "https://test4.in-silico.ch" end end end