inferno_core 0.4.7 → 0.4.9

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: 465037be8e153e91216eb5318e39a92176efe14c868a7aa0f16c76b61d39dbd8
4
- data.tar.gz: 338f10609d31827ffd211968a4a5a95c759ee4e4ac381c92fd5a495a9124669b
3
+ metadata.gz: 470abbacaa895d2d3451f130734c0e34eec9303ec19858976f79b0456c0d619b
4
+ data.tar.gz: c60351312c3116c39260332b88675f2d8e2b0a3732be2dbf68c2a41c63cd62ab
5
5
  SHA512:
6
- metadata.gz: fa86e30c72fd8a8ad5fa4ebdf9deb8f04298a16f6601e9bb1128126a105573b681ce40f7a0941e967e78c86fd035e6dcc7f3c5cb232d02005793dbc272eb2e54
7
- data.tar.gz: 353befc4c0be11354e2caafab74c39503fc81eb17123a0bfa2bb8d3cca4c424506edfbac9977c35df4c4992170cded60b53b07d2887e63a6419766ad813a5e56
6
+ metadata.gz: 1ff98dd5180315c77a4627710a7bb9c5eaf82d87f81a173f849e24aadf6cad908feb71ac3d92b6a9ca14b38163cf9a821ce236c407e5eb688467e36295fd148e
7
+ data.tar.gz: 324efe61696b3e86b061adede76bd6c3a1d997f15e2c2e1225dc5edb3bc1f24f3ca7ec21b6363c060ed68eb1d66306baa247d34df8cb465a82c7d70b239a1bec
@@ -1,3 +1,5 @@
1
+ require 'tty-markdown'
2
+
1
3
  require_relative 'suite_input_template'
2
4
 
3
5
  module Inferno
@@ -12,8 +14,44 @@ module Inferno
12
14
  LONGDESC
13
15
  option :filename, banner: '<filename>', aliases: [:f]
14
16
  def input_template(suite_id)
17
+ ENV['NO_DB'] = 'true'
15
18
  SuiteInputTemplate.new.run(suite_id, options)
16
19
  end
20
+
21
+ desc 'describe SUITE_ID', 'Show information about a suite'
22
+ long_desc <<~LONGDESC
23
+ Display a suite's description and available options.
24
+ LONGDESC
25
+ def describe(suite_id)
26
+ ENV['NO_DB'] = 'true'
27
+ Inferno::Application.start(:suites)
28
+
29
+ suite = Inferno::Repositories::TestSuites.new.find(suite_id)
30
+
31
+ if suite.blank?
32
+ message = "No suite found with id `#{suite_id}`. Run `inferno suites` to see a list of available suites"
33
+
34
+ puts TTY::Markdown.parse(message)
35
+ return
36
+ end
37
+
38
+ description = ''
39
+ description += "# #{suite.title}\n"
40
+ description += "#{suite.description}\n" if suite.description
41
+
42
+ if suite.suite_options.present?
43
+ description += "***\n\n"
44
+ description += "# Suite Options\n\n"
45
+ suite.suite_options.each do |option|
46
+ description += "* `#{option.id}`: #{option.title}\n"
47
+ option.list_options.each do |list_option|
48
+ description += " * `#{list_option[:value]}`: #{list_option[:label]}\n"
49
+ end
50
+ end
51
+ end
52
+
53
+ puts TTY::Markdown.parse(description)
54
+ end
17
55
  end
18
56
  end
19
57
  end
@@ -1,7 +1,11 @@
1
+ require 'tty-markdown'
2
+
1
3
  module Inferno
2
4
  module CLI
3
5
  class Suites
4
6
  def run
7
+ ENV['NO_DB'] = 'true'
8
+
5
9
  require_relative '../../../inferno'
6
10
 
7
11
  Inferno::Application.start(:suites)
@@ -9,14 +13,18 @@ module Inferno
9
13
  suites = Inferno::Repositories::TestSuites.new.all
10
14
  suite_hash = suites.each_with_object({}) { |suite, hash| hash[suite.id] = suite.title }
11
15
 
12
- id_column_length = suite_hash.keys.map(&:length).max + 1
13
- title_column_length = suite_hash.values.map(&:length).max
16
+ id_column_length = suite_hash.keys.map(&:length).max + 2
17
+ title_column_length = suite_hash.values.map(&:length).max + 1
18
+
19
+ output = ''
20
+ output += "| #{'Title'.ljust(title_column_length)}| #{'ID'.ljust(id_column_length)}|\n"
21
+ output += "|-#{'-' * title_column_length}|-#{'-' * id_column_length}|\n"
14
22
 
15
- puts "#{'ID'.ljust(id_column_length)}| Title"
16
- puts "#{'-' * id_column_length}+-#{'-' * title_column_length}"
17
23
  suite_hash.each do |id, title|
18
- puts "#{id.ljust(id_column_length)}| #{title}"
24
+ output += "| #{title.ljust(title_column_length)}| #{id.ljust(id_column_length)}|\n"
19
25
  end
26
+
27
+ puts TTY::Markdown.parse(output)
20
28
  end
21
29
  end
22
30
  end
@@ -14,7 +14,7 @@ module Inferno
14
14
 
15
15
  session = repo.create(create_params(params))
16
16
 
17
- repo.apply_preset(session.id, params[:preset_id]) if params[:preset_id].present?
17
+ repo.apply_preset(session, params[:preset_id]) if params[:preset_id].present?
18
18
 
19
19
  res.body = serialize(session)
20
20
  rescue Sequel::ValidationFailed, Sequel::ForeignKeyConstraintViolation => e
@@ -32,7 +32,7 @@ module Inferno
32
32
  halt 404
33
33
  end
34
34
 
35
- test_sessions_repo.apply_preset(test_session_id, preset_id)
35
+ test_sessions_repo.apply_preset(test_session, preset_id)
36
36
  res.status = 200
37
37
  end
38
38
  end
@@ -2,6 +2,10 @@ Inferno::Application.boot(:suites) do
2
2
  init do
3
3
  use :logging
4
4
 
5
+ require 'inferno/entities/test'
6
+ require 'inferno/entities/test_group'
7
+ require 'inferno/entities/test_suite'
8
+
5
9
  files_to_load = Dir.glob(File.join(Dir.pwd, 'lib', '*.rb'))
6
10
 
7
11
  if ENV['LOAD_DEV_SUITES'].present?
@@ -12,6 +12,7 @@ module Inferno
12
12
  # @param test a value whose truthiness will determine whether the
13
13
  # assertion passes or fails
14
14
  # @param message [String] failure message
15
+ # @return [void]
15
16
  def assert(test, message = '')
16
17
  raise Exceptions::AssertionException, message unless test
17
18
  end
@@ -26,6 +27,7 @@ module Inferno
26
27
  # @param status [Integer, Array<Integer>] a single integer or an array of
27
28
  # integer status codes
28
29
  # @param response [Hash]
30
+ # @return [void]
29
31
  def assert_response_status(status, response: self.response)
30
32
  assert Array.wrap(status).include?(response[:status]), bad_response_status_message(status, response[:status])
31
33
  end
@@ -44,6 +46,7 @@ module Inferno
44
46
  # assert_resource_type(:capability_statement)
45
47
  # assert_resource_type('CapabilityStatement')
46
48
  # assert_resource_type(FHIR::CapabilityStatement)
49
+ # @return [void]
47
50
  def assert_resource_type(resource_type, resource: self.resource)
48
51
  resource_type_name = normalize_resource_type(resource_type)
49
52
 
@@ -61,8 +64,10 @@ module Inferno
61
64
  # @param resource [FHIR::Model]
62
65
  # @param profile_url [String] url of the profile to validate against,
63
66
  # defaults to validating against the base FHIR resource
64
- def assert_valid_resource(resource: self.resource, profile_url: nil)
65
- assert resource_is_valid?(resource:, profile_url:),
67
+ # @param validator [Symbol] the name of the validator to use
68
+ # @return [void]
69
+ def assert_valid_resource(resource: self.resource, profile_url: nil, validator: :default)
70
+ assert resource_is_valid?(resource:, profile_url:, validator:),
66
71
  invalid_resource_message(profile_url)
67
72
  end
68
73
 
@@ -93,6 +98,7 @@ module Inferno
93
98
  # 'Condition': nil
94
99
  # }
95
100
  # )
101
+ # @return [void]
96
102
  def assert_valid_bundle_entries(bundle: resource, resource_types: {})
97
103
  assert_resource_type('Bundle', resource: bundle)
98
104
 
@@ -148,6 +154,7 @@ module Inferno
148
154
  #
149
155
  # @param maybe_json_string [String]
150
156
  # @param message [String] extra failure message
157
+ # @return [void]
151
158
  def assert_valid_json(maybe_json_string, message = '')
152
159
  assert JSON.parse(maybe_json_string)
153
160
  rescue JSON::ParserError
@@ -158,6 +165,7 @@ module Inferno
158
165
  #
159
166
  # @param uri [String]
160
167
  # @param message [String] custom failure message
168
+ # @return [void]
161
169
  def assert_valid_http_uri(uri, message = '')
162
170
  error_message = message.presence || "\"#{uri}\" is not a valid URI"
163
171
  assert uri =~ /\A#{URI::DEFAULT_PARSER.make_regexp(['http', 'https'])}\z/, error_message
@@ -167,6 +175,7 @@ module Inferno
167
175
  #
168
176
  # @param type [String]
169
177
  # @param request [Inferno::Entities::Request]
178
+ # @return [void]
170
179
  def assert_response_content_type(type, request: self.request)
171
180
  header = request.response_header('Content-Type')
172
181
  assert header.present?, no_content_type_message
@@ -6,6 +6,7 @@ module Inferno
6
6
  # configuration provides a way to modify test behavior at boot time.
7
7
  #
8
8
  # The main features enabled by configuration are:
9
+ #
9
10
  # - Modifying the properties of a runnable's inputs. This could include
10
11
  # locking a particular input, making a particular input optional/required,
11
12
  # or changing an input's value.
@@ -81,6 +82,7 @@ module Inferno
81
82
  # will be applied to the runnable and all of its children.
82
83
  #
83
84
  # @param new_configuration [Hash]
85
+ # @return [Inferno::DSL::Configurable::Configuration]
84
86
  def config(new_configuration = {})
85
87
  @config ||= Configuration.new
86
88
 
@@ -243,6 +243,7 @@ module Inferno
243
243
  # @param block a block to configure the client
244
244
  # @see Inferno::FHIRClientBuilder Documentation for the client
245
245
  # configuration DSL
246
+ # @return [void]
246
247
  def fhir_client(name = :default, &block)
247
248
  fhir_client_definitions[name] = block
248
249
  end
@@ -99,7 +99,8 @@ module Inferno
99
99
  .select { |message| message.is_a? Hash }
100
100
  end
101
101
 
102
- # Filter out unwanted validation messages
102
+ # Filter out unwanted validation messages. Any messages for which the
103
+ # block evalutates to a truthy value will be excluded.
103
104
  #
104
105
  # @example
105
106
  # validator do
@@ -198,6 +198,7 @@ module Inferno
198
198
  # @param block a block to configure the client
199
199
  # @see Inferno::HTTPClientBuilder Documentation for the client
200
200
  # configuration DSL
201
+ # @return [void]
201
202
  def http_client(name = :default, &block)
202
203
  http_client_definitions[name] = block
203
204
  end
@@ -8,9 +8,10 @@ module Inferno
8
8
  # @param input_params [Hash] options for input such as type, description, or title
9
9
  # @option input_params [String] :title Human readable title for input
10
10
  # @option input_params [String] :description Description for the input
11
- # @option input_params [String] :type text | textarea | radio
11
+ # @option input_params [String] :type text | textarea | radio | oauth_credentials
12
12
  # @option input_params [String] :default The default value for the input
13
13
  # @option input_params [Boolean] :optional Set to true to not require input for test execution
14
+ # @option input_params [Boolean] :locked If true, the user can not alter the value
14
15
  # @option input_params [Hash] :options Possible input option formats based on input type
15
16
  # @option options [Array] :list_options Array of options for input formats that require a list of possible values
16
17
  # @return [void]
@@ -46,7 +47,7 @@ module Inferno
46
47
  # @param identifier [Symbol] identifier for the output
47
48
  # @param other_identifiers [Symbol] array of symbols if specifying multiple outputs
48
49
  # @param output_definition [Hash] options for output
49
- # @option output_definition [String] :type text | textarea | oauth_credentials
50
+ # @option output_definition [String] :type text, textarea, or oauth_credentials
50
51
  # @return [void]
51
52
  # @example
52
53
  # output :patient_id, :condition_id, :observation_id
@@ -121,7 +121,7 @@ module Inferno
121
121
  expires_in = token_response_body['expires_in'].is_a?(Numeric) ? token_response_body['expires_in'] : nil
122
122
 
123
123
  self.access_token = token_response_body['access_token']
124
- self.refresh_token = token_response_body['refresh_token']
124
+ self.refresh_token = token_response_body['refresh_token'] if token_response_body['refresh_token'].present?
125
125
  self.expires_in = expires_in
126
126
  self.token_retrieval_time = DateTime.now
127
127
 
@@ -89,6 +89,7 @@ module Inferno
89
89
  # Specify the named requests made by a test
90
90
  #
91
91
  # @param identifiers [Symbol] one or more request identifiers
92
+ # @return [void]
92
93
  def makes_request(*identifiers)
93
94
  named_requests_made.concat(identifiers).uniq!
94
95
  identifiers.each do |identifier|
@@ -99,6 +100,7 @@ module Inferno
99
100
  # Specify the name for a request received by a test
100
101
  #
101
102
  # @param identifier [Symbol]
103
+ # @return [void]
102
104
  def receives_request(identifier)
103
105
  config.add_request(identifier)
104
106
  @incoming_request_name = identifier
@@ -112,6 +114,7 @@ module Inferno
112
114
  # Specify the named requests used by a test
113
115
  #
114
116
  # @param identifiers [Symbol] one or more request identifiers
117
+ # @return [void]
115
118
  def uses_request(*identifiers)
116
119
  named_requests_used.concat(identifiers).uniq!
117
120
  identifiers.each do |identifier|
@@ -5,6 +5,7 @@ module Inferno
5
5
  # Halt execution of the current test and mark it as passed.
6
6
  #
7
7
  # @param message [String]
8
+ # @return [void]
8
9
  def pass(message = '')
9
10
  raise Exceptions::PassException, message
10
11
  end
@@ -14,6 +15,7 @@ module Inferno
14
15
  #
15
16
  # @param test [Boolean]
16
17
  # @param message [String]
18
+ # @return [void]
17
19
  def pass_if(test, message = '')
18
20
  raise Exceptions::PassException, message if test
19
21
  end
@@ -21,6 +23,7 @@ module Inferno
21
23
  # Halt execution of the current test and mark it as skipped.
22
24
  #
23
25
  # @param message [String]
26
+ # @return [void]
24
27
  def skip(message = '')
25
28
  raise Exceptions::SkipException, message
26
29
  end
@@ -30,6 +33,7 @@ module Inferno
30
33
  #
31
34
  # @param test [Boolean]
32
35
  # @param message [String]
36
+ # @return [void]
33
37
  def skip_if(test, message = '')
34
38
  raise Exceptions::SkipException, message if test
35
39
  end
@@ -37,6 +41,7 @@ module Inferno
37
41
  # Halt execution of the current test and mark it as omitted.
38
42
  #
39
43
  # @param message [String]
44
+ # @return [void]
40
45
  def omit(message = '')
41
46
  raise Exceptions::OmitException, message
42
47
  end
@@ -46,6 +51,7 @@ module Inferno
46
51
  #
47
52
  # @param test [Boolean]
48
53
  # @param message [String]
54
+ # @return [void]
49
55
  def omit_if(test, message = '')
50
56
  raise Exceptions::OmitException, message if test
51
57
  end
@@ -75,6 +81,7 @@ module Inferno
75
81
  # @param message [String]
76
82
  # @param timeout [Integer] Number of seconds to wait for an incoming
77
83
  # request
84
+ # @return [void]
78
85
  def wait(identifier:, message: '', timeout: 300)
79
86
  identifier(identifier)
80
87
  wait_timeout(timeout)
@@ -268,7 +268,6 @@ module Inferno
268
268
  #
269
269
  # @param optional [Boolean]
270
270
  # @return [void]
271
- #
272
271
  def optional(optional = true) # rubocop:disable Style/OptionalBooleanParameter
273
272
  @optional = optional
274
273
  end
@@ -347,6 +346,7 @@ module Inferno
347
346
  # route. The block has access to the `request` method which returns a
348
347
  # {Inferno::Entities::Request} object with the information for the
349
348
  # incoming request.
349
+ # @return [void]
350
350
  def resume_test_route(method, path, &block)
351
351
  route_class = Class.new(ResumeTestRoute) do |klass|
352
352
  klass.singleton_class.instance_variable_set(:@test_run_identifier_block, block)
@@ -368,6 +368,7 @@ module Inferno
368
368
  # compatible object (e.g. a `Proc` object, a [Sinatra
369
369
  # app](http://sinatrarb.com/)) as described in the [Hanami Router
370
370
  # documentation.](https://github.com/hanami/router/tree/f41001d4c3ee9e2d2c7bb142f74b43f8e1d3a265#mount-rack-applications)
371
+ # @return [void]
371
372
  def route(method, path, handler)
372
373
  Inferno.routes << { method:, path:, handler:, suite: }
373
374
  end
@@ -414,6 +415,7 @@ module Inferno
414
415
  # group from: :ig_v2_group do
415
416
  # required_suite_options ig_version: 'ig_v2'
416
417
  # end
418
+ # @return [void]
417
419
  def required_suite_options(suite_option_requirements)
418
420
  @suite_option_requirements =
419
421
  suite_option_requirements.map do |key, value|
@@ -436,6 +438,7 @@ module Inferno
436
438
  end
437
439
  end
438
440
 
441
+ # @private
439
442
  def inspect
440
443
  non_dynamic_ancestor = ancestors.find { |ancestor| !ancestor.to_s.start_with? '#' }
441
444
  "#<#{non_dynamic_ancestor}".tap do |inspect_string|
@@ -58,29 +58,29 @@ module Inferno
58
58
  # Find a response header
59
59
  #
60
60
  # @param name [String] the header name
61
- # @return [Inferno::Entities::RequestHeader, nil]
61
+ # @return [Inferno::Entities::Header, nil]
62
62
  def response_header(name)
63
63
  response_headers.find { |header| header.name.casecmp(name).zero? }
64
64
  end
65
65
 
66
66
  # Find a request header
67
67
  #
68
- # @param name [String] the header name
69
- # @return [Inferno::Entities::RequestHeader, nil]
68
+ # @param name [String] the header name.
69
+ # @return [Inferno::Entities::Header, nil]
70
70
  def request_header(name)
71
71
  request_headers.find { |header| header.name.casecmp(name).zero? }
72
72
  end
73
73
 
74
74
  # All of the request headers
75
75
  #
76
- # @return [Array<Inferno::Entities::RequestHeader>]
76
+ # @return [Array<Inferno::Entities::Header>]
77
77
  def request_headers
78
78
  headers.select(&:request?)
79
79
  end
80
80
 
81
81
  # All of the response headers
82
82
  #
83
- # @return [Array<Inferno::Entities::RequestHeader>]
83
+ # @return [Array<Inferno::Entities::Header>]
84
84
  def response_headers
85
85
  headers.select(&:response?)
86
86
  end
@@ -131,7 +131,7 @@ module Inferno
131
131
 
132
132
  # Return the FHIR resource from the response body.
133
133
  #
134
- # @return [FHIR::Model]
134
+ # @return [FHIR::Model, nil]
135
135
  def resource
136
136
  FHIR.from_contents(response_body)
137
137
  end
@@ -28,6 +28,11 @@ module Inferno
28
28
  @messages ||= []
29
29
  end
30
30
 
31
+ # Add a message to the result.
32
+ #
33
+ # @param type [String] error, warning, or info
34
+ # @param message [String]
35
+ # @return [void]
31
36
  def add_message(type, message)
32
37
  messages << { type: type.to_s, message: format_markdown(message) }
33
38
  end
@@ -40,7 +45,6 @@ module Inferno
40
45
  # @example
41
46
  # output(patient_id: '5', bearer_token: 'ABC')
42
47
  def output(outputs)
43
- # TODO: update to track outputs that need to be updated
44
48
  outputs.each do |key, value|
45
49
  send("#{key}=", value)
46
50
  outputs_to_persist[key] = value
@@ -158,6 +162,7 @@ module Inferno
158
162
  end
159
163
  end
160
164
 
165
+ # @private
161
166
  def repository
162
167
  Inferno::Repositories::Tests.new
163
168
  end
@@ -1,6 +1,5 @@
1
1
  require_relative '../dsl'
2
2
  require_relative '../repositories/test_groups'
3
- require_relative '../repositories/test_sessions'
4
3
 
5
4
  module Inferno
6
5
  module Entities
@@ -29,6 +28,7 @@ module Inferno
29
28
  end
30
29
 
31
30
  class << self
31
+ # @private
32
32
  def repository
33
33
  Inferno::Repositories::TestGroups.new
34
34
  end
@@ -54,12 +54,14 @@ module Inferno
54
54
  # Methods to configure Inferno::DSL::Runnable
55
55
 
56
56
  # Add a child group
57
+ # @return [void]
57
58
  def group(...)
58
59
  child_metadata(group_metadata)
59
60
  define_child(...)
60
61
  end
61
62
 
62
63
  # Add a test
64
+ # @return [void]
63
65
  def test(...)
64
66
  child_metadata(test_metadata)
65
67
  define_child(...)
@@ -109,6 +111,7 @@ module Inferno
109
111
  # UI, and this group must be run as a group.
110
112
  #
111
113
  # @param value [Boolean]
114
+ # @return [void]
112
115
  def run_as_group(value = true) # rubocop:disable Style/OptionalBooleanParameter
113
116
  @run_as_group = value
114
117
  end
@@ -28,6 +28,7 @@ module Inferno
28
28
  @default_group
29
29
  end
30
30
 
31
+ # @private
31
32
  def repository
32
33
  Inferno::Repositories::TestSuites.new
33
34
  end
@@ -44,6 +45,7 @@ module Inferno
44
45
  # Methods to configure Inferno::DSL::Runnable
45
46
 
46
47
  # Add a child group
48
+ # @return [void]
47
49
  def group(...)
48
50
  child_metadata(group_metadata)
49
51
  define_child(...)
@@ -93,6 +95,7 @@ module Inferno
93
95
  # @yieldreturn [Array<Hash>] An array of message hashes containing the
94
96
  # keys `:type` and `:message`. Type options are `info`, `warning`, and
95
97
  # `error`.
98
+ # @return [void]
96
99
  def check_configuration(&block)
97
100
  @check_configuration_block = block
98
101
  end
@@ -134,6 +137,7 @@ module Inferno
134
137
  # group from: :ig_v2_group do
135
138
  # required_suite_options ig_version: 'ig_v2'
136
139
  # end
140
+ # @return [void]
137
141
  def suite_option(identifier, **option_params)
138
142
  suite_options << DSL::SuiteOption.new(option_params.merge(id: identifier))
139
143
  end
@@ -27,7 +27,7 @@ end
27
27
  module InfernoJson
28
28
  def from_json(json)
29
29
  resource = super(json)
30
- resource.source_text = json
30
+ resource&.source_text = json
31
31
  resource
32
32
  end
33
33
  end
@@ -37,7 +37,7 @@ end
37
37
  module InfernoXml
38
38
  def from_xml(xml)
39
39
  resource = super(xml)
40
- resource.source_text = xml
40
+ resource&.source_text = xml
41
41
  resource
42
42
  end
43
43
  end