Module: Resttestrail::Requests

Defined in:
lib/resttestrail/requests.rb

Defined Under Namespace

Modules: Case_Priority, Case_Type

Constant Summary collapse

URI =
"/index.php?/api/v2"
ADD_CASE =
"/add_case/"
GET_CASE =
"/get_case/"
GET_CASES =
"/get_cases/"
DELETE_CASE =
"/delete_case/"
ADD_RUN =
"/add_run/"
GET_RUN =
"/get_run/"
DELETE_RUN =
"/delete_run/"
ADD_RESULT_FOR_CASE =
"/add_result_for_case/"
CLOSE_RUN =
"/close_run/"
TEST_STATUS_PASSED =
1
TEST_STATUS_FAILED =
5
TEST_STATUS_BLOCKED =
2

Class Method Summary collapse

Class Method Details

.add_case(section_id, title, type_id, priority_id, estimate, milestone_id, refs) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/resttestrail/requests.rb', line 41

def self.add_case(section_id, title, type_id, priority_id, estimate, milestone_id, refs)
  uri = "#{URI}#{ADD_CASE}#{section_id}"
  request = Net::HTTP::Post.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
  body = {"title" => title, "type_id" => type_id, "priority_id" => priority_id}
  body.merge!("estimate" => estimate) if (!estimate.nil? && estimate.is_a?(String))
  body.merge!("milestone_id" => milestone_id) if (!milestone_id.nil? && milestone_id.is_a?(Integer))
  body.merge!("refs" => refs) if (!refs.nil? && refs.is_a?(String))
  request.body = body.to_json
  request
end

.add_result_for_case(run_id, test_case_id, status, elapsed_time_secs, comment = nil, defects = nil) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/resttestrail/requests.rb', line 83

def self.add_result_for_case(run_id, test_case_id, status, elapsed_time_secs, comment=nil, defects=nil)
  uri = "#{URI}#{ADD_RESULT_FOR_CASE}#{run_id}/#{test_case_id}"
  request = Net::HTTP::Post.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
  body = {"status_id" => status}
  unless elapsed_time_secs.nil?
    elapsed_time_secs = 1 if elapsed_time_secs < 1
    elapsed_time = elapsed_time_secs.round.to_s+"s"
    body.merge!("elapsed" => elapsed_time)
  end
  body.merge!("comment" => comment) if (!comment.nil? && comment.is_a?(String))
  body.merge!("defects" => defects[0...250]) if (!defects.nil? && defects.is_a?(String))
  request.body = body.to_json
  request
end

.add_run(run_name, suite_id) ⇒ Object



68
69
70
71
72
73
# File 'lib/resttestrail/requests.rb', line 68

def self.add_run(run_name, suite_id)
  uri = "#{URI}#{ADD_RUN}#{Resttestrail.config.project_id}"
  request = Net::HTTP::Post.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
  request.body = {"suite_id" => suite_id, "name" => run_name, "include_all" => true}.to_json
  request
end

.basic_auth_stringObject



103
104
105
# File 'lib/resttestrail/requests.rb', line 103

def self.basic_auth_string
  @@basic_auth_string ||= "Basic " + Base64.encode64("#{Resttestrail.config.username}:#{Resttestrail.config.password}")
end

.close_run(run_id) ⇒ Object



98
99
100
101
# File 'lib/resttestrail/requests.rb', line 98

def self.close_run(run_id)
  uri = "#{URI}#{CLOSE_RUN}#{run_id}"
  Net::HTTP::Post.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
end

.delete_case(case_id) ⇒ Object



64
65
66
# File 'lib/resttestrail/requests.rb', line 64

def self.delete_case(case_id)
  Net::HTTP::Post.new("#{URI}#{DELETE_CASE}#{case_id}", initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
end

.delete_run(run_id) ⇒ Object



79
80
81
# File 'lib/resttestrail/requests.rb', line 79

def self.delete_run(run_id)
  Net::HTTP::Post.new("#{URI}#{DELETE_RUN}#{run_id}", initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
end

.get_case(case_id) ⇒ Object



52
53
54
# File 'lib/resttestrail/requests.rb', line 52

def self.get_case(case_id)
  Net::HTTP::Get.new("#{URI}#{GET_CASE}#{case_id}", initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
end

.get_cases(suite_id, section_id, filters) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/resttestrail/requests.rb', line 56

def self.get_cases(suite_id, section_id, filters)
  uri = "#{URI}#{GET_CASES}#{Resttestrail.config.project_id}"
  uri += "&suite_id=#{suite_id}" unless suite_id.nil?
  uri += "&section_id=#{section_id}" unless section_id.nil?
  uri += "&#{filters}" unless filters.nil?
  Net::HTTP::Get.new(uri, initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
end

.get_run(run_id) ⇒ Object



75
76
77
# File 'lib/resttestrail/requests.rb', line 75

def self.get_run(run_id)
  Net::HTTP::Get.new("#{URI}#{GET_RUN}#{run_id}", initheader = {'Content-Type' => 'application/json', 'Authorization' => basic_auth_string})
end