inferno_core 0.3.5 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40fa8983d93a7fc191a7d03bdb78c0bd80e138cfe5245d377c15f28360fb6b03
4
- data.tar.gz: 4aa592411c216c13bc55ebcef30ce2019522cc3575edc184fcb10593eb28239a
3
+ metadata.gz: 669dde4b0ad34993f363e538ed2d7eae59d4211f0b988a7e6306231fd54d74c0
4
+ data.tar.gz: 5149b96b6931d27a41cd0c3b0a5665024b297c6d8e612e574582cb630ef29867
5
5
  SHA512:
6
- metadata.gz: bb0f7e9aafced3a1181cd40d8638f4ac07fefc0239ab771b85ce22aaec3785b7328ca82969cd83b1617051201fa149272ba80a53a05789129e6ee35302cf3a1b
7
- data.tar.gz: 5f14e0db2c0a2d3238198600a736790ea549ea11c91bb84578dda2e3de2270c31cb314b44972ec2fbc6635aa77b93f0ce4df2926d45c072745b19a1d6371b34f
6
+ metadata.gz: d5a839c224c59795ab5f79fdd18de124ba6eae8d2cdf60c1afeae4f7bf091ac1a0321ff97e7939753de1d05441df1152929e3d3ba2e743d9777ea39fc0603806
7
+ data.tar.gz: 602ac59a4417b6751d3e661d15ac55f4d7ac2f2ee171b9ac284637b3d4693f36ae85f09fbd63011fa570609dd1c8f54c7ee5c35fa28f1c909185bec2b28f0234
@@ -11,8 +11,8 @@ module Inferno
11
11
 
12
12
  PARAMS = [:test_session_id, :test_suite_id, :test_group_id, :test_id].freeze
13
13
 
14
- def verify_runnable(runnable, inputs)
15
- missing_inputs = runnable&.missing_inputs(inputs)
14
+ def verify_runnable(runnable, inputs, selected_suite_options)
15
+ missing_inputs = runnable&.missing_inputs(inputs, selected_suite_options)
16
16
  user_runnable = runnable&.user_runnable?
17
17
  raise Inferno::Exceptions::RequiredInputsNotFound, missing_inputs if missing_inputs&.any?
18
18
  raise Inferno::Exceptions::NotUserRunnableException unless user_runnable
@@ -26,7 +26,7 @@ module Inferno
26
26
  &.last
27
27
 
28
28
  if input.nil?
29
- Inferno::Application['logger'].warning(
29
+ Inferno::Application['logger'].warn(
30
30
  "Unknown input `#{input_params[:name]}` for #{test_run.runnable.id}: #{test_run.runnable.title}"
31
31
  )
32
32
  next
@@ -51,11 +51,15 @@ module Inferno
51
51
  return
52
52
  end
53
53
 
54
- verify_runnable(repo.build_entity(create_params(params)).runnable, params[:inputs])
54
+ verify_runnable(
55
+ repo.build_entity(create_params(params)).runnable,
56
+ params[:inputs],
57
+ test_session.suite_options
58
+ )
55
59
 
56
60
  test_run = repo.create(create_params(params).merge(status: 'queued'))
57
61
 
58
- self.body = serialize(test_run)
62
+ self.body = serialize(test_run, suite_options: test_session.suite_options)
59
63
 
60
64
  persist_inputs(params, test_run)
61
65
 
@@ -3,6 +3,8 @@ module Inferno
3
3
  module Controllers
4
4
  module TestRuns
5
5
  class Show < Controller
6
+ include Import[test_sessions_repo: 'repositories.test_sessions']
7
+
6
8
  def call(params)
7
9
  test_run = repo.find(params[:id])
8
10
  halt 404 if test_run.nil?
@@ -17,7 +19,8 @@ module Inferno
17
19
  end
18
20
  end
19
21
 
20
- self.body = serialize(test_run)
22
+ test_session = test_sessions_repo.find(test_run.test_session_id)
23
+ self.body = serialize(test_run, suite_options: test_session.suite_options)
21
24
  end
22
25
  end
23
26
  end
@@ -6,9 +6,8 @@ module Inferno
6
6
  PARAMS = [:test_suite_id, :suite_options].freeze
7
7
 
8
8
  def call(raw_params)
9
- query_params = raw_params.to_h
10
- body_params = JSON.parse(request.body.string).symbolize_keys
11
- params = query_params.merge(body_params)
9
+ params = raw_params.to_h
10
+ params.merge!(JSON.parse(request.body.string).symbolize_keys) unless request.body.string.blank?
12
11
 
13
12
  session = repo.create(create_params(params))
14
13
 
@@ -6,9 +6,13 @@ module Inferno
6
6
  class Input < Serializer
7
7
  identifier :name
8
8
 
9
- field :label, if: :field_present?
9
+ field :title, if: :field_present?
10
10
  field :description, if: :field_present?
11
- field :required, if: :field_present?
11
+ field :type, if: :field_present?
12
+ field :default, if: :field_present?
13
+ field :optional, if: :field_present?
14
+ field :options, if: :field_present?
15
+ field :locked, if: :field_present?
12
16
  field :value, if: :field_present?
13
17
  end
14
18
  end
@@ -7,7 +7,10 @@ module Inferno
7
7
  field :short_id
8
8
  field :title
9
9
  field :short_title
10
- field :available_inputs, name: :inputs, extractor: HashValueExtractor, blueprint: Input
10
+ field :inputs do |test, options|
11
+ suite_options = options[:suite_options]
12
+ Input.render_as_hash(test.available_inputs(suite_options).values)
13
+ end
11
14
  field :output_definitions, name: :outputs, extractor: HashValueExtractor
12
15
  field :description
13
16
  field :short_description
@@ -10,18 +10,25 @@ module Inferno
10
10
  field :description
11
11
  field :short_description
12
12
  field :input_instructions
13
- field :test_count
14
13
  field :run_as_group?, name: :run_as_group
15
14
  field :user_runnable?, name: :user_runnable
16
15
  field :optional?, name: :optional
17
16
 
17
+ field :test_count do |group, options|
18
+ group.test_count(options[:suite_options])
19
+ end
18
20
  field :test_groups do |group, options|
19
- TestGroup.render_as_hash(group.groups(options[:suite_options]))
21
+ suite_options = options[:suite_options]
22
+ TestGroup.render_as_hash(group.groups(suite_options), suite_options: suite_options)
20
23
  end
21
24
  field :tests do |group, options|
22
- Test.render_as_hash(group.tests(options[:suite_options]))
25
+ suite_options = options[:suite_options]
26
+ Test.render_as_hash(group.tests(suite_options), suite_options: suite_options)
27
+ end
28
+ field :inputs do |group, options|
29
+ suite_options = options[:suite_options]
30
+ Input.render_as_hash(group.available_inputs(suite_options).values)
23
31
  end
24
- field :available_inputs, name: :inputs, extractor: HashValueExtractor, blueprint: Input
25
32
  field :output_definitions, name: :outputs, extractor: HashValueExtractor
26
33
  end
27
34
  end
@@ -6,7 +6,9 @@ module Inferno
6
6
  field :test_session_id
7
7
 
8
8
  field :status
9
- field :test_count
9
+ field :test_count do |test_run, options|
10
+ test_run.test_count(options[:suite_options])
11
+ end
10
12
 
11
13
  field :test_group_id, if: :field_present?
12
14
  field :test_suite_id, if: :field_present?
@@ -9,8 +9,13 @@ module Inferno
9
9
  field :description
10
10
  field :short_description
11
11
  field :input_instructions
12
- field :test_count
13
12
  field :version
13
+ field :links
14
+
15
+ field :test_count do |suite, options|
16
+ suite.test_count(options[:suite_options])
17
+ end
18
+
14
19
  association :suite_options, blueprint: SuiteOption
15
20
  association :presets, view: :summary, blueprint: Preset
16
21
  end
@@ -18,10 +23,14 @@ module Inferno
18
23
  view :full do
19
24
  include_view :summary
20
25
  field :test_groups do |suite, options|
21
- TestGroup.render_as_hash(suite.groups(options[:suite_options]))
26
+ suite_options = options[:suite_options]
27
+ TestGroup.render_as_hash(suite.groups(suite_options), suite_options: suite_options)
22
28
  end
23
29
  field :configuration_messages
24
- field :available_inputs, name: :inputs, extractor: HashValueExtractor, blueprint: Input
30
+ field :inputs do |suite, options|
31
+ suite_options = options[:suite_options]
32
+ Input.render_as_hash(suite.available_inputs(suite_options).values)
33
+ end
25
34
  end
26
35
  end
27
36
  end
@@ -4,7 +4,7 @@ Inferno::Application.boot(:presets) do
4
4
  init do
5
5
  use :suites
6
6
 
7
- files_to_load = Dir.glob(File.join(Dir.pwd, 'config', 'presets', '*.json'))
7
+ files_to_load = Dir.glob(['config/presets/*.json', 'config/presets/*.json.erb'])
8
8
  files_to_load.map! { |path| File.realpath(path) }
9
9
  presets_repo = Inferno::Repositories::Presets.new
10
10
 
@@ -1,3 +1,5 @@
1
+ require 'faraday_middleware'
2
+
1
3
  require_relative 'request_storage'
2
4
  require_relative 'tcp_exception_handler'
3
5
 
@@ -75,7 +77,7 @@ module Inferno
75
77
  if client
76
78
  client.get(url, nil, options[:headers])
77
79
  elsif url.match?(%r{\Ahttps?://})
78
- Faraday.get(url, nil, options[:headers])
80
+ connection.get(url, nil, options[:headers])
79
81
  else
80
82
  raise StandardError, 'Must use an absolute url or define an HTTP client with a base url'
81
83
  end
@@ -83,6 +85,14 @@ module Inferno
83
85
  end
84
86
  end
85
87
 
88
+ # @private
89
+ def connection
90
+ Faraday.new do |f|
91
+ f.request :url_encoded
92
+ f.use FaradayMiddleware::FollowRedirects
93
+ end
94
+ end
95
+
86
96
  # Perform an HTTP POST request
87
97
  #
88
98
  # @param url [String] if this request is using a defined client, this will
@@ -103,7 +113,7 @@ module Inferno
103
113
  if client
104
114
  client.post(url, body, options[:headers])
105
115
  elsif url.match?(%r{\Ahttps?://})
106
- Faraday.post(url, body, options[:headers])
116
+ connection.post(url, body, options[:headers])
107
117
  else
108
118
  raise StandardError, 'Must use an absolute url or define an HTTP client with a base url'
109
119
  end
@@ -128,7 +138,7 @@ module Inferno
128
138
  if client
129
139
  client.delete(url, nil, options[:headers])
130
140
  elsif url.match?(%r{\Ahttps?://})
131
- Faraday.delete(url, nil, options[:headers])
141
+ connection.delete(url, nil, options[:headers])
132
142
  else
133
143
  raise StandardError, 'Must use an absolute url or define an HTTP client with a base url'
134
144
  end
@@ -167,7 +177,7 @@ module Inferno
167
177
  if client
168
178
  response = client.get(url, nil, options[:headers]) { |req| req.options.on_data = collector }
169
179
  elsif url.match?(%r{\Ahttps?://})
170
- response = Faraday.get(url, nil, options[:headers]) { |req| req.options.on_data = collector }
180
+ response = connection.get(url, nil, options[:headers]) { |req| req.options.on_data = collector }
171
181
  else
172
182
  raise StandardError, 'Must use an absolute url or define an HTTP client with a base url'
173
183
  end
@@ -1,3 +1,5 @@
1
+ require 'faraday_middleware'
2
+
1
3
  module Inferno
2
4
  module DSL
3
5
  # This module contains the HTTP DSL available to test writers.
@@ -12,7 +14,10 @@ module Inferno
12
14
  params = { url: url }
13
15
  params.merge!(headers: headers) if headers
14
16
 
15
- Faraday.new(params)
17
+ Faraday.new(params) do |f|
18
+ f.request :url_encoded
19
+ f.use FaradayMiddleware::FollowRedirects
20
+ end
16
21
  end
17
22
 
18
23
  # Define the base url for an HTTP client. A string or symbol can be
@@ -90,17 +90,17 @@ module Inferno
90
90
  end
91
91
 
92
92
  # @private
93
- def required_inputs
94
- available_inputs
93
+ def required_inputs(selected_suite_options)
94
+ available_inputs(selected_suite_options)
95
95
  .reject { |_, input| input.optional }
96
96
  .map { |_, input| input.name }
97
97
  end
98
98
 
99
99
  # @private
100
- def missing_inputs(submitted_inputs)
100
+ def missing_inputs(submitted_inputs, selected_suite_options)
101
101
  submitted_inputs = [] if submitted_inputs.nil?
102
102
 
103
- required_inputs.map(&:to_s) - submitted_inputs.map { |input| input[:name] }
103
+ required_inputs(selected_suite_options).map(&:to_s) - submitted_inputs.map { |input| input[:name] }
104
104
  end
105
105
 
106
106
  # Define a particular order for inputs to be presented in the API/UI
@@ -153,52 +153,46 @@ module Inferno
153
153
  # Inputs available for this runnable's children. A running list of outputs
154
154
  # created by the children is used to exclude any inputs which are provided
155
155
  # by an earlier child's output.
156
- def children_available_inputs
157
- @children_available_inputs ||=
158
- begin
159
- child_outputs = []
160
- all_children.each_with_object({}) do |child, definitions|
161
- new_definitions = child.available_inputs.map(&:dup)
162
- new_definitions.each do |input, new_definition|
163
- existing_definition = definitions[input]
164
-
165
- updated_definition =
166
- if existing_definition.present?
167
- existing_definition.merge_with_child(new_definition)
168
- else
169
- new_definition
170
- end
171
-
172
- next if child_outputs.include?(updated_definition.name.to_sym)
173
-
174
- definitions[updated_definition.name.to_sym] = updated_definition
156
+ def children_available_inputs(selected_suite_options = nil)
157
+ child_outputs = []
158
+ children(selected_suite_options).each_with_object({}) do |child, definitions|
159
+ new_definitions = child.available_inputs(selected_suite_options).map(&:dup)
160
+ new_definitions.each do |input, new_definition|
161
+ existing_definition = definitions[input]
162
+
163
+ updated_definition =
164
+ if existing_definition.present?
165
+ existing_definition.merge_with_child(new_definition)
166
+ else
167
+ new_definition
175
168
  end
176
169
 
177
- child_outputs.concat(child.all_outputs).uniq!
178
- end
170
+ next if child_outputs.include?(updated_definition.name.to_sym)
171
+
172
+ definitions[updated_definition.name.to_sym] = updated_definition
179
173
  end
174
+
175
+ child_outputs.concat(child.all_outputs).uniq!
176
+ end
180
177
  end
181
178
 
182
179
  # @private
183
180
  # Inputs available for the user for this runnable and all its children.
184
- def available_inputs
185
- @available_inputs ||=
186
- begin
187
- available_inputs =
188
- config.inputs
189
- .slice(*inputs)
190
- .each_with_object({}) do |(_, input), inputs|
191
- inputs[input.name.to_sym] = input
192
- end
193
-
194
- available_inputs.each do |input, current_definition|
195
- child_definition = children_available_inputs[input]
196
- current_definition.merge_with_child(child_definition)
181
+ def available_inputs(selected_suite_options = nil)
182
+ available_inputs =
183
+ config.inputs
184
+ .slice(*inputs)
185
+ .each_with_object({}) do |(_, input), inputs|
186
+ inputs[input.name.to_sym] = Entities::Input.new(input.to_hash)
197
187
  end
198
188
 
199
- available_inputs = children_available_inputs.merge(available_inputs)
200
- order_available_inputs(available_inputs)
201
- end
189
+ available_inputs.each do |input, current_definition|
190
+ child_definition = children_available_inputs(selected_suite_options)[input]
191
+ current_definition.merge_with_child(child_definition)
192
+ end
193
+
194
+ available_inputs = children_available_inputs(selected_suite_options).merge(available_inputs)
195
+ order_available_inputs(available_inputs)
202
196
  end
203
197
  end
204
198
  end
@@ -13,7 +13,8 @@ module Inferno
13
13
  :default,
14
14
  :optional,
15
15
  :options,
16
- :locked
16
+ :locked,
17
+ :value
17
18
  ].freeze
18
19
  include Entities::Attributes
19
20
 
@@ -68,8 +68,8 @@ module Inferno
68
68
  super.merge(test_session: test_session).compact
69
69
  end
70
70
 
71
- def test_count
72
- @test_count ||= runnable.test_count
71
+ def test_count(selected_suite_options = [])
72
+ @test_count ||= runnable.test_count(selected_suite_options)
73
73
  end
74
74
  end
75
75
  end
@@ -93,6 +93,12 @@ module Inferno
93
93
  def suite_options
94
94
  @suite_options ||= []
95
95
  end
96
+
97
+ def links(links = nil)
98
+ return @links if links.nil?
99
+
100
+ @links = links
101
+ end
96
102
  end
97
103
  end
98
104
  end