Class: Hiptest::Client
- Inherits:
-
Object
- Object
- Hiptest::Client
- Defined in:
- lib/hiptest-publisher/client.rb
Instance Attribute Summary collapse
-
#async_options ⇒ Object
writeonly
Sets the attribute async_options.
-
#cli_options ⇒ Object
readonly
Returns the value of attribute cli_options.
Instance Method Summary collapse
- #available_test_runs ⇒ Object
- #fetch_project ⇒ 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.
36 37 38 39 40 |
# File 'lib/hiptest-publisher/client.rb', line 36 def initialize(, reporter = nil) @cli_options = @reporter = reporter || NullReporter.new @async_options = { max_attempts: 200, sleep_time_between_attemps: 5 } end |
Instance Attribute Details
#async_options=(value) ⇒ Object (writeonly)
Sets the attribute async_options
34 35 36 |
# File 'lib/hiptest-publisher/client.rb', line 34 def (value) @async_options = value end |
#cli_options ⇒ Object (readonly)
Returns the value of attribute cli_options.
33 34 35 |
# File 'lib/hiptest-publisher/client.rb', line 33 def @cli_options end |
Instance Method Details
#available_test_runs ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/hiptest-publisher/client.rb', line 117 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 ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hiptest-publisher/client.rb', line 94 def fetch_project cached = export_cache.cache_for(url) unless cached.nil? @reporter. I18n.t(:using_cached_data) do return cached end end content = @reporter. I18n.t(:fetching_data) do break fetch_project_export if use_synchronous_fetch? begin fetch_project_export_asynchronously rescue AsyncExportUnavailable fetch_project_export end end export_cache.cache(url, content) content end |
#global_failure_url ⇒ Object
52 53 54 |
# File 'lib/hiptest-publisher/client.rb', line 52 def global_failure_url "#{.site}/report_global_failure/#{.token}/#{.test_run_id}/" end |
#project_export_filters ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/hiptest-publisher/client.rb', line 56 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
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/hiptest-publisher/client.rb', line 129 def push_results # Code from: https://github.com/nicksieger/multipart-post uploaded = {} Dir.glob(.push.gsub('\\', '/')).each do |filename| uploaded["file-#{filename.normalize}"] = filename end if .global_failure_on_missing_reports && uploaded.empty? return send_post_request(global_failure_url) end send_multipart_request(url, uploaded) end |
#test_run_export_filter ⇒ Object
87 88 89 90 91 92 |
# File 'lib/hiptest-publisher/client.rb', line 87 def test_run_export_filter value = @cli_options.filter_on_status return '' if value.nil? || value.empty? return "?filter_status=#{value}" end |
#url ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/hiptest-publisher/client.rb', line 42 def url if .push? "#{.site}/import_test_results/#{.token}/#{.push_format}#{push_query_parameters}" 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 |