qa 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ {
2
+ "term": {
3
+ "url": {
4
+ "@context": "http://www.w3.org/ns/hydra/context.jsonld",
5
+ "@type": "IriTemplate",
6
+ "template": "http://localhost/test_default/term?uri={?term_uri}",
7
+ "variableRepresentation": "BasicRepresentation",
8
+ "mapping": [
9
+ {
10
+ "@type": "IriTemplateMapping",
11
+ "variable": "term_uri",
12
+ "property": "hydra:freetextQuery",
13
+ "required": true
14
+ }
15
+ ]
16
+ },
17
+ "qa_replacement_patterns": {
18
+ "term_id": "term_uri"
19
+ },
20
+ "term_id": "URI",
21
+ "results": {
22
+ "id_predicate": "http://id.loc.gov/vocabulary/identifiers/lccn",
23
+ "label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
24
+ }
25
+ },
26
+ "search": {}
27
+ }
@@ -65,15 +65,20 @@ describe Qa::Authorities::Getty::AAT do
65
65
  subject { authority.request_options }
66
66
  it { is_expected.to eq(accept: "application/sparql-results+json") }
67
67
  end
68
-
68
+ # rubocop:disable Metrics/LineLength
69
69
  describe "#sparql" do
70
- subject { authority.sparql('search_term') }
71
- it {
72
- is_expected.to eq 'SELECT ?s ?name {
73
- ?s a skos:Concept; luc:term "search_term";
74
- skos:inScheme <http://vocab.getty.edu/aat/> ;
75
- gvp:prefLabelGVP [skosxl:literalForm ?name].
76
- FILTER regex(?name, "search_term", "i") .
77
- } ORDER BY ?name' }
70
+ context "using a single subject term" do
71
+ subject { authority.sparql('search_term') }
72
+ it {
73
+ is_expected.to eq %(SELECT ?s ?name { ?s a skos:Concept; luc:term "search_term"; skos:inScheme <http://vocab.getty.edu/aat/> ; gvp:prefLabelGVP [skosxl:literalForm ?name]. FILTER regex(?name, "search_term", "i") . } ORDER BY ?name)
74
+ }
75
+ end
76
+ context "using a two subject terms" do
77
+ subject { authority.sparql('search term') }
78
+ it {
79
+ is_expected.to eq %(SELECT ?s ?name { ?s a skos:Concept; luc:term "search term"; skos:inScheme <http://vocab.getty.edu/aat/> ; gvp:prefLabelGVP [skosxl:literalForm ?name]. FILTER ((regex(?name, "search", "i")) && (regex(?name, "term", "i"))) . } ORDER BY ?name)
80
+ }
81
+ end
78
82
  end
83
+ # rubocop:enable Metrics/LineLength
79
84
  end
@@ -65,31 +65,20 @@ describe Qa::Authorities::Getty::TGN do
65
65
  subject { authority.request_options }
66
66
  it { is_expected.to eq(accept: "application/sparql-results+json") }
67
67
  end
68
-
68
+ # rubocop:disable Metrics/LineLength
69
69
  describe "#sparql" do
70
70
  context "using a single subject term" do
71
71
  subject { authority.sparql('search_term') }
72
72
  it {
73
- is_expected.to eq 'SELECT DISTINCT ?s ?name ?par {
74
- ?s a skos:Concept; luc:term "search_term";
75
- skos:inScheme <http://vocab.getty.edu/tgn/> ;
76
- gvp:prefLabelGVP [skosxl:literalForm ?name] ;
77
- gvp:parentString ?par .
78
- FILTER regex(?name, "search_term", "i") .
79
- } ORDER BY ?name ASC(?par)' }
73
+ is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search_term"; skos:inScheme <http://vocab.getty.edu/ulan/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER regex(?name, "search_term", "i") . } ORDER BY ?name ASC(?par))
74
+ }
80
75
  end
81
76
  context "using a two subject terms" do
82
77
  subject { authority.sparql('search term') }
83
- # rubocop:disable Metrics/LineLength
84
78
  it {
85
- is_expected.to eq "SELECT DISTINCT ?s ?name ?par {
86
- ?s a skos:Concept; luc:term \"search term\";
87
- skos:inScheme <http://vocab.getty.edu/tgn/> ;
88
- gvp:prefLabelGVP [skosxl:literalForm ?name] ;
89
- gvp:parentString ?par .
90
- FILTER ((regex(CONCAT(?name, ', ', REPLACE(str(?par), \",[^,]+,[^,]+$\", \"\")), \"search\",\"i\" ) && regex(CONCAT(?name, ', ', REPLACE(str(?par), \",[^,]+,[^,]+$\", \"\")), \"term\",\"i\" ) ) && (regex(?name, \"search\",\"i\" ) || regex(?name, \"term\",\"i\" ) ) ) .
91
- } ORDER BY ?name ASC(?par)" }
92
- # rubocop:enable Metrics/LineLength
79
+ is_expected.to eq %(SELECT DISTINCT ?s ?name ?par { ?s a skos:Concept; luc:term "search term"; skos:inScheme <http://vocab.getty.edu/ulan/> ; gvp:prefLabelGVP [skosxl:literalForm ?name] ; gvp:parentString ?par . FILTER ((regex(?name, "search", "i") || regex(?alt, "search", "i")) && (regex(?name, "term", "i") || regex(?alt, "term", "i"))) . } ORDER BY ?name ASC(?par))
80
+ }
93
81
  end
94
82
  end
83
+ # rubocop:enable Metrics/LineLength
95
84
  end
@@ -77,19 +77,19 @@ describe Qa::Authorities::Getty::Ulan do
77
77
  foaf:focus/gvp:biographyPreferred [schema:description ?bio] ;
78
78
  skos:altLabel ?alt .
79
79
  FILTER regex(?name, "search_term", "i") .
80
- } ORDER BY ?name' }
80
+ } ORDER BY ?name'.gsub(/[\s\n]+/, ' ') }
81
81
  end
82
82
  context "using a two subject terms" do
83
83
  subject { authority.sparql('search term') }
84
84
  it {
85
- is_expected.to eq "SELECT DISTINCT ?s ?name ?bio {
86
- ?s a skos:Concept; luc:term \"search term\";
85
+ is_expected.to eq %(SELECT DISTINCT ?s ?name ?bio {
86
+ ?s a skos:Concept; luc:term "search term";
87
87
  skos:inScheme <http://vocab.getty.edu/ulan/> ;
88
88
  gvp:prefLabelGVP [skosxl:literalForm ?name] ;
89
89
  foaf:focus/gvp:biographyPreferred [schema:description ?bio] ;
90
90
  skos:altLabel ?alt .
91
- FILTER (regex(CONCAT(?name, ' ', ?alt), \"search\",\"i\" ) && regex(CONCAT(?name, ' ', ?alt), \"term\",\"i\" ) ) .
92
- } ORDER BY ?name" }
91
+ FILTER ((regex(?name, "search", "i") || regex(?alt, "search", "i")) && (regex(?name, "term", "i") || regex(?alt, "term", "i"))) .
92
+ } ORDER BY ?name).gsub(/[\s\n]+/, ' ') }
93
93
  end
94
94
  end
95
95
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qa::Authorities::LinkedData::AuthorityService do
4
+ let(:auth_names) do
5
+ [:AGROVOC,
6
+ :LOC,
7
+ :LOD_ENCODING_CONFIG,
8
+ :LOD_FULL_CONFIG,
9
+ :LOD_LANG_DEFAULTS,
10
+ :LOD_LANG_MULTI_DEFAULTS,
11
+ :LOD_LANG_NO_DEFAULTS,
12
+ :LOD_LANG_PARAM,
13
+ :LOD_MIN_CONFIG,
14
+ :LOD_SEARCH_ONLY_CONFIG,
15
+ :LOD_SORT,
16
+ :LOD_TERM_ID_PARAM_CONFIG,
17
+ :LOD_TERM_ONLY_CONFIG,
18
+ :LOD_TERM_URI_PARAM_CONFIG,
19
+ :OCLC_FAST]
20
+ end
21
+
22
+ describe '#authority_configs' do
23
+ let(:result) { described_class.authority_configs }
24
+ it 'returns all authorities' do
25
+ expect(result).to be_kind_of(Hash)
26
+ expect(result.keys).to match_array auth_names
27
+ expect(result.values.first).to be_kind_of(Hash)
28
+ expect(result.values.first).to have_key(:term)
29
+ expect(result.values.first).to have_key(:search)
30
+ end
31
+ end
32
+
33
+ describe '#authority_config' do
34
+ let(:result) { described_class.authority_config(:LOD_FULL_CONFIG) }
35
+ it 'returns a single authority' do
36
+ expect(result).to be_kind_of(Hash)
37
+ expect(result).to have_key(:term)
38
+ expect(result).to have_key(:search)
39
+ end
40
+ end
41
+
42
+ describe '#authority_names' do
43
+ it "returns a list of all authorities' names" do
44
+ expect(described_class.authority_names).to eq auth_names
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,58 @@
1
+ RSpec.describe Qa::Configuration do
2
+ subject { described_class.new }
3
+
4
+ it { is_expected.to respond_to(:cors_headers?) }
5
+ it { is_expected.to respond_to(:enable_cors_headers) }
6
+ it { is_expected.to respond_to(:disable_cors_headers) }
7
+ it { is_expected.to respond_to(:authorized_reload_token=) }
8
+ it { is_expected.to respond_to(:authorized_reload_token) }
9
+ it { is_expected.to respond_to(:valid_authority_reload_token?) }
10
+
11
+ describe '#enable_cors_headers' do
12
+ it 'turns on cors headers support' do
13
+ subject.enable_cors_headers
14
+ expect(subject.cors_headers?).to be true
15
+ end
16
+ end
17
+
18
+ describe '#disable_cors_headers' do
19
+ it 'turns off cors headers support' do
20
+ subject.disable_cors_headers
21
+ expect(subject.cors_headers?).to be false
22
+ end
23
+ end
24
+
25
+ describe '#valid_authority_reload_token?' do
26
+ it 'defaults to invalid' do
27
+ expect(subject.valid_authority_reload_token?('any value')).to be false
28
+ end
29
+
30
+ context 'when token is set to blank' do
31
+ before do
32
+ subject.authorized_reload_token = ''
33
+ end
34
+
35
+ it 'returns false if token matches' do
36
+ expect(subject.valid_authority_reload_token?('')).to be false
37
+ end
38
+
39
+ it "returns false if token doesn't match" do
40
+ expect(subject.valid_authority_reload_token?('any value')).to be false
41
+ end
42
+ end
43
+
44
+ context 'when token has a value' do
45
+ before do
46
+ subject.authorized_reload_token = 'A_TOKEN'
47
+ end
48
+
49
+ it 'returns true if the passed in token matches' do
50
+ expect(subject.valid_authority_reload_token?('A_TOKEN')).to be true
51
+ end
52
+
53
+ it 'returns false if the passed in token does not match' do
54
+ expect(subject.valid_authority_reload_token?('BAD TOKEN')).to be false
55
+ end
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Anderson
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2018-10-04 00:00:00.000000000 Z
19
+ date: 2018-11-16 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord-import
@@ -278,8 +278,6 @@ files:
278
278
  - app/views/layouts/qa/application.html.erb
279
279
  - config/authorities.yml
280
280
  - config/authorities/linked_data/agrovoc.json
281
- - config/authorities/linked_data/agrovoc_ld4l_cache.json
282
- - config/authorities/linked_data/geonames_ld4l_cache.json
283
281
  - config/authorities/linked_data/loc.json
284
282
  - config/authorities/linked_data/oclc_fast.json
285
283
  - config/authorities/states.yml
@@ -332,6 +330,7 @@ files:
332
330
  - lib/qa/authorities/getty/tgn.rb
333
331
  - lib/qa/authorities/getty/ulan.rb
334
332
  - lib/qa/authorities/linked_data.rb
333
+ - lib/qa/authorities/linked_data/authority_service.rb
335
334
  - lib/qa/authorities/linked_data/config.rb
336
335
  - lib/qa/authorities/linked_data/config/search_config.rb
337
336
  - lib/qa/authorities/linked_data/config/term_config.rb
@@ -385,6 +384,7 @@ files:
385
384
  - spec/fixtures/authorities/linked_data/lod_sort.json
386
385
  - spec/fixtures/authorities/linked_data/lod_term_id_param_config.json
387
386
  - spec/fixtures/authorities/linked_data/lod_term_only_config.json
387
+ - spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json
388
388
  - spec/fixtures/funders-find-response.json
389
389
  - spec/fixtures/funders-noquery.json
390
390
  - spec/fixtures/funders-noresults.json
@@ -436,6 +436,7 @@ files:
436
436
  - spec/lib/authorities/getty/tgn_spec.rb
437
437
  - spec/lib/authorities/getty/ulan_spec.rb
438
438
  - spec/lib/authorities/getty_spec.rb
439
+ - spec/lib/authorities/linked_data/authority_service_spec.rb
439
440
  - spec/lib/authorities/linked_data/config_spec.rb
440
441
  - spec/lib/authorities/linked_data/find_term_spec.rb
441
442
  - spec/lib/authorities/linked_data/generic_authority_spec.rb
@@ -451,6 +452,7 @@ files:
451
452
  - spec/lib/authorities/table_based_authority_spec.rb
452
453
  - spec/lib/authorities/tgnlang_spec.rb
453
454
  - spec/lib/authorities_loc_subauthorities.rb
455
+ - spec/lib/configuration_spec.rb
454
456
  - spec/lib/mesh_data_parser_spec.rb
455
457
  - spec/lib/services/rdf_authority_parser_spec.rb
456
458
  - spec/lib/tasks/mesh.rake_spec.rb
@@ -492,10 +494,12 @@ test_files:
492
494
  - spec/test_app_templates/lib/generators/test_app_generator.rb
493
495
  - spec/test_app_templates/Gemfile.extra
494
496
  - spec/lib/tasks/mesh.rake_spec.rb
497
+ - spec/lib/configuration_spec.rb
495
498
  - spec/lib/authorities_loc_subauthorities.rb
496
499
  - spec/lib/mesh_data_parser_spec.rb
497
500
  - spec/lib/authorities/linked_data/config_spec.rb
498
501
  - spec/lib/authorities/linked_data/search_config_spec.rb
502
+ - spec/lib/authorities/linked_data/authority_service_spec.rb
499
503
  - spec/lib/authorities/linked_data/search_query_spec.rb
500
504
  - spec/lib/authorities/linked_data/term_config_spec.rb
501
505
  - spec/lib/authorities/linked_data/find_term_spec.rb
@@ -566,6 +570,7 @@ test_files:
566
570
  - spec/fixtures/authorities/linked_data/lod_lang_defaults.json
567
571
  - spec/fixtures/authorities/linked_data/lod_term_only_config.json
568
572
  - spec/fixtures/authorities/linked_data/lod_lang_no_defaults.json
573
+ - spec/fixtures/authorities/linked_data/lod_term_uri_param_config.json
569
574
  - spec/fixtures/authorities/linked_data/lod_full_config.json
570
575
  - spec/fixtures/authorities/linked_data/lod_lang_param.json
571
576
  - spec/fixtures/authorities/authority_D.yml
@@ -1,85 +0,0 @@
1
- {
2
- "term": {
3
- "url": {
4
- "@context": "http://www.w3.org/ns/hydra/context.jsonld",
5
- "@type": "IriTemplate",
6
- "template": "http://services.ld4l.org/ld4l_services/agrovoc_lookup.jsp?uri={?term_uri}",
7
- "variableRepresentation": "BasicRepresentation",
8
- "mapping": [
9
- {
10
- "@type": "IriTemplateMapping",
11
- "variable": "term_uri",
12
- "property": "hydra:freetextQuery",
13
- "required": true,
14
- "encode": true
15
- }
16
- ]
17
- },
18
- "qa_replacement_patterns": {
19
- "term_id": "term_uri"
20
- },
21
- "term_id": "URI",
22
- "results": {
23
- "label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
24
- "altlabel_predicate": "http://www.w3.org/2004/02/skos/core#altLabel",
25
- "broader_predicate": "http://www.w3.org/2004/02/skos/core#broader",
26
- "narrower_predicate": "http://www.w3.org/2004/02/skos/core#narrower",
27
- "sameas_predicate": "http://www.w3.org/2004/02/skos/core#exactMatch"
28
- }
29
- },
30
- "search": {
31
- "url": {
32
- "@context": "http://www.w3.org/ns/hydra/context.jsonld",
33
- "@type": "IriTemplate",
34
- "template": "http://services.ld4l.org/ld4l_services/agrovoc_batch.jsp?query={?query}&maxRecords={?maxRecords}&entity={?subauth}&lang={?lang}",
35
- "variableRepresentation": "BasicRepresentation",
36
- "mapping": [
37
- {
38
- "@type": "IriTemplateMapping",
39
- "variable": "query",
40
- "property": "hydra:freetextQuery",
41
- "required": true
42
- },
43
- {
44
- "@type": "IriTemplateMapping",
45
- "variable": "subauth",
46
- "property": "hydra:freetextQuery",
47
- "required": false,
48
- "default": ""
49
- },
50
- {
51
- "@type": "IriTemplateMapping",
52
- "variable": "maxRecords",
53
- "property": "hydra:freetextQuery",
54
- "required": false,
55
- "default": "20"
56
- },
57
- {
58
- "@type": "IriTemplateMapping",
59
- "variable": "lang",
60
- "property": "hydra:freetextQuery",
61
- "required": false,
62
- "default": "en"
63
- }
64
- ]
65
- },
66
- "qa_replacement_patterns": {
67
- "query": "query",
68
- "subauth": "subauth"
69
- },
70
- "results": {
71
- "id_predicate": "http://purl.org/dc/terms/identifier",
72
- "label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
73
- "sort_predicate": "http://vivoweb.org/ontology/core#rank"
74
- },
75
- "subauthorities": {
76
- "person": "Person",
77
- "organization": "Organization",
78
- "place": "Place",
79
- "intangible": "Intangible",
80
- "geocoordinates": "GeoCoordinates",
81
- "work": "Work"
82
- }
83
- }
84
- }
85
-
@@ -1,102 +0,0 @@
1
- {
2
- "term": {
3
- "url": {
4
- "@context": "http://www.w3.org/ns/hydra/context.jsonld",
5
- "@type": "IriTemplate",
6
- "template": "http://services.ld4l.org/ld4l_services/geonames_lookup.jsp?uri={?term_uri}",
7
- "variableRepresentation": "BasicRepresentation",
8
- "mapping": [
9
- {
10
- "@type": "IriTemplateMapping",
11
- "variable": "term_uri",
12
- "property": "hydra:freetextQuery",
13
- "required": true,
14
- "encode": true
15
- }
16
- ]
17
- },
18
- "qa_replacement_patterns": {
19
- "term_id": "term_uri"
20
- },
21
- "term_id": "URI",
22
- "results": {
23
- "label_predicate": "http://www.geonames.org/ontology#name",
24
- "altlabel_predicate": "http://www.geonames.org/ontology#countryCode",
25
- "broader_predicate": "http://www.geonames.org/ontology#parentFeature",
26
- "sameas_predicate": "http://www.w3.org/2000/01/rdf-schema#seeAlso"
27
- }
28
- },
29
- "search": {
30
- "url": {
31
- "@context": "http://www.w3.org/ns/hydra/context.jsonld",
32
- "@type": "IriTemplate",
33
- "template": "http://services.ld4l.org/ld4l_services/geonames_batch.jsp?query={?query}&entity={?subauth}&maxRecords={?maxRecords}&lang={?lang}",
34
- "variableRepresentation": "BasicRepresentation",
35
- "mapping": [
36
- {
37
- "@type": "IriTemplateMapping",
38
- "variable": "query",
39
- "property": "hydra:freetextQuery",
40
- "required": true
41
- },
42
- {
43
- "@type": "IriTemplateMapping",
44
- "variable": "subauth",
45
- "property": "hydra:freetextQuery",
46
- "required": false,
47
- "default": "all"
48
- },
49
- {
50
- "@type": "IriTemplateMapping",
51
- "variable": "maxRecords",
52
- "property": "hydra:freetextQuery",
53
- "required": false,
54
- "default": "20"
55
- },
56
- {
57
- "@type": "IriTemplateMapping",
58
- "variable": "lang",
59
- "property": "hydra:freetextQuery",
60
- "required": false,
61
- "default": "en"
62
- }
63
- ]
64
- },
65
- "qa_replacement_patterns": {
66
- "query": "query",
67
- "subauth": "subauth"
68
- },
69
- "language": ["en"],
70
- "results": {
71
- "label_predicate": "http://www.geonames.org/ontology#name",
72
- "altlabel_predicate": "http://www.geonames.org/ontology#countryCode",
73
- "sort_predicate": "http://vivoweb.org/ontology/core#rank",
74
- "context": {
75
- "Parent": "http://www.geonames.org/ontology#parentADM1",
76
- "Parent2": "http://www.geonames.org/ontology#parentADM2",
77
- "Parent Country": "http://www.geonames.org/ontology#parentCountry",
78
- "Children": "http://www.geonames.org/ontology#childrenFeatures",
79
- "Country": "http://www.geonames.org/ontology#countryCode",
80
- "Population": "http://www.geonames.org/ontology#population",
81
- "Latitude": "http://www.w3.org/2003/01/geo/wgs84_pos#lat",
82
- "Longitude": "http://www.w3.org/2003/01/geo/wgs84_pos#long",
83
- "Altitude": "http://www.w3.org/2003/01/geo/wgs84_pos#alt",
84
- "Feature Class": "http://www.geonames.org/ontology#featureClass",
85
- "Feature Code": "http://www.geonames.org/ontology#featureCode"
86
- }
87
- },
88
- "subauthorities": {
89
- "area": "A",
90
- "place": "P",
91
- "area_and_place": "AP",
92
- "water": "H",
93
- "park": "L",
94
- "road": "R",
95
- "spot": "S",
96
- "terrain": "T",
97
- "undersea": "U",
98
- "vegetation": "V",
99
- "all": "all"
100
- }
101
- }
102
- }