itriagetestrail 0.7.6 → 0.7.7

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: c55a3a224b93562741e22ea21e41e5a635b5da77
4
- data.tar.gz: bfbaf3ab3a5b7be50a453fbfddc7f684d71d8866
3
+ metadata.gz: 14b7fb818edd695a537a8acccf3ce811b2b80fe6
4
+ data.tar.gz: 40ead653fcf3fe91fec75e955c35962a308016c5
5
5
  SHA512:
6
- metadata.gz: 58ffaf21e4f17ef9b35d62b447e07fb19310211a6a585574df0b976fa66baba84ecb5f6e94c000a74db91a7d32847ba0164555770c6e2d691c09b4b1ee66fc6b
7
- data.tar.gz: fc167be6c3bfdb7311754dc410c55616ff47640a35f9a9de7113dcf8c0845f9545205e45503322c17d4ad4e2bb60130a0c383331e132c506f7219b9269c78189
6
+ metadata.gz: d2f26dc39ac84a78b61db9c4c9ebb83859db44c1dfd8187c193cc70839aa336b58a8ab0b39d59b44c9ef7c1cd91565c9cb8de4a3777231845fdc5454968f25c8
7
+ data.tar.gz: 39eef8fecf7959a3e3d304cc3ce7f5ec3e47407d68c7ff25a7e2986a911c5e6679bb67a7666de20a506d9dc8ae9a1f6c19d2181761509dd80baa2565fb71ced7
@@ -1,3 +1,3 @@
1
1
  module Itriagetestrail
2
- VERSION = '0.7.6'
2
+ VERSION = '0.7.7'
3
3
  end
@@ -2,6 +2,7 @@ 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
6
 
6
7
  require 'tzinfo'
7
8
 
@@ -151,385 +152,7 @@ module Itriagetestrail
151
152
  @client.password = @testrail_config[:password]
152
153
  end
153
154
 
154
- def projects
155
- @projects ||= @client.send_get("get_projects")
156
- end
157
-
158
- def project_by_name(name)
159
- res = -1
160
- projects.each do |project|
161
- res = project if project['name'] == name
162
- end
163
- res
164
- end
165
-
166
- def project_by_id(id)
167
- res = -1
168
- projects.each do |project|
169
- res = project if project['id'] == id.to_i
170
- end
171
- res
172
- end
173
-
174
- def set_project
175
- requested_id = @testrail_config[:projectId]
176
- case requested_id
177
- when nil, ''
178
- # a project id was not provided, fetch it from TestRail by project name
179
- res = project_by_name(@testrail_config[:projectName])
180
- if res == -1
181
- @execute = false
182
- return
183
- end
184
- @project_id = res['id']
185
- @suite_mode = res['suite_mode']
186
- else
187
- # use the requested project id
188
- @project_id = requested_id
189
- @suite_mode = project_by_id(@project_id)['suite_mode']
190
- end
191
- end
192
-
193
- # TestRail Suites
194
- def testrail_suites
195
- case @suite_mode
196
- when 2,3
197
- @suites = @client.send_get("get_suites/#{@project_id}")
198
- end
199
- end
200
-
201
- def testrail_suite_id(suite_name)
202
- res = -1
203
- @suites.each do |suite|
204
- res = suite['id'] if suite['name'] == suite_name
205
- end
206
- res
207
- end
208
-
209
- def add_testrail_suite(suite_name)
210
- body = { name: suite_name }
211
- res = @client.send_post("add_suite/#{@project_id}", body)
212
- testrail_suite = res['id']
213
-
214
- #re-establish suites
215
- testrail_suites
216
-
217
- testrail_suite
218
- end
219
-
220
- # TestRail Sections
221
- def testrail_sections
222
- case @suite_mode
223
- when 2,3
224
- @suite_id = testrail_suite_id(@suite_name)
225
- @sections = @client.send_get("get_sections/#{@project_id}&suite_id=#{@suite_id}")
226
- else
227
- @sections = @client.send_get("get_sections/#{@project_id}")
228
- end
229
- end
230
-
231
- def testrail_section_id(section_title)
232
- res = -1
233
- @sections.each do |section|
234
- res = section['id'] if section['name'] == section_title
235
- end
236
- res
237
- end
238
-
239
- def add_testrail_section(section_title)
240
- if @suite_name
241
- body = {
242
- name: section_title,
243
- suite_id: testrail_suite_id(@suite_name)
244
- }
245
- else
246
- body = {
247
- name: section_title
248
- }
249
- end
250
-
251
- res = @client.send_post("add_section/#{@project_id}", body)
252
-
253
- testrail_section = res['id']
254
-
255
- # re-establish sections
256
- testrail_sections
257
-
258
- testrail_section
259
- end
260
-
261
- #TestRail Milestones
262
- def normalize_milestone
263
- case @testrail_config[:origin]
264
- when 'prd', 'production', 'origin/production'
265
- 'Production'
266
- when 'stg', 'staging', 'origin/staging'
267
- 'Staging'
268
- when 'dev', 'development', 'origin/development'
269
- 'Development'
270
- when 'local', ''
271
- 'Local'
272
- when 'master', 'origin/master'
273
- if @testrail_config[:masterMilestone].nil? || @testrail_config[:masterMilestone].empty?
274
- 'Master'
275
- else
276
- @testrail_config[:masterMilestone]
277
- end
278
- else
279
- 'Dev Branch'
280
- end
281
- end
282
-
283
- # returns timestamp for begining of first day of current quarter
284
- def milestone_period_start
285
- time_zone = TZInfo::Timezone.get('America/Denver')
286
- current_year = time_zone.now.year
287
- month = time_zone.now.mon
288
-
289
- # determine which quarter we are in
290
- if month <= 3
291
- time_zone.utc_to_local(Time.utc(current_year, 1, 1))
292
- elsif month <= 6
293
- time_zone.utc_to_local(Time.utc(current_year, 4, 1))
294
- elsif month <= 9
295
- time_zone.utc_to_local(Time.utc(current_year, 7, 1))
296
- else
297
- time_zone.utc_to_local(Time.utc(current_year, 10, 1))
298
- end
299
- end
300
-
301
- # determine the due date (end of quarter) for milestone being added
302
- def milestone_due_date
303
- time_zone = TZInfo::Timezone.get('America/Denver')
304
- current_year = time_zone.now.year
305
- month = time_zone.now.mon
306
-
307
- # determine which quarter we are in
308
- if month <= 3
309
- Time.utc(current_year, 3, 31).strftime('%s')
310
- elsif month <= 6
311
- Time.utc(current_year, 6, 30).strftime('%s')
312
- elsif month <= 9
313
- Time.utc(current_year, 9, 30).strftime('%s')
314
- else
315
- Time.new(current_year, 12, 31).strftime('%s')
316
- end
317
- end
318
-
319
- def fetch_milestone(requested_milestone_name)
320
- milestones = @client.send_get("get_milestones/#{@project_id}")
321
- res = -1
322
- milestones.each do |milestone|
323
- res = milestone['id'] if milestone['name'] == requested_milestone_name
324
- end
325
-
326
- if res == -1
327
- # We need to add the milestone to TestRail
328
-
329
- body = {
330
- name: requested_milestone_name,
331
- due_on: milestone_due_date
332
- }
333
-
334
- res = @client.send_post("add_milestone/#{@project_id}", body)['id']
335
- end
336
- res
337
- end
338
-
339
- def milestone_archive_name(milestone_name, date)
340
- year = date.year
341
- month = date.mon
342
-
343
- if month <= 3
344
- "#{milestone_name} #{year}-Q1"
345
- elsif month <= 6
346
- "#{milestone_name} #{year}-Q2"
347
- elsif month <= 9
348
- "#{milestone_name} #{year}-Q3"
349
- else
350
- "#{milestone_name} #{year}-Q4"
351
- end
352
- end
353
-
354
- def milestone_runs(milestone_name)
355
- # use the matching milestone id for project
356
- milestone_id = fetch_milestone(milestone_name)
357
155
 
358
- # fetch all test runs associated with the milestone id for project
359
- @client.send_get("get_runs/#{@project_id}&milestone_id=#{milestone_id}&is_completed=1") || []
360
- end
361
-
362
- def rename_milestone(id, new_name)
363
- # todo: rename milestone with previous_milestone
364
- body = { name: new_name }
365
- res = @client.send_post("update_milestone/#{id}", body)['id']
366
- end
367
-
368
- def reset_milestone(milestone_name)
369
- runs = milestone_runs(milestone_name)
370
- if runs.size > 0
371
- last_run_time = Time.at(runs.last['completed_on'])
372
- if last_run_time < milestone_period_start
373
- rename_milestone(@milestone_id, milestone_archive_name(milestone_name, last_run_time))
374
- @milestone_id = fetch_milestone(@milestone_name)
375
- end
376
- end
377
- end
378
-
379
- # TestRail Cases
380
- def testrail_ids
381
- case @suite_mode
382
- when 2,3
383
- @test_cases = @client.send_get("get_cases/#{@project_id}&suite_id=#{@suite_id}&type_id=3")
384
- else
385
- @test_cases = @client.send_get("get_cases/#{@project_id}&type_id=3")
386
- end
387
-
388
- @test_case_ids = []
389
-
390
- @test_cases.each { |test_case| @test_case_ids << test_case['id'] }
391
- end
392
-
393
- def testrail_test_case_id(external_id)
394
- res = -1
395
- @test_cases.each do |test_case|
396
- if test_case['custom_external_case_id'] == external_id
397
- res = test_case['id']
398
- end
399
- end
400
- res
401
- end
402
-
403
- def associate_result(external_id)
404
- test_case_id = testrail_test_case_id(external_id)
405
- # store the test case id with the local result
406
- @results[:results].each do |result|
407
- next unless result[:external_id] == external_id
408
- @external_results[:results] << { case_id: test_case_id,
409
- status_id: result['status_id'],
410
- comment: result['comment'] }
411
- end
412
- end
413
-
414
- # add the test case if it doesn't exist
415
- def add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
416
- body = {
417
- title: scenario_title,
418
- custom_external_case_id: external_id,
419
- custom_steps: scenario_steps,
420
- type_id: 3
421
- }
422
-
423
- @client.send_post("add_case/#{section_id}", body)
424
-
425
- # refresh test case ids
426
- testrail_ids
427
- end
428
-
429
- def test_name
430
- label = ''
431
- label += "App Version:#{@app_version}" unless @app_version.nil? || @app_version == ''
432
- label += " Jenkins Build:#{@jenkins_build}" unless @jenkins_build .nil? || @jenkins_build == ''
433
- label.strip!
434
- label = 'Regression' if label == ''
435
- label + ' (' + @time_zone.now.strftime('%-I:%M %p') + ')'
436
- end
437
-
438
- def extend_testrail_run
439
- # Reset test scope to include all cases
440
- body = { include_all: true }
441
- @client.send_post("update_run/#{@run_id}", body)
442
- end
443
-
444
- def existing_cases_from_description
445
- # Grabs from testrail run description
446
- run = @client.send_get("get_run/#{@run_id}")
447
- @description = run["description"]
448
- @description.nil? ? [] : @description.split(",")
449
- end
450
-
451
- def existing_cases_from_run
452
-
453
- tests = @client.send_get("get_tests/#{@run_id}&status_id=1,2,4,5") || []
454
-
455
- cases = []
456
-
457
- tests.each do |test|
458
-
459
- cases << test["case_id"]
460
-
461
- end
462
- cases
463
- end
464
-
465
- # open a test run to submit test results
466
- def add_testrail_run
467
- body = {
468
- name: test_name,
469
- description: '',
470
- include_all: true,
471
- milestone_id: @milestone_id
472
- }
473
-
474
- unless @testrail_config[:include_all] || true
475
- body[:include_all] = false
476
- body[:case_ids] = @test_case_ids
477
- end
478
-
479
- case @suite_mode
480
- when 2,3
481
- body[:suite_id] = @suite_id
482
- end
483
- res = @client.send_post("add_run/#{@project_id}", body)
484
- @run_id = res['id']
485
- end
486
-
487
- def send_results_to_testrail
488
- return unless @results[:results].size != 0
489
- # copy what is in the results
490
- @submitted[:results] << @results[:results]
491
-
492
- begin
493
- send = { results: @results[:results] }
494
- res = @client.send_post("add_results_for_cases/#{@run_id}", send)
495
- clear_results
496
- rescue StandardError => e
497
- raise e
498
- end
499
- end
500
-
501
- def update_test_suite(scenario_title, external_id, scenario_steps)
502
- feature = external_id.split(';')[0].split('#')[0]
503
-
504
- # if the testrail case does not exist, update cases
505
- if testrail_test_case_id(external_id) == -1
506
-
507
- section_id = testrail_section_id(feature)
508
-
509
- # if the testrail section does not exist, update sections
510
- section_id = add_testrail_section(feature) if section_id == -1
511
-
512
- add_testrail_test_case(scenario_title, external_id, scenario_steps, section_id)
513
- sleep 1
514
- end
515
- # store the case id associated with the external_id
516
- associate_result(external_id)
517
- end
518
-
519
- def store_result(scenario_title, external_id, scenario_steps, status_id, comment)
520
- update_test_suite scenario_title, external_id, scenario_steps
521
-
522
- case_id = testrail_test_case_id(external_id)
523
- @results[:results] << {
524
- case_id: case_id,
525
- scenario_title: scenario_title,
526
- external_id: external_id,
527
- scenario_steps: scenario_steps,
528
- status_id: status_id,
529
- comment: comment,
530
- custom_branch_name: @testrail_config[:origin]
531
- }
532
- end
533
156
 
534
157
  def close_run?()
535
158
  # do not close a run if a run id was supplied. other test suites related to the job will need it.
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.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - a801069
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-08 00:00:00.000000000 Z
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler