Class: OnlyofficeTestrailWrapper::TestrailSection

Inherits:
TestrailApiObject show all
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_section.rb

Overview

Class for description of test sections

Author:

  • Roman.Zagudaev

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • name (String) (defaults to: '')

    name of test section, default = “”

  • id (Integer) (defaults to: nil)

    id of test section, default = nil

  • parent_id (Integer) (defaults to: nil)

    id of parent section, default = nil

  • suite_id (Integer) (defaults to: nil)

    id of test suite



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_namesArray, TestrailCase

Returns cases inside section.

Returns:



18
19
20
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 18

def cases_names
  @cases_names
end

#idInteger

Returns Id of test section.

Returns:

  • (Integer)

    Id of test section



10
11
12
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 10

def id
  @id
end

#nameString

Returns Name of test section.

Returns:

  • (String)

    Name of test section



14
15
16
# File 'lib/onlyoffice_testrail_wrapper/testrail_section.rb', line 14

def name
  @name
end

#parent_idInteger

Returns Id of parent test section.

Returns:

  • (Integer)

    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_idInteger

Returns Id of suite.

Returns:

  • (Integer)

    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

Parameters:

  • title (String)

    name of test case to add

  • type_id (Integer) (defaults to: 3)

    type of test case to add (Default = 3)

  • priority_id (Integer) (defaults to: 4)

    id of priority of case (Default = 4)

  • custom_steps (String) (defaults to: '')

    steps to perform

Returns:

  • (TestCaseTestrail)

    created test case



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

#deleteObject



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_casesArray, TestCaseTestrail

Get all cases of section

Returns:

  • (Array, TestCaseTestrail)

    array of test cases



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}&section_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

Parameters:

  • name (String)

    name of test case

Returns:



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