Class: OnlyofficeTestrailWrapper::TestrailSection
- Inherits:
-
TestrailApiObject
- Object
- TestrailApiObject
- OnlyofficeTestrailWrapper::TestrailSection
- Defined in:
- lib/onlyoffice_testrail_wrapper/testrail_section.rb
Overview
Class for description of test sections
Instance Attribute Summary collapse
-
#cases_names ⇒ Array, TestrailCase
Cases inside section.
-
#id ⇒ Integer
Id of test section.
-
#name ⇒ String
Name of test section.
-
#parent_id ⇒ Integer
Id of parent test section.
-
#suite_id ⇒ Integer
Id of suite.
Instance Method Summary collapse
- #case(name_or_id) ⇒ Object
-
#create_new_case(title, type_id = 3, priority_id = 4, custom_steps = '') ⇒ TestCaseTestrail
Add test case to current Section.
- #delete ⇒ Object
- #get_case_by_id(id) ⇒ Object
- #get_case_by_name(name) ⇒ Object
-
#get_cases ⇒ Array, TestCaseTestrail
Get all cases of section.
-
#init_case_by_name(name) ⇒ TestrailCase
Init case by it’s name.
-
#initialize(name = '', parent_id = nil, suite_id = nil, id = nil) ⇒ TestSectionTestRail
constructor
Default constructor.
- #update(name = @name, parent_id = @parent_id) ⇒ Object
Methods inherited from TestrailApiObject
#init_from_hash, #name_id_pairs
Constructor Details
#initialize(name = '', parent_id = nil, suite_id = nil, id = nil) ⇒ TestSectionTestRail
Default constructor
26 27 28 29 30 31 32 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 26 def initialize(name = '', parent_id = nil, suite_id = nil, id = nil) super() @id = id @name = name @suite_id = suite_id @parent_id = parent_id end |
Instance Attribute Details
#cases_names ⇒ Array, TestrailCase
Returns cases inside section.
18 19 20 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 18 def cases_names @cases_names end |
#id ⇒ Integer
Returns Id of test section.
10 11 12 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 10 def id @id end |
#name ⇒ String
Returns Name of test section.
14 15 16 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 14 def name @name end |
#parent_id ⇒ Integer
Returns Id of parent test section.
12 13 14 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 12 def parent_id @parent_id end |
#suite_id ⇒ Integer
Returns Id of suite.
16 17 18 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 16 def suite_id @suite_id end |
Instance Method Details
#case(name_or_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 34 def case(name_or_id) case name_or_id.class.to_s when 'Fixnum' get_case_by_id name_or_id when 'String' if name_or_id.to_s.length > 250 OnlyofficeLoggerHelper.log("There is limit for testcase name for 250 symbols. '#{name_or_id}' too long. It will cut") name_or_id = name_or_id.to_s[0..249] end init_case_by_name name_or_id else raise 'Wrong argument. Must be name [String] or id [Integer]' end end |
#create_new_case(title, type_id = 3, priority_id = 4, custom_steps = '') ⇒ TestCaseTestrail
Add test case to current Section
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 86 def create_new_case(title, type_id = 3, priority_id = 4, custom_steps = '') new_case = TestrailCase.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_case/#{@id}", title: StringHelper.warnstrip!(title.to_s), type_id: type_id, priority_id: priority_id, custom_steps: custom_steps)) new_case.instance_variable_set(:@section, self) OnlyofficeLoggerHelper.log "Created new case: #{new_case.title}" @cases_names[new_case.title] = new_case.id new_case end |
#delete ⇒ Object
108 109 110 111 112 113 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 108 def delete @suite.sections_names.delete @name Testrail2.http_post "index.php?/api/v2/delete_section/#{@id}", {} OnlyofficeLoggerHelper.log "Deleted section: #{@name}" nil end |
#get_case_by_id(id) ⇒ Object
49 50 51 52 53 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 49 def get_case_by_id(id) test_case = TestrailCase.new.init_from_hash(Testrail2.http_get("index.php?/api/v2/get_case/#{id}")) test_case.instance_variable_set :@section, self test_case end |
#get_case_by_name(name) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 64 def get_case_by_name(name) get_cases if @cases_names.nil? corrected_case_name = StringHelper.warnstrip!(name.to_s) return nil if @cases_names[corrected_case_name].nil? get_case_by_id(@cases_names[corrected_case_name]) end |
#get_cases ⇒ Array, TestCaseTestrail
Get all cases of section
57 58 59 60 61 62 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 57 def get_cases # raise 'Project id is not identified' if @project_id.nil? cases = Testrail2.http_get("index.php?/api/v2/get_cases/#{@project_id}&suite_id=#{@suite_id}§ion_id=#{@id}") @cases_names = name_id_pairs(cases, 'title') if @cases_names.nil? cases end |
#init_case_by_name(name) ⇒ TestrailCase
Init case by it’s name
75 76 77 78 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 75 def init_case_by_name(name) test_case = get_case_by_name name test_case.nil? ? create_new_case(name) : test_case end |
#update(name = @name, parent_id = @parent_id) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 98 def update(name = @name, parent_id = @parent_id) @suite.sections_names.delete @name @suite.sections_names[StringHelper.warnstrip!(name.to_s)] = @id updated_section = TestrailSection.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/update_section/#{@id}", name: name, parent_id: parent_id)) OnlyofficeLoggerHelper.log "Updated section: #{updated_section.name}" updated_section end |