diff --git a/.gitignore b/.gitignore index 8838121..bdb47d9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +/coverage +.idea/ diff --git a/Gemfile b/Gemfile index 757c4fa..14855f2 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,9 @@ group :development, :test do #Codecov for coverage processing gem 'simplecov' gem 'simplecov-cobertura' + + # Mocking HTTP requests to third parties. + gem 'webmock' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index c1fe9b1..8d82190 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,6 +85,8 @@ GEM capistrano (~> 3.0) sshkit (~> 1.2) concurrent-ruby (1.2.2) + crack (0.4.5) + rexml crass (1.0.6) debug (1.6.2) irb (>= 1.3.6) @@ -98,6 +100,7 @@ GEM faraday-net_http (3.0.0) globalid (1.1.0) activesupport (>= 5.0) + hashdiff (1.0.1) i18n (1.12.0) concurrent-ruby (~> 1.0) io-console (0.5.11) @@ -236,6 +239,10 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.3.0) + webmock (3.19.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -266,6 +273,7 @@ DEPENDENCIES simplecov-cobertura stathat (~> 0.1.7) tzinfo-data + webmock RUBY VERSION ruby 3.1.2p20 diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 3b023cb..d79a5ad 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -70,18 +70,10 @@ def set_query end end - # prepares the sequences query - def set_sequences - rel_name = @equate_il ? :peptides : :original_peptides - @sequences = Sequence.joins(rel_name => :uniprot_entry) - .where(sequence: @input) - end - # Reorders the results according to the input order def filter_input_order @input_order.select! do |s| - key = @equate_il ? s.tr('I', 'L') : s - @result.key? key + @result.key? s end end diff --git a/app/controllers/mpa/pept2data_controller.rb b/app/controllers/mpa/pept2data_controller.rb index 4dbce6a..a281cf6 100644 --- a/app/controllers/mpa/pept2data_controller.rb +++ b/app/controllers/mpa/pept2data_controller.rb @@ -1,13 +1,7 @@ class Mpa::Pept2dataController < Mpa::MpaController include SuffixArrayHelper - def get_time - Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) - end - def pept2data - start = get_time - peptides = params[:peptides] || [] missed = params[:missed].nil? ? false : params[:missed] equate_il = params[:equate_il].nil? ? true : params[:equate_il] @@ -32,8 +26,5 @@ def pept2data Lineage.find(taxa).each do |lineage| @lineages[lineage.taxon_id] = lineage.to_a_idx end - - @timings = Hash.new - @timings["total"] = get_time - start end end diff --git a/app/controllers/private_api/proteins_controller.rb b/app/controllers/private_api/proteins_controller.rb index ba8f132..a6dd9b7 100644 --- a/app/controllers/private_api/proteins_controller.rb +++ b/app/controllers/private_api/proteins_controller.rb @@ -19,6 +19,8 @@ def proteins return end + puts peptide + # Request the suffix array search service search_result = search([ peptide ], equate_il).first @@ -29,8 +31,6 @@ def proteins return end - puts search_result - @lca = search_result["lca"] @proteins = UniprotEntry .includes(:taxon) @@ -48,7 +48,6 @@ def proteins # Lineage van de lca ophalen lca_lineage = Lineage.find(@lca) - puts lca_lineage.inspect finished = (@lca == 1) while !finished && lca_lineage.has_next? next_rank = lca_lineage.next_t diff --git a/app/views/api/pept2ec/pept2ec.json.jbuilder b/app/views/api/pept2ec/pept2ec.json.jbuilder index c999f20..01d2373 100644 --- a/app/views/api/pept2ec/pept2ec.json.jbuilder +++ b/app/views/api/pept2ec/pept2ec.json.jbuilder @@ -1,8 +1,7 @@ json.array! @input_order do |peptide| - seq_index = @equate_il ? peptide.tr('I', 'L') : peptide - if @result.key? seq_index + if @result.key? peptide json.peptide peptide - json.total_protein_count @result[seq_index][:total] - json.ec(@result[seq_index][:ec].sort_by { |v| -v[:protein_count] }) + json.total_protein_count @result[peptide][:total] + json.ec(@result[peptide][:ec].sort_by { |v| -v[:protein_count] }) end end diff --git a/app/views/api/pept2funct/pept2funct.json.jbuilder b/app/views/api/pept2funct/pept2funct.json.jbuilder index 7d7586b..0958d7c 100644 --- a/app/views/api/pept2funct/pept2funct.json.jbuilder +++ b/app/views/api/pept2funct/pept2funct.json.jbuilder @@ -1,10 +1,9 @@ json.array! @input_order do |peptide| - seq_index = @equate_il ? peptide.tr('I', 'L') : peptide - if @result.key? seq_index + if @result.key? peptide json.peptide peptide - json.total_protein_count @result[seq_index][:total] - json.ec(@result[seq_index][:ec].sort_by { |value| -value[:protein_count] }) - json.partial! partial: 'api/pept2go', locals: { data: @result[seq_index][:go] } - json.partial! partial: 'api/pept2interpro', locals: { data: @result[seq_index][:ipr] } + json.total_protein_count @result[peptide][:total] + json.ec(@result[peptide][:ec].sort_by { |value| -value[:protein_count] }) + json.partial! partial: 'api/pept2go', locals: { data: @result[peptide][:go] } + json.partial! partial: 'api/pept2interpro', locals: { data: @result[peptide][:ipr] } end end diff --git a/app/views/api/pept2go/pept2go.json.jbuilder b/app/views/api/pept2go/pept2go.json.jbuilder index f75b59f..5428ed3 100644 --- a/app/views/api/pept2go/pept2go.json.jbuilder +++ b/app/views/api/pept2go/pept2go.json.jbuilder @@ -1,8 +1,7 @@ json.array! @input_order do |peptide| - seq_index = @equate_il ? peptide.tr('I', 'L') : peptide - if @result.key? seq_index + if @result.key? peptide json.peptide peptide - json.total_protein_count @result[seq_index][:total] - json.partial! partial: 'api/pept2go', locals: { data: @result[seq_index][:go] } + json.total_protein_count @result[peptide][:total] + json.partial! partial: 'api/pept2go', locals: { data: @result[peptide][:go] } end end diff --git a/app/views/api/pept2interpro/pept2interpro.json.jbuilder b/app/views/api/pept2interpro/pept2interpro.json.jbuilder index 22cdc29..ad5804c 100644 --- a/app/views/api/pept2interpro/pept2interpro.json.jbuilder +++ b/app/views/api/pept2interpro/pept2interpro.json.jbuilder @@ -1,8 +1,7 @@ json.array! @input_order do |peptide| - seq_index = @equate_il ? peptide.tr('I', 'L') : peptide - if @result.key? seq_index + if @result.key? peptide json.peptide peptide - json.total_protein_count @result[seq_index][:total] - json.partial! partial: 'api/pept2interpro', locals: { data: @result[seq_index][:ipr] } + json.total_protein_count @result[peptide][:total] + json.partial! partial: 'api/pept2interpro', locals: { data: @result[peptide][:ipr] } end end diff --git a/app/views/api/pept2lca/pept2lca.json.jbuilder b/app/views/api/pept2lca/pept2lca.json.jbuilder index 61ca845..9a9f0d5 100644 --- a/app/views/api/pept2lca/pept2lca.json.jbuilder +++ b/app/views/api/pept2lca/pept2lca.json.jbuilder @@ -1,7 +1,6 @@ json.array! @input_order do |peptide| - seq_index = @equate_il ? peptide.tr('I', 'L') : peptide - if @result.key? seq_index + if @result.key? peptide json.peptide peptide - json.partial! partial: 'api/pept2lca', locals: { data: @result[seq_index] } + json.partial! partial: 'api/pept2lca', locals: { data: @result[peptide] } end end diff --git a/app/views/api/pept2taxa/pept2taxa.json.erb b/app/views/api/pept2taxa/pept2taxa.json.erb index 08ddf41..4bd8f0b 100644 --- a/app/views/api/pept2taxa/pept2taxa.json.erb +++ b/app/views/api/pept2taxa/pept2taxa.json.erb @@ -1,10 +1,9 @@ <%= Oj.dump( - @input_order.map do |k| - seq_index = @equate_il ? k.gsub(/I/,'L') : k - v = @result[seq_index] + @input_order.map do |peptide| + v = @result[peptide] v.map do |p| - res = { "peptide" => k, + res = { "peptide" => peptide, "taxon_id" => p.id, "taxon_name" => p.name, "taxon_rank" => p.rank, diff --git a/app/views/api/peptinfo/peptinfo.json.jbuilder b/app/views/api/peptinfo/peptinfo.json.jbuilder index 209e382..2498cc9 100644 --- a/app/views/api/peptinfo/peptinfo.json.jbuilder +++ b/app/views/api/peptinfo/peptinfo.json.jbuilder @@ -1,11 +1,10 @@ json.array! @input_order do |peptide| - seq_index = @equate_il ? peptide.tr('I', 'L') : peptide - if @result.key? seq_index + if @result.key? peptide json.peptide peptide - json.total_protein_count @result[seq_index][:total] - json.ec(@result[seq_index][:ec].sort_by { |value| -value[:protein_count] }) - json.partial! partial: 'api/pept2go', locals: { data: @result[seq_index][:go] } - json.partial! partial: 'api/pept2interpro', locals: { data: @result[seq_index][:ipr] } - json.partial! partial: 'api/pept2lca', locals: { data: @result[seq_index][:lca] } + json.total_protein_count @result[peptide][:total] + json.ec(@result[peptide][:ec].sort_by { |value| -value[:protein_count] }) + json.partial! partial: 'api/pept2go', locals: { data: @result[peptide][:go] } + json.partial! partial: 'api/pept2interpro', locals: { data: @result[peptide][:ipr] } + json.partial! partial: 'api/pept2lca', locals: { data: @result[peptide][:lca] } end end diff --git a/app/views/mpa/pept2data/pept2data.json.jbuilder b/app/views/mpa/pept2data/pept2data.json.jbuilder index 1191d0f..12abf2a 100644 --- a/app/views/mpa/pept2data/pept2data.json.jbuilder +++ b/app/views/mpa/pept2data/pept2data.json.jbuilder @@ -7,4 +7,3 @@ json.peptides @response do |peptide| json.data peptide["fa"]["data"] end end -json.timings @timings diff --git a/config/database.yml b/config/database.yml index 06f9ee6..50186e3 100644 --- a/config/database.yml +++ b/config/database.yml @@ -17,6 +17,7 @@ development: # Do not set this db to the same as development or production. test: <<: *default + username: unipept database: unipept_test url: <%= ENV['TEST_DATABASE_URL'] || ENV['DATABASE_URL'] %> diff --git a/db/schema.rb b/db/schema.rb index a4a15ae..85000b9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -27,17 +27,32 @@ t.string "project_website", limit: 200 end + create_table "ec_cross_references", id: :integer, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=ascii", force: :cascade do |t| + t.integer "uniprot_entry_id", null: false, unsigned: true + t.string "ec_number_code", limit: 15, null: false + end + create_table "ec_numbers", id: :integer, limit: 2, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| t.string "code", limit: 15, null: false t.string "name", limit: 155, null: false end + create_table "go_cross_references", id: :integer, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=ascii", force: :cascade do |t| + t.integer "uniprot_entry_id", null: false, unsigned: true + t.string "go_term_code", limit: 15, null: false + end + create_table "go_terms", id: :integer, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| t.string "code", limit: 15, null: false t.string "namespace", limit: 18, null: false t.string "name", limit: 200, null: false end + create_table "interpro_cross_references", id: :integer, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=ascii", force: :cascade do |t| + t.integer "uniprot_entry_id", null: false, unsigned: true + t.string "interpro_entry_code", limit: 9, null: false + end + create_table "interpro_entries", id: :integer, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=ascii", force: :cascade do |t| t.string "code", limit: 9, null: false t.string "category", limit: 32, null: false @@ -88,7 +103,6 @@ t.string "type", limit: 9, null: false t.string "name", limit: 150, null: false t.text "protein", null: false - t.text "fa", null: false end create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| diff --git a/test/controllers/api/pept2ec_controller_test.rb b/test/controllers/api/pept2ec_controller_test.rb index 1cd146a..f2ed99b 100644 --- a/test/controllers/api/pept2ec_controller_test.rb +++ b/test/controllers/api/pept2ec_controller_test.rb @@ -4,6 +4,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2ec' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[]}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}]} @@ -13,6 +15,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase end test 'should get pept2ec with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4}]}, {"peptide":"AAILER","total_protein_count":0,"ec":[]} @@ -22,6 +26,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase end test 'should get pept2ec with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[]}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}]} @@ -31,6 +37,8 @@ class Api::Pept2ecControllerTest < ActionController::TestCase end test 'should get pept2ec with extra and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4,"name":"Some Enzyme2"}]}, {"peptide":"AAILER","total_protein_count":0,"ec":[]} diff --git a/test/controllers/api/pept2funct_controller_test.rb b/test/controllers/api/pept2funct_controller_test.rb index d556740..4ddd781 100644 --- a/test/controllers/api/pept2funct_controller_test.rb +++ b/test/controllers/api/pept2funct_controller_test.rb @@ -4,6 +4,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2funct' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0005525","protein_count":3},{"go_term":"GO:0046872","protein_count":3},{"go_term":"GO:0007049","protein_count":3}],"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}],"go":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0000015","protein_count":1},{"go_term":"GO:0006096","protein_count":1},{"go_term":"GO:0009986","protein_count":1}],"ipr":[{"code":"IPR000169","protein_count":1}]} @@ -13,6 +15,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase end test 'should get pept2funct with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4}],"go":[{"go_term":"GO:0004674","protein_count":1},{"go_term":"GO:0005634","protein_count":1},{"go_term":"GO:0005524","protein_count":1},{"go_term":"GO:0016301","protein_count":1}],"ipr":[{"code":"IPR000169","protein_count":1}]}, {"peptide":"AAILER","total_protein_count":0,"ec":[],"go":[],"ipr":[]} @@ -22,6 +26,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase end test 'should get pept2funct with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"},{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}],"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}],"go":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}],"ipr":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site","type":"Active_site"}]} @@ -31,6 +37,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase end test 'should get pept2funct with domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0007049","protein_count":3}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3}]}],"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}],"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0009986","protein_count":1}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0000015","protein_count":1}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0006096","protein_count":1}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1}]}]} @@ -40,6 +48,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase end test 'should get pept2funct with extra and domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"}]}],"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}],"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}]} @@ -49,6 +59,8 @@ class Api::Pept2functControllerTest < ActionController::TestCase end test 'should get pept2funct with extra and domains and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4,"name":"Some Enzyme2"}],"go":[{"biological process":[{"go_term":"GO:0004674","protein_count":1,"name":"some function 5"},{"go_term":"GO:0016301","protein_count":1,"name":"some function 8"}]},{"molecular function":[{"go_term":"GO:0005634","protein_count":1,"name":"some function 6"}]},{"cellular component":[{"go_term":"GO:0005524","protein_count":1,"name":"some function 7"}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}]}, {"peptide":"AAILER","total_protein_count":0,"ec":[],"go":[],"ipr":[]} diff --git a/test/controllers/api/pept2go_controller_test.rb b/test/controllers/api/pept2go_controller_test.rb index 3356357..6b269c6 100644 --- a/test/controllers/api/pept2go_controller_test.rb +++ b/test/controllers/api/pept2go_controller_test.rb @@ -4,6 +4,8 @@ class Api::Pept2goControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2go' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"go":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0005525","protein_count":3},{"go_term":"GO:0046872","protein_count":3},{"go_term":"GO:0007049","protein_count":3}]}, {"peptide":"AAILER","total_protein_count":1,"go":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0000015","protein_count":1},{"go_term":"GO:0006096","protein_count":1},{"go_term":"GO:0009986","protein_count":1}]} @@ -13,14 +15,19 @@ class Api::Pept2goControllerTest < ActionController::TestCase end test 'should get pept2go with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ - {"peptide":"AAIER","total_protein_count":22,"go":[{"go_term":"GO:0004674","protein_count":1},{"go_term":"GO:0005634","protein_count":1},{"go_term":"GO:0005524","protein_count":1},{"go_term":"GO:0016301","protein_count":1}]},{"peptide":"AAILER","total_protein_count":0,"go":[]} + {"peptide":"AAIER","total_protein_count":22,"go":[{"go_term":"GO:0004674","protein_count":1},{"go_term":"GO:0005634","protein_count":1},{"go_term":"GO:0005524","protein_count":1},{"go_term":"GO:0016301","protein_count":1}]}, + {"peptide":"AAILER","total_protein_count":0,"go":[]} ]' get :pept2go, params: { input: %w[AAIER AAILER], format: 'json', equate_il: 'true' } end test 'should get pept2go with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"go":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"},{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}]}, {"peptide":"AAILER","total_protein_count":1,"go":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}]} @@ -30,6 +37,8 @@ class Api::Pept2goControllerTest < ActionController::TestCase end test 'should get pept2go with domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0007049","protein_count":3}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3}]}]}, {"peptide":"AAILER","total_protein_count":1,"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0009986","protein_count":1}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0000015","protein_count":1}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0006096","protein_count":1}]}]} @@ -39,6 +48,8 @@ class Api::Pept2goControllerTest < ActionController::TestCase end test 'should get pept2go with extra and domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"}]}]}, {"peptide":"AAILER","total_protein_count":1,"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"}]}]} @@ -48,6 +59,8 @@ class Api::Pept2goControllerTest < ActionController::TestCase end test 'should get pept2go with extra and domains and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"go":[{"biological process":[{"go_term":"GO:0004674","protein_count":1,"name":"some function 5"},{"go_term":"GO:0016301","protein_count":1,"name":"some function 8"}]},{"molecular function":[{"go_term":"GO:0005634","protein_count":1,"name":"some function 6"}]},{"cellular component":[{"go_term":"GO:0005524","protein_count":1,"name":"some function 7"}]}]}, {"peptide":"AAILER","total_protein_count":0,"go":[]} diff --git a/test/controllers/api/pept2interpro_controller_test.rb b/test/controllers/api/pept2interpro_controller_test.rb index c69b60a..dc68f88 100644 --- a/test/controllers/api/pept2interpro_controller_test.rb +++ b/test/controllers/api/pept2interpro_controller_test.rb @@ -4,6 +4,8 @@ class Api::Pept2interproControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2interpro' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ipr":[{"code":"IPR000169","protein_count":1}]} @@ -13,6 +15,8 @@ class Api::Pept2interproControllerTest < ActionController::TestCase end test 'should get pept2interpro with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ipr":[{"code":"IPR000169","protein_count":1}]}, {"peptide":"AAILER","total_protein_count":0,"ipr":[]} @@ -22,6 +26,8 @@ class Api::Pept2interproControllerTest < ActionController::TestCase end test 'should get pept2interpro with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ipr":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site","type":"Active_site"}]} @@ -31,6 +37,8 @@ class Api::Pept2interproControllerTest < ActionController::TestCase end test 'should get pept2interpro with domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1}]}]} @@ -40,6 +48,8 @@ class Api::Pept2interproControllerTest < ActionController::TestCase end test 'should get pept2interpro with extra and domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ipr":[]}, {"peptide":"AAILER","total_protein_count":1,"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}]} @@ -49,6 +59,8 @@ class Api::Pept2interproControllerTest < ActionController::TestCase end test 'should get pept2interpro with extra and domains and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}]}, {"peptide":"AAILER","total_protein_count":0,"ipr":[]} diff --git a/test/controllers/api/pept2lca_controller_test.rb b/test/controllers/api/pept2lca_controller_test.rb index a4ecf6c..26e66fa 100644 --- a/test/controllers/api/pept2lca_controller_test.rb +++ b/test/controllers/api/pept2lca_controller_test.rb @@ -4,6 +4,8 @@ class Api::Pept2lcaControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2lca' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom"}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"} @@ -13,6 +15,8 @@ class Api::Pept2lcaControllerTest < ActionController::TestCase end test 'should get pept2lca with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"} @@ -22,6 +26,8 @@ class Api::Pept2lcaControllerTest < ActionController::TestCase end test 'should get pept2lca with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":null,"subspecies_id":null,"varietas_id":null,"forma_id":null}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":1,"subspecies_id":null,"varietas_id":null,"forma_id":null} @@ -31,6 +37,8 @@ class Api::Pept2lcaControllerTest < ActionController::TestCase end test 'should get pept2lca with names' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom"}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"} @@ -40,6 +48,8 @@ class Api::Pept2lcaControllerTest < ActionController::TestCase end test 'should get pept2lca with extra and names' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":null,"species_name":"","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":1,"species_name":"species1","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""} @@ -49,6 +59,8 @@ class Api::Pept2lcaControllerTest < ActionController::TestCase end test 'should get pept2lca with extra and names and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":1,"species_name":"species1","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":1,"species_name":"species1","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""} diff --git a/test/controllers/api/pept2prot_controller_test.rb b/test/controllers/api/pept2prot_controller_test.rb index 61a7df9..19db784 100644 --- a/test/controllers/api/pept2prot_controller_test.rb +++ b/test/controllers/api/pept2prot_controller_test.rb @@ -4,6 +4,8 @@ class Api::Pept2protControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2prot' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","uniprot_id":"nr","protein_name":"some name","taxon_id":1,"protein":"ELABA"}, {"peptide":"AAILER","uniprot_id":"nr3","protein_name":"some name","taxon_id":2,"protein":"AAILERAGGAR"}, @@ -14,6 +16,8 @@ class Api::Pept2protControllerTest < ActionController::TestCase end test 'should get pept2prot with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","uniprot_id":"nr","protein_name":"some name","taxon_id":1,"protein":"ELABA"}, {"peptide":"AAIER","uniprot_id":"nr2","protein_name":"some name","taxon_id":2,"protein":"EIABA"}, @@ -25,21 +29,25 @@ class Api::Pept2protControllerTest < ActionController::TestCase end test 'should get pept2prot with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ - {"peptide":"AAIER","uniprot_id":"nr","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"1.2.3.4","go_references":"goid","interpro_references":"IPR000126"}, - {"peptide":"AAILER","uniprot_id":"nr3","protein_name":"some name","taxon_id":2,"taxon_name":"kingdom1","ec_references":"","go_references":"","interpro_references":""}, - {"peptide":"AAILER","uniprot_id":"nr4","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"","go_references":"","interpro_references":""} + {"peptide":"AAIER","uniprot_id":"nr","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"1.2.3.4","go_references":"goid","interpro_references":"IPR000126","protein":"ELABA"}, + {"peptide":"AAILER","uniprot_id":"nr3","protein_name":"some name","taxon_id":2,"taxon_name":"kingdom1","ec_references":"","go_references":"","interpro_references":"","protein":"AAILERAGGAR"}, + {"peptide":"AAILER","uniprot_id":"nr4","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"","go_references":"","interpro_references":"","protein":"AAILERA"} ]' get :pept2prot, params: { input: %w[AAIER AAILER], format: 'json', extra: 'true' } end test 'should get pept2prot with extra and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ - {"peptide":"AAIER","uniprot_id":"nr","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"1.2.3.4","go_references":"goid","interpro_references":"IPR000126"}, - {"peptide":"AAIER","uniprot_id":"nr2","protein_name":"some name","taxon_id":2,"taxon_name":"kingdom1","ec_references":"","go_references":"","interpro_references":""}, - {"peptide":"AAILER","uniprot_id":"nr3","protein_name":"some name","taxon_id":2,"taxon_name":"kingdom1","ec_references":"","go_references":"","interpro_references":""}, - {"peptide":"AAILER","uniprot_id":"nr4","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"","go_references":"","interpro_references":""} + {"peptide":"AAIER","uniprot_id":"nr","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"1.2.3.4","go_references":"goid","interpro_references":"IPR000126","protein":"ELABA"}, + {"peptide":"AAIER","uniprot_id":"nr2","protein_name":"some name","taxon_id":2,"taxon_name":"kingdom1","ec_references":"","go_references":"","interpro_references":"","protein":"EIABA"}, + {"peptide":"AAILER","uniprot_id":"nr3","protein_name":"some name","taxon_id":2,"taxon_name":"kingdom1","ec_references":"","go_references":"","interpro_references":"","protein":"AAILERAGGAR"}, + {"peptide":"AAILER","uniprot_id":"nr4","protein_name":"some name","taxon_id":1,"taxon_name":"species1","ec_references":"","go_references":"","interpro_references":"","protein":"AAILERA"} ]' get :pept2prot, params: { input: %w[AAIER AAILER], format: 'json', equate_il: 'true', extra: 'true' } diff --git a/test/controllers/api/pept2taxa_controller_test.rb b/test/controllers/api/pept2taxa_controller_test.rb index 755d5fa..4b99a1d 100644 --- a/test/controllers/api/pept2taxa_controller_test.rb +++ b/test/controllers/api/pept2taxa_controller_test.rb @@ -4,6 +4,8 @@ class Api::Pept2taxaControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2taxa' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"}, @@ -14,6 +16,8 @@ class Api::Pept2taxaControllerTest < ActionController::TestCase end test 'should get pept2taxa with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"}, {"peptide":"AAIER","taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom"}, @@ -25,6 +29,8 @@ class Api::Pept2taxaControllerTest < ActionController::TestCase end test 'should get pept2taxa with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":1,"subspecies_id":null,"varietas_id":null,"forma_id":null}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":1,"subspecies_id":null,"varietas_id":null,"forma_id":null}, @@ -35,6 +41,8 @@ class Api::Pept2taxaControllerTest < ActionController::TestCase end test 'should get pept2taxa with names' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species"}, @@ -45,6 +53,8 @@ class Api::Pept2taxaControllerTest < ActionController::TestCase end test 'should get pept2taxa with extra and names' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":1,"species_name":"species1","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""}, {"peptide":"AAILER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":1,"species_name":"species1","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""}, @@ -55,6 +65,8 @@ class Api::Pept2taxaControllerTest < ActionController::TestCase end test 'should get pept2taxa with extra and names and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":1,"species_name":"species1","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""}, {"peptide":"AAIER","taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom","superkingdom_id":null,"superkingdom_name":"","kingdom_id":2,"kingdom_name":"kingdom1","subkingdom_id":null,"subkingdom_name":"","superphylum_id":null,"superphylum_name":"","phylum_id":null,"phylum_name":"","subphylum_id":null,"subphylum_name":"","superclass_id":null,"superclass_name":"","class_id":null,"class_name":"","subclass_id":null,"subclass_name":"","infraclass_id":null,"infraclass_name":"","superorder_id":null,"superorder_name":"","order_id":null,"order_name":"","suborder_id":null,"suborder_name":"","infraorder_id":null,"infraorder_name":"","parvorder_id":null,"parvorder_name":"","superfamily_id":null,"superfamily_name":"","family_id":null,"family_name":"","subfamily_id":null,"subfamily_name":"","tribe_id":null,"tribe_name":"","subtribe_id":null,"subtribe_name":"","genus_id":null,"genus_name":"","subgenus_id":null,"subgenus_name":"","species_group_id":null,"species_group_name":"","species_subgroup_id":null,"species_subgroup_name":"","species_id":null,"species_name":"","subspecies_id":null,"subspecies_name":"","varietas_id":null,"varietas_name":"","forma_id":null,"forma_name":""}, diff --git a/test/controllers/api/peptinfo_controller_test.rb b/test/controllers/api/peptinfo_controller_test.rb index 125f7ae..b44e127 100644 --- a/test/controllers/api/peptinfo_controller_test.rb +++ b/test/controllers/api/peptinfo_controller_test.rb @@ -4,6 +4,8 @@ class Api::PeptinfoControllerTest < ActionController::TestCase teardown :assert_success test 'should get peptinfo' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0005525","protein_count":3},{"go_term":"GO:0046872","protein_count":3},{"go_term":"GO:0007049","protein_count":3}],"ipr":[],"taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom"}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}],"go":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0000015","protein_count":1},{"go_term":"GO:0006096","protein_count":1},{"go_term":"GO:0009986","protein_count":1}],"ipr":[{"code":"IPR000169","protein_count":1}],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species"} @@ -13,6 +15,8 @@ class Api::PeptinfoControllerTest < ActionController::TestCase end test 'should get peptinfo with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4}],"go":[{"go_term":"GO:0004674","protein_count":1},{"go_term":"GO:0005634","protein_count":1},{"go_term":"GO:0005524","protein_count":1},{"go_term":"GO:0016301","protein_count":1}],"ipr":[{"code":"IPR000169","protein_count":1}],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species"}, {"peptide":"AAILER","total_protein_count":0,"ec":[],"go":[],"ipr":[],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species"} @@ -22,6 +26,8 @@ class Api::PeptinfoControllerTest < ActionController::TestCase end test 'should get peptinfo with extra' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"},{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}],"ipr":[],"taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":null,"subspecies_id":null,"varietas_id":null,"forma_id":null}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}],"go":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}],"ipr":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site","type":"Active_site"}],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":1,"subspecies_id":null,"varietas_id":null,"forma_id":null} @@ -31,6 +37,8 @@ class Api::PeptinfoControllerTest < ActionController::TestCase end test 'should get peptinfo with domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3},{"go_term":"GO:0007049","protein_count":3}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3}]}],"ipr":[],"taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom"}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1}],"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1},{"go_term":"GO:0009986","protein_count":1}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1},{"go_term":"GO:0000015","protein_count":1}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1},{"go_term":"GO:0006096","protein_count":1}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1}]}],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species"} @@ -40,6 +48,8 @@ class Api::PeptinfoControllerTest < ActionController::TestCase end test 'should get peptinfo with extra and domains' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":3,"ec":[],"go":[{"molecular function":[{"go_term":"GO:0051301","protein_count":3,"name":"some function 9"},{"go_term":"GO:0007049","protein_count":3,"name":"some function 12"}]},{"cellular component":[{"go_term":"GO:0005525","protein_count":3,"name":"some function 10"}]},{"biological process":[{"go_term":"GO:0046872","protein_count":3,"name":"some function 11"}]}],"ipr":[],"taxon_id":2,"taxon_name":"kingdom1","taxon_rank":"kingdom","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":null,"subspecies_id":null,"varietas_id":null,"forma_id":null}, {"peptide":"AAILER","total_protein_count":1,"ec":[{"ec_number":"4.2.1.11","protein_count":1,"name":"Some Enzyme3"}],"go":[{"cellular component":[{"go_term":"GO:0005576","protein_count":1,"name":"some function 16"},{"go_term":"GO:0009986","protein_count":1,"name":"some function 21"}]},{"molecular function":[{"go_term":"GO:0000287","protein_count":1,"name":"some function 17"},{"go_term":"GO:0000015","protein_count":1,"name":"some function 19"}]},{"biological process":[{"go_term":"GO:0004634","protein_count":1,"name":"some function 18"},{"go_term":"GO:0006096","protein_count":1,"name":"some function 20"}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":1,"subspecies_id":null,"varietas_id":null,"forma_id":null} @@ -49,6 +59,8 @@ class Api::PeptinfoControllerTest < ActionController::TestCase end test 'should get peptinfo with extra and domains and il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '[ {"peptide":"AAIER","total_protein_count":22,"ec":[{"ec_number":"2.7.11.1","protein_count":4,"name":"Some Enzyme2"}],"go":[{"biological process":[{"go_term":"GO:0004674","protein_count":1,"name":"some function 5"},{"go_term":"GO:0016301","protein_count":1,"name":"some function 8"}]},{"molecular function":[{"go_term":"GO:0005634","protein_count":1,"name":"some function 6"}]},{"cellular component":[{"go_term":"GO:0005524","protein_count":1,"name":"some function 7"}]}],"ipr":[{"Active_site":[{"code":"IPR000169","protein_count":1,"name":"Cysteine peptidase, cysteine active site"}]}],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":1,"subspecies_id":null,"varietas_id":null,"forma_id":null}, {"peptide":"AAILER","total_protein_count":0,"ec":[],"go":[],"ipr":[],"taxon_id":1,"taxon_name":"species1","taxon_rank":"species","superkingdom_id":null,"kingdom_id":2,"subkingdom_id":null,"superphylum_id":null,"phylum_id":null,"subphylum_id":null,"superclass_id":null,"class_id":null,"subclass_id":null,"infraclass_id":null,"superorder_id":null,"order_id":null,"suborder_id":null,"infraorder_id":null,"parvorder_id":null,"superfamily_id":null,"family_id":null,"subfamily_id":null,"tribe_id":null,"subtribe_id":null,"genus_id":null,"subgenus_id":null,"species_group_id":null,"species_subgroup_id":null,"species_id":1,"subspecies_id":null,"varietas_id":null,"forma_id":null} diff --git a/test/controllers/mpa/pept2data_controller_test.rb b/test/controllers/mpa/pept2data_controller_test.rb index 985bb8a..8a8e83a 100644 --- a/test/controllers/mpa/pept2data_controller_test.rb +++ b/test/controllers/mpa/pept2data_controller_test.rb @@ -4,10 +4,12 @@ class Mpa::Pept2dataControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2data' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '{ "peptides":[ - {"sequence":"AAIER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":22,"EC":4,"GO":2,"IPR":3},"data":{"EC:2.7.11.1":4,"GO:0004674":1,"GO:0005634":1,"GO:0005524":1,"GO:0016301":1,"IPR:IPR000169":1}}}, - {"sequence":"AAILER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":0,"EC":0,"GO":0,"IPR":0},"data":{}}} + {"sequence":"AAILER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":1,"EC":1,"GO":1,"IPR":1},"data":{"EC:4.2.1.11": 1,"GO:0005576": 1,"GO:0000287": 1,"GO:0004634": 1,"GO:0000015": 1,"GO:0006096": 1,"GO:0009986": 1,"IPR:IPR000169": 1}}}, + {"sequence":"AAIER","lca":2,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"fa":{"counts":{"all":3,"EC":0,"GO":3,"IPR":0},"data":{"GO:0051301":3,"GO:0005525":3,"GO:0046872":3,"GO:0007049":3}}} ] }' @@ -15,36 +17,16 @@ class Mpa::Pept2dataControllerTest < ActionController::TestCase end test 'should get pept2data with il' do - @expected = '{ - "peptides":[ - {"sequence":"AAIER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":22,"EC":4,"GO":2,"IPR":3},"data":{"EC:2.7.11.1":4,"GO:0004674":1,"GO:0005634":1,"GO:0005524":1,"GO:0016301":1,"IPR:IPR000169":1}}}, - {"sequence":"AAILER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":0,"EC":0,"GO":0,"IPR":0},"data":{}}} - ] - }' - - get :pept2data, params: { peptides: %w[AAIER AAILER], format: 'json', equate_il: 'true' } - end + stub_http_request! 'test/fixtures/index/response_equate.json' - test 'should get pept2data with missed' do @expected = '{ "peptides":[ - {"sequence":"AAIER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":22,"EC":4,"GO":2,"IPR":3},"data":{"EC:2.7.11.1":4,"GO:0004674":1,"GO:0005634":1,"GO:0005524":1,"GO:0016301":1,"IPR:IPR000169":1}}}, - {"sequence":"AAILER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":0,"EC":0,"GO":0,"IPR":0},"data":{}}} + {"sequence":"AAILER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":0,"EC":0,"GO":0,"IPR":0},"data":{}}}, + {"sequence":"AAIER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":22,"EC":4,"GO":2,"IPR":3},"data":{"EC:2.7.11.1":4,"GO:0004674":1,"GO:0005634":1,"GO:0005524":1,"GO:0016301":1,"IPR:IPR000169":1}}} ] }' - get :pept2data, params: { peptides: %w[AAIER AAILER], format: 'json', missed: 'true' } - end - - test 'should get pept2data with missed and il' do - @expected = '{ - "peptides":[ - {"sequence":"AAIER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":22,"EC":4,"GO":2,"IPR":3},"data":{"EC:2.7.11.1":4,"GO:0004674":1,"GO:0005634":1,"GO:0005524":1,"GO:0016301":1,"IPR:IPR000169":1}}}, - {"sequence":"AAILER","lca":1,"lineage":[null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,1,null,null,null,null],"fa":{"counts":{"all":0,"EC":0,"GO":0,"IPR":0},"data":{}}} - ] - }' - - get :pept2data, params: { peptides: %w[AAIER AAILER], format: 'json', equate_il: 'true', missed: 'true' } + get :pept2data, params: { peptides: %w[AAIER AAILER], format: 'json', equate_il: 'true' } end private diff --git a/test/controllers/mpa/pept2filtered_controller_test.rb b/test/controllers/mpa/pept2filtered_controller_test.rb index 2d1da4d..1989660 100644 --- a/test/controllers/mpa/pept2filtered_controller_test.rb +++ b/test/controllers/mpa/pept2filtered_controller_test.rb @@ -4,14 +4,29 @@ class Mpa::Pept2filteredControllerTest < ActionController::TestCase teardown :assert_success test 'should get pept2filtered' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '{ "peptides":[ - {"sequence":"AALER","taxa":[1,2],"fa":{"go_terms":["goid"],"ec_numbers":["EC:1.2.3.4"],"interpro_entries":["IPR:000126"]}}, - {"sequence":"AALLER","taxa":[2,1],"fa":{"go_terms":[],"ec_numbers":[],"interpro_entries":[]}} + {"sequence":"AAILER","taxa":[1, 2],"fa":{"counts":{"GO":1, "EC":1, "all":1, "IPR":1}, "data":{"EC:4.2.1.11":1, "GO:0005576":1, "GO:0000287":1, "GO:0004634":1, "GO:0000015":1, "GO:0006096":1, "GO:0009986":1, "IPR:IPR000169":1}}}, + {"sequence":"AAIER","taxa":[1],"fa":{"counts":{"IPR":0, "EC":0, "all":3, "GO":3}, "data":{"GO:0051301":3, "GO:0005525":3, "GO:0046872":3, "GO:0007049":3}}} ] }' - get :pept2filtered, params: { peptides: %w[AAIER AALER AAILER AALLER], taxa: %w[1 2 13 14 15], format: 'json' } + get :pept2filtered, params: { peptides: %w[AAIER AAILER], taxa: %w[1 2 13 14 15], format: 'json' } + end + + test 'should get pept2filtered with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + + @expected = '{ + "peptides":[ + {"sequence":"AAILER","taxa":[1, 2],"fa":{"counts":{"GO":0, "EC":0, "all":0, "IPR":0}, "data":{}}}, + {"sequence":"AAIER","taxa":[1, 2],"fa":{"counts":{"IPR":3, "EC":4, "all":22, "GO":2}, "data":{"EC:2.7.11.1":4, "GO:0004674":1, "GO:0005634":1, "GO:0005524":1, "GO:0016301":1, "IPR:IPR000169":1}}} + ] + }' + + get :pept2filtered, params: { peptides: %w[AAIER AAILER], taxa: %w[1 2 13 14 15], format: 'json', equate_il: 'true' } end private diff --git a/test/controllers/private_api/proteins_controller_test.rb b/test/controllers/private_api/proteins_controller_test.rb index 36cf54d..3a4e679 100644 --- a/test/controllers/private_api/proteins_controller_test.rb +++ b/test/controllers/private_api/proteins_controller_test.rb @@ -4,28 +4,36 @@ class PrivateApi::ProteinsControllerTest < ActionController::TestCase teardown :assert_success test 'should get proteins' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '{ - "lca":1,"common_lineage":[2,1],"proteins":[{"uniprotAccessionId":"nr2","name":"some name","organism":2,"ecNumbers":[],"goTerms":[],"interproEntries":[]},{"uniprotAccessionId":"nr","name":"some name","organism":1,"ecNumbers":["1.2.3.4"],"goTerms":["goid"],"interproEntries":["IPR000126"]}] + "lca":1,"common_lineage":[],"proteins":[{"uniprotAccessionId":"nr3","name":"some name","organism":2,"ecNumbers":[],"goTerms":[],"interproEntries":[]},{"uniprotAccessionId":"nr4","name":"some name","organism":1,"ecNumbers":[],"goTerms":[],"interproEntries":[]}] }' - get :proteins, params: { peptide: "AAIER" } + get :proteins, params: { peptide: "AAILER" } end test 'should get proteins with il' do + stub_http_request! 'test/fixtures/index/response_equate.json' + @expected = '{ - "lca":1,"common_lineage":[2,1],"proteins":[{"uniprotAccessionId":"nr2","name":"some name","organism":2,"ecNumbers":[],"goTerms":[],"interproEntries":[]},{"uniprotAccessionId":"nr","name":"some name","organism":1,"ecNumbers":["1.2.3.4"],"goTerms":["goid"],"interproEntries":["IPR000126"]}] + "lca":1, "common_lineage":[], "proteins":[{"uniprotAccessionId":"nr3", "name":"some name", "organism":2, "ecNumbers":[], "goTerms":[], "interproEntries":[]}, {"uniprotAccessionId":"nr4", "name":"some name", "organism":1, "ecNumbers":[], "goTerms":[], "interproEntries":[]}] }' - get :proteins, params: { peptide: "AAIER", equate_il: 'true' } + get :proteins, params: { peptide: "AAILER", equate_il: 'true' } end test 'should get proteins no match' do + stub_http_request! 'test/fixtures/index/response_empty.json' + @expected = '{"lca":-1,"common_lineage":[],"proteins":[]}' get :proteins, params: { peptide: "AAAAAAAAA" } end test 'should get proteins too short sequence' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '{ "name":"Sequence too short", "message":"The peptide sequence you provided is too short. It should contain at least 5 valid amino acids." @@ -35,6 +43,8 @@ class PrivateApi::ProteinsControllerTest < ActionController::TestCase end test 'should get proteins without peptides' do + stub_http_request! 'test/fixtures/index/response.json' + @expected = '{ "name":"Invalid peptide provided", "message":"No peptide sequence was provided. Please provide a valid peptide sequence." diff --git a/test/fixtures/index/response.json b/test/fixtures/index/response.json new file mode 100644 index 0000000..193e8e7 --- /dev/null +++ b/test/fixtures/index/response.json @@ -0,0 +1,60 @@ +{ + "result": [ + { + "sequence": "AAILER", + "lca": 1, + "taxa": [ + 1, + 2 + ], + "uniprot_accession_numbers": [ + "nr3", + "nr4" + ], + "fa": { + "counts": { + "GO": 1, + "EC": 1, + "all": 1, + "IPR": 1 + }, + "data": { + "EC:4.2.1.11": 1, + "GO:0005576": 1, + "GO:0000287": 1, + "GO:0004634": 1, + "GO:0000015": 1, + "GO:0006096": 1, + "GO:0009986": 1, + "IPR:IPR000169": 1 + } + }, + "cutoff_used": false + }, + { + "sequence": "AAIER", + "lca": 2, + "taxa": [ + 1 + ], + "uniprot_accession_numbers": [ + "nr" + ], + "fa": { + "counts": { + "IPR": 0, + "EC": 0, + "all": 3, + "GO": 3 + }, + "data": { + "GO:0051301": 3, + "GO:0005525": 3, + "GO:0046872": 3, + "GO:0007049": 3 + } + }, + "cutoff_used": false + } + ] +} diff --git a/test/fixtures/index/response_empty.json b/test/fixtures/index/response_empty.json new file mode 100644 index 0000000..2508159 --- /dev/null +++ b/test/fixtures/index/response_empty.json @@ -0,0 +1,3 @@ +{ + "result": [] +} diff --git a/test/fixtures/index/response_equate.json b/test/fixtures/index/response_equate.json new file mode 100644 index 0000000..bbf741a --- /dev/null +++ b/test/fixtures/index/response_equate.json @@ -0,0 +1,55 @@ +{ + "result": [ + { + "sequence": "AAILER", + "lca": 1, + "taxa": [ + 1, + 2 + ], + "uniprot_accession_numbers": [ + "nr3", + "nr4" + ], + "fa": { + "counts": { + "GO": 0, + "EC": 0, + "all": 0, + "IPR": 0 + }, + "data": {} + }, + "cutoff_used": false + }, + { + "sequence": "AAIER", + "lca": 1, + "taxa": [ + 1, + 2 + ], + "uniprot_accession_numbers": [ + "nr", + "nr2" + ], + "fa": { + "counts": { + "IPR": 3, + "EC": 4, + "all": 22, + "GO": 2 + }, + "data": { + "EC:2.7.11.1": 4, + "GO:0004674": 1, + "GO:0005634": 1, + "GO:0005524": 1, + "GO:0016301": 1, + "IPR:IPR000169": 1 + } + }, + "cutoff_used": false + } + ] +} diff --git a/test/fixtures/peptides.yml b/test/fixtures/peptides.yml deleted file mode 100644 index dd43bfb..0000000 --- a/test/fixtures/peptides.yml +++ /dev/null @@ -1,57 +0,0 @@ -# == Schema Information -# -# Table name: peptides -# -# id :integer unsigned, not null, primary key -# sequence_id :integer unsigned, not null -# original_sequence_id :integer unsigned, not null -# uniprot_entry_id :integer unsigned, not null -# - -pept1: - id: 1 - sequence_id: 1 - original_sequence_id: 2 - uniprot_entry_id: 1 - -pept2: - id: 2 - sequence_id: 1 - original_sequence_id: 1 - uniprot_entry_id: 2 - -pept3: - id: 3 - sequence_id: 5 - original_sequence_id: 4 - uniprot_entry_id: 3 - -pept4: - id: 4 - sequence_id: 5 - original_sequence_id: 4 - uniprot_entry_id: 4 - -pept5: - id: 5 - sequence_id: 6 - original_sequence_id: 6 - uniprot_entry_id: 3 - -pept6: - id: 6 - sequence_id: 7 - original_sequence_id: 7 - uniprot_entry_id: 5 - -pept7: - id: 7 - sequence_id: 7 - original_sequence_id: 7 - uniprot_entry_id: 6 - -pept8: - id: 8 - sequence_id: 7 - original_sequence_id: 7 - uniprot_entry_id: 7 diff --git a/test/fixtures/sequences.yml b/test/fixtures/sequences.yml deleted file mode 100644 index 04d808d..0000000 --- a/test/fixtures/sequences.yml +++ /dev/null @@ -1,74 +0,0 @@ -# == Schema Information -# -# Table name: sequences -# -# id :integer unsigned, not null, primary key -# sequence :string(50) not null -# lca :integer unsigned -# lca_il :integer unsigned -# fa :binary(16777215) -# fa_il :binary(16777215) -# - -sequence1: - id: 1 - sequence: "AALER" - lca: 2 - lca_il: 1 - fa: '{"num":{"all":1,"EC":1,"GO":1, "IPR":1},"data":{"GO:0016569":1,"GO:0006281":1,"GO:0000781":1,"EC:2.7.11.1":1,"IPR:IPR000169":1}}' - fa_il: '{"num":{"all":22,"EC":4,"GO":2,"IPR":3},"data":{"EC:2.7.11.1":4,"GO:0004674":1,"GO:0005634":1,"GO:0005524":1,"GO:0016301":1,"IPR:IPR000169":1}}' - -sequence2: - id: 2 - sequence: "AAIER" - lca: 2 - lca_il: 1 - fa: '{"num":{"all":3,"EC":0,"GO":3},"data":{"GO:0051301":3,"GO:0005525":3,"GO:0046872":3,"GO:0007049":3}}' - fa_il: '{"num":{"all":4,"EC":1,"GO":4, "IPR":2},"data":{"GO:0005759":1,"GO:0004760":1,"GO:0051301":3,"GO:0005739":1,"IPR:IPR000169":1}}' -sequence3: - id: 3 - sequence: "RANDOM" - lca: 1 - lca_il: 1 - fa: - fa_il: - -sequence4: - id: 4 - sequence: "AAILER" - lca: 1 - lca_il: 2 - fa: '{"num":{"all":1,"EC":1,"GO":1,"IPR":1},"data":{"GO:0005576":1,"GO:0000287":1,"GO:0004634":1,"GO:0000015":1,"GO:0006096":1,"EC:4.2.1.11":1,"GO:0009986":1,"IPR:IPR000169":1}}' - fa_il: - -sequence5: - id: 5 - sequence: "AALLER" - lca: 2 - lca_il: 1 - fa: - fa_il: - -sequence6: - id: 6 - sequence: "AGGAR" - lca: 1 - lca_il: 1 - fa: - fa_il: - -sequence7: - id: 7 - sequence: "TEST" - lca: 13 - lca_il: 13 - fa: - fa_il: - -sequence8: - id: 8 - sequence: "TAST" - lca: 13 - lca_il: 13 - fa: - fa_il: diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml deleted file mode 100644 index 60edadf..0000000 --- a/test/fixtures/users.yml +++ /dev/null @@ -1,20 +0,0 @@ -# == Schema Information -# -# Table name: users -# -# id :integer not null, primary key -# username :string(8) not null -# admin :integer default(0), not null -# - -bart: - username: bart - admin: 0 - -bart_admin: - username: bmesuere - admin: 1 - -guest: - username: guest - admin: 1 diff --git a/test/models/peptide_test.rb b/test/models/peptide_test.rb deleted file mode 100644 index 529f78e..0000000 --- a/test/models/peptide_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -# == Schema Information -# -# Table name: peptides -# -# id :integer unsigned, not null, primary key -# sequence_id :integer unsigned, not null -# original_sequence_id :integer unsigned, not null -# uniprot_entry_id :integer unsigned, not null -# - -require 'test_helper' - -class PeptideTest < ActiveSupport::TestCase - test 'should fail to create new peptide' do - assert_not Peptide.new.save - end - - test 'should raise error on save' do - peptide = peptides(:pept1) - assert_raises(ActiveRecord::ReadOnlyRecord) { peptide.save } - end - - test 'should raise error on sequence_id change' do - peptide = peptides(:pept1) - assert_raises(ActiveRecord::ActiveRecordError) { peptide.update_attribute(:sequence_id, 35) } - end - - test 'should raise error on delete' do - peptide = peptides(:pept1) - assert_raises(ActiveRecord::ReadOnlyRecord) { peptide.delete } - end - - test 'should raise error on destroy' do - peptide = peptides(:pept1) - assert_raises(ActiveRecord::ReadOnlyRecord) { peptide.destroy } - end -end diff --git a/test/models/sequence_test.rb b/test/models/sequence_test.rb deleted file mode 100644 index 1957440..0000000 --- a/test/models/sequence_test.rb +++ /dev/null @@ -1,262 +0,0 @@ -# == Schema Information -# -# Table name: sequences -# -# id :integer unsigned, not null, primary key -# sequence :string(50) not null -# lca :integer unsigned -# lca_il :integer unsigned -# fa :binary(16777215) -# fa_il :binary(16777215) -# - -require 'test_helper' - -class SequenceTest < ActiveSupport::TestCase - test 'should fail to create new sequence' do - assert_not Sequence.new.save - end - - test 'should raise error on save' do - sequence = sequences(:sequence1) - assert_raises(ActiveRecord::ReadOnlyRecord) { sequence.save } - end - - test 'should raise error on new save' do - sequence = Sequence.new(id: 20, sequence: 'NO', lca: 1, lca_il: 1, fa: '{}', fa_il: '{}') - assert_raises(ActiveRecord::ReadOnlyRecord) { sequence.save } - end - - test 'should raise error on sequence change' do - sequence = sequences(:sequence1) - assert_raises(ActiveRecord::ActiveRecordError) { sequence.update_attribute(:sequence, 'AAAAAAA') } - end - - test 'should raise error on lca change' do - sequence = sequences(:sequence1) - assert_raises(ActiveRecord::ActiveRecordError) { sequence.update_attribute(:lca, 35) } - end - - test 'should raise error on lca_il change' do - sequence = sequences(:sequence1) - assert_raises(ActiveRecord::ActiveRecordError) { sequence.update_attribute(:lca_il, 35) } - end - - test 'should raise error on delete' do - sequence = sequences(:sequence1) - assert_raises(ActiveRecord::ReadOnlyRecord) { sequence.delete } - end - - test 'should raise error on destroy' do - sequence = sequences(:sequence1) - assert_raises(ActiveRecord::ReadOnlyRecord) { sequence.destroy } - end - - test 'should give correct result for peptides' do - peptide1 = peptides(:pept1) - peptide2 = peptides(:pept2) - sequence = sequences(:sequence1) - assert_equal [peptide1, peptide2], sequence.peptides.to_a - assert_equal [peptide1, peptide2], sequence.peptides(true).to_a - assert_equal [peptide2], sequence.peptides(false).to_a - end - - test 'should give correct result for lineages' do - sequence1 = sequences(:sequence1) - lineage1 = lineages(:lineage1) - lineage2 = lineages(:lineage2) - assert_raises(ArgumentError) { sequence1.lineages('a') } - assert_raises(ArgumentError) { sequence1.lineages(true, 'a') } - assert_equal [lineage1, lineage2], sequence1.lineages.to_a - assert_equal [lineage1, lineage2], sequence1.lineages(true).to_a - assert_equal [lineage1, lineage2], sequence1.lineages(true, true).to_a - assert_equal [lineage1, lineage2], sequence1.lineages(true, false).to_a - assert_equal [lineage2], sequence1.lineages(false).to_a - assert_equal [lineage2], sequence1.lineages(false, true).to_a - assert_equal [lineage2], sequence1.lineages(false, false).to_a - end - - test 'should eager load for lineages' do - sequence1 = sequences(:sequence1) - lineage = sequence1.lineages(true).first - assert_not lineage.association(:name).loaded? - lineage = sequence1.lineages(true, false).first - assert_not lineage.association(:name).loaded? - lineage = sequence1.lineages(true, true).first - assert lineage.association(:name).loaded? - assert lineage.association(:species_t).loaded? - lineage = sequence1.lineages(false).first - assert_not lineage.association(:name).loaded? - lineage = sequence1.lineages(false, false).first - assert_not lineage.association(:name).loaded? - lineage = sequence1.lineages(false, true).first - assert lineage.association(:name).loaded? - assert lineage.association(:species_t).loaded? - end - - test 'should give correct result for calculate_lca' do - sequence1 = sequences(:sequence1) - taxon1 = taxons(:taxon1) - taxon2 = taxons(:taxon2) - assert_equal taxon1.id, sequence1.calculate_lca - assert_equal taxon1.id, sequence1.calculate_lca(true) - assert_equal taxon1, sequence1.calculate_lca(true, true) - assert_equal taxon1.id, sequence1.calculate_lca(true, false) - assert_equal taxon2.id, sequence1.calculate_lca(false) - assert_equal taxon2, sequence1.calculate_lca(false, true) - assert_equal taxon2.id, sequence1.calculate_lca(false, false) - end - - test 'should give correct result for calculate_fa' do - expected_nil_fallback = { 'num' => { 'all' => 0, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} } - data1 = { seq: sequences(:sequence1), - exp_fa: { 'num' => { 'all' => 1, 'EC' => 1, 'GO' => 1, 'IPR' => 1 }, 'data' => { 'GO:0016569' => 1, 'GO:0006281' => 1, 'GO:0000781' => 1, 'EC:2.7.11.1' => 1, "IPR:IPR000169" => 1 } }, - exp_il: { 'num' => { 'all' => 22, 'EC' => 4, 'GO' => 2, 'IPR' => 3 }, 'data' => { 'EC:2.7.11.1' => 4, 'GO:0004674' => 1, 'GO:0005634' => 1, 'GO:0005524' => 1, 'GO:0016301' => 1, "IPR:IPR000169" => 1 } } } - data2 = { seq: sequences(:sequence2), - exp_fa: { 'num' => { 'all' => 3, 'EC' => 0, 'GO' => 3 }, 'data' => { 'GO:0051301' => 3, 'GO:0005525' => 3, 'GO:0046872' => 3, 'GO:0007049' => 3 } }, - exp_il: { 'num' => { 'all' => 4, 'EC' => 1, 'GO' => 4, 'IPR' => 2 }, 'data' => { 'GO:0005759' => 1, 'GO:0004760' => 1, 'GO:0051301' => 3, 'GO:0005739' => 1, "IPR:IPR000169" => 1 } } } - data3 = { seq: sequences(:sequence3), - exp_fa: expected_nil_fallback, - exp_il: expected_nil_fallback } - data4 = { seq: sequences(:sequence4), - exp_fa: { 'num' => { 'all' => 1, 'EC' => 1, 'GO' => 1, 'IPR' => 1 }, 'data' => { 'GO:0005576' => 1, 'GO:0000287' => 1, 'GO:0004634' => 1, 'GO:0000015' => 1, 'GO:0006096' => 1, 'EC:4.2.1.11' => 1, 'GO:0009986' => 1, "IPR:IPR000169" => 1 } }, - exp_il: expected_nil_fallback } - - [data1, data2, data3, data4].each do |seq| - assert_equal seq[:exp_fa], seq[:seq].calculate_fa(false) - assert_equal seq[:exp_il], seq[:seq].calculate_fa(true) - assert_equal seq[:exp_il], seq[:seq].calculate_fa - end - end - - test 'should give correct result for calculate_fa if hash, string given' do - sequence = Sequence.new( - fa: { 'num' => { 'all' => 1, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} }, - fa_il: { 'num' => { 'all' => 2, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} } - ) - sequenceStr = Sequence.new( - fa: '{"num":{"all":1, "EC" : 0, "GO" : 0, "IPR" : 0 }, "data" : {} }', - fa_il: '{ "num" : { "all" : 2, "EC" : 0, "GO" : 0, "IPR" : 0 }, "data" : {} }' - ) - assert_equal ({ 'num' => { 'all' => 1, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} }), sequence.calculate_fa(false) - assert_equal ({ 'num' => { 'all' => 2, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} }), sequence.calculate_fa(true) - - assert_equal sequence.calculate_fa(false), sequenceStr.calculate_fa(false) - assert_equal sequence.calculate_fa(true), sequenceStr.calculate_fa(true) - - # Doube check because JSON decoding is cached - assert_equal ({ 'num' => { 'all' => 1, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} }), sequenceStr.calculate_fa(false) - assert_equal ({ 'num' => { 'all' => 2, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} }), sequenceStr.calculate_fa(true) - end - - test 'should give correct result for calculate_fa if no data' do - sequence = Sequence.new( - fa: false, - fa_il: false - ) - - 2.times do - assert_nil sequence.calculate_fa(false) - assert_nil sequence.calculate_fa(true) - assert_nil sequence.fa - assert_nil sequence.fa_il - end - end - - test 'should give correct result for single_search' do - sequence1 = sequences(:sequence1) - sequence2 = sequences(:sequence2) - assert_raises(ArgumentError) { Sequence.single_search('AAAAAA', 5) } - assert_raises(SequenceTooShortError) { Sequence.single_search('AAAA') } - assert_nil Sequence.single_search('UNKNOWN') - assert_equal sequence1, Sequence.single_search('AALER') - assert_equal sequence1, Sequence.single_search('AALER', true) - assert_equal sequence1, Sequence.single_search('AALER', false) - assert_equal sequence1, Sequence.single_search('AAIER') - assert_equal sequence1, Sequence.single_search('AAIER', true) - assert_equal sequence2, Sequence.single_search('AAIER', false) - end - - test 'should eager load with single_search' do - sequence = Sequence.single_search('AALER') - assert sequence.peptides.loaded? - assert_not sequence.original_peptides.loaded? - assert sequence.peptides.first.association(:uniprot_entry).loaded? - assert sequence.peptides.first.uniprot_entry.association(:taxon).loaded? - assert sequence.peptides.first.uniprot_entry.ec_cross_references.loaded? - assert sequence.peptides.first.uniprot_entry.go_cross_references.loaded? - end - - test 'should give correct result for advanced_single_search' do - sequence1 = sequences(:sequence1) - sequence2 = sequences(:sequence2) - assert_raises(ArgumentError) { Sequence.advanced_single_search('AAAAAA', 5) } - assert_raises(NoMatchesFoundError) { Sequence.advanced_single_search('AAAAAA') } - assert_raises(NoMatchesFoundError) { Sequence.advanced_single_search('AAAAARA') } - assert_raises(SequenceTooShortError) { Sequence.advanced_single_search('AARAAR') } - assert_equal [sequence1, sequence1], Sequence.advanced_single_search('AALERAAIER').to_a - assert_equal [sequence1, sequence1], Sequence.advanced_single_search('AALERAAIER', true).to_a - assert_equal [sequence1, sequence2], Sequence.advanced_single_search('AALERAAIER', false).to_a - end - - test 'should eager load with advanced_single_search' do - sequence = Sequence.advanced_single_search('AALERAAIER').first - assert sequence.peptides.loaded? - assert_not sequence.original_peptides.loaded? - assert sequence.peptides.first.association(:uniprot_entry).loaded? - assert sequence.peptides.first.uniprot_entry.association(:taxon).loaded? - assert sequence.peptides.first.uniprot_entry.association(:lineage).loaded? - end - - test 'should give correct result for peptides_relation_name' do - assert_equal :peptides, Sequence.peptides_relation_name(true) - assert_equal :original_peptides, Sequence.peptides_relation_name(false) - assert_raises(ArgumentError) { Sequence.peptides_relation_name(5) } - end - - test 'should give correct result for lca_t_relation_name' do - assert_equal :lca_il_t, Sequence.lca_t_relation_name(true) - assert_equal :lca_t, Sequence.lca_t_relation_name(false) - assert_raises(ArgumentError) { Sequence.lca_t_relation_name(5) } - end - - test 'should give correct result for list_sequences' do - assert_equal [], Sequence.list_sequences([55]) - assert_equal ['AALER'], Sequence.list_sequences([1]) - assert_equal %w[AALER AAIER].sort, Sequence.list_sequences([1, 2]).sort - end - - test 'should not crash with empty input list_sequences' do - assert_equal [], Sequence.list_sequences([]) - end - - test 'should give correct result for filter_unique_uniprot_peptides' do - assert_equal [], Sequence.filter_unique_uniprot_peptides([2, 1], 1) - assert_equal [1, 2].sort, Sequence.filter_unique_uniprot_peptides([2, 1], 2) - end - - test 'should give correct result for boolean?' do - assert_not Sequence.boolean? 0 - assert_not Sequence.boolean? 55 - assert_not Sequence.boolean? [] - assert_not Sequence.boolean? 'true' - assert_not Sequence.boolean? nil - assert Sequence.boolean? true - assert Sequence.boolean? false - end - - test 'should give correct result for missed_cleavage' do - assert_equal 2, Sequence.missed_cleavage('AAILERAGGAR', false).lca - assert_equal ({ 'num' => { 'all' => 1, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} }), Sequence.missed_cleavage('AAILERAGGAR', false).fa - assert_nil Sequence.missed_cleavage('AAILERAGGAR', false).fa_il - assert_nil Sequence.missed_cleavage('AAILERAGGAR', false).lca_il - assert_equal 2, Sequence.missed_cleavage('AAILERAGGAR', true).lca_il - assert_nil Sequence.missed_cleavage('AAILERAGGAR', true).lca - assert_equal 2, Sequence.missed_cleavage('AALLERAGGAR', true).lca_il - assert_equal ({ 'num' => { 'all' => 1, 'EC' => 0, 'GO' => 0, 'IPR' => 0 }, 'data' => {} }), Sequence.missed_cleavage('AALLERAGGAR', true).fa_il - assert_nil Sequence.missed_cleavage('AALLERAGGAR', true).lca - assert_nil Sequence.missed_cleavage('AALLERAGGAR', true).fa - assert_nil Sequence.missed_cleavage('AALLERAGGAR', false) - assert_nil Sequence.missed_cleavage('AAIIERAGGAR', false) - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index a5fcbbb..8e2dd2e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,12 +2,23 @@ require_relative "../config/environment" require "rails/test_help" +require 'webmock' +include WebMock::API +WebMock.enable! + require 'simplecov' SimpleCov.start 'rails' require 'simplecov-cobertura' SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter +def stub_http_request!(response_json_file) + response = File.new Rails.root.join(response_json_file) + + stub_request(:post, 'http://localhost:3000/analyse') + .to_return(body: response, headers: { 'Content-Type' => 'application/json' }, status: 200) +end + class ActiveSupport::TestCase # Run tests in parallel with specified workers parallelize(workers: :number_of_processors)