-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V3 resource and image_resource tests improved #29
Changes from 3 commits
bf8dbe0
58fabde
21708b2
52c15cc
7d6f96a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,174 @@ | ||
describe IIIF::V3::Presentation::Resource do | ||
describe '#required_keys' do | ||
it 'id' do | ||
expect(subject.required_keys).to include('id') | ||
end | ||
it 'type' do | ||
expect(subject.required_keys).to include('type') | ||
end | ||
end | ||
|
||
describe '#prohibited_keys' do | ||
it 'contains the expected key names' do | ||
keys = described_class::PAGING_PROPERTIES + | ||
%w{ | ||
nav_date | ||
viewing_direction | ||
start_canvas | ||
content_annotations | ||
} | ||
expect(subject.prohibited_keys).to include(*keys) | ||
end | ||
end | ||
|
||
describe "#{described_class}.abstract_resource_only_keys" do | ||
it_behaves_like 'it has the appropriate methods for abstract_resource_only_keys v3' | ||
describe '#uri_only_keys' do | ||
it 'id' do | ||
expect(subject.uri_only_keys).to include('id') | ||
end | ||
end | ||
|
||
describe "#{described_class}.int_only_keys" do | ||
it_behaves_like 'it has the appropriate methods for integer-only keys v3' | ||
describe '#initialize' do | ||
it 'allows subclasses to override type' do | ||
subclass = Class.new(described_class) do | ||
def initialize(hsh={}) | ||
hsh = { 'type' => 'a:SubClass' } | ||
super(hsh) | ||
end | ||
end | ||
sub = subclass.new | ||
expect(sub['type']).to eq 'a:SubClass' | ||
end | ||
end | ||
|
||
describe "#{described_class}.numeric_only_keys" do | ||
it_behaves_like 'it has the appropriate methods for numeric-only keys v3' | ||
describe '#validate' do | ||
it 'raises an IllegalValueError if id is not URI' do | ||
subject['id'] = 'foo' | ||
subject['type'] = 'image/jpeg' | ||
exp_err_msg = "id must be an http(s) URI for #{described_class}" | ||
expect { subject.validate }.to raise_error(IIIF::V3::Presentation::IllegalValueError, exp_err_msg) | ||
end | ||
it 'raises an IllegalValueError if id is not http' do | ||
subject['id'] = 'ftp://www.example.org' | ||
subject['type'] = 'image/jpeg' | ||
exp_err_msg = "id must be an http(s) URI for #{described_class}" | ||
expect { subject.validate }.to raise_error(IIIF::V3::Presentation::IllegalValueError, exp_err_msg) | ||
end | ||
end | ||
|
||
describe "#{described_class}.define_methods_for_string_only_keys" do | ||
it_behaves_like 'it has the appropriate methods for string-only keys v3' | ||
describe 'realistic examples' do | ||
describe 'non-image examples from http://prezi3.iiif.io/api/presentation/3.0' do | ||
describe 'audio' do | ||
let(:file_id) { 'http://example.org/iiif/book1/res/music.mp3' } | ||
let(:file_type) { 'dctypes:Sound' } | ||
let(:file_mimetype) { 'audio/mpeg' } | ||
let(:resource_object) { IIIF::V3::Presentation::Resource.new({ | ||
'id' => file_id, | ||
'type' => file_type, | ||
'format' => file_mimetype | ||
})} | ||
it 'validates' do | ||
expect{resource_object.validate}.not_to raise_error | ||
end | ||
it 'has expected required values' do | ||
expect(resource_object.id).to eq file_id | ||
end | ||
it 'has expected other values' do | ||
expect(resource_object.type).to eq file_type | ||
expect(resource_object.format).to eq file_mimetype | ||
expect(resource_object.service).to eq [] | ||
end | ||
end | ||
describe 'text' do | ||
let(:file_id) { 'http://example.org/iiif/book1/res/tei-text-p1.xml' } | ||
let(:file_type) { 'dctypes:Text' } | ||
let(:file_mimetype) { 'application/tei+xml' } | ||
let(:resource_object) { IIIF::V3::Presentation::Resource.new({ | ||
'id' => file_id, | ||
'type' => file_type, | ||
'format' => file_mimetype | ||
})} | ||
it 'validates' do | ||
expect{resource_object.validate}.not_to raise_error | ||
end | ||
it 'has expected required values' do | ||
expect(resource_object.id).to eq file_id | ||
end | ||
it 'has expected other values' do | ||
expect(resource_object.type).to eq file_type | ||
expect(resource_object.format).to eq file_mimetype | ||
expect(resource_object.service).to eq [] | ||
end | ||
end | ||
|
||
end | ||
describe 'stanford' do | ||
describe 'non-image resource per purl code' do | ||
let(:file_id) { 'https://example.org/file/abc666/ocr.txt' } | ||
let(:file_type) { 'Document' } | ||
let(:file_mimetype) { 'text/plain' } | ||
let(:resource_object) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think i've seen rubocop complain about not using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah - I've seen that too. At this point, I think I'm inclined to just let it ride. |
||
resource = IIIF::V3::Presentation::Resource.new | ||
resource['id'] = file_id | ||
resource['type'] = file_type | ||
resource.format = file_mimetype | ||
resource | ||
} | ||
describe 'world visible' do | ||
it 'validates' do | ||
expect{resource_object.validate}.not_to raise_error | ||
end | ||
it 'has expected required values' do | ||
expect(resource_object.id).to eq file_id | ||
end | ||
it 'has expected other values' do | ||
expect(resource_object.type).to eq file_type | ||
expect(resource_object.format).to eq file_mimetype | ||
expect(resource_object.service).to eq [] | ||
end | ||
end | ||
describe 'requires login' do | ||
# let(:auth_token_service) { | ||
# IIIF::V3::Presentation::Service.new({ | ||
# 'id' => 'https://example.org/image/iiif/token', | ||
# 'profile' => IIIF::V3::Presentation::Service::IIIF_AUTHENTICATION_V1_TOKEN_PROFILE | ||
# })} | ||
let(:service_label) { 'login message' } | ||
let(:token_service_id) { 'https://example.org/iiif/token' } | ||
let(:login_service) { | ||
IIIF::V3::Presentation::Service.new( | ||
'id' => 'https://example.org/auth/iiif', | ||
'profile' => 'http://iiif.io/api/auth/1/login', | ||
'label' => service_label, | ||
'service' => [{ | ||
'id' => token_service_id, | ||
'profile' => 'http://iiif.io/api/auth/1/token' | ||
}] | ||
) | ||
} | ||
let(:resource_object_w_login) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto multiline block on this and |
||
resource = resource_object | ||
resource.service = login_service | ||
resource | ||
} | ||
it 'validates' do | ||
expect{resource_object_w_login.validate}.not_to raise_error | ||
end | ||
it 'has expected service value' do | ||
service_obj = resource_object_w_login.service | ||
expect(service_obj.class).to eq IIIF::V3::Presentation::Service | ||
expect(service_obj.keys.size).to eq 4 | ||
expect(service_obj.id).to eq 'https://example.org/auth/iiif' | ||
expect(service_obj.profile).to eq IIIF::V3::Presentation::Service::IIIF_AUTHENTICATION_V1_LOGIN_PROFILE | ||
expect(service_obj.label).to eq service_label | ||
expect(service_obj.service.class).to eq Array | ||
expect(service_obj.service.size).to eq 1 | ||
expect(service_obj.service.first.keys.size).to eq 2 | ||
expect(service_obj.service.first['id']).to eq token_service_id | ||
expect(service_obj.service.first['profile']).to eq IIIF::V3::Presentation::Service::IIIF_AUTHENTICATION_V1_TOKEN_PROFILE | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the superclass takes care of validating against the more general
URI::regexp
, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does now! Good catch!