我最初的天真的方法给了我一些误导性的错误,说不存在确实存在的路线。
def hamming(s1, s2):
#Return the Hamming distance between equal-length sequences
if len(s1) != len(s2):
raise ValueError("Undefined for sequences of unequal length")
return sum(ch1 != ch2 for ch1, ch2 in zip(s1, s2))
for x in Bio.SeqIO.parse("reads.fastq","fastq"):
reads_array.append(x)
nmer = 7
l_chosen = ['gttattt','attattt','tgctagt']
chosen_reads = []
for x in reads_array:
s2 = str(x.seq)
for s in [s2[i:i+nmer] for i in range(len(s2)-nmer-1)]:
for ds in l_chosen:
dist = hamming(ds,s)
if dist == 0:
print s2, s,ds,dist
chosen_reads.append(x)
我的测试实施:
camdennarzt@SECUR-T:~/Developer/Ruby/m2 [master L|✚ 1] $ rake test test/integration/application_test.rb
Run options: --seed 55863
# Running:
EEEEEEEEE
Fabulous run in 0.224684s, 44.5070 runs/s, 8.9014 assertions/s.
1) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#new_path:
ActionController::UrlGenerationError: No route matches {:action=>"new", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
2) Error:
ApplicationTest#test_enforces_ssl_for_WelcomeController#index_path:
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"WelcomeController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
3) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#update_path:
ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
4) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#confirm_path:
ActionController::UrlGenerationError: No route matches {:action=>"confirm", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
5) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#destroy_path:
ActionController::UrlGenerationError: No route matches {:action=>"destroy", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
6) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#index_path:
ActionController::UrlGenerationError: No route matches {:action=>"index", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
7) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#show_path:
ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
8) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#edit_path:
ActionController::UrlGenerationError: No route matches {:action=>"edit", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
9) Error:
ApplicationTest#test_enforces_ssl_for_SubscriptionsController#create_path:
ActionController::UrlGenerationError: No route matches {:action=>"create", :controller=>"SubscriptionsController"}
test/integration/application_test.rb:16:in `block (3 levels) in <class:ApplicationTest>'
9 runs, 0 assertions, 0 failures, 9 errors, 0 skips
camdennarzt@SECUR-T:~/Developer/Ruby/m2 [master L|✚ 1] $ rake routes
Prefix Verb URI Pattern Controller#Action
subscriptions GET /subscriptions(.:format) subscriptions#index
POST /subscriptions(.:format) subscriptions#create
new_subscription GET /subscriptions/new(.:format) subscriptions#new
edit_subscription GET /subscriptions/:id/edit(.:format) subscriptions#edit
subscription GET /subscriptions/:id(.:format) subscriptions#show
PATCH /subscriptions/:id(.:format) subscriptions#update
PUT /subscriptions/:id(.:format) subscriptions#update
DELETE /subscriptions/:id(.:format) subscriptions#destroy
confirm_subscription GET /subscriptions/confirm/:id(.:format) subscriptions#confirm
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
user_unlock POST /users/unlock(.:format) devise/unlocks#create
new_user_unlock GET /users/unlock/new(.:format) devise/unlocks#new
GET /users/unlock(.:format) devise/unlocks#show
root GET / welcome#index
metahealthzone GET /metahealthzone(.:format) welcome#metahealthzone
contact_us GET /contact_us(.:format) welcome#contact_us
customer_care GET /customer-care(.:format) customer_care/welcome#customer_care
customer_care_metabolistics GET /customer-care/metabolistics(.:format) customer_care/welcome#metabolistics
customer_care_glossary GET /customer-care/glossary(.:format) customer_care/welcome#glossary
customer_care_research GET /customer-care/research(.:format) customer_care/welcome#research
info GET /info(.:format) info/welcome#info
info_patients GET /info/patients(.:format) info/welcome#patients
info_professionals GET /info/professionals(.:format) info/welcome#professionals
info_distributors GET /info/distributors(.:format) info/welcome#distributors
我如何解决这个问题,以便a)运行,b)测试ssl是否被强制执行。 (我知道如何使用ssl w / require 'test_helper'
class ApplicationTest < ActionDispatch::IntegrationTest
Rails.application.eager_load!
ApplicationController.descendants.each do |c|
c.action_methods.each do |a|
test "enforces ssl for #{c}\##{a} path" do
get url_for(controller: c, action: a)
assert_response :success
assert https?, 'not https'
assert_empty response.body.split('"').select {|e| e.include? 'http:'}
end
end
end
end
制作测试请求,但我希望看到http呼叫使用https或重定向进行响应)
答案 0 :(得分:0)
我认为,你可以将它作为测试体使用:
# http request
get url_for(controller: c, action: a)
refute https?, 'is https!'
assert_response :redirect
assert_equal request.url.gsub("http://","https://"), response.headers['Location']
follow_redirect!
assert https?, 'not https'