Method: TmcHelpers#twb_post_testcase

Defined in:
lib/helpers/tmc_helpers/tmc_helpers.rb

#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