Module: TmcHelpers

Includes:
CsvHelper, EmailHelper, HttpHelper, SnmpHelper, SshHelper
Included in:
BaseMonitor, TestCase, TestTrace
Defined in:
lib/helpers/tmc_helpers/tmc_helpers.rb

Overview

The Helpers module contains methods that can be used in test cases, methods, and prerequisites

Instance Method Summary collapse

Methods included from HttpHelper

#web_request

Methods included from CsvHelper

#csv_parse, #csv_read

Methods included from SshHelper

#ssh_to

Methods included from EmailHelper

#send_email, #send_email_setup

Methods included from SnmpHelper

#snmp_get, #snmp_set

Instance Method Details

#aws_config(region: nil, access_key_id: nil, secret_access_key: nil) ⇒ Object

Public: Configures AWS.

region - String region (default: nil). access_key_id - String S3 access key ID (default: nil). secret_access_key - String S3 secret access key (default: nil).

Returns nothing.



32
33
34
35
36
37
38
39
40
41
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 32

def aws_config(region: nil, access_key_id: nil, secret_access_key: nil)
  with_aws do
    if access_key_id.nil? || secret_access_key.nil?
      logger.warn("AWS not configured: Missing `access_key_id' or `secret_access_key'")
      return
    end
    Aws.config.update(credentials: Aws::Credentials.new(access_key_id, secret_access_key))
    Aws.config.update(region: region) unless region.nil?
  end
end

#aws_create_s3_bucket(bucket, options = {}) ⇒ Object

Public: Creates an AWS S3 bucket. TODO: VERIFY FUNCTIONALITY

bucket - String name of bucket. options - Hash of options to pass to create (default: {}).

Returns nothing.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 49

def aws_create_s3_bucket(bucket, options={})
  logger.info("Creating S3 bucket: #{bucket}")
  aws do |s3|
    b = s3.bucket(bucket)
    if b.exists?
      raise 'Bucket already exists!'
    end
    b.create(options)
  end
  nil
end

#aws_delete_s3(bucket, name, options = {}) ⇒ Object

Public: Deletes an object from an AWS S3 bucket.

bucket - String name of bucket. name - String name of object to delete. options - Hash of options to pass to delete (default: {}).

Returns nothing.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 151

def aws_delete_s3(bucket, name, options={})
  logger.info("Deleting object from S3 bucket '#{bucket}': #{name}")
  aws do |s3|
    b = s3.bucket(bucket)
    unless b.exists?
      raise 'Bucket does not exist!'
    end
    o = b.object(name)
    unless o.exists?
      raise 'Object does not exist!'
    end
    o.delete(options)
  end
end

#aws_delete_s3_bucket(bucket) ⇒ Object

Public: Deletes an AWS S3 bucket. TODO: VERIFY FUNCTIONALITY

bucket - String name of bucket.

Returns nothing.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 66

def aws_delete_s3_bucket(bucket)
  logger.info("Deleting S3 bucket: #{bucket}")
  aws do |s3|
    b = s3.bucket(bucket)
    unless b.exists?
      raise 'Bucket does not exist!'
    end
    b.delete!
  end
  nil
end

#aws_read_s3(bucket, name, options = {}) ⇒ Object

Public: Reads an object from an AWS S3 bucket.

bucket - String name of bucket. name - String name of object to read. options - Hash of options to pass to read (default: {}).

Returns the String object value.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 129

def aws_read_s3(bucket, name, options={})
  logger.info("Reading object from S3 bucket '#{bucket}': #{name}")
  aws do |s3|
    b = s3.bucket(bucket)
    unless b.exists?
      raise 'Bucket does not exist!'
    end
    o = b.object(name)
    unless o.exists?
      raise 'Object does not exist!'
    end
    o.get(options).body.string
  end
end

#aws_upload_s3(bucket, name, path, options = {}) ⇒ Object

Public: Uploads an object to an AWS S3 bucket.

bucket - String name of bucket. The bucket will be created if it does not exist. name - String name of object to write. The object will be overwritten if it already exists. path - String path to object. options - Hash of options to pass to upload (default: {}).

Returns the public URI::HTTP for the object.



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 86

def aws_upload_s3(bucket, name, path, options={})
  logger.info("Uploading file to S3 bucket '#{bucket}': #{path} (#{get_readable_size(File.size(path))})")
  aws do |s3|
    o = get_or_create_s3_bucket(s3, bucket).object(name)
    o.upload_file(Pathname.new(path), {acl: 'public-read'}.merge(options))
    url = o.public_url
    logger.info("New file URL: #{url}")
    url
    # do the upload this way to protect the file after N seconds (1 week in this case)
    #o.upload_file(Pathname.new(path), options)
    #o.presigned_url(:get, expires_in: 604800)
  end
end

#aws_write_s3(bucket, name, data, options = {}) ⇒ Object

Public: Writes an object to an AWS S3 bucket.

bucket - String name of bucket. The bucket will be created if it does not exist. name - String name of object to write. The object will be overwritten if it already exists. data - String data to write to object. options - Hash of options to pass to put (default: {}).

Returns the public URI::HTTP for the object.



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 108

def aws_write_s3(bucket, name, data, options={})
  logger.info("Writing object to S3 bucket '#{bucket}': #{name} (#{get_readable_size(data.size)})")
  aws do |s3|
    o = get_or_create_s3_bucket(s3, bucket).object(name)
    o.put({body: data, acl: 'public-read'}.merge(options))
    url = o.public_url
    logger.info("New object URL: #{url}")
    url
    # do the PUT this way to protect the file after N seconds (1 week in this case)
    #o.put(options.merge(body: data))
    #o.presigned_url(:get, expires_in: 604800)
  end
end

#get_clean_ocr_text(inputString, options = {:removeSpaces => false, :toUppercase => false, :removeSpecials => false, :replaceB3 => false, :replaceB8 => false, :replaceG6 => false, :replaceO0 => false, :replaceTL => false, :replaceS5 => false}) ⇒ Object

Public: Returns a modified string with common OCR replacements inputString - string to be cleaned options - operations to be applied to the input string



954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 954

def get_clean_ocr_text(inputString, options = {:removeSpaces => false,
                                                :toUppercase => false,
                                                :removeSpecials => false,
                                                :replaceB3 => false,
                                                :replaceB8 => false,
                                                :replaceG6 => false,
                                                :replaceO0 => false,
                                                :replaceTL => false,
                                                :replaceS5 => false})
	modifiedString = inputString
	if options[:removeSpaces]
		modifiedString = modifiedString.gsub(/\s+/, '')
	end
	if options[:toUppercase]
		modifiedString = modifiedString.upcase
	end
	if options[:removeSpecials]
		modifiedString = modifiedString.gsub(/[^A-Za-z0-9]/, '')
	end
	if options[:replaceB3]
		modifiedString = modifiedString.gsub(/[3B]/, 'B')
	end
	if options[:replaceB8]
		modifiedString = modifiedString.gsub(/[8B]/, 'B')
	end
	if options[:replaceG6]
		modifiedString = modifiedString.gsub(/[G6]/, 'G')
	end
	if options[:replaceO0]
		modifiedString = modifiedString.gsub(/[0O]/, 'O')
	end
	if options[:replaceTL]
		modifiedString = modifiedString.gsub(/[LlT]/, 'L')
	end
	if options[:replaceS5]
		modifiedString = modifiedString.gsub(/[S5]/, 'S')
	end

	return modifiedString
end

#get_readable_size(size_bytes) ⇒ Object

Public: Gets a readable string for the given size in bytes.

size_bytes - Integer size in bytes.

Returns a String readable size in bytes.



1066
1067
1068
1069
1070
1071
1072
1073
1074
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1066

def get_readable_size(size_bytes)
  units = %w(B KB MB GB TB)
  Array(0..units.length - 1).reverse.each do |i|
    mult = 1000.0 ** i
    if size_bytes >= (mult == 1 ? 0 : mult)
      return "#{(size_bytes / mult).round(1)} #{units[i]}"
    end
  end
end

#get_readable_time(time_sec) ⇒ Object

Public: Gets a readable string for the given time in seconds.

time_sec - Numeric seconds.

Returns a String readable time.



1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1081

def get_readable_time(time_sec)
  parts = []
  h = (time_sec / 3600.0).to_i
  parts << "#{h}h" if h > 0
  time_sec -= (h * 3600)
  m = (time_sec / 60.0).to_i
  parts << "#{m}m" if m > 0
  time_sec -= (m * 60)
  s = time_sec.to_i
  parts << "#{s}s" if s > 0
  ms = ((time_sec - s) * 1000.0).round
  parts << "#{ms}ms" if ms > 0 || parts.empty?
  parts.join(', ')
end

#get_string_similarity(s1, s2, options = {}) ⇒ Object

identical strings. This is based on the Levenshtein distance algorithm s1 - string to compare s2 - string to compare options - options to process strings (see: get_clean_ocr_text)



925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 925

def get_string_similarity(s1, s2, options = {})
   s1 = get_clean_ocr_text(s1, options)
   s2 = get_clean_ocr_text(s2, options)

	if s1 == s2
		return 1.0
	end

	n = s1.length
	m = s2.length
	d = Array.new(n + 1) { Array.new(m +1) }

	(0..n).each {|i| d[i][0] = i}
	(0..m).each {|j| d[0][j] = j}

	for i in 1..n
		for j in 1..m
			cost = s2[j - 1] == s1[i - 1] ? 0 : 1
			d[i][j] = [d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost].min
		end
	end

	denom = [n, m].max
	return 1.0 - (d[n][m] / denom.to_f)
end

#get_substring_similarity(expected, read, options = {}) ⇒ Object

Public: Computes the similarity of two strings by searching the read string for

the expected string within

expected - the string expected by the test read - the string read from screen options - options for cleaning common OCR text errors. see get_clean_ocr_text



897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 897

def get_substring_similarity(expected, read, options = {})
  expected = get_clean_ocr_text(expected, options)
  read = get_clean_ocr_text(read, options)

max_similarity = 0

# if the expected string is longer than the read string
# padding will need to be added
if expected.length > read.length
	read = read.ljust(expected.length, ' ')
end

i = 0
until i > read.length - expected.length do
	substring = read[i, expected.length]
	similarity = get_string_similarity(expected, substring)
	max_similarity = [similarity, max_similarity].max
	i += 1
end

return max_similarity
end

#is_rating?(rating) ⇒ Boolean

Public: Checks if the given value is a valid movie/series rating.

rating - String rating to validate.

Returns a Boolean true if the rating is valid, otherwise false.

Returns:

  • (Boolean)


356
357
358
359
360
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 356

def is_rating?(rating)
  valid_ratings = %w(TV-G TV-PG TV-14 TV-MA G PG PG-13 R NC-17 NR)
  logger.info("Checking if #{rating.inspect} is a valid rating (#{valid_ratings.join(', ')})")
  valid_ratings.include?(rating)
end

#is_year?(yyyy) ⇒ Boolean

Public: Checks if the given number looks like a modern year (1900 - 2999).

yyyy - Integer number to validate.

Returns a Boolean true if the number looks like a year, otherwise false.

Returns:

  • (Boolean)


344
345
346
347
348
349
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 344

def is_year?(yyyy)
  min = 1900
  max = 2999
  logger.info("Checking if #{yyyy.inspect} is a valid year (#{min} - #{max})")
  yyyy.to_i >= min && yyyy.to_i < max
end

#jsonify(obj, camel_case: true) ⇒ Object

Public: Converts a Ruby object to standard JSON format, i.e. :is_on_screen becomes :isOnScreen, etc.

obj - Object to convert.

Returns the converted Object.



1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1000

def jsonify(obj, camel_case: true)
  if obj.is_a?(Hash)
    Hash[obj.map {|k,v| [jsonify(k.to_sym, camel_case: camel_case), jsonify(v, camel_case: camel_case)]}]
  elsif obj.is_a?(Array)
    obj.map {|v| jsonify(v, camel_case: camel_case)}
  elsif obj.is_a?(Symbol)
    camel_case ? to_camel_case(obj) : obj
  else
    obj
  end
end

#pick_random(*items) ⇒ Object

Public: Picks a random item from the given array.

items - Splat Array of items from which to pick.

Returns the randomly-chosen item Object.



329
330
331
332
333
334
335
336
337
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 329

def pick_random(*items)
  if items.first.is_a?(Array)
    items = items.first
  end
  logger.info("Picking random item from: #{items.inspect}")
  item = items[items.count > 1 ? rand(items.count) : 0]
  logger.info("Picked #{item.inspect}")
  item
end

#rubify(json, snake_case: true) ⇒ Object

Public: Converts a JSON object to standard Ruby format, i.e. ‘isOnScreen’ becomes :is_on_screen, etc.

obj - Object to convert.

Returns the converted Object.



1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1017

def rubify(json, snake_case: true)
  if json.is_a?(Hash)
    Hash[json.map {|k,v| [rubify(k.to_sym, snake_case: snake_case), rubify(v, snake_case: snake_case)]}]
  elsif json.is_a?(Array)
    json.map {|v| self.rubify(v, snake_case: snake_case)}
  elsif json.is_a?(Symbol)
    snake_case ? to_snake_case(json) : json
  else
    json
  end
end

#send_webex_alert(token, room_id, text: nil, markdown: nil) ⇒ Object

Public: Can send an alert to a WebEx room. Must have token to pass into first param.

token - Obtain token by creating bot @ developer.webex.com/docs/bots room_id - Create room in webex, add bot to room. Then, can get roomId here: developer.webex.com/docs/api/v1/rooms/list-rooms text - text to send into message body (default: nil) markdown - useful if you would like to create markdown text instead of plain. (default: nil)



1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1103

def send_webex_alert(token, room_id, text: nil, markdown: nil)
  web_post("https://api.ciscospark.com/v1/messages",  { json: {
                                                            text: text.to_s, # to_s incase user doesn't sanitize.
                                                            roomId: room_id.to_s,
                                                            markdown: markdown.to_s
  },
  # pass token into header
     headers: {
       "Authorization": "Bearer #{token}"
      }
  })
end

#to_camel_case(value) ⇒ Object

Public: Converts a value into camelCase

value - String or Symbol value to convert

Returns the String or Symbol converted to camelCase.



1054
1055
1056
1057
1058
1059
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1054

def to_camel_case(value)
  parts = value.to_s.split('_').reject {|part| part.empty?}
  camel_case = parts[0].slice(0, 1).downcase + parts[0].slice(1..-1) +
    parts[1..-1].map { |part| part.slice(0, 1).upcase + part.slice(1..-1) }.join
  value.is_a?(Symbol) ? camel_case.to_sym : camel_case
end

#to_pascal_case(value) ⇒ Object

Public: Converts a value into PascalCase

value - String or Symbol value to convert

Returns the String or Symbol converted to PascalCase.



1044
1045
1046
1047
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1044

def to_pascal_case(value)
  pascal_case = value.to_s.split('_').map { |part| part.slice(0, 1).upcase + part.slice(1..-1) }.join
  value.is_a?(Symbol) ? pascal_case.to_sym : pascal_case
end

#to_snake_case(value) ⇒ Object

Public: Converts a value into snake_case

value - String or Symbol to convert

Returns the String or Symbol converted to snake_case.



1034
1035
1036
1037
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 1034

def to_snake_case(value)
  snake_case = value.to_s.gsub(/(?<!^)([A-Z])/, '_\1').downcase
  value.is_a?(Symbol) ? snake_case.to_sym : snake_case
end

#twb_case_exists?Boolean

Public: Checks to see if a Case Instance ID exists for the current Slot and Test Case in the Job.

Returns a Boolean true if a Case Instance ID exists for the current suite. Else, returns a Boolean false.

Returns:

  • (Boolean)


378
379
380
381
382
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 378

def twb_case_exists?
  test_data.refresh
  return true if test_data.fetch("twb_case_id#{id}_slot#{dut.slot}_iter#{iteration}".to_sym, false)
  return false
end

#twb_get_case_instance_id(args = {}) ⇒ Object

Public: Gets a Case Instance ID for the current twb_suite_name. If one exists already it is used, otherwise a POST to TWB retrieves a new one.

twb_suite_name - String name of the test suite (default: test_data).

Returns the String case_instance_id for the current test case if successful. Else, returns nil.



408
409
410
411
412
413
414
415
416
417
418
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 408

def twb_get_case_instance_id(args={})
  test_suite_name = args.fetch(:twb_suite_name, test_data[:twb_suite_name])
  # Check if the Suite & Case Instance Id has already been written to disk
  if twb_case_exists?
    test_data.refresh
    return test_data.fetch("twb_case_id#{id}_slot#{dut.slot}_iter#{iteration}".to_sym, false)
  else
    suite_instance_id = twb_get_suite_instance_id
    return twb_post_testcase(:twb_suite_name => test_suite_name, :suite_instance_id => suite_instance_id)
  end
end

#twb_get_suite_instance_id(args = {}) ⇒ Object

Public: Gets a Suite Instance ID for the current twb_suite_name. If one exists already it is used, otherwise a POST to TWB retrieves a new one.

twb_suite_name - String name of the test suite (default: test_data). program_application_name - String name of the program application (default: test_data).

Returns the String suite_instance_id for the suite or current Job if successful. Else, returns nil.



390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 390

def twb_get_suite_instance_id(args={})
  test_suite_name = args.fetch(:twb_suite_name, test_data[:twb_suite_name])
  # Check to see if the Suite Instance Id has already been written to disk
  test_data.refresh
  if twb_suite_exists?
    return test_data.fetch("twb_suite_id_slot#{dut.slot}_iter#{iteration}".to_sym, nil) if test_data[:report_per_slot]
    return test_data.fetch(:twb_suite_id, false)
  else
    program_application_name = args.fetch(:program_application_name, test_data[:program_application_name])
    return twb_post_suite(:twb_suite_name => test_suite_name, :program_application_name => program_application_name)
  end
end

#twb_post_screenshot(args = {}) ⇒ Object

Public: Takes a screenshot on current STB and POSTS to TWB. The user has the ability to set the Suite & Case instance ID or if a Suite &/or Case ID already exists for the twb_suite_name or current Job Name, those will be used. In the case where neither a Suite & Case instance ID are provided and they don’t already exist for the twb_suite_name or Job Name, new ones will be retrieved from TWB.

twb_suite_name - String name of the Test Suite Name to report to (default: test_data) program_application_name - String name of the Program Application to report to (default: test_data). ss_filename - String filename of image to POST. If none is provided a screenshot on active stb will be captured (default: nil) timeout - Integer total milliseconds to wait for a response (default: 5.min). verify_mode - Integer desired HTTP verify mode (default: nil). uri - String full URI for the resource to request(default: “charter.testworkbench.com/ords/test/postScreenshots/#case_instance_id”). case_instance_id - result of twb_get_case_instance_id suite_instance_id - result of twb_get_suite_instance_id size - number from 0 to 100 for percentage size of the image quality - number from 0 to 100 for image quality

Returns the path to the screenshot file, ss_filename



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 434

def twb_post_screenshot(args={})
  test_suite_name = (args.key?(:twb_suite_name)) ? args[:twb_suite_name] : test_data[:twb_suite_name]
  program_application_name = (args.key?(:program_application_name)) ? args[:program_application_name] : test_data[:program_application_name]
  suite_instance_id = (args.key?(:suite_instance_id)) ? args[:suite_instance_id] : twb_get_suite_instance_id(:twb_suite_name => test_suite_name, :program_application_name => program_application_name)

  image_size = args.fetch(:size, 100).to_i
  image_size = (image_size > 100) ? 100 : image_size
  image_size = (image_size < 0) ? 0 : image_size

  image_quality = args.fetch(:quality, 100).to_i
  image_quality = (image_quality > 100) ? 100 : image_quality
  image_quality = (image_quality < 0) ? 0 : image_quality


  case_instance_id = (args.key?(:case_instance_id)) ? args[:case_instance_id] : twb_get_case_instance_id(:twb_suite_name => test_suite_name)
  ss_filename = args.fetch(:ss_filename, nil)
  timeout = args.fetch(:timeout, 5.min)
  verify_mode = args.fetch(:verify_mode, 0)
  headers = {'Content-Type' => 'image/jpeg'}
  uri = args.fetch(
      :uri,
      "http://charter.testworkbench.com/ords/test/postScreenshots/#{case_instance_id}"
  )
  tmc_current_screenshots = Hash[test_data.fetch(:tmc_current_screenshots, [])]
  if tmc_current_screenshots[id].nil?
    test_data[:tmc_current_screenshots] = tmc_current_screenshots.update(id => 1).to_a  # can't use hash because of integer keys
  else
    tmc_current_screenshots[id] += 1
    test_data[:tmc_current_screenshots] = tmc_current_screenshots.to_a  # can't use hash because of integer keys
  end
  if ss_filename.nil?
    ss_filename = "twb_suite_#{suite_instance_id}_case_#{case_instance_id}_screenshot_#{tmc_current_screenshots[id]}.jpg"
    data = dut.capture_screen(:filename => ss_filename, :format => :raw, :size => image_size, :quality => image_quality)
  else
    data = ss_filename
  end
  web_post(uri, :headers => headers,
                  :verify_mode => verify_mode, :timeout => timeout, :body => data
  ).json
  return ss_filename
end

#twb_post_screenshot!(args = {}) ⇒ Object

Public: Takes a screenshot on current STB and POSTS to TWB. The user has the ability to set the Suite & Case instance ID or if a Suite &/or Case ID already exists for the twb_suite_name or current Job Name, those will be used. In the case where neither a Suite & Case instance ID are provided and they don’t already exist for the twb_suite_name or Job Name, new ones will be retrieved from TWB and added to the args.

twb_suite_name - String name of the Test Suite Name to report to (default: test_data) program_application_name - String name of the Program Application to report to (default: test_data). ss_filename - String filename of image to POST. If none is provided a screenshot on active stb will be captured (default: nil) timeout - Integer total milliseconds to wait for a response (default: 5.min). verify_mode - Integer desired HTTP verify mode (default: nil). uri - String full URI for the resource to request(default: “charter.testworkbench.com/ords/test/postScreenshots/#case_instance_id”). case_instance_id - result of twb_get_case_instance_id suite_instance_id - result of twb_get_suite_instance_id size - number from 0 to 100 for percentage size of the image quality - number from 0 to 100 for image quality

Returns the path to the screenshot file, ss_filename



782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 782

def twb_post_screenshot!(args={})
  args[:twb_suite_name] = test_data[:twb_suite_name] unless args.key?(:twb_suite_name)
  test_suite_name = args[:twb_suite_name]
  args[:program_application_name] = test_data[:program_application_name] unless args.key?(:program_application_name)
  program_application_name = args[:program_application_name]
  description = args[:description]
  description = 'Starting Test...' if description.nil?
  unless args.key?(:suite_instance_id)
      args[:suite_instance_id] = twb_get_suite_instance_id(
          :twb_suite_name => test_suite_name, 
          :program_application_name => program_application_name,
          :description => description
      )
  end
  args[:case_instance_id] = twb_get_case_instance_id(:twb_suite_name => test_suite_name) unless args.key?(:case_instance_id)
  twb_post_screenshot(args)
end

#twb_post_suite(args = {}) ⇒ Object

Public: POSTs the Suite level results to TWB and retrieves the Suite Instance ID. If there is already a Suite Instance ID associated with the current test_suite_name it will be used instead.

tester_name - String name of tester (default: current_user). report_to_scorecard - String value of ‘Y’ or ‘N’ indicating scorecard is/isn’t used (default: ‘N’). footprints - String comma separated list of values (default ”).

Returns the String suite_instance_id for the suite if successful. Else, returns nil.



535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 535

def twb_post_suite(args={})
  # Check to see if the Suite Instance Id has already been written to Test Data
  return twb_get_suite_instance_id if twb_suite_exists?

  test_suite_name = args.fetch(:twb_suite_name, test_data[:twb_suite_name])
  tester_name = args.fetch(:tester_name, current_user['name'])
  program_application_name = args.fetch(:program_application_name, test_data[:program_application_name])
  report_to_score_card = args.fetch(:report_to_score_card, test_data[:report_to_score_card])
  report_to_score_card = 'N' if report_to_score_card.to_s.empty?
  footprints = args.fetch(:footprints, test_data[:footprints])
  footprints = '' if footprints.to_s.empty?
  environment = args.fetch(:spectrum_environment, current_workspace)
  device = args.fetch(:device, 'undefined') # dvr or non-dvr
  device = 'dvr' if dut.model.include?('210')
  device = 'non-dvr' if dut.model.include?('110')
  slot = args.fetch(:slot, dut.slot)
  mac_address = args.fetch(:mac_address, dut.mac_address)
  mac_address = 'undefined' if mac_address.to_s.empty?
  machine_name = args.fetch(:machine_name, server_name)
  uri = args.fetch(:uri, 'http://charter.testworkbench.com/ords/test/suite/')
  # Build hash for required params
  rb_hash = {
      :test_suite_name => test_suite_name,
      :tester_name => tester_name,
      :program_application_name => program_application_name,
      :report_to_score_card => report_to_score_card,
      :footprints => footprints,
      :environment => environment,
      :device => device,
      :tmc_slot => slot,
      :box_mac_address => mac_address,
      :machine_name => machine_name
  }
  # Add optional params to hash (these aren't published in TomDocs)
  project_release = args.fetch(:project_release, nil)
  rb_hash[:project_release] = project_release unless project_release.nil?
  device_version = args.fetch(:device_version, nil)
  rb_hash[:device_version] = device_version unless device_version.nil?
  browser = args.fetch(:browser, nil)
  rb_hash[:browser] = browser unless browser.nil?
  browser_version = args.fetch(:browser_version, nil)
  rb_hash[:browser_version] = browser_version unless browser_version.nil?
  operating_system = args.fetch(:operating_system, nil)
  rb_hash[:operating_system] = operating_system unless operating_system.nil?
  operating_system_version = args.fetch(:operating_system_version, nil)
  rb_hash[:operating_system_version] = operating_system_version unless operating_system_version.nil?
  target_test_plan_name = args.fetch(:target_test_plan_name, nil)
  rb_hash[:target_test_plan_name] = target_test_plan_name unless target_test_plan_name.nil?
  custom_1 = args.fetch(:custom_1, nil)
  rb_hash[:custom_1] = custom_1 unless custom_1.nil?
  custom_2 = args.fetch(:custom_2, nil)
  rb_hash[:custom_2] = custom_2 unless custom_2.nil?
  custom_3 = args.fetch(:custom_3, nil)
  rb_hash[:custom_3] = custom_3 unless custom_3.nil?
  eligible_to_report = args.fetch(:eligible_to_report, nil)
  rb_hash[:eligible_to_report] = eligible_to_report unless eligible_to_report.nil?
  device_type = args.fetch(:device_type, nil)
  rb_hash[:device_type] = device_type unless device_type.nil?
  # POST /suite/
  logger.debug('POST /suite/')
  resp = web_post(uri, :verify_mode => 0, :json => rb_hash).json
  logger.warn("Failed to connect to Test Work Bench") if resp.nil?
  suite_instance_id = resp['suite_instance_id']
  if suite_instance_id.nil?
    logger.warn('Failed to retrieve Suite Instance ID from TWB!')
    logger.warn("Error Message: #{resp['error_message']}")
    logger.warn("Program List: #{resp['program_list']}") if resp['program_list']
    return nil
  else
    logger.debug("Suite Instance ID Retrieved: #{suite_instance_id}")
    test_data.refresh
    if test_data[:report_per_slot] # if users want to report to individual suites for individual slots
      test_data["twb_suite_id_slot#{dut.slot}_iter#{iteration}".to_sym] = suite_instance_id
    else
      test_data[:twb_suite_id] = suite_instance_id
    end
    return suite_instance_id
  end
end

#twb_post_testcase(args = {}) ⇒ Object

Public: POSTs the Case level results to TWB and retrieves the Case Instance ID.

uri - String full URI for the resource to request (default: “twb.dev-charter.net/ords/preprod/testcase/”). test_case_name - String name of the test case (default: test_data). suite_instance_id - result of twb_get_suite_instance_id

Returns the String Case Instance ID if successful. Else, returns nil.



622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 622

def twb_post_testcase(args={})
  # Check to see if the Case Instance Id has already been written to disk
  return twb_get_case_instance_id if twb_case_exists?

  test_case_name = args.fetch(:test_case_name, self.name)
  test_suite_name = (args.key?(:twb_suite_name)) ? args[:twb_suite_name] : test_data[:twb_suite_name]
  program_application_name = (args.key?(:program_application_name)) ? args[:program_application_name] : test_data[:program_application_name]

  suite_instance_id = (args.key?(:suite_instance_id)) ? args[:suite_instance_id] : twb_get_suite_instance_id(:twb_suite_name => test_suite_name,:program_application_name => program_application_name)

  uri = args.fetch(
      :uri,
      'http://charter.testworkbench.com/ords/test/testcase/'
  )
  # Build hash for required params
  rb_hash = {
      :test_case_name => test_case_name,
      :suite_instance_id => suite_instance_id
  }
  # Add optional params to hash (these aren't published in TomDocs)
  head_end = args.fetch(:head_end, nil)
  rb_hash[:head_end] = head_end unless head_end.nil?
  stb_id = args.fetch(:stb_id, nil)
  rb_hash[:stb_id] = stb_id unless stb_id.nil?
  box_serial_no = args.fetch(:box_serial_no, nil)
  rb_hash[:box_serial_no] = box_serial_no unless box_serial_no.nil?
  box_mac_address = args.fetch(:box_mac_address, nil)
  rb_hash[:box_mac_address] = box_mac_address unless box_mac_address.nil?
  box_model_number = args.fetch(:box_model_number, nil)
  rb_hash[:box_model_number] = box_model_number unless box_model_number.nil?
  ams_number = args.fetch(:ams_number, nil)
  rb_hash[:ams_number] = ams_number unless ams_number.nil?
  sgui_id = args.fetch(:sgui_id, nil)
  rb_hash[:sgui_id] = sgui_id unless sgui_id.nil?
  zodiac_version = args.fetch(:zodiac_version, nil)
  rb_hash[:zodiac_version] = zodiac_version unless zodiac_version.nil?
  custom_1 = args.fetch(:custom_1, nil)
  rb_hash[:custom_1] = custom_1 unless custom_1.nil?
  custom_2 = args.fetch(:custom_2, nil)
  rb_hash[:custom_2] = custom_2 unless custom_2.nil?
  custom_3 = args.fetch(:custom_3, nil)
  rb_hash[:custom_3] = custom_3 unless custom_3.nil?
  # POST /testcase/
  logger.debug('POST /testcase/')
  resp = web_post(uri, :verify_mode => 0, :json => rb_hash).json
  case_instance_id = resp['case_instance_id']
  if case_instance_id.nil?
    logger.warn("Failed to POST Testcase and retrieve Case Instance ID for Suite Instance ID #{suite_instance_id}")
    logger.warn("Error Message: #{resp['error_message']}")
    return nil
  else
    logger.debug("Case Instance ID Retrieved: #{case_instance_id}")
    # Write Case ID to Test Data
    test_data.refresh
    test_data["twb_case_id#{id}_slot#{dut.slot}_iter#{iteration}".to_sym] = case_instance_id
    return case_instance_id
  end
end

#twb_post_teststep(args = {}) ⇒ Object

Public: POSTs the Step level results to TWB.

s3_screenshot - Boolean true/false indicating if a screenshot should be saved to S3 bucket (default: false). description - String description of results (default: ‘Step Passed.’). twb_suite_name - String name of the test suite (default: test_data). program_application_name - String name of the program application (default: test_data). screenshot - Boolean true/false indicating a screenshot is/isn’t sent (default: false). ss_filename - String filename of image to POST. If none is provided a screenshot on active stb will be captured (default: nil) access_key_id - String S3 access key ID (default: TWB access key). secret_access_key - String S3 secret access key (default: TWB secret access key). bucket_name - String S3 bucket name (default: ‘charter-testworkbench-com’). aws_folder - String folder name where image will POST (default: TMC_Screenshots). case_instance_id - result of twb_get_case_instance_id suite_instance_id - result of twb_get_suite_instance_id

Returns String return message if successful. Else, returns nil.



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 697

def twb_post_teststep(args={})
  tcr_auto_detail_text = args.fetch(:description, 'Step Passed.')
  post_screenshot = args.fetch(:screenshot, false)
  post_s3_screenshot = args.fetch(:s3_screenshot, false)
  ss_filename = args.fetch(:ss_filename, nil)
  test_suite_name = (args.key?(:twb_suite_name)) ? args[:twb_suite_name] : test_data[:twb_suite_name]
  program_application_name = (args.key?(:program_application_name)) ? args[:program_application_name] : test_data[:program_application_name]

  suite_instance_id = (args.key?(:suite_instance_id)) ? args[:suite_instance_id] : twb_get_suite_instance_id(:twb_suite_name => test_suite_name,:program_application_name => program_application_name)

  case_instance_id = (args.key?(:case_instance_id)) ? args[:case_instance_id] : twb_get_case_instance_id(:twb_suite_name => test_suite_name)

  # POST /teststep/
  logger.debug('POST /teststep/')
  uri = args.fetch(
      :uri,
      'http://charter.testworkbench.com/ords/test/teststep/'
  )
  result = args.fetch(:result_value, 'Passed')
  result = 'Passed' if result == :PASS
  result = 'Failed' if result == :FAIL
  if post_s3_screenshot
    access_key_id = args.fetch(:access_key_id, 'AKIAJR4GME4RASTKVXXQ')
    secret_access_key = args.fetch(:secret_access_key, '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')
    bucket_name = args.fetch(:bucket_name, 'charter-testworkbench-com')
    aws_folder = args.fetch(:aws_folder, 'TMC_Screenshots')
    image_path = twb_prep_s3_screenshot(:access_key_id => access_key_id,
                                        :secret_access_key => secret_access_key,
                                        :bucket_name => bucket_name,
                                        :suite_instance_id => suite_instance_id,
                                        :case_instance_id => case_instance_id,
                                        :aws_folder => aws_folder,
                                        :ss_filename => ss_filename)
    resp = web_post(uri, :verify_mode => 0, :json => {
        :suite_instance_id => suite_instance_id,
        :case_instance_id => case_instance_id,
        :step_status => result,
        :actual_description => tcr_auto_detail_text,
        #:component => 'at mail',
        :image_path => image_path
    }).json
  else
    resp = web_post(uri, :verify_mode => 0, :json => {
        :suite_instance_id => suite_instance_id,
        :case_instance_id => case_instance_id,
        :step_status => result,
        :actual_description => tcr_auto_detail_text,
        #:component => 'at mail',
        #:image_path => 'S3 server location'
    }).json
  end
  if post_screenshot
    twb_post_screenshot(
        :twb_suite_name => test_suite_name,
        :program_application_name => program_application_name,
        :suite_instance_id => suite_instance_id,
        :case_instance_id => case_instance_id,
        :ss_filename => ss_filename
    )
  end
  return_msg = resp['return_msg']
  if return_msg.nil?
    logger.warn('Failed to POST Teststep to TWB!')
    return nil
  else
    logger.debug("Return Msg: #{return_msg}")
    return return_msg
  end
end

#twb_post_teststep!(args = {}) ⇒ Object

Public: POSTs the Step level results to TWB. Edits the args to add missing data

s3_screenshot - Boolean true/false indicating if a screenshot should be saved to S3 bucket (default: false). description - String description of results (default: ‘Step Passed.’). twb_suite_name - String name of the test suite (default: test_data). program_application_name - String name of the program application (default: test_data). screenshot - Boolean true/false indicating a screenshot is/isn’t sent (default: false). ss_filename - String filename of image to POST. If none is provided a screenshot on active stb will be captured (default: nil) access_key_id - String S3 access key ID (default: TWB access key). secret_access_key - String S3 secret access key (default: TWB secret access key). bucket_name - String S3 bucket name (default: ‘charter-testworkbench-com’). aws_folder - String folder name where image will POST (default: TMC_Screenshots). case_instance_id - result of twb_get_case_instance_id suite_instance_id - result of twb_get_suite_instance_id

Returns String return message if successful. Else, returns nil.



816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 816

def twb_post_teststep!(args={})
  args[:twb_suite_name] = test_data[:twb_suite_name] unless args.key?(:twb_suite_name)
  test_suite_name = args[:twb_suite_name]
  args[:program_application_name] = test_data[:program_application_name] unless args.key?(:program_application_name)
  program_application_name = args[:program_application_name]
  description = args[:description]
  description = 'Starting Test...' if description.nil?
  unless args.key?(:suite_instance_id)
      args[:suite_instance_id] = twb_get_suite_instance_id(
          :twb_suite_name => test_suite_name, 
          :program_application_name => program_application_name,
          :description => description
      )
  end
  args[:case_instance_id] = twb_get_case_instance_id(:twb_suite_name => test_suite_name) unless args.key?(:case_instance_id)
  twb_post_teststep(args)
end

#twb_prep_s3_screenshot(args = {}) ⇒ Object

Public: Writes a screenshot to an AWS S3 bucket in preparation for reporting to TWB.

access_key_id - String S3 access key ID (default: TWB access key). secret_access_key - String S3 secret access key (default: TWB secret access key). region - Symbol S3 region (default: us-west-2).

:us-east-1 - N. Virginia
:us-east-2 - Ohio
:us-west-1 - N. California
:us-west-2 - Oregon

bucket_name - String S3 bucket name (default: ‘charter-testworkbench-com’). aws_folder - String folder name where image will POST (default: TMC_Screenshots). ss_filename - String filename of image to POST. If none is provided a screenshot on active stb will be captured (default: nil) size - number from 0 to 100 for percentage size of the image quality - number from 0 to 100 for image quality

Returns the public URI::HTTP for the object.



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 492

def twb_prep_s3_screenshot(args={})
  suite_instance_id = (args.key?(:suite_instance_id)) ? args[:suite_instance_id] : twb_get_suite_instance_id
  case_instance_id = (args.key?(:case_instance_id)) ? args[:case_instance_id] : twb_get_case_instance_id

  image_size = args.fetch(:size, 100).to_i
  image_size = (image_size > 100) ? 100 : image_size
  image_size = (image_size < 1) ? 1 : image_size

  image_quality = args.fetch(:quality, 100).to_i
  image_quality = (image_quality > 100) ? 100 : image_quality
  image_quality = (image_quality < 0) ? 0 : image_quality

  access_key_id = args.fetch(:access_key_id, 'AKIAJR4GME4RASTKVXXQ')
  secret_access_key = args.fetch(:secret_access_key, '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')
  region = args.fetch(:region, 'us-east-2')
  bucket_name = args.fetch(:bucket_name, 'charter-testworkbench-com')
  aws_folder = args.fetch(:aws_folder, 'TMC_Screenshots')
  ss_filename = args.fetch(:ss_filename, nil)
  tmc_current_screenshots = Hash[test_data.fetch(:tmc_current_screenshots, [])]
  if tmc_current_screenshots[id].nil?
    test_data[:tmc_current_screenshots] = tmc_current_screenshots.update(id => 1).to_a  # can't use hash because of integer keys
  else
    tmc_current_screenshots[id] += 1
    test_data[:tmc_current_screenshots] = tmc_current_screenshots.to_a  # can't use hash because of integer keys
  end
  filename = "twb_suite_#{suite_instance_id}_case_#{case_instance_id}_screenshot_#{tmc_current_screenshots[id]}.jpg"
  # Prep the screenshot
  if ss_filename.nil?
    data = dut.capture_screen(:filename => filename, :format => :raw, :size => image_size, :quality => image_quality)
  else
    data = ss_filename
  end
  aws_write_s3(bucket_name, "#{aws_folder}/#{filename}", data)
  return "#{aws_folder}/#{filename}"
end

#twb_suite_exists?Boolean

Public: Checks to see if a Suite Instance ID exists for the current twb_suite_name.

Returns a Boolean true if a Suite Instance ID exists for the current suite. Else, returns a Boolean false.

Returns:

  • (Boolean)


365
366
367
368
369
370
371
372
373
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 365

def twb_suite_exists?
  test_data.refresh
  if test_data[:report_per_slot]
    return true if test_data.fetch("twb_suite_id_slot#{dut.slot}_iter#{iteration}".to_sym, false)
    return false
  end
  return true if test_data.fetch(:twb_suite_id, false)
  return false
end

#until_condition(condition, args = {}, &block) ⇒ Object

Public: Yields the given block until the specified criteria are met or times out.

condition - Symbol condition to test. May be one of the following:

:not_empty    - Returns when the result of the block is not empty.
:not_nil      - Returns when the result of the block is not nil.
:same         - Returns when the result of the block is the same twice in a row.
:equals       - Returns when the given value equals the result of the block.
:not_equals   - Returns when the given value does not equal the result of the block.
:includes     - Returns when the given value is included in the result of the block.
:not_includes - Returns when the given value is not included in the result of the block.

value - Object value (default: nil). Required if needed to test condition. timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). allow_empty - Boolean indicating whether to consider empty objects (String, Array, etc.)

matching when the criteria is :same (default: false).

block - Block to yield.

Returns the final result of yielding the block.



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 270

def until_condition(condition, args={}, &block)
  message = args.fetch(:message, 'executing provided block')
  timeout = args.fetch(:timeout, 30.sec)
  value_str = args[:value].nil? ? '' : " #{args[:value].inspect}"
  logger.info("#{message.capitalize} until #{condition}#{value_str} or timeout (#{timeout} ms)")
  ret = nil
  last_ret = -1
  start_time = Time.now
  while (Time.now - start_time) <= (timeout / 1.sec)
    ret = block.call
    case condition
      when :not_empty
        break unless ret.nil? || ret.empty?
      when :not_nil
        break unless ret.nil?
      when :same
        break if ret == last_ret && (args[:allow_empty] || !ret.empty?)
        last_ret = ret
      when :equals
        if args[:value].is_a?(Regexp)
          break if !ret.nil? && ret =~ args[:value]
        else
          break if ret == args[:value]
        end
      when :not_equals
        if args[:value].is_a?(Regexp)
          break unless ret.nil? || ret =~ args[:value]
        else
          break unless ret == args[:value]
        end
      when :includes
        unless ret.nil?
          if args[:value].is_a?(Regexp)
            break unless ret.select { |val| val =~ args[:value] }.empty?
          else
            break if ret.include?(args[:value])
          end
        end
      when :not_includes
        unless ret.nil?
          if args[:value].is_a?(Regexp)
            break if ret.select { |val| val =~ args[:value] }.empty?
          else
            break unless ret.include?(args[:value])
          end
        end
      else
        raise "Invalid condition: #{condition}"
    end
    sleep(100)
  end
  ret
end

#until_equals(value, args = {}, &block) ⇒ Object

Public: Yields the given block until the result equals the specified value.

value - Object value that must equal the result of the block. timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). block - Block to yield.

Returns the final result of yielding the block.



208
209
210
211
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 208

def until_equals(value, args={}, &block)
  args[:value] = value
  until_condition(:equals, args, &block)
end

#until_includes(value, args = {}, &block) ⇒ Object

Public: Yields the given block until the result includes the specified value.

value - Object value that must be included in the result of the block. timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). block - Block to yield.

Returns the final result of yielding the block.



234
235
236
237
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 234

def until_includes(value, args={}, &block)
  args[:value] = value
  until_condition(:includes, args, &block)
end

#until_not_empty(args = {}, &block) ⇒ Object

Public: Yields the given block until the result is not empty.

timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). block - Block to yield.

Returns the final result of yielding the block.



173
174
175
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 173

def until_not_empty(args={}, &block)
  until_condition(:not_empty, args, &block)
end

#until_not_equals(value, args = {}, &block) ⇒ Object

Public: Yields the given block until the result does not equal the specified value.

value - Object value that must equal the result of the block. timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). block - Block to yield.

Returns the final result of yielding the block.



221
222
223
224
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 221

def until_not_equals(value, args={}, &block)
  args[:value] = value
  until_condition(:not_equals, args, &block)
end

#until_not_includes(value, args = {}, &block) ⇒ Object

Public: Yields the given block until the result does not include the specified value.

value - Object value that must not be included in the result of the block. timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). block - Block to yield.

Returns the final result of yielding the block.



247
248
249
250
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 247

def until_not_includes(value, args={}, &block)
  args[:value] = value
  until_condition(:not_includes, args, &block)
end

#until_not_nil(args = {}, &block) ⇒ Object

Public: Yields the given block until the result is not nil.

timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). block - Block to yield.

Returns the final result of yielding the block.



184
185
186
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 184

def until_not_nil(args={}, &block)
  until_condition(:not_nil, args, &block)
end

#until_same(args = {}, &block) ⇒ Object

Public: Yields the given block until the result is the same twice in a row.

timeout - Integer total milliseconds to try meeting the criteria before timing out (default: 30.sec). message - String custom message to log (default: ‘executing provided block’). allow_empty - Boolean indicating whether to consider empty objects (String, Array, etc.) matching (default: false). block - Block to yield.

Returns the final result of yielding the block.



196
197
198
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 196

def until_same(args={}, &block)
  until_condition(:same, args, &block)
end

#web_delete(uri, args = {}) ⇒ Object

Public: Performs a DELETE request for the given URI.

uri - String full URI for the resource to DELETE. body - String data to populate the request body (default: nil). json - Hash JSON object to send in the request body (default: nil). By default no JSON will be included. form_data - Hash form data to send in the request (default: nil). By default no form data will be included. basic_auth - Hash of basic authentication :username and :password to use (default: nil). headers - Hash of headers to add to the request (default: {}). timeout - Integer total milliseconds to wait for a response (default: 5.min).

Returns the Hash JSON response, or nil if there was an error.



888
889
890
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 888

def web_delete(uri, args={})
  web_request(:delete, uri, args)
end

#web_get(uri, args = {}) ⇒ Object

Public: Performs a GET request for the given URI.

uri - String full URI for the resource to GET. body - String data to populate the request body (default: nil). headers - Hash of headers to add to the request (default: {}). basic_auth - Hash of basic authentication :username and :password to use (default: nil). timeout - Integer total milliseconds to wait for a response (default: 5.min).

Returns the Hash JSON response, or nil if there was an error.



843
844
845
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 843

def web_get(uri, args={})
  web_request(:get, uri, args)
end

#web_post(uri, args = {}) ⇒ Object

Public: Performs a POST request for the given URI.

uri - String full URI for the resource to POST. body - String data to populate the request body (default: nil). json - Hash JSON object to send in the request body (default: nil). By default no JSON will be included. form_data - Hash form data to send in the request (default: nil). By default no form data will be included. basic_auth - Hash of basic authentication :username and :password to use (default: nil). headers - Hash of headers to add to the request (default: {}). timeout - Integer total milliseconds to wait for a response (default: 5.min).

Returns the Hash JSON response, or nil if there was an error.



858
859
860
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 858

def web_post(uri, args={})
  web_request(:post, uri, args)
end

#web_put(uri, args = {}) ⇒ Object

Public: Performs a PUT request for the given URI.

uri - String full URI for the resource to PUT. body - String data to populate the request body (default: nil). json - Hash JSON object to send in the request body (default: nil). By default no JSON will be included. form_data - Hash form data to send in the request (default: nil). By default no form data will be included. basic_auth - Hash of basic authentication :username and :password to use (default: nil). headers - Hash of headers to add to the request (default: {}). timeout - Integer total milliseconds to wait for a response (default: 5.min).

Returns the Hash JSON response, or nil if there was an error.



873
874
875
# File 'lib/helpers/tmc_helpers/tmc_helpers.rb', line 873

def web_put(uri, args={})
  web_request(:put, uri, args)
end