This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
rights_metadata_spec.rb
430 lines (400 loc) · 17.2 KB
/
rights_metadata_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Dor::RightsMetadataDS do
before { stub_config }
after { unstub_config }
before do
@item = instantiate_fixture('druid:bb046xn0881', Dor::Item)
allow(Dor).to receive(:find).with(@item.pid).and_return(@item)
allow(Dor::Config.workflow.client).to receive(:milestones).and_return([])
end
it '#new' do
expect { described_class.new }.not_to raise_error
end
it 'has a rightsMetadata datastream accessible' do
expect(@item.datastreams['rightsMetadata']).to be_a(described_class)
expect(@item.rightsMetadata).to eq(@item.datastreams['rightsMetadata'])
end
describe 'upd_rights_xml_for_rights_type' do
let(:original_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world></world>
</machine>
</access>
<access type="read">
<machine>
<group>stanford</group>
<world rule="no-download"></world>
<location rule="no-download">reading_room</location>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:world_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<world/>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:world_no_download_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<world rule="no-download"/>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:stanford_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<group>stanford</group>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:stanford_no_download_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<group rule="no-download">stanford</group>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:loc_spec_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<location>spec</group>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:dark_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<none/>
</machine>
</access>
<access type="read">
<machine>
<none/>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:citation_only_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<none/>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
let(:loc_unsupported_rights_xml) do
<<-XML
<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<location>unsupported</group>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.</human>
<human type="creativeCommons">Attribution Non-Commercial 3.0 Unported</human>
<machine type="creativeCommons">by-nc</machine>
</use>
</rightsMetadata>
XML
end
it 'has the expected rights xml when read rights are set to world' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'world')
expect(rights_ng_xml).to be_equivalent_to world_rights_xml
end
it 'has the expected rights xml when read rights are set to world with the no-download rule' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'world-nd')
expect(rights_ng_xml).to be_equivalent_to world_no_download_rights_xml
end
it 'has the expected rights xml when read rights are set to group stanford' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'stanford')
expect(rights_ng_xml).to be_equivalent_to stanford_rights_xml
end
it 'has the expected rights xml when read rights are set to group stanford with the no-download rule' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'stanford-nd')
expect(rights_ng_xml).to be_equivalent_to stanford_no_download_rights_xml
end
it 'has the expected rights xml when read rights are set to location spec' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'loc:spec')
expect(rights_ng_xml).to be_equivalent_to loc_spec_rights_xml
end
it 'has the expected rights xml when read rights are set to dark' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'dark')
expect(rights_ng_xml).to be_equivalent_to dark_rights_xml
end
it 'has the expected rights xml when read rights are set to citation only' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'none')
expect(rights_ng_xml).to be_equivalent_to citation_only_rights_xml
end
it 'will set an unrecognized location, because it is not where rights type code is validated' do
rights_ng_xml = Nokogiri::XML(original_rights_xml)
described_class.upd_rights_xml_for_rights_type(rights_ng_xml, 'loc:unsupported')
expect(rights_ng_xml).to be_equivalent_to loc_unsupported_rights_xml
end
end
describe 'set_read_rights' do
it 'will raise an exception when an unsupported rights type is given' do
expect { @item.rightsMetadata.set_read_rights 'loc:unsupported' }.to raise_error ArgumentError, "Argument 'loc:unsupported' is not a recognized value"
end
it 'will set the xml properly and indicate that datastream content has changed' do
expect(described_class).to receive(:upd_rights_xml_for_rights_type).with(@item.rightsMetadata.ng_xml, 'world')
expect(@item.rightsMetadata).to receive(:ng_xml_will_change!).and_call_original
@item.rightsMetadata.set_read_rights 'world'
expect(@item.rightsMetadata.instance_variable_get(:@dra_object)).to be_nil
end
end
describe 'rightsMetadata' do
before do
@rm = @item.rightsMetadata
end
it 'has accessors from defined terminology' do
expect(@rm.copyright).to eq ['Courtesy of the Revs Institute for Automotive Research. All rights reserved unless otherwise indicated.']
expect(@rm.use_statement).to eq ['Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.']
expect(@rm.use_license).to eq ['by-nc']
## use.human differs from use_statement: the former hits multiple elements, the latter only one
expect(@rm.use.human).to eq ['Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.', 'Attribution Non-Commercial 3.0 Unported']
end
it 'has a Dor::RightsAuth dra_object' do
expect(@rm.dra_object).to be_a(Dor::RightsAuth)
expect(@rm.dra_object.index_elements).to match a_hash_including(primary: 'world_qualified', errors: [])
end
it 'reads creative commons licenses correctly' do
expect(@rm.creative_commons).to eq ['by-nc']
# The following tests fail if terminology defined with :type instead of :path => '/x/y[@type=...]'
expect(@rm.creative_commons_human).not_to include 'Users must contact the The Revs Institute for Automotive Research for re-use and reproduction information.'
expect(@rm.creative_commons_human).to eq ['Attribution Non-Commercial 3.0 Unported']
end
it 'does not test open data commons licenses' do
skip
end
end
describe 'to_solr' do
before do
allow(OpenURI).to receive(:open_uri).with('https://purl-test.stanford.edu/bb046xn0881.xml').and_return('<xml/>')
end
it 'has correct primary' do
doc = @item.to_solr
expect(doc).to match a_hash_including(
'rights_primary_ssi' => 'world_qualified',
'rights_descriptions_ssim' => include(
'location: reading_room (no-download)', 'stanford', 'world (no-download)', 'dark (file)'
),
'metadata_source_ssi' => 'DOR',
'title_tesim' => ['Indianapolis 500'],
'rights_characteristics_ssim' => include(
'world_discover', 'has_group_rights', 'has_rule', 'group|stanford', 'location', 'location_with_rule',
'world_read', 'world|no-download', 'profile:group1|location1|world1', 'none_read_file'
),
'use_license_machine_ssi' => 'by-nc',
'use_licenses_machine_ssim' => ['by-nc'],
'obj_rights_locations_ssim' => ['reading_room']
)
expect(doc).not_to include(
'rights_errors_ssim', 'file_rights_locations_ssim', 'obj_rights_agents_ssim', 'file_rights_agents_ssim'
) # don't include empties
end
it 'filters access_restricted from what gets aggregated into rights_descriptions_ssim' do
rights_md_ds = described_class.new
mock_dra_obj = double(Dor::RightsAuth)
expect(mock_dra_obj).to receive(:index_elements).with(no_args).at_least(:once).and_return(
primary: 'access_restricted',
errors: [],
terms: [],
obj_locations_qualified: [{ location: 'someplace', rule: 'somerule' }],
file_groups_qualified: [{ group: 'somegroup', rule: 'someotherrule' }]
)
expect(rights_md_ds).to receive(:dra_object).and_return(mock_dra_obj)
doc = rights_md_ds.to_solr
expect(doc).to match a_hash_including(
'rights_primary_ssi' => 'access_restricted',
'rights_descriptions_ssim' => include('location: someplace (somerule)', 'somegroup (file) (someotherrule)')
)
expect(doc).not_to match a_hash_including(
'rights_descriptions_ssim' => include('access_restricted')
)
end
it 'filters world_qualified from what gets aggregated into rights_descriptions_ssim' do
rights_md_ds = described_class.new
mock_dra_obj = double(Dor::RightsAuth)
expect(mock_dra_obj).to receive(:index_elements).with(no_args).at_least(:once).and_return(
primary: 'world_qualified',
errors: [],
terms: [],
obj_world_qualified: [{ rule: 'somerule' }]
)
expect(rights_md_ds).to receive(:dra_object).and_return(mock_dra_obj)
doc = rights_md_ds.to_solr
expect(doc).to match a_hash_including(
'rights_primary_ssi' => 'world_qualified',
'rights_descriptions_ssim' => include('world (somerule)')
)
expect(doc).not_to match a_hash_including(
'rights_descriptions_ssim' => include('world_qualified')
)
end
it 'includes the simple fields that are present' do
rights_md_ds = described_class.new
mock_dra_obj = double(Dor::RightsAuth)
expect(mock_dra_obj).to receive(:index_elements).with(no_args).at_least(:once).and_return(
primary: 'access_restricted',
errors: [],
terms: [],
obj_locations: ['location'],
file_locations: ['file_specific_location'],
obj_agents: ['agent'],
file_agents: ['file_specific_agent']
)
expect(rights_md_ds).to receive(:dra_object).and_return(mock_dra_obj)
doc = rights_md_ds.to_solr
expect(doc).to match a_hash_including(
'obj_rights_locations_ssim' => ['location'],
'file_rights_locations_ssim' => ['file_specific_location'],
'obj_rights_agents_ssim' => ['agent'],
'file_rights_agents_ssim' => ['file_specific_agent']
)
end
end
end