test_joska 1.1.5 → 1.1.7

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
  SHA256:
3
- metadata.gz: 747364f57a5b9c5bccf98d7e4627e6148b140d218d3206405485d4db2612e33a
4
- data.tar.gz: c3466a1008bb36d65d81767a59987eb87b6ae33246c3d3fca54438c3efa9c90e
3
+ metadata.gz: f0f655909c47f9cafab17b7efea3156c7585d3a4795d0b0049323fe952f84f6d
4
+ data.tar.gz: 580e3b6b22976e1c8bf971c73a846dcd8fba625c8e2ba40be795d8eb31b13988
5
5
  SHA512:
6
- metadata.gz: 37f6244566dd393f1fef7f1f31867709fb417cde5cb3454d2a542d5f95254fdc296c704215cb3643024870aa3dbc2ca63942e321b0b005087d6d8bd923b990df
7
- data.tar.gz: 4ccb4ca80ea7ccaba8cae3753f23bbb44c727ce63febe35970006e1f675b58509fe244a8ba8fec5dbc9ada139f53a97a949d92cedb897dcb2f0507182ac36f19
6
+ metadata.gz: c74f63230d7dd571c3361d5af957d1796b2dfb5e4e4c16c07376de735e34ff7ef37bc9a1be0f5135dd22a0936178b0f7432412b9005dcacea8faeb9f58d4e818
7
+ data.tar.gz: c21c4cfbd43906bd75bf9390a6af91171614941bfa75f4e72f1bb276c4dc2bf7affa6d7932dacbaadaaa55441b7893bb1ec6edfd44e468eb12cbedcec0d64902
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test_joska (1.1.5)
4
+ test_joska (1.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,16 +1,21 @@
1
1
  module TestJoska
2
2
 
3
+ require 'report_builder'
4
+ require 'json'
5
+ require 'rest-client'
6
+ require 'zip'
7
+
3
8
  @@raise_on_error = false
4
9
 
5
10
  @@verbose = false
6
11
 
7
- @@URL = {}
12
+ @@URL = nil
8
13
 
9
- @@HEAD = {}
14
+ @@HEAD = nil
10
15
 
11
16
  @@standard_endpoint = ""
12
17
 
13
- @@standard_environment = ""
18
+ @@standard_header = ""
14
19
 
15
20
  @@internal_log = ""
16
21
 
@@ -18,15 +23,17 @@ module TestJoska
18
23
 
19
24
  @@has_token = false
20
25
 
21
- def jskSetEndpoint(endpoint)
26
+ def jskSetStandardEndpoint(endpoint)
22
27
 
23
28
  @@standard_endpoint = endpoint
24
29
 
25
30
  end
26
31
 
27
- def jskSetEnvironment(environment)
32
+ def jskSetStandardHeader(header)
33
+
34
+ return @@standard_header = @@HEAD[header] if header.kind_of?(String)
28
35
 
29
- @@standard_environment = environment
36
+ @@standard_header = header
30
37
 
31
38
  end
32
39
 
@@ -36,26 +43,28 @@ module TestJoska
36
43
  p @@URL
37
44
  p @@HEAD
38
45
  p @@standard_endpoint
39
- p @@standard_environment
46
+ p @@standard_header
40
47
  p @@internal_log
41
48
  p @@url_log
42
49
  end
43
50
 
44
51
  def jskSetup(options)
45
52
 
46
- @@raise_on_error = options["raise_on_error"]
53
+ @@raise_on_error = options["raise_on_error"] if options["raise_on_error"]
47
54
 
48
- @@verbose = options["verbose"]
55
+ @@verbose = options["verbose"] if options["verbose"]
49
56
 
50
- @@URL = options["url_parts"]
57
+ @@URL = options["url_parts"] if options["url_parts"]
51
58
 
52
- @@HEAD = options["headers"]
59
+ @@HEAD = options["headers"] if options["headers"]
53
60
 
54
- @@standard_endpoint = options["standard_endpoint"]
61
+ @@standard_endpoint = options["standard_endpoint"] if options["standard_endpoint"]
62
+
63
+ @@standard_header = @@HEAD[options["standard_header_name"]] if options["standard_header_name"]
55
64
 
56
- @@standard_environment = options["standard_environment"]
65
+ @@standard_header = options["standard_header"] if options["standard_header"]
57
66
 
58
- @@has_token = options["has_token"]
67
+ @@has_token = options["has_token"] if options["has_token"]
59
68
 
60
69
  end
61
70
 
@@ -91,13 +100,17 @@ module TestJoska
91
100
 
92
101
  end
93
102
 
94
- def request(method, product, type, details=nil, payload=nil, header_type=nil, endpoint=nil, env=nil)
103
+ def request(method, product, type, details=nil, payload=nil, header=nil, endpoint=nil)
95
104
 
96
- endpoint = endpoint ? endpoint : @@standard_endpoint
105
+ raise "URL_parts não configurada" if !@@URL
97
106
 
98
- url = jskUrlBuilder(product, type, details, endpoint, env)
107
+ endpoint = @@standard_endpoint if !endpoint
99
108
 
100
- header_type ? header = @@HEAD[header_type] : header = @@HEAD[endpoint]
109
+ url = jskUrlBuilder(product, type, details, endpoint)
110
+
111
+ header = @@standard_header if !header
112
+
113
+ header = @@HEAD[header] if header.kind_of?(String)
101
114
 
102
115
  payload = payload.to_json if payload
103
116
 
@@ -145,15 +158,15 @@ module TestJoska
145
158
 
146
159
  end
147
160
 
148
- def jskUrlBuilder(product, type, details, endpoint, env=nil)
161
+ def jskUrlBuilder(product, type, details, endpoint)
149
162
 
150
- env = env ? env : @@standard_environment
163
+ raise "URL_parts não configurada" if !@@URL
151
164
 
152
165
  details = "" if !details
153
166
 
154
167
  details = [details] if !details.kind_of?(Array)
155
168
 
156
- url = @@URL[product]["base"]["#{env}_#{endpoint}"]
169
+ url = @@URL[product]["base"][endpoint]
157
170
 
158
171
  if !@@URL[product]["path"][type].kind_of?(Array)
159
172
 
@@ -310,4 +323,219 @@ module TestJoska
310
323
 
311
324
  end
312
325
 
326
+
327
+ def jskSlackExcelSender(options)
328
+
329
+ name = options["name"]
330
+
331
+ project = options["project"]
332
+
333
+ project_type = options["project_type"]
334
+
335
+ environment = options["environment"]
336
+
337
+ additional_info = options["additional_info"]
338
+
339
+ report_path = options["report_path"]
340
+
341
+ slack_url = options["slack_url"]
342
+
343
+ send_server = options["send_server"]
344
+
345
+ send_slack = options["send_slack"]
346
+
347
+ send_excel = options["send_excel"]
348
+
349
+ rep_id = 0
350
+
351
+ slack_payload = {}
352
+
353
+ excel_payload = {}
354
+
355
+ t = Time.now
356
+
357
+ generated_report_path = "#{report_path}/report_#{project}_#{project_type}_#{environment} #{t.strftime('%d_%m_%y %H_%M_%S')}"
358
+
359
+ options = {
360
+ input_path: report_path,
361
+ report_path: generated_report_path,
362
+ report_types: [:html],
363
+ report_title: "Report: #{project} #{project_type} #{environment}",
364
+ additional_info: additional_info
365
+ }
366
+
367
+ ReportBuilder.build_report options
368
+
369
+ if send_server
370
+
371
+ p "Enviando para o servidor..."
372
+
373
+ file_to_transfer = "#{generated_report_path}.html"
374
+
375
+ zipfile_name = "#{report_path}/mandar.zip"
376
+
377
+ File.delete(zipfile_name) if File.exist?(zipfile_name)
378
+
379
+ Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
380
+
381
+ file_to_transfer = file_to_transfer.split('/').last
382
+
383
+ zipfile.add(file_to_transfer, File.join(report_path, file_to_transfer))
384
+
385
+ end
386
+
387
+ file_to_send = File.new(zipfile_name, 'rb')
388
+
389
+ payload = {
390
+ :report => file_to_send,
391
+ :usr => name,
392
+ :project => "#{project}_#{project_type}",
393
+ :env => environment,
394
+ :simple => true
395
+ }
396
+
397
+ url = "http://corp-report01.compute.br-sao-1.cvccorp.cloud:4444"
398
+
399
+ repId = ""
400
+
401
+ RestClient::Request.execute(method: 'post', url: "#{url}/generate", payload: payload) do |response|
402
+
403
+ repId = response.message
404
+
405
+ end
406
+
407
+ if repId.to_i == 0
408
+
409
+ p "Deu algum problema no servidor"
410
+
411
+ end
412
+
413
+ end
414
+
415
+ if send_slack || send_excel
416
+
417
+ rep = JSON.parse(File.read("#{report_path}/report.json"))
418
+
419
+ scn_status = {}
420
+
421
+ step_status = {}
422
+
423
+ scn_status["success"] = 0
424
+
425
+ excel_report = []
426
+
427
+ rep.each do |esq|
428
+
429
+ esq["elements"].each do |scn|
430
+
431
+ cur_scn = "success" if scn["type"] == "scenario"
432
+
433
+ excel_scenario = {
434
+ "Produto"=> project,
435
+ "Cenário"=> esq["name"],
436
+ "Status"=> "passed",
437
+ "Erro"=> nil,
438
+ "Data"=> t.strftime('%d/%m/%y'),
439
+ "Ambiente"=> environment,
440
+ "Tipo"=> project_type,
441
+ "Hora"=> t.strftime('%H:%M:%S')
442
+ }
443
+
444
+ scn["steps"].each do |step|
445
+
446
+ if cur_scn == "success" && step["result"]["status"] != "passed"
447
+
448
+ excel_scenario["Status"] = step["result"]["status"]
449
+
450
+ excel_scenario["Erro"] = step["result"]["error_message"].split("\n").first.split("(RuntimeError)").first
451
+
452
+ cur_scn = step["result"]["status"]
453
+
454
+ end
455
+
456
+ step_status[step["result"]["status"]] ? step_status[step["result"]["status"]] += 1 : step_status[step["result"]["status"]] = 1
457
+
458
+ end
459
+
460
+ excel_report.push(excel_scenario) if scn["keyword"] != "Contexto"
461
+
462
+ scn_status[cur_scn] ? scn_status[cur_scn] += 1 : scn_status[cur_scn] = 1 if cur_scn
463
+
464
+ end
465
+
466
+ end
467
+
468
+ not_passed = 0
469
+
470
+ slack_title = "Teste de #{project} #{project_type} no ambiente #{environment} concluido"
471
+
472
+ slack_msg = "Cenários: "
473
+
474
+ scn_status.keys. each do |key|
475
+
476
+ slack_msg = "#{slack_msg}#{key} : #{scn_status[key]} / "
477
+
478
+ not_passed += scn_status[key] if key != "success"
479
+
480
+ end
481
+
482
+ slack_msg = slack_msg.chomp("/ ")
483
+
484
+ slack_msg = "#{slack_msg}\nSteps: "
485
+
486
+ step_status.keys. each do |key| slack_msg = "#{slack_msg}#{key} : #{step_status[key]} / " end
487
+
488
+ slack_msg = slack_msg.chomp("/ ")
489
+
490
+ total = not_passed + scn_status["success"]
491
+
492
+ green = (255*scn_status["success"]/total).to_s(16).upcase
493
+
494
+ green = "0#{green}" if green.length == 1
495
+
496
+ red = (255*not_passed/total).to_s(16).upcase
497
+
498
+ red = "0#{red}" if red.length == 1
499
+
500
+ slack_color = "##{red}#{green}00"
501
+
502
+ link = nil
503
+
504
+ link = "#{url}/#{name}/#{project}_#{project_type}/#{environment}/#{repId}" if repId.to_i != 0
505
+
506
+ slack_payload = {
507
+ "attachments" => [
508
+ {
509
+ "color": slack_color,
510
+ "title": slack_title,
511
+ "title_link": link,
512
+ "text": slack_msg
513
+ }
514
+ ]
515
+ }.to_json
516
+
517
+ excel_payload = {"scenarios"=>excel_report}
518
+
519
+ end
520
+
521
+ if send_slack
522
+
523
+ p "Enviando para o slack..."
524
+
525
+ RestClient::Request.execute(method: "post", url: slack_url, payload: slack_payload)
526
+
527
+ end
528
+
529
+ if send_excel
530
+
531
+ p "Envidando para o excel..."
532
+
533
+ excel_url = "http://corp-report01.compute.br-sao-1.cvccorp.cloud:8080/upload"
534
+
535
+ p RestClient::Request.execute(method: "post", url: excel_url, payload: excel_payload)
536
+
537
+ end
538
+
539
+ end
540
+
313
541
  end
@@ -1,3 +1,3 @@
1
1
  module TestJoska
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_joska
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Diogo Dovas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-11 00:00:00.000000000 Z
11
+ date: 2019-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler