itriagetestrail 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f790a108a246bd32d40671679a904a1e41c8fc0f
4
- data.tar.gz: 67559f3e5e0d1b8672de8bafc54777c497a405a9
3
+ metadata.gz: 0e4b34fc68615740cb5247064b7635c603149c7e
4
+ data.tar.gz: 08b07991a0d6917d176e1fe72f209e3f2527ff18
5
5
  SHA512:
6
- metadata.gz: 5969ef31999a2dfa57f143fb6b87a67aede417aef781fd9d1672e017b5df1ef0e74e52d292307b4261bed8307c70d8b351ab7ae355059e28fff4f2807b4a9b9a
7
- data.tar.gz: 7d9943e4b9574798686842f08c566abe84b13ec9445c4e6d91a6556bc3a49bf57f595102a24ba993b8d395c2aa03ea3db499b889ffd068608c3117b3231e3e5a
6
+ metadata.gz: 0ef107f0a6f489c7d4bab0f85ccc176d124316ab9dce714a6667b81990a890e63b97fe3e6ac8d66cb591d1b61179dac96da9db8b4ee30aa3aa23e245b2c94e55
7
+ data.tar.gz: 443c46a032847a4779671bd61e82696d28b130b92cc536f4d66b793f5ab4548f4752a6938005504b548c675106fc9000df0bc69e8cd90383901151083aae48a6
@@ -1,9 +1,7 @@
1
1
  require 'thread'
2
2
 
3
3
  class Pool
4
-
5
4
  def initialize(size)
6
-
7
5
  @size = size
8
6
  @jobs = Queue.new
9
7
 
@@ -24,9 +24,8 @@ module TestRail
24
24
  attr_accessor :password
25
25
 
26
26
  def initialize(base_url)
27
- if !base_url.match(/\/$/)
28
- base_url += '/'
29
- end
27
+ valid_regex = %r{/\/$/}
28
+ base_url += '/' unless valid_regex.match(base_url)
30
29
  @url = base_url + 'index.php?/api/v2/'
31
30
  end
32
31
 
@@ -63,6 +62,7 @@ module TestRail
63
62
  end
64
63
 
65
64
  private
65
+
66
66
  def make_connection(url)
67
67
  conn = Net::HTTP.new(url.host, url.port)
68
68
  if url.scheme == 'https'
@@ -105,7 +105,7 @@ module TestRail
105
105
  error = 'No additional error message received'
106
106
  end
107
107
 
108
- raise APIError, "TestRail API returned HTTP #{response.code} #{error}"
108
+ fail APIError, "TestRail API returned HTTP #{response.code} #{error}"
109
109
  end
110
110
  result
111
111
  end
@@ -1,3 +1,3 @@
1
1
  module Itriagetestrail
2
- VERSION = "0.0.3"
2
+ VERSION = '0.0.4'
3
3
  end
@@ -1,29 +1,34 @@
1
- require "itriagetestrail/version"
2
- require_relative "itriagetestrail/testrail_binding"
3
- require_relative "itriagetestrail/pool"
4
- #require 'testrail-rails'
5
-
1
+ require 'itriagetestrail/version'
2
+ require_relative 'itriagetestrail/testrail_binding'
3
+ require_relative 'itriagetestrail/pool'
6
4
 
7
5
  module Itriagetestrail
8
6
  class TestRailInterface
9
- # code goes here...
10
7
  attr_accessor :client
11
8
  attr_accessor :sections
12
9
  attr_accessor :test_cases
13
10
  attr_accessor :test_case_ids
14
11
  attr_accessor :run_id
15
12
  attr_accessor :execute
16
- attr_reader :results
17
- attr_reader :external_results
18
13
  attr_accessor :pool
19
14
  attr_accessor :batch_size
15
+ attr_reader :results
16
+ attr_reader :external_results
20
17
 
21
- def initialize(execute, testrail_config)
18
+ def initialize(testrail_config, origin)
22
19
  @run_id = 0
23
20
  @setup = false
24
21
  @testrail_config = testrail_config
25
22
  @project_id = @testrail_config['project_id']
26
- @execute = execute
23
+ @milestone_name = normalize_milestone(origin)
24
+
25
+ if @testrail_config['send_local_results?'] && @milestone_name == 'Local'
26
+ @execute = true
27
+ elsif @milestone_name == 'Local'
28
+ @execute = false
29
+ else
30
+ @execute = true
31
+ end
27
32
  end
28
33
 
29
34
  def setup?
@@ -47,6 +52,8 @@ module Itriagetestrail
47
52
  # Get the test rail ids
48
53
  testrail_ids
49
54
 
55
+ @milestone_id = fetch_milestone(@milestone_name)
56
+
50
57
  add_testrail_run
51
58
 
52
59
  @pool = Pool.new(1)
@@ -67,25 +74,52 @@ module Itriagetestrail
67
74
 
68
75
  def testrail_section_id(section_title)
69
76
  res = -1
70
- @sections.each { | section |
77
+ @sections.each do |section|
78
+ res = section['id'] if section['name'] == section_title
79
+ end
80
+ res
81
+ end
71
82
 
72
- if section['name'] == section_title
73
- res = section['id']
74
- end
75
- }
83
+ def normalize_milestone(origin)
84
+ case origin
85
+ when 'local', ''
86
+ 'Local'
87
+ when 'master'
88
+ 'Master'
89
+ else
90
+ 'Dev Branch'
91
+ end
92
+ end
93
+
94
+ def fetch_milestone(requested_milestone_name)
95
+ milestones = @client.send_get("get_milestones/#{@project_id}")
96
+ res = -1
97
+ milestones.each do |milestone|
98
+ res = milestone['id'] if milestone['name'] == requested_milestone_name
99
+ end
100
+
101
+ if res == -1
102
+ # We need to add the milestone to TestRail
103
+
104
+ body = {
105
+ name: requested_milestone_name
106
+ }
107
+
108
+ res = @client.send_post("add_milestone/#{@project_id}", body)['id']
109
+ end
76
110
  res
77
111
  end
78
112
 
79
113
  def add_testrail_section(section_title)
80
114
  body = {
81
- :name => section_title
115
+ name: section_title
82
116
  }
83
117
 
84
118
  res = @client.send_post("add_section/#{@project_id}", body)
85
119
 
86
120
  testrail_section = res['id']
87
121
 
88
- #re-establish sections
122
+ # re-establish sections
89
123
  testrail_sections
90
124
 
91
125
  testrail_section
@@ -93,68 +127,65 @@ module Itriagetestrail
93
127
 
94
128
  # TestRail Cases
95
129
  def testrail_ids
96
-
97
130
  @test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3")
98
131
 
99
132
  @test_case_ids = []
100
133
 
101
- @test_cases.each { |test_case| @test_case_ids << test_case['id']}
134
+ @test_cases.each { |test_case| @test_case_ids << test_case['id'] }
102
135
  end
103
136
 
104
137
  def testrail_test_case_id(external_id)
105
-
106
138
  res = -1
107
- @test_cases.each { | test_case |
108
-
139
+ @test_cases.each do |test_case|
109
140
  if test_case['custom_external_case_id'] == external_id
110
141
  res = test_case['id']
111
142
  end
112
- }
143
+ end
113
144
  res
114
145
  end
115
146
 
116
147
  def associate_result(external_id)
117
-
118
148
  test_case_id = testrail_test_case_id(external_id)
119
- #store the test case id with the local result
120
- @results[:results].each { |result|
121
-
122
- if result['external_id'] == external_id
123
- @external_results['results'] << {case_id: test_case_id, status_id: result['status_id'], comment: result['comment']}
124
- end
125
- }
149
+ # store the test case id with the local result
150
+ @results[:results].each do |result|
151
+ next unless result['external_id'] == external_id
152
+ @external_results['results'] << { case_id: test_case_id,
153
+ status_id: result['status_id'],
154
+ comment: result['comment'] }
155
+ end
126
156
  end
127
157
 
128
158
  # add the test case if it doesn't exist
129
159
  def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
130
160
  body = {
131
- :title => scenario_title,
132
- :custom_external_case_id => external_id,
133
- :custom_steps => scenario_steps,
134
- :type_id => 3
161
+ title: scenario_title,
162
+ custom_external_case_id: external_id,
163
+ custom_steps: scenario_steps,
164
+ type_id: 3
135
165
  }
136
166
 
137
167
  @client.send_post("add_case/#{section_id}", body)
138
168
 
139
- #refresh test case ids
169
+ # refresh test case ids
140
170
  testrail_ids
141
171
  end
142
172
 
143
173
  # open a test run to submit test results
144
174
  def add_testrail_run
145
-
146
- if @testrail_config['include_all?'] then
175
+ if @testrail_config['include_all?']
147
176
 
148
177
  body = {
149
- :name => "POC Regression on #{Time.now}",
150
- :include_all => true
178
+ name: "POC Regression on #{Time.zone.now}",
179
+ include_all: true,
180
+ milestone_id: @milestone_id
151
181
  }
152
182
  else
153
183
 
154
184
  body = {
155
- :name => "POC Regression on #{Time.now}",
156
- :include_all => false,
157
- :case_ids => @test_case_ids
185
+ name: "POC Regression on #{Time.zone.now}",
186
+ include_all: false,
187
+ case_ids: @test_case_ids,
188
+ milestone_id: @milestone_id
158
189
  }
159
190
  end
160
191
 
@@ -164,79 +195,59 @@ module Itriagetestrail
164
195
  end
165
196
 
166
197
  def send_results_to_testrail
167
- if @results[:results].size != 0
168
-
169
- # copy what is in the results
170
- @submitted[:results] << @results[:results]
171
-
172
- send = {:results => @results[:results]}
173
- # Commenting out the multi-threading stuff
174
- # @pool.schedule do
175
- #make sure tests are part of current run
176
- begin
177
- res = @client.send_post("add_results_for_cases/#{@run_id}", send)
178
- puts res
179
- rescue Exception => e
180
- raise e
181
- end
182
- # end
183
-
184
- # @results[:results] = @results[:results] - send[:results]
198
+ return unless @results[:results].size == 0
199
+ # copy what is in the results
200
+ @submitted[:results] << @results[:results]
201
+
202
+ begin
203
+ send = { results: @results[:results] }
204
+ res = @client.send_post("add_results_for_cases/#{@run_id}", send)
205
+ puts res
206
+ rescue StandardError => e
207
+ raise e
185
208
  end
186
209
  end
187
210
 
188
211
  def update_test_suite(scenario_title, external_id, scenario_steps)
189
-
190
- # establish variables
191
- #@external_id = result['external_id']
192
-
193
212
  feature = external_id.split(';')[0]
194
213
 
195
214
  section_id = testrail_section_id(feature)
196
215
 
197
- #if the testrail section does not exist, update sections
198
- if section_id == -1
216
+ # if the testrail section does not exist, update sections
217
+ section_id = add_testrail_section(feature) if section_id == -1
199
218
 
200
- section_id = add_testrail_section(feature)
201
- end
202
-
203
- #if the testrail case does not exist, update cases
219
+ # if the testrail case does not exist, update cases
204
220
  if testrail_test_case_id(external_id) == -1
205
221
 
206
- #@scenario_title = result['scenario_title']
222
+ # @scenario_title = result['scenario_title']
207
223
 
208
224
  add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
209
225
  sleep 1
210
226
  end
211
227
 
212
- #store the case id associated with the external_id
228
+ # store the case id associated with the external_id
213
229
  associate_result(external_id)
214
230
  end
215
231
 
216
-
217
232
  def store_result(scenario_title, external_id, scenario_steps, status_id, comment)
218
-
219
233
  update_test_suite scenario_title, external_id, scenario_steps
220
234
 
221
235
  case_id = testrail_test_case_id(external_id)
222
236
 
223
- @results[:results] << {case_id: case_id, scenario_title: scenario_title, external_id: external_id, scenario_steps: scenario_steps, status_id: status_id, comment: comment }
224
-
225
- # Removes multi-threading
226
- # if @results[:results].size >= @batch_size
227
- #
228
- # send_results_to_testrail
229
- #
230
- # end
237
+ @results[:results] << {
238
+ case_id: case_id,
239
+ scenario_title: scenario_title,
240
+ external_id: external_id,
241
+ scenario_steps: scenario_steps,
242
+ status_id: status_id,
243
+ comment: comment
244
+ }
231
245
  end
232
246
 
233
247
  def shutdown
234
248
  @pool.shutdown
235
249
 
236
- if @testrail_config['close_run?']
237
- @client.send_post("close_run/#{@run_id}", {})
238
- end
250
+ @client.send_post("close_run/#{@run_id}", {}) if @testrail_config['close_run?']
239
251
  end
240
-
241
252
  end
242
253
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itriagetestrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - a801069
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler