From 8fd0ab610483fd7c9948c05ef2a940647b1117fb Mon Sep 17 00:00:00 2001 From: gebele Date: Mon, 12 Nov 2018 15:46:38 +0100 Subject: service-tests for public repo --- .gitignore | 1 + Dockerfile | 23 +++ service-tests/service-tests.rb | 277 +++++++++++++++++++++++++++++++ service-tests/test-batch-with-errors.csv | 5 + service-tests/test.csv | 2 + start.sh | 21 +++ test.sh | 50 ++++++ 7 files changed, 379 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 service-tests/service-tests.rb create mode 100644 service-tests/test-batch-with-errors.csv create mode 100644 service-tests/test.csv create mode 100755 start.sh create mode 100755 test.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5093a29 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +scripts/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9bedbe5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM insilicotox/lazar-dev +MAINTAINER in-silico toxicology GmbH + +RUN sudo pacman-db-upgrade +RUN sudo pacman -Syyu --noconfirm +RUN sudo pacman -S --noconfirm msmtp msmtp-mta +RUN sudo pacman -Scc --noconfirm + +RUN cd lazar && \ + git checkout "master" + +RUN mkdir -p /home/ist/log + +COPY service-tests /home/ist/service-tests +RUN sudo chown -R ist:ist service-tests + +COPY test.sh /home/ist/test.sh +RUN sudo chmod +x /home/ist/test.sh + +COPY start.sh /home/ist/start.sh +RUN sudo chmod +x /home/ist/start.sh + +ENTRYPOINT ["/home/ist/start.sh"] diff --git a/service-tests/service-tests.rb b/service-tests/service-tests.rb new file mode 100644 index 0000000..f0897af --- /dev/null +++ b/service-tests/service-tests.rb @@ -0,0 +1,277 @@ +# 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 "(7S,9S)-7-[(2R,4S,5S,6S)-4-amino-5-hydroxy-6-methyloxan-2-yl]oxy-6,9,11-trihydroxy-9-(2-hydroxyacetyl)-4-methoxy-8,10-dihydro-7H-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 + diff --git a/service-tests/test-batch-with-errors.csv b/service-tests/test-batch-with-errors.csv new file mode 100644 index 0000000..2f5c2c1 --- /dev/null +++ b/service-tests/test-batch-with-errors.csv @@ -0,0 +1,5 @@ +SMILES +"O=P(OCC)(SC(C)CC)SC(C)CC" +O=C1CCC2(O1)C=C(C(=O)C(=C2)C(C)(C)C)C(C)(C)C +O[C@@H]8[C@@H](O)[C@@H]1O[C@H](CO)[C@H]8O[C@H]7O[C@H](CO)[C@@H](O[C@H]6O[C@H](CO)[C@@H](O[C@H]5O[C@H](CO)[C@@H](O[C@H]4O[C@H](CO)[C@@H](O[C@H]3O[C@H](CO)[C@@H](O[C@H]2O[C@H](CO)[C@@H](O1)[C@H](O)[C@H]2O)[C@H](O)[C@H]3O)[C@H](O)[C@H]4O)[C@H](O)[C@H]5O)[C +Toast \ No newline at end of file diff --git a/service-tests/test.csv b/service-tests/test.csv new file mode 100644 index 0000000..7d074a3 --- /dev/null +++ b/service-tests/test.csv @@ -0,0 +1,2 @@ +SMILES +O=[N+]([O-])c1ccccc1 diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..86bd54a --- /dev/null +++ b/start.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# start basic services +sudo mongod & +R CMD Rserve --vanilla & + +# fetch and load database content +if [ ! -d "$HOME/dump" ]; then + wget https://dump.in-silico.ch/dump.tar.gz + tar xfvz dump.tar.gz + mongorestore +fi + +ln -s "$HOME/scripts/batch-login.rb" "$HOME/batch-login.rb" +sudo chown ist:ist ~/batch-login.rb +ln -s "$HOME/scripts/.msmtprc" "$HOME/.msmtprc" +sudo chown ist:ist ~/.msmtprc +sudo chmod 600 ~/.msmtprc + +./test.sh + diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..ef0206c --- /dev/null +++ b/test.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +TITLE="Service Tests" +HOME="/home/ist" +TESTDIR="$HOME/service-tests" + +. $HOME/.bashrc + +DATE=`date +%y%m%d` +separator="============================" + +LOGDIR="$HOME/log" +ERRLOG="$LOGDIR/$DATE-err.log" +LOG="$LOGDIR/$DATE.log" +MSG="$HOME/msg.log" +rm "$LOG" 2>/dev/null +rm "$ERRLOG" 2>/dev/null +rm "$MSG" 2>/dev/null + +touch $LOG +touch $ERRLOG +touch $MSG + +cd $TESTDIR +tests=(service-tests.rb) +for t in ${tests[@]}; do + echo $separator | tee -a $LOG $MSG + echo " "$t|tr [a-z] [A-Z] | tee -a $LOG $MSG + echo " "`date` | tee -a $LOG $MSG + echo $separator | tee -a $LOG $MSG + echo ruby $t | tee -a $LOG $MSG + # whole test output to logfile only + ruby $t >> $LOG + # take last occurrence of regex to end of the file + awk '/^Finished in/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' $LOG >> $MSG + echo "" >> $LOG +done + +# MAIL +file="$HOME/scripts/recipients" +recipients=$(cat $file) +if grep -q "Error:" $LOG; then ERRMSG=" ERROR (`grep -c ' Error:' $LOG`)"; else ERRMSG=" OK "; fi +if grep -q "Failure:" $LOG; then FAILMSG=" FAIL (`grep -c ' Failure:' $LOG`)"; else FAILMSG=""; fi + +for p in ${recipients[@]}; do + #{ printf "To: $p\nSubject: [service tests] -$TITLE- $DATE $ERRMSG $FAILMSG\n"; cat $MSG; } | msmtp -a default $p + { printf "To: $p\nSubject: [service tests] -$TITLE- $DATE $ERRMSG $FAILMSG\n"; cat $LOG; } | msmtp -a default $p +done + +exit 0 -- cgit v1.2.3