bonnie_bundler 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +6 -6
- data/bonnie-bundler.gemspec +1 -1
- data/lib/bonnie_bundler.rb +1 -0
- data/lib/measures/loading/cql_loader.rb +25 -12
- data/lib/measures/loading/exceptions.rb +0 -2
- data/lib/measures/loading/value_set_loader.rb +77 -97
- data/lib/util/vsac_api.rb +274 -0
- data/test/fixtures/PVC2_v5_4_Unused_Support_Libraries.zip +0 -0
- data/test/fixtures/vcr_cassettes/valid_vsac_response_pvc_unused_libraries.yml +4286 -0
- data/test/fixtures/vcr_cassettes/vs_loading_500_response.yml +633 -0
- data/test/fixtures/vcr_cassettes/vs_loading_empty_concept_list.yml +174 -0
- data/test/fixtures/vcr_cassettes/vs_loading_meausre_defined_no_backup_profile.yml +1237 -0
- data/test/fixtures/vcr_cassettes/vs_loading_release.yml +17035 -0
- data/test/fixtures/vcr_cassettes/vsac_auth_bad_credentials.yml +57 -0
- data/test/fixtures/vcr_cassettes/vsac_auth_bad_ticket.yml +57 -0
- data/test/fixtures/vcr_cassettes/vsac_auth_good_credentials.yml +57 -0
- data/test/fixtures/vcr_cassettes/vsac_auth_good_credentials_and_simple_call.yml +177 -0
- data/test/fixtures/vcr_cassettes/vsac_util_get_profiles.yml +74 -0
- data/test/fixtures/vcr_cassettes/vsac_util_get_program_details_CMS_Hybrid.yml +57 -0
- data/test/fixtures/vcr_cassettes/vsac_util_get_program_details_CMS_eCQM.yml +64 -0
- data/test/fixtures/vcr_cassettes/vsac_util_get_program_details_HL7_C-CDA.yml +58 -0
- data/test/fixtures/vcr_cassettes/vsac_util_get_program_details_invalid.yml +53 -0
- data/test/fixtures/vcr_cassettes/vsac_util_get_programs.yml +64 -0
- data/test/fixtures/vcr_cassettes/vsac_vs_include_draft_no_profile.yml +57 -0
- data/test/fixtures/vcr_cassettes/vsac_vs_include_draft_with_profile.yml +177 -0
- data/test/fixtures/vcr_cassettes/vsac_vs_no_options.yml +177 -0
- data/test/fixtures/vcr_cassettes/vsac_vs_not_found.yml +164 -0
- data/test/fixtures/vcr_cassettes/vsac_vs_release.yml +4802 -0
- data/test/fixtures/vcr_cassettes/vsac_vs_version.yml +370 -0
- data/test/test_helper.rb +9 -4
- data/test/unit/cql_loader_test.rb +42 -15
- data/test/unit/load_mat_export_test.rb +10 -13
- data/test/unit/measure_complexity_test.rb +1 -1
- data/test/unit/measure_diff_test.rb +4 -4
- data/test/unit/storing_mat_export_package_test.rb +1 -1
- data/test/unit/value_set_loading_test.rb +58 -16
- data/test/unit/vsac_api_auth_test.rb +129 -0
- data/test/unit/vsac_api_test.rb +77 -0
- data/test/unit/vsac_api_util_test.rb +139 -0
- metadata +29 -3
@@ -16,11 +16,8 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
16
16
|
user = User.new
|
17
17
|
user.save
|
18
18
|
measure_details = { 'episode_of_care'=> false }
|
19
|
-
|
20
|
-
|
21
|
-
includeDraft=true
|
22
|
-
ticket_granting_ticket=nil
|
23
|
-
Measures::CqlLoader.load(@cql_draft_measure_mat_export, user, measure_details, ENV['VSAC_USERNAME'], ENV['VSAC_PASSWORD'], overwrite_valuesets, cache, includeDraft, ticket_granting_ticket).save
|
19
|
+
|
20
|
+
Measures::CqlLoader.load(@cql_draft_measure_mat_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'], include_draft: true }, get_ticket_granting_ticket).save
|
24
21
|
assert_equal 1, CqlMeasure.all.count
|
25
22
|
measure = CqlMeasure.all.first
|
26
23
|
assert_equal "Screening for Depression", measure.title
|
@@ -42,7 +39,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
42
39
|
|
43
40
|
VCR.use_cassette("valid_vsac_response") do
|
44
41
|
measure_details = { 'episode_of_care'=> false }
|
45
|
-
Measures::CqlLoader.load(@cql_mat_export, user, measure_details,
|
42
|
+
Measures::CqlLoader.load(@cql_mat_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
46
43
|
assert_equal 1, CqlMeasure.all.count
|
47
44
|
end
|
48
45
|
|
@@ -60,7 +57,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
60
57
|
user = User.new
|
61
58
|
user.save
|
62
59
|
measure_details = { 'episode_of_care'=> false }
|
63
|
-
Measures::CqlLoader.load(@cql_mat_export, user, measure_details,
|
60
|
+
Measures::CqlLoader.load(@cql_mat_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
64
61
|
assert_equal 1, CqlMeasure.all.count
|
65
62
|
measure = CqlMeasure.all.first
|
66
63
|
assert_equal "BCSTest", measure.title
|
@@ -77,7 +74,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
77
74
|
user.save
|
78
75
|
|
79
76
|
measure_details = { 'episode_of_care'=> false }
|
80
|
-
Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details,
|
77
|
+
Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
81
78
|
assert_equal 1, CqlMeasure.all.count
|
82
79
|
measure = CqlMeasure.all.first
|
83
80
|
assert_equal "Test 158", measure.title
|
@@ -96,7 +93,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
96
93
|
user.save
|
97
94
|
|
98
95
|
measure_details = { 'episode_of_care'=> false }
|
99
|
-
Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details,
|
96
|
+
Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
100
97
|
assert_equal 1, CqlMeasure.all.count
|
101
98
|
measure = CqlMeasure.all.first
|
102
99
|
assert_equal "Test 158", measure.title
|
@@ -114,7 +111,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
114
111
|
user.save
|
115
112
|
|
116
113
|
measure_details = { 'episode_of_care'=> false }
|
117
|
-
Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details,
|
114
|
+
Measures::CqlLoader.load(@cql_mat_5_4_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
118
115
|
assert_equal 1, CqlMeasure.all.count
|
119
116
|
measure = CqlMeasure.all.first
|
120
117
|
assert_equal 1, CqlMeasurePackage.all.count
|
@@ -132,7 +129,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
132
129
|
user.save
|
133
130
|
|
134
131
|
measure_details = { 'episode_of_care'=> false }
|
135
|
-
Measures::CqlLoader.load(@cql_multi_library_mat_export, user, measure_details,
|
132
|
+
Measures::CqlLoader.load(@cql_multi_library_mat_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
136
133
|
assert_equal 1, CqlMeasure.all.count
|
137
134
|
measure = CqlMeasure.all.first
|
138
135
|
assert_equal (measure.elm.instance_of? Array), true
|
@@ -154,7 +151,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
154
151
|
user2 = User.new
|
155
152
|
user2.save
|
156
153
|
VCR.use_cassette("valid_vsac_response_158") do
|
157
|
-
Measures::CqlLoader.load(cql_mat_export, user, {}).save
|
154
|
+
Measures::CqlLoader.load(cql_mat_export, user, {}, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
158
155
|
end
|
159
156
|
|
160
157
|
measure = CqlMeasure.all.by_user(user).first
|
@@ -168,7 +165,7 @@ class LoadMATExportTest < ActiveSupport::TestCase
|
|
168
165
|
# Add the same measure not associated with a user, there should be 2 measures and
|
169
166
|
# and twice as many value sets in the db after loading
|
170
167
|
VCR.use_cassette("valid_vsac_response_158") do
|
171
|
-
Measures::CqlLoader.load(cql_mat_export, user2, {}).save
|
168
|
+
Measures::CqlLoader.load(cql_mat_export, user2, {}, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
172
169
|
end
|
173
170
|
measure2 = CqlMeasure.all.by_user(user2).first
|
174
171
|
assert_equal 1, CqlMeasure.by_user(user).count
|
@@ -12,7 +12,7 @@ class MeasureComplexityTest < ActiveSupport::TestCase
|
|
12
12
|
user = User.new
|
13
13
|
user.save
|
14
14
|
measure_details = { 'episode_of_care'=> false }
|
15
|
-
Measures::CqlLoader.load(@cql_mat_export, user, measure_details,
|
15
|
+
Measures::CqlLoader.load(@cql_mat_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
16
16
|
assert_equal 1, CqlMeasure.all.count
|
17
17
|
measure = CqlMeasure.all.first
|
18
18
|
assert_equal 10, measure.complexity["variables"].length
|
@@ -10,7 +10,7 @@ class MeasureDiffTest < ActiveSupport::TestCase
|
|
10
10
|
user = User.new
|
11
11
|
user.save
|
12
12
|
measure_details = { 'episode_of_care'=> false }
|
13
|
-
Measures::CqlLoader.load(@previous_measure, user, measure_details,
|
13
|
+
Measures::CqlLoader.load(@previous_measure, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
14
14
|
end
|
15
15
|
assert_equal 1, CqlMeasure.all.count
|
16
16
|
measure = CqlMeasure.all.first
|
@@ -27,7 +27,7 @@ class MeasureDiffTest < ActiveSupport::TestCase
|
|
27
27
|
user = User.new
|
28
28
|
user.save
|
29
29
|
measure_details = { 'episode_of_care'=> false }
|
30
|
-
Measures::CqlLoader.load(@updated_measure, user, measure_details,
|
30
|
+
Measures::CqlLoader.load(@updated_measure, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
31
31
|
end
|
32
32
|
assert_equal 1, CqlMeasure.all.count
|
33
33
|
measure = CqlMeasure.all.first
|
@@ -44,7 +44,7 @@ class MeasureDiffTest < ActiveSupport::TestCase
|
|
44
44
|
user = User.new
|
45
45
|
user.save
|
46
46
|
measure_details = { 'episode_of_care'=> false }
|
47
|
-
Measures::CqlLoader.load(@previous_measure, user, measure_details,
|
47
|
+
Measures::CqlLoader.load(@previous_measure, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
48
48
|
end
|
49
49
|
assert_equal 1, CqlMeasure.all.count
|
50
50
|
assert_equal 1, CqlMeasurePackage.all.count
|
@@ -55,7 +55,7 @@ class MeasureDiffTest < ActiveSupport::TestCase
|
|
55
55
|
user = User.new
|
56
56
|
user.save
|
57
57
|
measure_details = { 'episode_of_care'=> false }
|
58
|
-
Measures::CqlLoader.load(@updated_measure, user, measure_details,
|
58
|
+
Measures::CqlLoader.load(@updated_measure, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
59
59
|
end
|
60
60
|
assert_equal 2, CqlMeasure.all.count
|
61
61
|
assert_equal 2, CqlMeasurePackage.all.count
|
@@ -14,7 +14,7 @@ class StoringMATExportPackageTest < ActiveSupport::TestCase
|
|
14
14
|
user.save
|
15
15
|
|
16
16
|
measure_details = { 'episode_of_care'=> false }
|
17
|
-
Measures::CqlLoader.load(@cql_mat_export, user, measure_details,
|
17
|
+
Measures::CqlLoader.load(@cql_mat_export, user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket).save
|
18
18
|
assert_equal 1, CqlMeasure.all.count
|
19
19
|
measure = CqlMeasure.all.first
|
20
20
|
assert_equal "Test 158", measure.title
|
@@ -15,7 +15,7 @@ class ValueSetLoadingTest < ActiveSupport::TestCase
|
|
15
15
|
VCR.use_cassette("vs_loading_draft_no_profile_version") do
|
16
16
|
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts.zip")
|
17
17
|
measure_details = {}
|
18
|
-
measure = Measures::CqlLoader.load(mat_file, @user, measure_details,
|
18
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'], include_draft: true }, get_ticket_granting_ticket)
|
19
19
|
measure.value_sets.each do |vs|
|
20
20
|
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
21
21
|
assert_equal 154, vs.concepts.count
|
@@ -29,7 +29,7 @@ class ValueSetLoadingTest < ActiveSupport::TestCase
|
|
29
29
|
VCR.use_cassette("vs_loading_draft_profile") do
|
30
30
|
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts_With_Profiles.zip")
|
31
31
|
measure_details = {}
|
32
|
-
measure = Measures::CqlLoader.load(mat_file, @user, measure_details,
|
32
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'], include_draft: true }, get_ticket_granting_ticket)
|
33
33
|
measure.value_sets.each do |vs|
|
34
34
|
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
35
35
|
assert_equal 154, vs.concepts.count
|
@@ -44,7 +44,7 @@ class ValueSetLoadingTest < ActiveSupport::TestCase
|
|
44
44
|
VCR.use_cassette("vs_loading_draft_verion") do
|
45
45
|
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts_Version.zip")
|
46
46
|
measure_details = {}
|
47
|
-
measure = Measures::CqlLoader.load(mat_file, @user, measure_details,
|
47
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { profile: APP_CONFIG['vsac']['default_profile'], include_draft: true }, get_ticket_granting_ticket)
|
48
48
|
measure.value_sets.each do |vs|
|
49
49
|
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
50
50
|
assert_equal 154, vs.concepts.count
|
@@ -54,11 +54,11 @@ class ValueSetLoadingTest < ActiveSupport::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
test 'Loading without IncludeDraft and no Profile or Version' do
|
57
|
-
# Expects that
|
57
|
+
# Expects that provided profile will be used
|
58
58
|
VCR.use_cassette("vs_loading_no_profile_version") do
|
59
59
|
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts.zip")
|
60
60
|
measure_details = {}
|
61
|
-
measure = Measures::CqlLoader.load(mat_file, @user, measure_details,
|
61
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { measure_defined: true, profile: APP_CONFIG['vsac']['default_profile'] }, get_ticket_granting_ticket)
|
62
62
|
measure.value_sets.each do |vs|
|
63
63
|
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
64
64
|
assert_equal 154, vs.concepts.count
|
@@ -67,24 +67,40 @@ class ValueSetLoadingTest < ActiveSupport::TestCase
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
test '
|
71
|
-
# Expects that
|
72
|
-
VCR.use_cassette("
|
70
|
+
test 'Loading with measure_defined and no backup_profile' do
|
71
|
+
# Expects that no vsac options will be used. just bare query with only oid parameter
|
72
|
+
VCR.use_cassette("vs_loading_meausre_defined_no_backup_profile") do
|
73
73
|
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts.zip")
|
74
74
|
measure_details = {}
|
75
|
-
|
76
|
-
|
75
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { measure_defined: true }, get_ticket_granting_ticket)
|
76
|
+
measure.value_sets.each do |vs|
|
77
|
+
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
78
|
+
assert_equal 175, vs.concepts.count
|
79
|
+
end
|
77
80
|
end
|
78
|
-
assert_equal 'Error Loading Value Sets from VSAC: undefined method `id\' for "fake user":String', exception.message
|
79
81
|
end
|
80
82
|
end
|
81
|
-
|
82
|
-
test 'Loading
|
83
|
+
|
84
|
+
test 'Loading with release' do
|
85
|
+
# Expects that the provided release will be used
|
86
|
+
VCR.use_cassette("vs_loading_release") do
|
87
|
+
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts.zip")
|
88
|
+
measure_details = {}
|
89
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { release: 'eCQM Update 2018 EP-EC and EH' }, get_ticket_granting_ticket)
|
90
|
+
measure.value_sets.each do |vs|
|
91
|
+
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
92
|
+
assert_equal 162, vs.concepts.count
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'Loading measure defined value sets defined by Profile' do
|
83
99
|
# Expects that given profile will be used
|
84
100
|
VCR.use_cassette("vs_loading_profile") do
|
85
101
|
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts_With_Profiles.zip")
|
86
102
|
measure_details = {}
|
87
|
-
measure = Measures::CqlLoader.load(mat_file, @user, measure_details,
|
103
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { measure_defined: true }, get_ticket_granting_ticket)
|
88
104
|
measure.value_sets.each do |vs|
|
89
105
|
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
90
106
|
assert_equal 152, vs.concepts.count
|
@@ -93,12 +109,12 @@ class ValueSetLoadingTest < ActiveSupport::TestCase
|
|
93
109
|
end
|
94
110
|
end
|
95
111
|
|
96
|
-
test 'Loading
|
112
|
+
test 'Loading measure defined value sets defined by Version' do
|
97
113
|
# Expects that given version will be used
|
98
114
|
VCR.use_cassette("vs_loading_version") do
|
99
115
|
mat_file = File.new File.join("test", "fixtures", "vs_loading", "DocofMeds_v5_1_Artifacts_Version.zip")
|
100
116
|
measure_details = {}
|
101
|
-
measure = Measures::CqlLoader.load(mat_file, @user, measure_details,
|
117
|
+
measure = Measures::CqlLoader.load(mat_file, @user, measure_details, { measure_defined: true }, get_ticket_granting_ticket)
|
102
118
|
measure.value_sets.each do |vs|
|
103
119
|
if vs.oid == "2.16.840.1.113883.3.600.1.1834"
|
104
120
|
assert_equal 148, vs.concepts.count
|
@@ -106,4 +122,30 @@ class ValueSetLoadingTest < ActiveSupport::TestCase
|
|
106
122
|
end
|
107
123
|
end
|
108
124
|
end
|
125
|
+
|
126
|
+
test 'Loading valueset that returns an empty concept list' do
|
127
|
+
# DO NOT re-record this cassette. the response for this valueset may have changed.
|
128
|
+
VCR.use_cassette("vs_loading_empty_concept_list") do
|
129
|
+
# As of 4/11/18 this value set uses a codesystem not in Latest eCQM profile and returns an empty concept list
|
130
|
+
value_sets = [ { oid: '2.16.840.1.113762.1.4.1179.2'} ]
|
131
|
+
error = assert_raise Util::VSAC::VSEmptyError do
|
132
|
+
Measures::ValueSetLoader.load_value_sets_from_vsac(value_sets, { profile: 'Latest eCQM', include_draft: true }, get_ticket_granting_ticket, @user, 'fake-measure-id')
|
133
|
+
end
|
134
|
+
assert_equal '2.16.840.1.113762.1.4.1179.2', error.oid
|
135
|
+
assert_equal 0, HealthDataStandards::SVS::ValueSet.by_user(@user).where(version: 'Draft-fake-measure-id', oid: '2.16.840.1.113762.1.4.1179.2').count
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
test 'Loading valueset that causes 500 response from VSAC' do
|
140
|
+
VCR.use_cassette("vs_loading_500_response") do
|
141
|
+
# Adding an alphabetic character on to the end of the oid. unfortuately a nominal parameter situation cannot be found to cause
|
142
|
+
# a 500 response at the time of this test creation. but it is a situation that has happened for non-author accounts occasionally
|
143
|
+
value_sets = [ { oid: '2.16.840.1.113762.1.4.1179.2f'} ]
|
144
|
+
error = assert_raise Util::VSAC::VSACError do
|
145
|
+
Measures::ValueSetLoader.load_value_sets_from_vsac(value_sets, { profile: 'Latest eCQM', include_draft: true }, get_ticket_granting_ticket, @user, 'fake-measure-id')
|
146
|
+
end
|
147
|
+
assert_equal 'Server error response from VSAC for (2.16.840.1.113762.1.4.1179.2f).', error.message
|
148
|
+
assert_equal 0, HealthDataStandards::SVS::ValueSet.by_user(@user).where(version: 'Draft-fake-measure-id', oid: '2.16.840.1.113762.1.4.1179.2f').count
|
149
|
+
end
|
150
|
+
end
|
109
151
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'vcr_setup.rb'
|
3
|
+
|
4
|
+
# Tests that ensure VSAC authentication related situations are handled
|
5
|
+
class VSACAPIAuthTest < ActiveSupport::TestCase
|
6
|
+
|
7
|
+
test 'valid username and password provided' do
|
8
|
+
VCR.use_cassette("vsac_auth_good_credentials") do
|
9
|
+
assert_nothing_raised do
|
10
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
11
|
+
assert_not_nil api.ticket_granting_ticket
|
12
|
+
assert_not_nil api.ticket_granting_ticket[:ticket]
|
13
|
+
assert_not_nil api.ticket_granting_ticket[:expires]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'invalid username and password provided' do
|
19
|
+
VCR.use_cassette("vsac_auth_bad_credentials") do
|
20
|
+
assert_raise Util::VSAC::VSACInvalidCredentialsError do
|
21
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: 'baduser', password: 'badpass')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'empty username and password provided' do
|
27
|
+
api = nil
|
28
|
+
assert_nothing_raised do
|
29
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: nil, password: nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
# now attempt to get a valueset
|
33
|
+
assert_raise Util::VSAC::VSACNoCredentialsError do
|
34
|
+
api.get_valueset('2.16.840.1.113762.1.4.1')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'provided username but no password' do
|
39
|
+
api = nil
|
40
|
+
assert_nothing_raised do
|
41
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: "vsacuser")
|
42
|
+
end
|
43
|
+
|
44
|
+
# now attempt to get a valueset
|
45
|
+
assert_raise Util::VSAC::VSACNoCredentialsError do
|
46
|
+
api.get_valueset('2.16.840.1.113762.1.4.1')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'provided password but no username' do
|
51
|
+
api = nil
|
52
|
+
assert_nothing_raised do
|
53
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: "vsacuser")
|
54
|
+
end
|
55
|
+
|
56
|
+
# now attempt to get a valueset
|
57
|
+
assert_raise Util::VSAC::VSACNoCredentialsError do
|
58
|
+
api.get_valueset('2.16.840.1.113762.1.4.1')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'valid ticket_granting_ticket provided and used' do
|
63
|
+
VCR.use_cassette("vsac_auth_good_credentials_and_simple_call") do
|
64
|
+
# first get a ticket_granting_ticket
|
65
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
66
|
+
assert_not_nil api.ticket_granting_ticket
|
67
|
+
|
68
|
+
reused_ticket_granting_ticket = {
|
69
|
+
ticket: api.ticket_granting_ticket[:ticket],
|
70
|
+
expires: api.ticket_granting_ticket[:expires]
|
71
|
+
}
|
72
|
+
|
73
|
+
newApi = nil
|
74
|
+
# ensure that nothing is raised when constucting api using reused tgt
|
75
|
+
assert_nothing_raised do
|
76
|
+
newApi = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], ticket_granting_ticket: reused_ticket_granting_ticket)
|
77
|
+
valueset = api.get_valueset('2.16.840.1.113762.1.4.1')
|
78
|
+
assert_not_nil valueset
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test 'ticket_granting_ticket provided is missing or missing fields' do
|
84
|
+
# empty object
|
85
|
+
assert_raise Util::VSAC::VSACArgumentError do
|
86
|
+
Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], ticket_granting_ticket: {})
|
87
|
+
end
|
88
|
+
|
89
|
+
# missing ticket
|
90
|
+
assert_raise Util::VSAC::VSACArgumentError do
|
91
|
+
Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], ticket_granting_ticket: { expires: Time.now + 2.hours })
|
92
|
+
end
|
93
|
+
|
94
|
+
# missing expires
|
95
|
+
assert_raise Util::VSAC::VSACArgumentError do
|
96
|
+
Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], ticket_granting_ticket: { ticket: "ImATicketGrantingTicket" })
|
97
|
+
end
|
98
|
+
|
99
|
+
# nil, this shouln't throw an error, It will assume no credentials provided
|
100
|
+
assert_nothing_raised do
|
101
|
+
Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], ticket_granting_ticket: nil)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
test 'ticket_granting_ticket provided expires time has expired' do
|
106
|
+
assert_raise Util::VSAC::VSACTicketExpiredError do
|
107
|
+
Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'],
|
108
|
+
ticket_granting_ticket: { ticket: "ImATicketGrantingTicket", expires: Time.now - 10.minutes })
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
test 'ticket_granting_ticket provided ticket is bad' do
|
113
|
+
api = nil
|
114
|
+
assert_nothing_raised do
|
115
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'],
|
116
|
+
ticket_granting_ticket: { ticket: "ImABadTicketGrantingTicket", expires: Time.now + 10.minutes })
|
117
|
+
end
|
118
|
+
|
119
|
+
# attempt to get something with the bad ticket
|
120
|
+
VCR.use_cassette("vsac_auth_bad_ticket") do
|
121
|
+
assert_raise Util::VSAC::VSACTicketExpiredError do
|
122
|
+
api.get_valueset('2.16.840.1.113762.1.4.1')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# make sure the API has marked the ticket expired
|
127
|
+
assert_equal true, api.ticket_granting_ticket[:expires] <= Time.now
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'vcr_setup.rb'
|
3
|
+
|
4
|
+
class VSACApiTest < ActiveSupport::TestCase
|
5
|
+
test 'api with insufficent config' do
|
6
|
+
assert_raise Util::VSAC::VSACArgumentError do
|
7
|
+
Util::VSAC::VSACAPI.new(config: {})
|
8
|
+
end
|
9
|
+
|
10
|
+
assert_raise Util::VSAC::VSACArgumentError do
|
11
|
+
Util::VSAC::VSACAPI.new(config: nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_raise Util::VSAC::VSACArgumentError do
|
15
|
+
Util::VSAC::VSACAPI.new(config: { auth_url: "hi.com", content_url: "there"})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'get_valueset with version' do
|
20
|
+
VCR.use_cassette("vsac_vs_version") do
|
21
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
22
|
+
vs = api.get_valueset("2.16.840.1.113883.3.600.1.1834", version: "MU2 EP Update 2014-07-01")
|
23
|
+
assert_not_nil vs
|
24
|
+
doc = Nokogiri::XML(vs)
|
25
|
+
assert_equal 148, doc.xpath("ns0:RetrieveMultipleValueSetsResponse/ns0:DescribedValueSet/ns0:ConceptList/ns0:Concept").count
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'get_valuest with include_draft no profile' do
|
30
|
+
VCR.use_cassette("vsac_vs_include_draft_no_profile") do
|
31
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
32
|
+
assert_raise Util::VSAC::VSACArgumentError do
|
33
|
+
api.get_valueset("2.16.840.1.113883.3.600.1.1834", include_draft: true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test 'get_valueset with include_draft specified profile' do
|
39
|
+
VCR.use_cassette("vsac_vs_include_draft_with_profile") do
|
40
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
41
|
+
vs = api.get_valueset("2.16.840.1.113762.1.4.1", include_draft: true, profile: "eCQM Update 2018-05-04")
|
42
|
+
assert_not_nil vs
|
43
|
+
doc = Nokogiri::XML(vs)
|
44
|
+
assert_equal 2, doc.xpath("ns0:RetrieveMultipleValueSetsResponse/ns0:DescribedValueSet/ns0:ConceptList/ns0:Concept").count
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'get_valueset no options' do
|
49
|
+
VCR.use_cassette("vsac_vs_no_options") do
|
50
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
51
|
+
vs = api.get_valueset("2.16.840.1.113762.1.4.1")
|
52
|
+
assert_not_nil vs
|
53
|
+
doc = Nokogiri::XML(vs)
|
54
|
+
assert_equal 2, doc.xpath("ns0:RetrieveMultipleValueSetsResponse/ns0:DescribedValueSet/ns0:ConceptList/ns0:Concept").count
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'get_valueset not found' do
|
59
|
+
VCR.use_cassette("vsac_vs_not_found") do
|
60
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
61
|
+
assert_raise Util::VSAC::VSNotFoundError do
|
62
|
+
api.get_valueset("bad.oid")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'get_valueset with release' do
|
68
|
+
VCR.use_cassette("vsac_vs_release") do
|
69
|
+
api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], username: ENV['VSAC_USERNAME'], password: ENV['VSAC_PASSWORD'])
|
70
|
+
vs = api.get_valueset("2.16.840.1.113762.1.4.1", release: "MU2 EP Update 2014-05-30")
|
71
|
+
assert_not_nil vs
|
72
|
+
doc = Nokogiri::XML(vs)
|
73
|
+
assert_equal 3, doc.xpath("ns0:RetrieveMultipleValueSetsResponse/ns0:DescribedValueSet/ns0:ConceptList/ns0:Concept").count
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|