itriagetestrail 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 432fa8e6b5a030aaca3eed94a324d003170fb0cf
4
- data.tar.gz: 13f1cc9d4e0df1fd3c27603f4c323c3b17d83124
3
+ metadata.gz: 60a7641e7255058ed13e18ca80a789133c7e5eba
4
+ data.tar.gz: 1311492cd1cd2f59dc9cfe20a303d126b5c15430
5
5
  SHA512:
6
- metadata.gz: ace825d2e12f6e999f824651104f949498267f6d5229d1ad1523796cfc5c120d345c8f789c7ef5409205117fa92fa4ffe8a8a2379f5f524bbc630eaed2f76021
7
- data.tar.gz: f9a604a63303972818a1c8ed8f30572bec117d98cb8de51c6d9774df140b41a0f8e1ff0b80647d568a3628b64b8a40c07308e4c12c1ac4befa8f01dc361bd67b
6
+ metadata.gz: 3a261214a074fd3f997371f7824e1767439cd81c237f28286326644ccee5e0bb630c50b872b9282cbe1419bb46221be0ec820ba32a38c82f0130cdcdc9e0d3b0
7
+ data.tar.gz: 256e30f116140fc04f1c02d98d1642e7667e79f6a4c6bebdc8a5644af81df80001a1178073d893e61e0d0c8e80f40967f1644712ac9062c9b74a84bb7fa51047
@@ -2,503 +2,18 @@ require_relative 'itriagetestrail/version'
2
2
  require_relative 'itriagetestrail/testrail_binding'
3
3
 
4
4
  require_relative 'itriagetestrail/pool'
5
+ require_relative 'itriagetestrail/testrail_objects/milestones'
6
+ require_relative 'itriagetestrail/testrail_objects/projects'
7
+ require_relative 'itriagetestrail/testrail_objects/sections'
8
+ require_relative 'itriagetestrail/testrail_objects/suites'
9
+ require_relative 'itriagetestrail/testrail_objects/test_cases'
10
+ require_relative 'itriagetestrail/testrail_objects/test_plans'
11
+ require_relative 'itriagetestrail/testrail_objects/test_results'
12
+ require_relative 'itriagetestrail/testrail_objects/test_runs'
5
13
 
6
14
  require 'tzinfo'
7
15
 
8
16
  module Itriagetestrail
9
- module Projects
10
- # populate projects instance variable with all projects objects in the testrail site
11
- def projects
12
- @projects ||= @client.send_get("get_projects")
13
- end
14
-
15
- def project_by_name(name)
16
- res = -1
17
- projects.each do |project|
18
- res = project if project['name'] == name
19
- end
20
- res
21
- end
22
-
23
- # return the project object for a given project id
24
- def project_by_id(id)
25
- res = -1
26
- projects.each do |project|
27
- res = project if project['id'] == id.to_i
28
- end
29
- res
30
- end
31
-
32
- # set the project_id by a requested project from config/environment variable
33
- def set_project
34
- requested_id = @testrail_config[:projectId]
35
- case requested_id
36
- when nil, ''
37
- # a project id was not provided, fetch it from TestRail by project name
38
- res = project_by_name(@testrail_config[:projectName])
39
- if res == -1
40
- @execute = false
41
- return
42
- end
43
- @project_id = res['id']
44
- @suite_mode = res['suite_mode']
45
- else
46
- # use the requested project id
47
- @project_id = requested_id
48
- @suite_mode = project_by_id(@project_id)['suite_mode']
49
- end
50
- end
51
- end
52
-
53
- module Suites
54
- # TestRail Suites
55
- def testrail_suites
56
- case @suite_mode
57
- when 2,3
58
- @suites = @client.send_get("get_suites/#{@project_id}")
59
- end
60
- end
61
-
62
- def testrail_suite_id(suite_name)
63
- res = -1
64
- @suites.each do |suite|
65
- res = suite['id'] if suite['name'] == suite_name
66
- end
67
- res
68
- end
69
-
70
- def add_testrail_suite(suite_name)
71
- body = { name: suite_name }
72
- res = @client.send_post("add_suite/#{@project_id}", body)
73
- testrail_suite = res['id']
74
-
75
- #re-establish suites
76
- testrail_suites
77
-
78
- testrail_suite
79
- end
80
- end
81
-
82
- module Milestones
83
-
84
- # Establish the milestone name based on origin passed in,
85
- # usually origin represents a branch or environment
86
- def normalize_milestone
87
- if @testrail_config[:milestone].nil? || @testrail_config[:milestone].empty?
88
- case @testrail_config[:origin]
89
- when 'prd', 'production', 'origin/production'
90
- 'Production'
91
- when 'stg', 'staging', 'origin/staging'
92
- 'Staging'
93
- when 'dev', 'development', 'origin/development'
94
- 'Development'
95
- when 'local', ''
96
- 'Local'
97
- when 'master', 'origin/master'
98
- 'Master'
99
- else
100
- 'Dev Branch'
101
- end
102
- else
103
- @testrail_config[:milestone]
104
- end
105
- end
106
-
107
- # returns timestamp for begining of first day of current quarter
108
- def milestone_period_start
109
- time_zone = TZInfo::Timezone.get('America/Denver')
110
- current_year = time_zone.now.year
111
- month = time_zone.now.mon
112
-
113
- # determine which quarter we are in
114
- if month <= 3
115
- time_zone.utc_to_local(Time.utc(current_year, 1, 1))
116
- elsif month <= 6
117
- time_zone.utc_to_local(Time.utc(current_year, 4, 1))
118
- elsif month <= 9
119
- time_zone.utc_to_local(Time.utc(current_year, 7, 1))
120
- else
121
- time_zone.utc_to_local(Time.utc(current_year, 10, 1))
122
- end
123
- end
124
-
125
- # determine the due date (end of quarter) for a new milestone being added
126
- def milestone_due_date
127
- time_zone = TZInfo::Timezone.get('America/Denver')
128
- current_year = time_zone.now.year
129
- month = time_zone.now.mon
130
-
131
- # determine which quarter we are in
132
- if month <= 3
133
- Time.utc(current_year, 3, 31).strftime('%s')
134
- elsif month <= 6
135
- Time.utc(current_year, 6, 30).strftime('%s')
136
- elsif month <= 9
137
- Time.utc(current_year, 9, 30).strftime('%s')
138
- else
139
- Time.new(current_year, 12, 31).strftime('%s')
140
- end
141
- end
142
-
143
- # returns the id for a requested milestone by name, or creates one if the milestone does not exist
144
- def fetch_milestone(requested_milestone_name)
145
- milestones = @client.send_get("get_milestones/#{@project_id}")
146
- res = -1
147
- milestones.each do |milestone|
148
- res = milestone['id'] if milestone['name'] == requested_milestone_name
149
- end
150
-
151
- if res == -1
152
- # We need to add the milestone to TestRail
153
-
154
- body = {
155
- name: requested_milestone_name,
156
- due_on: milestone_due_date
157
- }
158
-
159
- res = @client.send_post("add_milestone/#{@project_id}", body)['id']
160
- end
161
- res
162
- end
163
-
164
- # return a standardized name for a milestone to be archived
165
- def milestone_archive_name(milestone_name, date)
166
- year = date.year
167
- month = date.mon
168
-
169
- if month <= 3
170
- "#{milestone_name} #{year}-Q1"
171
- elsif month <= 6
172
- "#{milestone_name} #{year}-Q2"
173
- elsif month <= 9
174
- "#{milestone_name} #{year}-Q3"
175
- else
176
- "#{milestone_name} #{year}-Q4"
177
- end
178
- end
179
-
180
- # return all the runs associated with an existing milestone
181
- def milestone_runs(milestone_name)
182
- # use the matching milestone id for project
183
- milestone_id = fetch_milestone(milestone_name)
184
-
185
- # fetch all test runs associated with the milestone id for project
186
- @client.send_get("get_runs/#{@project_id}&milestone_id=#{milestone_id}&is_completed=1") || []
187
- end
188
-
189
- # testrail call to rename a milestone (for archiving)
190
- def rename_milestone(id, new_name)
191
- # todo: rename milestone with previous_milestone
192
- body = { name: new_name }
193
- res = @client.send_post("update_milestone/#{id}", body)['id']
194
- end
195
-
196
- # this archives a milestone at the turn of a quarter and creates a new one in its place
197
- def reset_milestone(milestone_name)
198
- runs = milestone_runs(milestone_name)
199
- if runs.size > 0
200
- last_run_time = Time.at(runs.last['completed_on'])
201
- if last_run_time < milestone_period_start
202
- rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
203
- @milestone_id = fetch_milestone(@milestone_name)
204
- end
205
- end
206
- end
207
- end
208
-
209
- module Sections
210
- # TestRail Sections
211
- def testrail_sections
212
- case @suite_mode
213
- when 2,3
214
- @suite_id = testrail_suite_id(@suite_name)
215
- @sections = @client.send_get("get_sections/#{@project_id}&suite_id=#{@suite_id}")
216
- else
217
- @sections = @client.send_get("get_sections/#{@project_id}")
218
- end
219
- end
220
-
221
- def testrail_section_id(section_title)
222
- res = -1
223
- @sections.each do |section|
224
- res = section['id'] if section['name'] == section_title
225
- end
226
- res
227
- end
228
-
229
- def add_testrail_section(section_title)
230
- if @suite_name
231
- body = {
232
- name: section_title,
233
- suite_id: testrail_suite_id(@suite_name)
234
- }
235
- else
236
- body = {
237
- name: section_title
238
- }
239
- end
240
-
241
- res = @client.send_post("add_section/#{@project_id}", body)
242
-
243
- testrail_section = res['id']
244
-
245
- # re-establish sections
246
- testrail_sections
247
-
248
- testrail_section
249
- end
250
- end
251
-
252
- module TestCases
253
- # TestRail Cases
254
- def testrail_ids
255
- case @suite_mode
256
- when 2,3
257
- @test_cases = @client.send_get("get_cases/#{@project_id}&suite_id=#{@suite_id}&type_id=3")
258
- else
259
- @test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3")
260
- end
261
-
262
- @test_case_ids = []
263
-
264
- @test_cases.each { |test_case| @test_case_ids << test_case['id'] }
265
- end
266
-
267
- def testrail_test_case_id(external_id)
268
- res = -1
269
- @test_cases.each do |test_case|
270
- if test_case['custom_external_case_id'] == external_id
271
- res = test_case['id']
272
- end
273
- end
274
- res
275
- end
276
-
277
- def associate_result(external_id)
278
- test_case_id = testrail_test_case_id(external_id)
279
- # store the test case id with the local result
280
- @results[:results].each do |result|
281
- next unless result[:external_id] == external_id
282
- @external_results[:results] << { case_id: test_case_id,
283
- status_id: result['status_id'],
284
- comment: result['comment'] }
285
- end
286
- end
287
-
288
- # add the test case if it doesn't exist
289
- def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
290
- body = {
291
- title: scenario_title,
292
- custom_external_case_id: external_id,
293
- custom_steps: scenario_steps,
294
- type_id: 3
295
- }
296
-
297
- @client.send_post("add_case/#{section_id}", body)
298
-
299
- # refresh test case ids
300
- testrail_ids
301
- end
302
-
303
- def test_name
304
- label = ''
305
- label += "App Version:#{@app_version}" unless @app_version.nil? || @app_version == ''
306
- label += " Jenkins Build:#{@jenkins_build}" unless @jenkins_build .nil? || @jenkins_build == ''
307
- label.strip!
308
- label = 'Regression' if label == ''
309
- label + ' (' + @time_zone.now.strftime('%-I:%M %p') + ')'
310
- end
311
- end
312
-
313
- module TestPlans
314
-
315
- def configuration_group(name)
316
- res = {}
317
- @configurations.each do |config|
318
- res = config if config['name'] == name
319
- end
320
- res
321
- end
322
-
323
- def config_id(name, value)
324
- res = {}
325
- configuration = configuration_group(name)
326
-
327
- return nil if configuration.empty?
328
- configuration['configs'].each do |config|
329
- res = config['id'] if config['name'] == value
330
- end
331
- res
332
- end
333
-
334
-
335
- def configurations
336
- @configurations = @client.send_get("get_configs/#{@project_id}")
337
- end
338
-
339
- def configuration_ids
340
-
341
- @configuration_ids = []
342
-
343
- # evaluate @testrail_comfig
344
- @configuration_ids << config_id('Browser', @testrail_config[:config][:browser]) unless @testrail_config[:config][:browser].nil?
345
- @configuration_ids << config_id('Browser Version', @testrail_config[:config][:browserVersion]) unless @testrail_config[:config][:browserVersion].nil?
346
- @configuration_ids << config_id('Platform', @testrail_config[:config][:platform]) unless @testrail_config[:config][:platform].nil?
347
- @configuration_ids << config_id('Android Version', @testrail_config[:config][:android]) unless @testrail_config[:config][:android].nil?
348
- @configuration_ids << config_id('Android Device', @testrail_config[:config][:androidDevice]) unless @testrail_config[:config][:androidDevice].nil?
349
- @configuration_ids << config_id('IOS Version', @testrail_config[:config][:ios]) unless @testrail_config[:config][:ios].nil?
350
-
351
- # remove the nils
352
- @configuration_ids.compact!
353
-
354
- @configuration_ids
355
- end
356
-
357
- def add_testrail_plan
358
-
359
- body = {
360
- name: test_name,
361
- description: '',
362
- milestone_id: @milestone_id
363
- }
364
-
365
- @plan = @client.send_post("add_plan/#{@project_id}", body)
366
- # todo: replace debugging
367
- puts @plan.inspect
368
-
369
- @plan_id = @plan['id']
370
- # todo: replace debugging
371
- puts @plan_id.inspect
372
- end
373
-
374
- def add_plan_entry
375
-
376
- # todo: refactor redundant assignments of @suite_id
377
- @suite_id = testrail_suite_id(@suite_name)
378
- body = {
379
- suite_id: @suite_id,
380
- # todo: replace hardcoded name
381
- name: 'replace this with config description',
382
- include_all: true,
383
- # todo: replace hardcoded config
384
- config_ids: configuration_ids,
385
- runs: [
386
- {
387
- include_all: true,
388
- config_ids: configuration_ids
389
- }
390
- ]
391
- }
392
-
393
- @plan_entry = @client.send_post("add_plan_entry/#{@plan_id}", body)
394
- # todo: replace debugging
395
- puts @plan_entry.inspect
396
- @run_id = @plan_entry['runs'][0]['id']
397
- # todo: replace debugging
398
- puts @run_id.inspect
399
- end
400
- end
401
-
402
- module TestRuns
403
- def extend_testrail_run
404
- # Reset test scope to include all cases
405
- body = { include_all: true }
406
- @client.send_post("update_run/#{@run_id}", body)
407
- end
408
-
409
- def existing_cases_from_description
410
- # Grabs from testrail run description
411
- run = @client.send_get("get_run/#{@run_id}")
412
- @description = run["description"]
413
- @description.nil? ? [] : @description.split(",")
414
- end
415
-
416
- def existing_cases_from_run(run_id = @run_id)
417
-
418
- tests = @client.send_get("get_tests/#{run_id}&status_id=1,2,4,5") || []
419
-
420
- cases = []
421
-
422
- tests.each do |test|
423
-
424
- cases << test["case_id"]
425
-
426
- end
427
- cases
428
- end
429
-
430
- # open a test run to submit test results
431
- def add_testrail_run
432
- body = {
433
- name: test_name,
434
- description: '',
435
- include_all: true,
436
- milestone_id: @milestone_id
437
- }
438
-
439
- unless @testrail_config[:include_all] || true
440
- body[:include_all] = false
441
- body[:case_ids] = @test_case_ids
442
- end
443
-
444
- case @suite_mode
445
- when 2,3
446
- body[:suite_id] = @suite_id
447
- end
448
- res = @client.send_post("add_run/#{@project_id}", body)
449
- @run_id = res['id']
450
- end
451
- end
452
-
453
- module TestResults
454
- def send_results_to_testrail
455
- return unless @results[:results].size != 0
456
- # copy what is in the results
457
- @submitted[:results] << @results[:results]
458
-
459
- begin
460
- send = { results: @results[:results] }
461
- res = @client.send_post("add_results_for_cases/#{@run_id}", send)
462
- clear_results
463
- rescue StandardError => e
464
- raise e
465
- end
466
- end
467
-
468
- def update_test_suite(scenario_title, external_id, scenario_steps)
469
- feature = external_id.split(';')[0].split('#')[0]
470
-
471
- # if the testrail case does not exist, update cases
472
- if testrail_test_case_id(external_id) == -1
473
-
474
- section_id = testrail_section_id(feature)
475
-
476
- # if the testrail section does not exist, update sections
477
- section_id = add_testrail_section(feature) if section_id == -1
478
-
479
- add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
480
- sleep 1
481
- end
482
- # store the case id associated with the external_id
483
- associate_result(external_id)
484
- end
485
-
486
- def store_result(scenario_title, external_id, scenario_steps, status_id, comment)
487
- update_test_suite scenario_title, external_id, scenario_steps
488
-
489
- case_id = testrail_test_case_id(external_id)
490
- @results[:results] << {
491
- case_id: case_id,
492
- scenario_title: scenario_title,
493
- external_id: external_id,
494
- scenario_steps: scenario_steps,
495
- status_id: status_id,
496
- comment: comment,
497
- custom_branch_name: @testrail_config[:origin]
498
- }
499
- end
500
- end
501
-
502
17
  class TestRailInterface
503
18
 
504
19
  include Projects
@@ -24,7 +24,6 @@ module Itriagetestrail
24
24
  store_result(@scenario_title, @external_id, @scenario_steps,
25
25
  "#{ENV['RERUN'] ? 5 : 4}".to_i, "#{scenario.exception.class}\n#{scenario.exception}\n#{scenario.exception.backtrace}")
26
26
  end
27
- send_results_to_testrail
28
27
  rescue => exception
29
28
  puts "TESTRAIL ENCOUNTERED AN ERROR: #{exception}\n #{@external_id} \n\n"
30
29
  end
@@ -22,7 +22,6 @@ module Itriagetestrail
22
22
  store_result(@scenario_title, @external_id, @scenario_steps,
23
23
  "#{ENV['RERUN'] ? 5 : 4}".to_i, "#{scenario.exception.class}\n#{scenario.exception}\n#{scenario.exception.backtrace}")
24
24
  end
25
- send_results_to_testrail
26
25
  rescue => exception
27
26
  puts "TESTRAIL ENCOUNTERED AN ERROR: #{exception}\n #{@external_id} \n\n"
28
27
  end
@@ -24,7 +24,6 @@ module Itriagetestrail
24
24
  store_result(@scenario_title, @external_id, @scenario_steps,
25
25
  "#{ENV['RERUN'] ? 5 : 4}".to_i, "#{scenario.exception.class}\n#{scenario.exception}\n#{scenario.exception.backtrace}")
26
26
  end
27
- send_results_to_testrail
28
27
  rescue => exception
29
28
  puts "TESTRAIL ENCOUNTERED AN ERROR: #{exception}\n #{@external_id} \n\n"
30
29
  end
@@ -12,7 +12,6 @@ module Itriagetestrail
12
12
  else
13
13
  store_result(test.name, @external_id, '', 5, failures.inspect)
14
14
  end
15
- send_results_to_testrail
16
15
  rescue => exception
17
16
  puts "TESTRAIL ENCOUNTERED AN ERROR: #{exception}\n #{@external_id} \n\n"
18
17
  end
@@ -1,3 +1,3 @@
1
1
  module Itriagetestrail
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itriagetestrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - a801069
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-09 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tzinfo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,19 +67,19 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: tzinfo
70
+ name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: 0.56.0
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: 0.56.0
69
83
  description: Plugin to export your cucumber tests in the Testrail
70
84
  email:
71
85
  executables: []
@@ -73,12 +87,12 @@ extensions: []
73
87
  extra_rdoc_files: []
74
88
  files:
75
89
  - lib/itriagetestrail.rb
90
+ - lib/itriagetestrail/framework_bindings/trcucumber13.rb
91
+ - lib/itriagetestrail/framework_bindings/trcucumber20.rb
92
+ - lib/itriagetestrail/framework_bindings/trcucumber30.rb
93
+ - lib/itriagetestrail/framework_bindings/trminitest.rb
76
94
  - lib/itriagetestrail/pool.rb
77
95
  - lib/itriagetestrail/testrail_binding.rb
78
- - lib/itriagetestrail/trcucumber13.rb
79
- - lib/itriagetestrail/trcucumber20.rb
80
- - lib/itriagetestrail/trcucumber30.rb
81
- - lib/itriagetestrail/trminitest.rb
82
96
  - lib/itriagetestrail/version.rb
83
97
  homepage:
84
98
  licenses: []
@@ -99,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
113
  version: '0'
100
114
  requirements: []
101
115
  rubyforge_project:
102
- rubygems_version: 2.4.5.1
116
+ rubygems_version: 2.5.2
103
117
  signing_key:
104
118
  specification_version: 4
105
119
  summary: Plugin to export your cucumber tests in the Testrail