adding tests, plus testrail reporting
Change-Id: I9435bfa7579a0382e6b30aebd022433aa0593706 Reviewed-on: https://gerrit.instructure.com/38454 Reviewed-by: Kyle Rosenbaum <kyler@instructure.com> Product-Review: Kyle Rosenbaum <kyler@instructure.com> QA-Review: Kyle Rosenbaum <kyler@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
parent
c0474dcd25
commit
a86e3fe481
|
@ -0,0 +1,5 @@
|
|||
test:
|
||||
url: https://testrails.url.com
|
||||
username: user@email.com
|
||||
password: password
|
||||
run_id: 3
|
|
@ -1,5 +1,7 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../common')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../helpers/external_tools_common')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../helpers/testrail_report')
|
||||
|
||||
|
||||
describe "account admin question bank" do
|
||||
include_examples "in-process server selenium tests"
|
||||
|
@ -87,6 +89,14 @@ describe "account admin question bank" do
|
|||
verify_added_question(name, question_text, multiple_choice_value)
|
||||
end
|
||||
|
||||
it "should add bank and multiple choice question" do
|
||||
report_test(71462) do
|
||||
question_bank2 = create_question_bank('question bank 2')
|
||||
get "/accounts/#{Account.default.id}/question_banks/#{question_bank2.id}"
|
||||
add_multiple_choice_question
|
||||
end
|
||||
end
|
||||
|
||||
it "should add a multiple choice question" do
|
||||
add_multiple_choice_question
|
||||
end
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
#
|
||||
# TestRail API binding for Ruby (API v2, available since TestRail 3.0)
|
||||
#
|
||||
# Learn more:
|
||||
#
|
||||
# http://docs.gurock.com/testrail-api2/start
|
||||
# http://docs.gurock.com/testrail-api2/accessing
|
||||
#
|
||||
# Copyright Gurock Software GmbH
|
||||
#
|
||||
|
||||
require 'net/http'
|
||||
require 'net/https'
|
||||
require 'uri'
|
||||
require 'json'
|
||||
|
||||
module TestRail
|
||||
class APIClient
|
||||
@url = ''
|
||||
@user = ''
|
||||
@password = ''
|
||||
|
||||
attr_accessor :user
|
||||
attr_accessor :password
|
||||
|
||||
def initialize(base_url)
|
||||
if !base_url.match(/\/$/)
|
||||
base_url += '/'
|
||||
end
|
||||
@url = base_url + 'index.php?/api/v2/'
|
||||
end
|
||||
|
||||
#
|
||||
# Send Get
|
||||
#
|
||||
# Issues a GET request (read) against the API and returns the result
|
||||
# (as Ruby hash).
|
||||
#
|
||||
# Arguments:
|
||||
#
|
||||
# uri The API method to call including parameters
|
||||
# (e.g. get_case/1)
|
||||
#
|
||||
def send_get(uri)
|
||||
_send_request('GET', uri, nil)
|
||||
end
|
||||
|
||||
#
|
||||
# Send POST
|
||||
#
|
||||
# Issues a POST request (write) against the API and returns the result
|
||||
# (as Ruby hash).
|
||||
#
|
||||
# Arguments:
|
||||
#
|
||||
# uri The API method to call including parameters
|
||||
# (e.g. add_case/1)
|
||||
# data The data to submit as part of the request (as
|
||||
# Ruby hash, strings must be UTF-8 encoded)
|
||||
#
|
||||
def send_post(uri, data)
|
||||
_send_request('POST', uri, data)
|
||||
end
|
||||
|
||||
private
|
||||
def _send_request(method, uri, data)
|
||||
url = URI.parse(@url + uri)
|
||||
if method == 'POST'
|
||||
request = Net::HTTP::Post.new(url.path + '?' + url.query)
|
||||
request.body = JSON.dump(data)
|
||||
else
|
||||
request = Net::HTTP::Get.new(url.path + '?' + url.query)
|
||||
end
|
||||
request.basic_auth(@user, @password)
|
||||
request.add_field('Content-Type', 'application/json')
|
||||
|
||||
conn = Net::HTTP.new(url.host, url.port)
|
||||
if url.scheme == 'https'
|
||||
conn.use_ssl = true
|
||||
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
end
|
||||
response = conn.request(request)
|
||||
|
||||
if response.body && !response.body.empty?
|
||||
result = JSON.parse(response.body)
|
||||
else
|
||||
result = {}
|
||||
end
|
||||
|
||||
if response.code != '200'
|
||||
if result && result.key?('error')
|
||||
error = '"' + result['error'] + '"'
|
||||
else
|
||||
error = 'No additional error message received'
|
||||
end
|
||||
raise APIError.new('TestRail API returned HTTP %s (%s)' %
|
||||
[response.code, error])
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
class APIError < StandardError
|
||||
end
|
||||
end
|
|
@ -0,0 +1,45 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/testrail')
|
||||
|
||||
config_path=File.expand_path('../../../../config/testrail.yml', __FILE__)
|
||||
if File.exists?(config_path)
|
||||
$configuration = YAML.load_file(config_path)
|
||||
else
|
||||
$configuration = nil
|
||||
end
|
||||
|
||||
unless $configuration.nil?
|
||||
$client = TestRail::APIClient.new($configuration['test']['url'])
|
||||
$client.user = $configuration['test']['username']
|
||||
$client.password = $configuration['test']['password']
|
||||
$run_ID = $configuration['test']['run_id']
|
||||
end
|
||||
|
||||
def upload_results(result, case_num)
|
||||
if result
|
||||
status = 1
|
||||
comment = 'Test Passed'
|
||||
else
|
||||
status = 5
|
||||
comment = 'Test Failed'
|
||||
end
|
||||
begin
|
||||
$client.send_post( "add_result_for_case/#{$run_ID}/#{case_num}",
|
||||
{ :status_id => status, :comment => comment, :custom_supportusername => 33 })
|
||||
rescue
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
def report_test(case_num)
|
||||
if $configuration.nil?
|
||||
yield
|
||||
else
|
||||
begin
|
||||
yield
|
||||
rescue Exception
|
||||
upload_results(false, case_num)
|
||||
raise
|
||||
end
|
||||
upload_results(true, case_num)
|
||||
end
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/helpers/quizzes_common')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/helpers/testrail_report')
|
||||
|
||||
describe "quizzes question banks" do
|
||||
include_examples "quizzes selenium tests"
|
||||
|
@ -7,13 +8,36 @@ describe "quizzes question banks" do
|
|||
course_with_teacher_logged_in
|
||||
end
|
||||
|
||||
it "should be able to create quiz questions" do
|
||||
bank = AssessmentQuestionBank.create!(:context => @course)
|
||||
get "/courses/#{@course.id}/question_banks/#{bank.id}"
|
||||
it "should be able to create question bank" do
|
||||
report_test(72402) do
|
||||
get "/courses/#{@course.id}/question_banks"
|
||||
question_bank_title = keep_trying_until do
|
||||
f(".add_bank_link").click
|
||||
wait_for_ajaximations
|
||||
question_bank_title = f("#assessment_question_bank_title")
|
||||
question_bank_title.should be_displayed
|
||||
question_bank_title
|
||||
end
|
||||
question_bank_title.send_keys('goober', :return)
|
||||
wait_for_ajaximations
|
||||
question_bank = AssessmentQuestionBank.find_by_title('goober')
|
||||
question_bank.should be_present
|
||||
question_bank.workflow_state.should == "active"
|
||||
f("#question_bank_adding .title").should(include_text('goober'))
|
||||
question_bank.bookmarked_for?(User.last).should be_true
|
||||
question_bank
|
||||
end
|
||||
end
|
||||
|
||||
f('.add_question_link').click
|
||||
wait_for_ajaximations
|
||||
expect { create_multiple_choice_question }.to change(AssessmentQuestion, :count).by(1)
|
||||
it "should be able to create quiz questions" do
|
||||
report_test(72403) do
|
||||
bank = AssessmentQuestionBank.create!(:context => @course)
|
||||
get "/courses/#{@course.id}/question_banks/#{bank.id}"
|
||||
|
||||
f('.add_question_link').click
|
||||
wait_for_ajaximations
|
||||
expect { create_multiple_choice_question }.to change(AssessmentQuestion, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "should tally up question bank question points" do
|
||||
|
@ -160,4 +184,4 @@ describe "quizzes question banks" do
|
|||
submit_form(group_form)
|
||||
f('#questions .group_top .group_display.name').should include_text('new group')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue