itriagetestrail 0.7.9 → 0.8.0

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: 28b1906d2269bbcf05cb4e8790115c7109e03235
4
- data.tar.gz: 3dc51fa5ecf7139401a728499c918704ce768059
3
+ metadata.gz: bbc60c37ef3fb6c4f949cef22b1a55c1e263be76
4
+ data.tar.gz: 17a62f1aa85419fc342f0b2a073f83ff90568e1e
5
5
  SHA512:
6
- metadata.gz: 1fff1da7c1fc54f3d88a01322c4bf7d4cd997ae73349ddcf4eb65a6bea01200b65a32c64482f23c049915d3a4a34c78e6e24a39a1f610afa0cc70b83f2046c1e
7
- data.tar.gz: d167735b489ecc053716761a23a2c53141e3208354f091f4b2dffab6e56f76f7988ad16e561f0f101e87eb6f50ab2d4713ee29c52b0e780ece5c574cf213e8f5
6
+ metadata.gz: 8318b0d8b5eff82c8193e48e4958b9ffd1d5089501f641ec6d48bc676a28dcbea9d81a9035324f3c54595497b02a187ce42cae526b314f950fb71ee338818fda
7
+ data.tar.gz: eaf156a26baa1297b2807d4539bc6545d2e808d0ae0d093ebc9c8ea6ecbe18f5f3979773fd6c4d0fd68e886e73bda479901e4718cfd653edb0d19e083140a476
@@ -2,12 +2,16 @@ require_relative 'itriagetestrail/version'
2
2
  require_relative 'itriagetestrail/testrail_binding'
3
3
 
4
4
  require_relative 'itriagetestrail/pool'
5
- require_relative 'itriagetestrail/modules'
5
+ require_relative 'itriagetestrail/helpers'
6
6
 
7
7
  require 'tzinfo'
8
8
 
9
9
  module Itriagetestrail
10
+
10
11
  class TestRailInterface
12
+
13
+ include Helpers
14
+
11
15
  attr_accessor :client
12
16
  attr_accessor :sections
13
17
  attr_accessor :test_cases
@@ -192,406 +196,3 @@ module Itriagetestrail
192
196
  end
193
197
 
194
198
 
195
- module Projects
196
- # populate projects instance variable with all projects objects in the testrail site
197
- def projects
198
- @projects ||= @client.send_get("get_projects")
199
- end
200
-
201
- def project_by_name(name)
202
- res = -1
203
- projects.each do |project|
204
- res = project if project['name'] == name
205
- end
206
- res
207
- end
208
-
209
- # return the project object for a given project id
210
- def project_by_id(id)
211
- res = -1
212
- projects.each do |project|
213
- res = project if project['id'] == id.to_i
214
- end
215
- res
216
- end
217
-
218
- # set the project_id by a requested project from config/environment variable
219
- def set_project
220
- requested_id = @testrail_config[:projectId]
221
- case requested_id
222
- when nil, ''
223
- # a project id was not provided, fetch it from TestRail by project name
224
- res = project_by_name(@testrail_config[:projectName])
225
- if res == -1
226
- @execute = false
227
- return
228
- end
229
- @project_id = res['id']
230
- @suite_mode = res['suite_mode']
231
- else
232
- # use the requested project id
233
- @project_id = requested_id
234
- @suite_mode = project_by_id(@project_id)['suite_mode']
235
- end
236
- end
237
- end
238
-
239
- module Suites
240
- # TestRail Suites
241
- def testrail_suites
242
- case @suite_mode
243
- when 2,3
244
- @suites = @client.send_get("get_suites/#{@project_id}")
245
- end
246
- end
247
-
248
- def testrail_suite_id(suite_name)
249
- res = -1
250
- @suites.each do |suite|
251
- res = suite['id'] if suite['name'] == suite_name
252
- end
253
- res
254
- end
255
-
256
- def add_testrail_suite(suite_name)
257
- body = { name: suite_name }
258
- res = @client.send_post("add_suite/#{@project_id}", body)
259
- testrail_suite = res['id']
260
-
261
- #re-establish suites
262
- testrail_suites
263
-
264
- testrail_suite
265
- end
266
- end
267
-
268
- module Milestones
269
-
270
- # Establish the milestone name based on origin passed in,
271
- # usually origin represents a branch or environment
272
- def normalize_milestone
273
- case @testrail_config[:origin]
274
- when 'prd', 'production', 'origin/production'
275
- 'Production'
276
- when 'stg', 'staging', 'origin/staging'
277
- 'Staging'
278
- when 'dev', 'development', 'origin/development'
279
- 'Development'
280
- when 'local', ''
281
- 'Local'
282
- when 'master', 'origin/master'
283
- if @testrail_config[:masterMilestone].nil? || @testrail_config[:masterMilestone].empty?
284
- 'Master'
285
- else
286
- @testrail_config[:masterMilestone]
287
- end
288
- else
289
- 'Dev Branch'
290
- end
291
- end
292
-
293
- # returns timestamp for begining of first day of current quarter
294
- def milestone_period_start
295
- time_zone = TZInfo::Timezone.get('America/Denver')
296
- current_year = time_zone.now.year
297
- month = time_zone.now.mon
298
-
299
- # determine which quarter we are in
300
- if month <= 3
301
- time_zone.utc_to_local(Time.utc(current_year, 1, 1))
302
- elsif month <= 6
303
- time_zone.utc_to_local(Time.utc(current_year, 4, 1))
304
- elsif month <= 9
305
- time_zone.utc_to_local(Time.utc(current_year, 7, 1))
306
- else
307
- time_zone.utc_to_local(Time.utc(current_year, 10, 1))
308
- end
309
- end
310
-
311
- # determine the due date (end of quarter) for a new milestone being added
312
- def milestone_due_date
313
- time_zone = TZInfo::Timezone.get('America/Denver')
314
- current_year = time_zone.now.year
315
- month = time_zone.now.mon
316
-
317
- # determine which quarter we are in
318
- if month <= 3
319
- Time.utc(current_year, 3, 31).strftime('%s')
320
- elsif month <= 6
321
- Time.utc(current_year, 6, 30).strftime('%s')
322
- elsif month <= 9
323
- Time.utc(current_year, 9, 30).strftime('%s')
324
- else
325
- Time.new(current_year, 12, 31).strftime('%s')
326
- end
327
- end
328
-
329
- # returns the id for a requested milestone by name, or creates one if the milestone does not exist
330
- def fetch_milestone(requested_milestone_name)
331
- milestones = @client.send_get("get_milestones/#{@project_id}")
332
- res = -1
333
- milestones.each do |milestone|
334
- res = milestone['id'] if milestone['name'] == requested_milestone_name
335
- end
336
-
337
- if res == -1
338
- # We need to add the milestone to TestRail
339
-
340
- body = {
341
- name: requested_milestone_name,
342
- due_on: milestone_due_date
343
- }
344
-
345
- res = @client.send_post("add_milestone/#{@project_id}", body)['id']
346
- end
347
- res
348
- end
349
-
350
- # return a standardized name for a milestone to be archived
351
- def milestone_archive_name(milestone_name, date)
352
- year = date.year
353
- month = date.mon
354
-
355
- if month <= 3
356
- "#{milestone_name} #{year}-Q1"
357
- elsif month <= 6
358
- "#{milestone_name} #{year}-Q2"
359
- elsif month <= 9
360
- "#{milestone_name} #{year}-Q3"
361
- else
362
- "#{milestone_name} #{year}-Q4"
363
- end
364
- end
365
-
366
- # return all the runs associated with an existing milestone
367
- def milestone_runs(milestone_name)
368
- # use the matching milestone id for project
369
- milestone_id = fetch_milestone(milestone_name)
370
-
371
- # fetch all test runs associated with the milestone id for project
372
- @client.send_get("get_runs/#{@project_id}&milestone_id=#{milestone_id}&is_completed=1") || []
373
- end
374
-
375
- # testrail call to rename a milestone (for archiving)
376
- def rename_milestone(id, new_name)
377
- # todo: rename milestone with previous_milestone
378
- body = { name: new_name }
379
- res = @client.send_post("update_milestone/#{id}", body)['id']
380
- end
381
-
382
- # this archives a milestone at the turn of a quarter and creates a new one in its place
383
- def reset_milestone(milestone_name)
384
- runs = milestone_runs(milestone_name)
385
- if runs.size > 0
386
- last_run_time = Time.at(runs.last['completed_on'])
387
- if last_run_time < milestone_period_start
388
- rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
389
- @milestone_id = fetch_milestone(@milestone_name)
390
- end
391
- end
392
- end
393
- end
394
-
395
- module Sections
396
- # TestRail Sections
397
- def testrail_sections
398
- case @suite_mode
399
- when 2,3
400
- @suite_id = testrail_suite_id(@suite_name)
401
- @sections = @client.send_get("get_sections/#{@project_id}&suite_id=#{@suite_id}")
402
- else
403
- @sections = @client.send_get("get_sections/#{@project_id}")
404
- end
405
- end
406
-
407
- def testrail_section_id(section_title)
408
- res = -1
409
- @sections.each do |section|
410
- res = section['id'] if section['name'] == section_title
411
- end
412
- res
413
- end
414
-
415
- def add_testrail_section(section_title)
416
- if @suite_name
417
- body = {
418
- name: section_title,
419
- suite_id: testrail_suite_id(@suite_name)
420
- }
421
- else
422
- body = {
423
- name: section_title
424
- }
425
- end
426
-
427
- res = @client.send_post("add_section/#{@project_id}", body)
428
-
429
- testrail_section = res['id']
430
-
431
- # re-establish sections
432
- testrail_sections
433
-
434
- testrail_section
435
- end
436
- end
437
-
438
- module TestCases
439
- # TestRail Cases
440
- def testrail_ids
441
- case @suite_mode
442
- when 2,3
443
- @test_cases = @client.send_get("get_cases/#{@project_id}&suite_id=#{@suite_id}&type_id=3")
444
- else
445
- @test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3")
446
- end
447
-
448
- @test_case_ids = []
449
-
450
- @test_cases.each { |test_case| @test_case_ids << test_case['id'] }
451
- end
452
-
453
- def testrail_test_case_id(external_id)
454
- res = -1
455
- @test_cases.each do |test_case|
456
- if test_case['custom_external_case_id'] == external_id
457
- res = test_case['id']
458
- end
459
- end
460
- res
461
- end
462
-
463
- def associate_result(external_id)
464
- test_case_id = testrail_test_case_id(external_id)
465
- # store the test case id with the local result
466
- @results[:results].each do |result|
467
- next unless result[:external_id] == external_id
468
- @external_results[:results] << { case_id: test_case_id,
469
- status_id: result['status_id'],
470
- comment: result['comment'] }
471
- end
472
- end
473
-
474
- # add the test case if it doesn't exist
475
- def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
476
- body = {
477
- title: scenario_title,
478
- custom_external_case_id: external_id,
479
- custom_steps: scenario_steps,
480
- type_id: 3
481
- }
482
-
483
- @client.send_post("add_case/#{section_id}", body)
484
-
485
- # refresh test case ids
486
- testrail_ids
487
- end
488
-
489
- def test_name
490
- label = ''
491
- label += "App Version:#{@app_version}" unless @app_version.nil? || @app_version == ''
492
- label += " Jenkins Build:#{@jenkins_build}" unless @jenkins_build .nil? || @jenkins_build == ''
493
- label.strip!
494
- label = 'Regression' if label == ''
495
- label + ' (' + @time_zone.now.strftime('%-I:%M %p') + ')'
496
- end
497
- end
498
-
499
- module TestRuns
500
- def extend_testrail_run
501
- # Reset test scope to include all cases
502
- body = { include_all: true }
503
- @client.send_post("update_run/#{@run_id}", body)
504
- end
505
-
506
- def existing_cases_from_description
507
- # Grabs from testrail run description
508
- run = @client.send_get("get_run/#{@run_id}")
509
- @description = run["description"]
510
- @description.nil? ? [] : @description.split(",")
511
- end
512
-
513
- def existing_cases_from_run
514
-
515
- tests = @client.send_get("get_tests/#{@run_id}&status_id=1,2,4,5") || []
516
-
517
- cases = []
518
-
519
- tests.each do |test|
520
-
521
- cases << test["case_id"]
522
-
523
- end
524
- cases
525
- end
526
-
527
- # open a test run to submit test results
528
- def add_testrail_run
529
- body = {
530
- name: test_name,
531
- description: '',
532
- include_all: true,
533
- milestone_id: @milestone_id
534
- }
535
-
536
- unless @testrail_config[:include_all] || true
537
- body[:include_all] = false
538
- body[:case_ids] = @test_case_ids
539
- end
540
-
541
- case @suite_mode
542
- when 2,3
543
- body[:suite_id] = @suite_id
544
- end
545
- res = @client.send_post("add_run/#{@project_id}", body)
546
- @run_id = res['id']
547
- end
548
- end
549
-
550
- module TestResults
551
- def send_results_to_testrail
552
- return unless @results[:results].size != 0
553
- # copy what is in the results
554
- @submitted[:results] << @results[:results]
555
-
556
- begin
557
- send = { results: @results[:results] }
558
- res = @client.send_post("add_results_for_cases/#{@run_id}", send)
559
- clear_results
560
- rescue StandardError => e
561
- raise e
562
- end
563
- end
564
-
565
- def update_test_suite(scenario_title, external_id, scenario_steps)
566
- feature = external_id.split(';')[0].split('#')[0]
567
-
568
- # if the testrail case does not exist, update cases
569
- if testrail_test_case_id(external_id) == -1
570
-
571
- section_id = testrail_section_id(feature)
572
-
573
- # if the testrail section does not exist, update sections
574
- section_id = add_testrail_section(feature) if section_id == -1
575
-
576
- add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
577
- sleep 1
578
- end
579
- # store the case id associated with the external_id
580
- associate_result(external_id)
581
- end
582
-
583
- def store_result(scenario_title, external_id, scenario_steps, status_id, comment)
584
- update_test_suite scenario_title, external_id, scenario_steps
585
-
586
- case_id = testrail_test_case_id(external_id)
587
- @results[:results] << {
588
- case_id: case_id,
589
- scenario_title: scenario_title,
590
- external_id: external_id,
591
- scenario_steps: scenario_steps,
592
- status_id: status_id,
593
- comment: comment,
594
- custom_branch_name: @testrail_config[:origin]
595
- }
596
- end
597
- end
@@ -0,0 +1,405 @@
1
+ module Helpers
2
+ module Projects
3
+ # populate projects instance variable with all projects objects in the testrail site
4
+ def projects
5
+ @projects ||= @client.send_get("get_projects")
6
+ end
7
+
8
+ def project_by_name(name)
9
+ res = -1
10
+ projects.each do |project|
11
+ res = project if project['name'] == name
12
+ end
13
+ res
14
+ end
15
+
16
+ # return the project object for a given project id
17
+ def project_by_id(id)
18
+ res = -1
19
+ projects.each do |project|
20
+ res = project if project['id'] == id.to_i
21
+ end
22
+ res
23
+ end
24
+
25
+ # set the project_id by a requested project from config/environment variable
26
+ def set_project
27
+ requested_id = @testrail_config[:projectId]
28
+ case requested_id
29
+ when nil, ''
30
+ # a project id was not provided, fetch it from TestRail by project name
31
+ res = project_by_name(@testrail_config[:projectName])
32
+ if res == -1
33
+ @execute = false
34
+ return
35
+ end
36
+ @project_id = res['id']
37
+ @suite_mode = res['suite_mode']
38
+ else
39
+ # use the requested project id
40
+ @project_id = requested_id
41
+ @suite_mode = project_by_id(@project_id)['suite_mode']
42
+ end
43
+ end
44
+ end
45
+
46
+ module Suites
47
+ # TestRail Suites
48
+ def testrail_suites
49
+ case @suite_mode
50
+ when 2,3
51
+ @suites = @client.send_get("get_suites/#{@project_id}")
52
+ end
53
+ end
54
+
55
+ def testrail_suite_id(suite_name)
56
+ res = -1
57
+ @suites.each do |suite|
58
+ res = suite['id'] if suite['name'] == suite_name
59
+ end
60
+ res
61
+ end
62
+
63
+ def add_testrail_suite(suite_name)
64
+ body = { name: suite_name }
65
+ res = @client.send_post("add_suite/#{@project_id}", body)
66
+ testrail_suite = res['id']
67
+
68
+ #re-establish suites
69
+ testrail_suites
70
+
71
+ testrail_suite
72
+ end
73
+ end
74
+
75
+ module Milestones
76
+
77
+ # Establish the milestone name based on origin passed in,
78
+ # usually origin represents a branch or environment
79
+ def normalize_milestone
80
+ case @testrail_config[:origin]
81
+ when 'prd', 'production', 'origin/production'
82
+ 'Production'
83
+ when 'stg', 'staging', 'origin/staging'
84
+ 'Staging'
85
+ when 'dev', 'development', 'origin/development'
86
+ 'Development'
87
+ when 'local', ''
88
+ 'Local'
89
+ when 'master', 'origin/master'
90
+ if @testrail_config[:masterMilestone].nil? || @testrail_config[:masterMilestone].empty?
91
+ 'Master'
92
+ else
93
+ @testrail_config[:masterMilestone]
94
+ end
95
+ else
96
+ 'Dev Branch'
97
+ end
98
+ end
99
+
100
+ # returns timestamp for begining of first day of current quarter
101
+ def milestone_period_start
102
+ time_zone = TZInfo::Timezone.get('America/Denver')
103
+ current_year = time_zone.now.year
104
+ month = time_zone.now.mon
105
+
106
+ # determine which quarter we are in
107
+ if month <= 3
108
+ time_zone.utc_to_local(Time.utc(current_year, 1, 1))
109
+ elsif month <= 6
110
+ time_zone.utc_to_local(Time.utc(current_year, 4, 1))
111
+ elsif month <= 9
112
+ time_zone.utc_to_local(Time.utc(current_year, 7, 1))
113
+ else
114
+ time_zone.utc_to_local(Time.utc(current_year, 10, 1))
115
+ end
116
+ end
117
+
118
+ # determine the due date (end of quarter) for a new milestone being added
119
+ def milestone_due_date
120
+ time_zone = TZInfo::Timezone.get('America/Denver')
121
+ current_year = time_zone.now.year
122
+ month = time_zone.now.mon
123
+
124
+ # determine which quarter we are in
125
+ if month <= 3
126
+ Time.utc(current_year, 3, 31).strftime('%s')
127
+ elsif month <= 6
128
+ Time.utc(current_year, 6, 30).strftime('%s')
129
+ elsif month <= 9
130
+ Time.utc(current_year, 9, 30).strftime('%s')
131
+ else
132
+ Time.new(current_year, 12, 31).strftime('%s')
133
+ end
134
+ end
135
+
136
+ # returns the id for a requested milestone by name, or creates one if the milestone does not exist
137
+ def fetch_milestone(requested_milestone_name)
138
+ milestones = @client.send_get("get_milestones/#{@project_id}")
139
+ res = -1
140
+ milestones.each do |milestone|
141
+ res = milestone['id'] if milestone['name'] == requested_milestone_name
142
+ end
143
+
144
+ if res == -1
145
+ # We need to add the milestone to TestRail
146
+
147
+ body = {
148
+ name: requested_milestone_name,
149
+ due_on: milestone_due_date
150
+ }
151
+
152
+ res = @client.send_post("add_milestone/#{@project_id}", body)['id']
153
+ end
154
+ res
155
+ end
156
+
157
+ # return a standardized name for a milestone to be archived
158
+ def milestone_archive_name(milestone_name, date)
159
+ year = date.year
160
+ month = date.mon
161
+
162
+ if month <= 3
163
+ "#{milestone_name} #{year}-Q1"
164
+ elsif month <= 6
165
+ "#{milestone_name} #{year}-Q2"
166
+ elsif month <= 9
167
+ "#{milestone_name} #{year}-Q3"
168
+ else
169
+ "#{milestone_name} #{year}-Q4"
170
+ end
171
+ end
172
+
173
+ # return all the runs associated with an existing milestone
174
+ def milestone_runs(milestone_name)
175
+ # use the matching milestone id for project
176
+ milestone_id = fetch_milestone(milestone_name)
177
+
178
+ # fetch all test runs associated with the milestone id for project
179
+ @client.send_get("get_runs/#{@project_id}&milestone_id=#{milestone_id}&is_completed=1") || []
180
+ end
181
+
182
+ # testrail call to rename a milestone (for archiving)
183
+ def rename_milestone(id, new_name)
184
+ # todo: rename milestone with previous_milestone
185
+ body = { name: new_name }
186
+ res = @client.send_post("update_milestone/#{id}", body)['id']
187
+ end
188
+
189
+ # this archives a milestone at the turn of a quarter and creates a new one in its place
190
+ def reset_milestone(milestone_name)
191
+ runs = milestone_runs(milestone_name)
192
+ if runs.size > 0
193
+ last_run_time = Time.at(runs.last['completed_on'])
194
+ if last_run_time < milestone_period_start
195
+ rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
196
+ @milestone_id = fetch_milestone(@milestone_name)
197
+ end
198
+ end
199
+ end
200
+ end
201
+
202
+ module Sections
203
+ # TestRail Sections
204
+ def testrail_sections
205
+ case @suite_mode
206
+ when 2,3
207
+ @suite_id = testrail_suite_id(@suite_name)
208
+ @sections = @client.send_get("get_sections/#{@project_id}&suite_id=#{@suite_id}")
209
+ else
210
+ @sections = @client.send_get("get_sections/#{@project_id}")
211
+ end
212
+ end
213
+
214
+ def testrail_section_id(section_title)
215
+ res = -1
216
+ @sections.each do |section|
217
+ res = section['id'] if section['name'] == section_title
218
+ end
219
+ res
220
+ end
221
+
222
+ def add_testrail_section(section_title)
223
+ if @suite_name
224
+ body = {
225
+ name: section_title,
226
+ suite_id: testrail_suite_id(@suite_name)
227
+ }
228
+ else
229
+ body = {
230
+ name: section_title
231
+ }
232
+ end
233
+
234
+ res = @client.send_post("add_section/#{@project_id}", body)
235
+
236
+ testrail_section = res['id']
237
+
238
+ # re-establish sections
239
+ testrail_sections
240
+
241
+ testrail_section
242
+ end
243
+ end
244
+
245
+ module TestCases
246
+ # TestRail Cases
247
+ def testrail_ids
248
+ case @suite_mode
249
+ when 2,3
250
+ @test_cases = @client.send_get("get_cases/#{@project_id}&suite_id=#{@suite_id}&type_id=3")
251
+ else
252
+ @test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3")
253
+ end
254
+
255
+ @test_case_ids = []
256
+
257
+ @test_cases.each { |test_case| @test_case_ids << test_case['id'] }
258
+ end
259
+
260
+ def testrail_test_case_id(external_id)
261
+ res = -1
262
+ @test_cases.each do |test_case|
263
+ if test_case['custom_external_case_id'] == external_id
264
+ res = test_case['id']
265
+ end
266
+ end
267
+ res
268
+ end
269
+
270
+ def associate_result(external_id)
271
+ test_case_id = testrail_test_case_id(external_id)
272
+ # store the test case id with the local result
273
+ @results[:results].each do |result|
274
+ next unless result[:external_id] == external_id
275
+ @external_results[:results] << { case_id: test_case_id,
276
+ status_id: result['status_id'],
277
+ comment: result['comment'] }
278
+ end
279
+ end
280
+
281
+ # add the test case if it doesn't exist
282
+ def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
283
+ body = {
284
+ title: scenario_title,
285
+ custom_external_case_id: external_id,
286
+ custom_steps: scenario_steps,
287
+ type_id: 3
288
+ }
289
+
290
+ @client.send_post("add_case/#{section_id}", body)
291
+
292
+ # refresh test case ids
293
+ testrail_ids
294
+ end
295
+
296
+ def test_name
297
+ label = ''
298
+ label += "App Version:#{@app_version}" unless @app_version.nil? || @app_version == ''
299
+ label += " Jenkins Build:#{@jenkins_build}" unless @jenkins_build .nil? || @jenkins_build == ''
300
+ label.strip!
301
+ label = 'Regression' if label == ''
302
+ label + ' (' + @time_zone.now.strftime('%-I:%M %p') + ')'
303
+ end
304
+ end
305
+
306
+ module TestRuns
307
+ def extend_testrail_run
308
+ # Reset test scope to include all cases
309
+ body = { include_all: true }
310
+ @client.send_post("update_run/#{@run_id}", body)
311
+ end
312
+
313
+ def existing_cases_from_description
314
+ # Grabs from testrail run description
315
+ run = @client.send_get("get_run/#{@run_id}")
316
+ @description = run["description"]
317
+ @description.nil? ? [] : @description.split(",")
318
+ end
319
+
320
+ def existing_cases_from_run
321
+
322
+ tests = @client.send_get("get_tests/#{@run_id}&status_id=1,2,4,5") || []
323
+
324
+ cases = []
325
+
326
+ tests.each do |test|
327
+
328
+ cases << test["case_id"]
329
+
330
+ end
331
+ cases
332
+ end
333
+
334
+ # open a test run to submit test results
335
+ def add_testrail_run
336
+ body = {
337
+ name: test_name,
338
+ description: '',
339
+ include_all: true,
340
+ milestone_id: @milestone_id
341
+ }
342
+
343
+ unless @testrail_config[:include_all] || true
344
+ body[:include_all] = false
345
+ body[:case_ids] = @test_case_ids
346
+ end
347
+
348
+ case @suite_mode
349
+ when 2,3
350
+ body[:suite_id] = @suite_id
351
+ end
352
+ res = @client.send_post("add_run/#{@project_id}", body)
353
+ @run_id = res['id']
354
+ end
355
+ end
356
+
357
+ module TestResults
358
+ def send_results_to_testrail
359
+ return unless @results[:results].size != 0
360
+ # copy what is in the results
361
+ @submitted[:results] << @results[:results]
362
+
363
+ begin
364
+ send = { results: @results[:results] }
365
+ res = @client.send_post("add_results_for_cases/#{@run_id}", send)
366
+ clear_results
367
+ rescue StandardError => e
368
+ raise e
369
+ end
370
+ end
371
+
372
+ def update_test_suite(scenario_title, external_id, scenario_steps)
373
+ feature = external_id.split(';')[0].split('#')[0]
374
+
375
+ # if the testrail case does not exist, update cases
376
+ if testrail_test_case_id(external_id) == -1
377
+
378
+ section_id = testrail_section_id(feature)
379
+
380
+ # if the testrail section does not exist, update sections
381
+ section_id = add_testrail_section(feature) if section_id == -1
382
+
383
+ add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
384
+ sleep 1
385
+ end
386
+ # store the case id associated with the external_id
387
+ associate_result(external_id)
388
+ end
389
+
390
+ def store_result(scenario_title, external_id, scenario_steps, status_id, comment)
391
+ update_test_suite scenario_title, external_id, scenario_steps
392
+
393
+ case_id = testrail_test_case_id(external_id)
394
+ @results[:results] << {
395
+ case_id: case_id,
396
+ scenario_title: scenario_title,
397
+ external_id: external_id,
398
+ scenario_steps: scenario_steps,
399
+ status_id: status_id,
400
+ comment: comment,
401
+ custom_branch_name: @testrail_config[:origin]
402
+ }
403
+ end
404
+ end
405
+ end
@@ -1,3 +1,3 @@
1
1
  module Itriagetestrail
2
- VERSION = '0.7.9'
2
+ VERSION = '0.8.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itriagetestrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a801069
@@ -59,7 +59,7 @@ extensions: []
59
59
  extra_rdoc_files: []
60
60
  files:
61
61
  - lib/itriagetestrail.rb
62
- - lib/itriagetestrail/modules.rb
62
+ - lib/itriagetestrail/helpers.rb
63
63
  - lib/itriagetestrail/pool.rb
64
64
  - lib/itriagetestrail/testrail_binding.rb
65
65
  - lib/itriagetestrail/trcucumber13.rb
@@ -1 +0,0 @@
1
-