Class: Testrail::Client
- Inherits:
-
Object
- Object
- Testrail::Client
- Defined in:
- lib/testrail_export/client.rb
Instance Method Summary collapse
- #add_project(project_name) ⇒ Object
- #add_results_for_cases(run_id, results) ⇒ Object
- #create_case(title, section_id) ⇒ Object
-
#create_run(suite) ⇒ Object
—————————————————-> runs <——————————————————.
- #create_section(name, suite, parent_id) ⇒ Object
- #create_suite(name, project_id) ⇒ Object
- #find_case(title, section, depth) ⇒ Object
-
#find_or_create_case(title, section, depth) ⇒ Object
—————————————————-> cases <—————————————————–.
- #find_or_create_section(name, suite, parent, depth) ⇒ Object
- #find_or_create_suite(name, project_id) ⇒ Object
- #find_section(name, suite, parent_id) ⇒ Object
- #find_suite_by_name(name, project_id) ⇒ Object
- #get_project(project_id) ⇒ Object
-
#get_projects ⇒ Object
—————————————————> projects —————————————————-.
-
#get_sections(suite) ⇒ Object
—————————————————> sections <—————————————————.
-
#get_suite(suite_id) ⇒ Object
—————————————————-> suites <—————————————————-.
- #get_suites(project_id) ⇒ Object
-
#initialize(args) ⇒ Client
constructor
A new instance of Client.
- #section_ids_at_depth(suite, depth) ⇒ Object
Constructor Details
#initialize(args) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/testrail_export/client.rb', line 32 def initialize(args) @projects = nil @sections = Hash.new @suite = Hash.new @suites = Hash.new @client = APIClient.new args[:url] %w(user password project).each do |key| raise Exception.new("TestRail configuration key :#{key} not set. Cannot continue without it.") if args[key.intern].nil? @client.send "#{key}=", args[key.intern] if %w(user password).include? key end end |
Instance Method Details
#add_project(project_name) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/testrail_export/client.rb', line 50 def add_project(project_name) @projects = nil # invalidate cached stuff @client.send_post('add_project', {name: project_name, announcement: AUTOMATED_DESCRIPTION, show_anouncement: true}) end |
#add_results_for_cases(run_id, results) ⇒ Object
137 138 139 |
# File 'lib/testrail_export/client.rb', line 137 def add_results_for_cases(run_id, results) @client.send_post("add_results_for_cases/#{run_id}", { results: results }) end |
#create_case(title, section_id) ⇒ Object
128 129 130 |
# File 'lib/testrail_export/client.rb', line 128 def create_case(title, section_id) @client.send_post("add_case/#{section_id}", { title: title }) end |
#create_run(suite) ⇒ Object
—————————————————-> runs <——————————————————
133 134 135 |
# File 'lib/testrail_export/client.rb', line 133 def create_run(suite) @client.send_post("add_run/#{suite['project_id']}", { suite_id: suite['id'], name: "#{nice_time_now} - #{suite['name']}", description: 'describe it somehow'}) end |
#create_section(name, suite, parent_id) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/testrail_export/client.rb', line 106 def create_section(name, suite, parent_id) @sections.delete(suite['id']) # invalidate cached values # TODO: check if JSON created have null for nil parent_id @client.send_post("add_section/#{suite['project_id']}", { name: name, suite_id: suite['id'], description: AUTOMATED_DESCRIPTION, parent_id: parent_id }) end |
#create_suite(name, project_id) ⇒ Object
78 79 80 81 82 |
# File 'lib/testrail_export/client.rb', line 78 def create_suite(name, project_id) @suites.delete(project_id) # invalidate cached stuff puts "TestRail Exporter [INFO] Creating suite: #{name} under project: #{ self.get_project(project_id)['name'] }" @client.send_post("add_suite/#{project_id}", { name: name, description: AUTOMATED_DESCRIPTION }) end |
#find_case(title, section, depth) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/testrail_export/client.rb', line 120 def find_case(title, section, depth) suite = self.get_suite(section['suite_id']) test_cases = @client.send_get("get_cases/#{suite['project_id']}&suite_id=#{suite['id']}") test_cases.find do |test_case| test_case['title'] == title && test_case['section_id'] == section['id'] end end |
#find_or_create_case(title, section, depth) ⇒ Object
—————————————————-> cases <—————————————————–
116 117 118 |
# File 'lib/testrail_export/client.rb', line 116 def find_or_create_case(title, section, depth) self.find_case(title, section, depth) || self.create_case(title, section['id']) end |
#find_or_create_section(name, suite, parent, depth) ⇒ Object
101 102 103 104 |
# File 'lib/testrail_export/client.rb', line 101 def find_or_create_section(name, suite, parent, depth) parent_id = (depth == 0) ? nil : parent['id'] self.find_section(name, suite, parent_id) || self.create_section(name, suite, parent_id) end |
#find_or_create_suite(name, project_id) ⇒ Object
84 85 86 |
# File 'lib/testrail_export/client.rb', line 84 def find_or_create_suite(name, project_id) self.find_suite_by_name(name, project_id) || self.create_suite(name, project_id) end |
#find_section(name, suite, parent_id) ⇒ Object
97 98 99 |
# File 'lib/testrail_export/client.rb', line 97 def find_section(name, suite, parent_id) get_sections(suite).select{ |s| s['parent_id'] == parent_id }.find{ |s| s['name'] == name.strip } end |
#find_suite_by_name(name, project_id) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/testrail_export/client.rb', line 70 def find_suite_by_name(name, project_id) suites = self.get_suites(project_id).select do |suite| suite['name'] == name end puts "TestRail Exporter [WARN] #{suites.size} suites found with name: #{name}. Using first one." if suites.size > 1 suites.first end |
#get_project(project_id) ⇒ Object
57 58 59 |
# File 'lib/testrail_export/client.rb', line 57 def get_project(project_id) self.get_projects.find { |project| project['id'] == project_id } end |
#get_projects ⇒ Object
—————————————————> projects —————————————————-
46 47 48 |
# File 'lib/testrail_export/client.rb', line 46 def get_projects @projects ||= @client.send_get('get_projects') end |
#get_sections(suite) ⇒ Object
—————————————————> sections <—————————————————
89 90 91 |
# File 'lib/testrail_export/client.rb', line 89 def get_sections(suite) @sections[suite['id']] ||= @client.send_get("get_sections/#{suite['project_id']}&suite_id=#{suite['id']}") end |
#get_suite(suite_id) ⇒ Object
—————————————————-> suites <—————————————————-
62 63 64 |
# File 'lib/testrail_export/client.rb', line 62 def get_suite(suite_id) @suite[suite_id] ||= @client.send_get("get_suite/#{suite_id}") end |
#get_suites(project_id) ⇒ Object
66 67 68 |
# File 'lib/testrail_export/client.rb', line 66 def get_suites(project_id) @suites[project_id] ||= @client.send_get("get_suites/#{project_id}") end |
#section_ids_at_depth(suite, depth) ⇒ Object
93 94 95 |
# File 'lib/testrail_export/client.rb', line 93 def section_ids_at_depth(suite, depth) self.get_sections(suite).select{ |s| s['depth'] == depth }.map{ |s| s['id'] } end |