Class: OnlyofficeTestrailWrapper::TestrailPlan

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

Overview

Class for working with testrail plan

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TestrailApiObject

#init_from_hash, #name_id_pairs

Constructor Details

#initialize(name = '', entries = [], description = '', milestone_id = nil, id = nil) ⇒ TestrailPlan

Returns a new instance of TestrailPlan.



29
30
31
32
33
34
35
36
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 29

def initialize(name = '', entries = [], description = '', milestone_id = nil, id = nil)
  super()
  @name = name
  @entries = entries
  @description = description
  @milestone_id = milestone_id
  @id = id
end

Instance Attribute Details

#created_onInteger (readonly)

Returns time since epoch on which plan created.

Returns:

  • (Integer)

    time since epoch on which plan created



23
24
25
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 23

def created_on
  @created_on
end

#descriptionString

Returns test plan description.

Returns:

  • (String)

    test plan description



15
16
17
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 15

def description
  @description
end

#entriesArray

Returns test plan entries(Suites).

Returns:

  • (Array)

    test plan entries(Suites)



17
18
19
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 17

def entries
  @entries
end

#errorString (readonly)

Returns error message if any happens.

Returns:

  • (String)

    error message if any happens



27
28
29
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 27

def error
  @error
end

#idInteger

Returns Id of test plan.

Returns:

  • (Integer)

    Id of test plan



9
10
11
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 9

def id
  @id
end

#is_completedTrue, False

Returns Completed this test plan or not.

Returns:

  • (True, False)

    Completed this test plan or not



21
22
23
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 21

def is_completed
  @is_completed
end

#milestone_idInteger

Returns milestone id.

Returns:

  • (Integer)

    milestone id



19
20
21
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 19

def milestone_id
  @milestone_id
end

#nameString

Returns test run name.

Returns:

  • (String)

    test run name



11
12
13
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 11

def name
  @name
end

#project_idInteger

Returns Id of project.

Returns:

  • (Integer)

    Id of project



13
14
15
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 13

def project_id
  @project_id
end

#urlString (readonly)

Returns url to current test plan.

Returns:

  • (String)

    url to current test plan



25
26
27
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 25

def url
  @url
end

Instance Method Details

#add_entry(name, suite_id, include_all = true, case_ids = [], assigned_to = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 38

def add_entry(name, suite_id, include_all = true, case_ids = [], assigned_to = nil)
  entry = TestrailPlanEntry.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_plan_entry/#{@id}",
                                                                   suite_id: suite_id,
                                                                   name: StringHelper.warnstrip!(name.to_s),
                                                                   include_all: include_all,
                                                                   case_ids: case_ids,
                                                                   assigned_to: assigned_to))
  OnlyofficeLoggerHelper.log "Added plan entry: #{name.to_s.strip}"
  entry.runs.each_with_index { |run, index| entry.runs[index] = TestrailRun.new.init_from_hash(run) }
  entry
end

#closenil

Close current plan

Returns:

  • (nil)


64
65
66
67
68
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 64

def close
  Testrail2.http_post("index.php?/api/v2/close_plan/#{@id}")
  OnlyofficeLoggerHelper.log("Closed plan: #{@name} with id #{@id}")
  nil
end

#deletenil

Delete current plan

Returns:

  • (nil)


56
57
58
59
60
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 56

def delete
  Testrail2.http_post "index.php?/api/v2/delete_plan/#{@id}", {}
  OnlyofficeLoggerHelper.log "Deleted plan: #{@name}"
  nil
end

#delete_entry(entry_id) ⇒ Object



50
51
52
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 50

def delete_entry(entry_id)
  Testrail2.http_post "index.php?/api/v2/delete_plan_entry/#{@id}/#{entry_id}", {}
end

#plan_durationsArray

Generate array of durations of runs

Returns:

  • (Array)

    array of durations, sorted by descrease



104
105
106
107
108
109
110
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 104

def plan_durations
  durations_hash = {}
  runs.each do |current_run|
    durations_hash[current_run.name] = current_run.duration
  end
  durations_hash.sort_by { |_, time| time }.reverse
end

#run(run_name) ⇒ Object

Get run from plan

Parameters:

  • run_name (String)

    run to find

Returns:

  • TestrailRun



84
85
86
87
88
89
90
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 84

def run(run_name)
  @entries.each do |entry|
    run = entry.runs.first
    return run if run.name == run_name
  end
  nil
end

#runsArray, TestrailRuns

Get all runs in current plan

Returns:

  • (Array, TestrailRuns)


94
95
96
97
98
99
100
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 94

def runs
  runs = []
  @entries.each do |entry|
    runs << entry.runs.first
  end
  runs
end

#tests_resultsObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/onlyoffice_testrail_wrapper/testrail_plan.rb', line 70

def tests_results
  run_results = {}
  @entries.each do |current_entrie|
    current_entrie.runs.each do |current_run|
      current_run.pull_tests_results
      run_results.merge!(current_run.name => current_run.test_results)
    end
  end
  run_results
end