From ea518191d873c397a13a672c572fb7653ad17ecb Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 26 Oct 2018 10:57:53 +0200 Subject: update service test --- test/lazarweb.rb | 193 --------------------------------------------------- test/service-test.rb | 41 +++++++++++ test/setup.rb | 7 -- 3 files changed, 41 insertions(+), 200 deletions(-) delete mode 100644 test/lazarweb.rb create mode 100644 test/service-test.rb delete mode 100644 test/setup.rb diff --git a/test/lazarweb.rb b/test/lazarweb.rb deleted file mode 100644 index a93b5bf..0000000 --- a/test/lazarweb.rb +++ /dev/null @@ -1,193 +0,0 @@ -require 'minitest/autorun' -require 'capybara' -require 'capybara-webkit' - -ENV['DISPLAY'] ="localhost:1.0" - -Capybara.register_driver :webkit do |app| - Capybara::Webkit::Driver.new(app).tap{|d| d.browser.ignore_ssl_errors} -end -Capybara.default_driver = :webkit -Capybara.default_max_wait_time = 20 -Capybara.javascript_driver = :webkit -Capybara.run_server = false -Capybara.app_host = "http://localhost:8088" - -begin - puts "Service URI is: http://localhost:8088" -rescue - puts "Unable to start service." - exit -end - -class LazarWebTest < MiniTest::Test - - def self.test_order - :sorted - end - - include Capybara::DSL - - def test_00_xsetup - `Xvfb :1 -screen 0 1024x768x16 2>/dev/null &` - sleep 2 - end - - def test_01_visit - visit('/predict') - assert page.has_content?('Lazar Toxicity Predictions') - assert page.has_content?("Draw a chemical structure") - assert page.has_content?("enter") - assert page.has_content?("upload") - assert page.has_content?("Select one or more endpoints") - assert page.has_content?("Acute toxicity") - assert page.has_content?("Fathead minnow") - assert page.has_content?("Carcinogenicity") - assert page.has_content?("Rat") - assert page.has_content?("Rodents (multiple species/sites)") - assert page.has_content?("Mouse") - assert page.has_content?("Maximum Recommended Daily Dose") - assert page.has_content?("Human") - assert page.has_content?("Predict") - end - - def test_02_insert_wrong_smiles - visit('/') - page.fill_in 'identifier', :with => "blahblah" - check('selection[Rat]') - first(:button, '>>').click - assert page.has_content?('Attention') - end - - def test_03_check_all_links_exists - visit('/') - links = ["Details | Validation", "SMILES", "toxicology gmbh 2004 - #{Time.now.year.to_s}"] - links.each{|l| assert page.has_link?(l), "true"} - end - - def test_04_model_details - visit("/") - details = page.all('a', :text => 'Details | Validation') - details[0].click - assert page.has_content?('Model:') - assert page.has_content?('Source: http://www.epa.gov/comptox/dsstox/sdf_epafhm.html') - assert page.has_content?('Algorithm: LAZAR') - assert page.has_content?('Type: regression') - assert page.has_content?('Training dataset: EPAFHM.csv') - assert page.has_content?('Training compounds: 617') - assert page.has_content?('Validation:') - assert page.has_content?('Num folds: 10') - details[0].click - # - details[1].click - assert page.has_content?('Model:') - assert page.has_content?('Source: http://www.epa.gov/ncct/dsstox/sdf_cpdbas.html') - assert page.has_content?('Algorithm: LAZAR') - assert page.has_content?('Type: classification') - assert page.has_content?('Training dataset: DSSTox_Carcinogenic_Potency_DBS_Rat.csv') - assert page.has_content?('Training compounds: 1195') - assert page.has_content?('Validation:') - assert page.has_content?('Num folds: 10') - details[1].click - # - details[2].click - assert page.has_content?('Model:') - assert page.has_content?('Source: http://www.epa.gov/ncct/dsstox/sdf_cpdbas.html') - assert page.has_content?('Algorithm: LAZAR') - assert page.has_content?('Type: classification') - assert page.has_content?('Training dataset: DSSTox_Carcinogenic_Potency_DBS_MultiCellCall.csv') - assert page.has_content?('Training compounds: 1116') - assert page.has_content?('Validation:') - assert page.has_content?('Num folds: 10') - details[2].click - # - details[3].click - assert page.has_content?('Model:') - assert page.has_content?('Source: http://www.epa.gov/ncct/dsstox/sdf_cpdbas.html') - assert page.has_content?('Algorithm: LAZAR') - assert page.has_content?('Type: classification') - assert page.has_content?('Training dataset: DSSTox_Carcinogenic_Potency_DBS_Mouse.csv') - assert page.has_content?('Training compounds: 973') - assert page.has_content?('Validation:') - assert page.has_content?('Num folds: 10') - details[3].click - # - details[4].click - assert page.has_content?('Model:') - assert page.has_content?('Source: http://www.epa.gov/comptox/dsstox/sdf_fdamdd.html') - assert page.has_content?('Algorithm: LAZAR') - assert page.has_content?('Type: regression') - assert page.has_content?('Training dataset: FDA_v3b_Maximum_Recommended_Daily_Dose_mmol.csv') - assert page.has_content?('Training compounds: 1216') - assert page.has_content?('Validation:') - assert page.has_content?('Num folds: 10') - details[4].click - end - - def test_05_predict - visit('/') - page.fill_in('identifier', :with => "NNc1ccccc1") - check('selection[Rat]') - first(:button, '>>').click - assert page.has_content?('Carcinogenicity (Rat)'), "true" - assert page.has_content?('Type: Classification'), "true" - assert page.has_content?('Prediction: active'), "true" - assert page.has_content?('Confidence: 0.019'), "true" - assert page.has_content?('Neighbors'), "true" - assert page.has_content?('Compound'), "true" - assert page.has_content?('Measured Activity'), "true" - assert page.has_content?('Similarity'), "true" -=begin - assert page.has_link?('Significant fragments'), "true" - assert page.has_link?('v'), "true" - open 'significant fragments' view - find_link('linkPredictionSf').click - sleep 5 - within_frame('details_overview') do - assert page.has_content?('Predominantly in compounds with activity "inactive"'), "true" - assert page.has_content?('Predominantly in compounds with activity "active"'), "true" - assert page.has_content?('p value'), "true" - # inactive - assert page.has_content?('[#6&a]:[#6&a]:[#6&a]:[#6&a]:[#6&a]-[#7&A]'), "true" - assert page.has_content?('0.98674'), "true" - assert page.has_content?('[#6&a]:[#6&a](-[#7&A])(:[#6&a]:[#6&a]:[#6&a])'), "true" - assert page.has_content?('0.97699'), "true" - assert page.has_content?('[#6&a]:[#6&a](-[#7&A])(:[#6&a]:[#6&a])'), "true" - assert page.has_content?('0.97699'), "true" - assert page.has_content?('[#6&a]:[#6&a](-[#7&A])(:[#6&a])'), "true" - assert page.has_content?('0.97699'), "true" - assert page.has_content?('[#6&a]:[#6&a]'), "true" - assert page.has_content?('0.99605'), "true" - assert page.has_content?('[#6&a]:[#6&a]:[#6&a]:[#6&a]'), "true" - assert page.has_content?('0.99791'), "true" - assert page.has_content?('[#6&a]:[#6&a]:[#6&a]:[#6&a]:[#6&a]'), "true" - assert page.has_content?('0.99985'), "true" - # active - assert page.has_content?('[#7&A]-[#7&A]'), "true" - assert page.has_content?('0.99993'), "true" - # close 'significant fragments' view - find_button('closebutton').click - end - find_link('link0').click - sleep 2 - assert page.has_content?('Supporting information'), "true" - first(:link, 'linkCompound').click - sleep 5 - within_frame('details_overview') do - assert page.has_content?('SMILES:'), "true" - assert page.has_content?('c1ccc(cc1)NN'), "true" - assert page.has_content?('InChI:'), "true" - assert page.has_content?('1S/C6H8N2/c7-8-6-4-2-1-3-5-6/h1-5,8H,7H2'), "true" - assert page.has_content?('Names:'), "true" - assert page.has_content?('Phenylhydrazine'), "true" - assert page.has_link?('PubChem read across'), "true" - end -=end - end - - def test_99_kill - `pidof Xvfb|xargs kill` - end - -end - diff --git a/test/service-test.rb b/test/service-test.rb new file mode 100644 index 0000000..de2cc0f --- /dev/null +++ b/test/service-test.rb @@ -0,0 +1,41 @@ +require 'minitest/autorun' +require 'rest-client' +require 'nokogiri' +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 + +class WebServiceTests < Minitest::Test + + def test_prediction + + # regression + response = RestClient.post "http://localhost:8088/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) + + # classification + response = RestClient.post "http://localhost:8088/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 + end + + def test_validation + + # regression + response = RestClient.get "http://localhost:8088/predict/modeldetails/#{$r_model}" + xml = Nokogiri::HTML.parse(response.body) + links = xml.css('a') + assert_equal "Algorithm::Caret.rf", links[3].children.text.strip + + # classification + response = RestClient.get "http://localhost:8088/predict/modeldetails/#{$c_model}" + xml = Nokogiri::HTML.parse(response.body) + links = xml.css('a') + assert_equal "Algorithm::Classification.weighted_majority_vote", links[3].children.text.strip + end + +end diff --git a/test/setup.rb b/test/setup.rb deleted file mode 100644 index 3dad683..0000000 --- a/test/setup.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'minitest/autorun' -require_relative '../lib/lazar.rb' -include OpenTox -TEST_DIR ||= File.expand_path(File.dirname(__FILE__)) -DATA_DIR ||= File.join(TEST_DIR,"data") -#$mongo.database.drop -#$gridfs = $mongo.database.fs # recreate GridFS indexes -- cgit v1.2.3