Class: Hiptest::Client
- Inherits:
-
Object
- Object
- Hiptest::Client
- Defined in:
- lib/hiptest-publisher/client.rb
Instance Attribute Summary collapse
-
#cli_options ⇒ Object
readonly
Returns the value of attribute cli_options.
Instance Method Summary collapse
- #available_test_runs ⇒ Object
- #fetch_project_export ⇒ Object
- #global_failure_url ⇒ Object
-
#initialize(cli_options, reporter = nil) ⇒ Client
constructor
A new instance of Client.
- #project_export_filters ⇒ Object
- #push_results ⇒ Object
- #test_run_export_filter ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(cli_options, reporter = nil) ⇒ Client
Returns a new instance of Client.
16 17 18 19 |
# File 'lib/hiptest-publisher/client.rb', line 16 def initialize(, reporter = nil) @cli_options = @reporter = reporter || NullReporter.new end |
Instance Attribute Details
#cli_options ⇒ Object (readonly)
Returns the value of attribute cli_options.
14 15 16 |
# File 'lib/hiptest-publisher/client.rb', line 14 def @cli_options end |
Instance Method Details
#available_test_runs ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hiptest-publisher/client.rb', line 81 def available_test_runs @available_test_runs ||= begin response = send_get_request("#{base_publication_path}/test_runs") if response.code_type == Net::HTTPNotFound :api_not_available else json_response = JSON.parse(response.body) json_response["test_runs"] end end end |
#fetch_project_export ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/hiptest-publisher/client.rb', line 73 def fetch_project_export response = send_get_request(url) if response.code_type == Net::HTTPNotFound raise ClientError, "No project found with this secret token." end response.body end |
#global_failure_url ⇒ Object
31 32 33 |
# File 'lib/hiptest-publisher/client.rb', line 31 def global_failure_url "#{.site}/report_global_failure/#{.token}/#{.test_run_id}/" end |
#project_export_filters ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hiptest-publisher/client.rb', line 35 def project_export_filters mapping = { filter_on_scenario_ids: 'filter_scenario_ids', filter_on_folder_ids: 'filter_folder_ids', filter_on_scenario_name: 'filter_scenario_name', filter_on_folder_name: 'filter_folder_name', filter_on_tags: 'filter_tags' } = [] mapping.each do |key, filter_name| value = @cli_options[key] next if value.nil? || value.empty? if [:filter_on_scenario_ids, :filter_on_folder_ids, :filter_on_tags].include?(key) value = value.split(',').map(&:strip).map{ |s| ERB::Util.url_encode(s) }.join(',') else value = ERB::Util.url_encode(value) end << "#{filter_name}=#{value}" if [:filter_on_folder_ids, :filter_on_folder_name].include?(key) && @cli_options[:not_recursive] << "not_recursive=true" end end return .empty? ? '' : "?#{.join('&')}" end |
#push_results ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hiptest-publisher/client.rb', line 93 def push_results # Code from: https://github.com/nicksieger/multipart-post uploaded = {} Dir.glob(.push.gsub('\\', '/')).each_with_index do |filename, index| uploaded["file-#{filename.normalize}"] = UploadIO.new(File.new(filename), "text", filename) end if .global_failure_on_missing_reports && uploaded.empty? return send_post_request(global_failure_url) end uri = URI.parse(url) send_request(Net::HTTP::Post::Multipart.new(uri, uploaded)) end |
#test_run_export_filter ⇒ Object
66 67 68 69 70 71 |
# File 'lib/hiptest-publisher/client.rb', line 66 def test_run_export_filter value = @cli_options.filter_on_status return '' if value.nil? || value.empty? return "?filter_status=#{value}" end |
#url ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/hiptest-publisher/client.rb', line 21 def url if .push? "#{.site}/import_test_results/#{.token}/#{.push_format}" elsif test_run_id "#{base_publication_path}/test_run/#{test_run_id}#{test_run_export_filter}" else "#{base_publication_path}/#{.leafless_export ? 'leafless_tests' : 'project'}#{project_export_filters}" end end |