qa 4.3.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 7e4ee1da3b72cee5194380a24b44e96793395d110cbe2234da55541da3f962c9
4
- data.tar.gz: 27dffc56d77c9e583000c99823a31fe8c90f3591ea3de04935c4e476bda9d289
2
+ SHA1:
3
+ metadata.gz: bc29035b13c98a73e85662eaeb115eabd0d12372
4
+ data.tar.gz: c509732acf8103e7587fcec0f1fd61824b6490ff
5
5
  SHA512:
6
- metadata.gz: ad1a1bc75bcde5877679a355e7afec3f992e869686f3c3c706d5e1ffee6ecdcc66c4be4a8572c9ca1c27b6b177b12b211debc8a579268037aff006872d3e9b5a
7
- data.tar.gz: 789919e7a524d155d69ae2ca0203900cc0509f613d94d3b2b14ed697e2c80134b9d13dd56fb013c9db052069296955f4b948b43ff95ae10f93e4dd2ccbd643d6
6
+ metadata.gz: 4dbb5d3904901814ad948f8d2f80bda6a1709ba4b84d65cde4746ffae13354255c4617825d88c58322bdb6d6345913ff034b25d658734ef56740d737c75d40b1
7
+ data.tar.gz: f4d641ec0744de995d7358c304220a39a4d0a37de684a66c1d9e2cdd3561ba5b5bf8d411f92148f09bfb1d756cf1d06f7478dda1ab86c39fc9f88201c480c939
@@ -154,7 +154,7 @@ class Qa::LinkedDataTermsController < ::ApplicationController
154
154
  end
155
155
 
156
156
  def create_request_header_service
157
- @request_header_service = request_header_service_class.new(request, params)
157
+ @request_header_service = request_header_service_class.new(request: request, params: params)
158
158
  end
159
159
 
160
160
  def init_authority
@@ -0,0 +1,26 @@
1
+ # Service to construct a request header that includes optional attributes for search and fetch requests.
2
+ module Qa
3
+ module LinkedData
4
+ class PerformanceDataService
5
+ # Construct performance data structure to include in the returned results (linked data module).
6
+ # @param access_time_s [Float] time to fetch the data from the external source and populate it in an RDF graph
7
+ # @param normalization_time_s [Float] time for QA to normalize the data
8
+ # @param fetched_size [Float] size of data in the RDF graph (in bytes)
9
+ # @param normalized_size [Float] size of the normalized data string (in bytes)
10
+ # @returns [Hash] performance data
11
+ # @see Qa::Authorities::LinkedData::SearchQuery
12
+ # @see Qa::Authorities::LinkedData::FindTerm
13
+ def self.performance_data(access_time_s:, normalize_time_s:, fetched_size:, normalized_size:)
14
+ {
15
+ fetch_time_s: access_time_s,
16
+ normalization_time_s: normalize_time_s,
17
+ fetched_bytes: fetched_size,
18
+ normalized_bytes: normalized_size,
19
+ fetch_bytes_per_s: fetched_size / access_time_s,
20
+ normalization_bytes_per_s: normalized_size / normalize_time_s,
21
+ total_time_s: (access_time_s + normalize_time_s)
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -12,7 +12,7 @@ module Qa
12
12
  # @option context [Boolean] true if context should be returned with the results; otherwise, false (default: false) (search only)
13
13
  # @option format [String] return data in this format (fetch only)
14
14
  # @note params may have additional attribute-value pairs that are passed through via replacements (only configured replacements are used)
15
- def initialize(request, params)
15
+ def initialize(request:, params:)
16
16
  @request = request
17
17
  @params = params
18
18
  end
@@ -39,6 +39,10 @@ module Qa::Authorities
39
39
  @prefixes ||= authority_config.fetch(:prefixes, {})
40
40
  end
41
41
 
42
+ def service_uri
43
+ @service_uri ||= authority_config.fetch(:service_uri, nil)
44
+ end
45
+
42
46
  def config_version
43
47
  @config_version ||= authority_config.fetch(:QA_CONFIG_VERSION, '1.0')
44
48
  end
@@ -8,7 +8,7 @@ module Qa::Authorities
8
8
  attr_reader :prefixes, :full_config, :search_config
9
9
  private :full_config, :search_config
10
10
 
11
- delegate :authority_name, to: :full_config
11
+ delegate :authority_name, :service_uri, to: :full_config
12
12
 
13
13
  # @param [Hash] config the search portion of the config
14
14
  # @param [Hash<Symbol><String>] prefixes URL map of prefixes to use with ldpaths
@@ -146,7 +146,7 @@ module Qa::Authorities
146
146
  search_config.fetch(:qa_replacement_patterns, {})
147
147
  end
148
148
 
149
- # @return [Boolean] true if supports language parameter; otherwise, false
149
+ # @return [Boolean] true if supports subauthorities; otherwise, false
150
150
  def supports_subauthorities?
151
151
  qa_replacement_patterns.key?(:subauth) && subauthorities?
152
152
  end
@@ -182,6 +182,22 @@ module Qa::Authorities
182
182
  @subauthorities ||= search_config.fetch(:subauthorities)
183
183
  end
184
184
 
185
+ # @return [String] name of parameter holding start record number
186
+ def start_record_parameter
187
+ qa_replacement_patterns.key?(:start_record) ? qa_replacement_patterns[:start_record] : nil
188
+ end
189
+
190
+ # @return [String] name of parameter holding number of requested records
191
+ def requested_records_parameter
192
+ qa_replacement_patterns.key?(:requested_records) ? qa_replacement_patterns[:requested_records] : nil
193
+ end
194
+
195
+ # @return [String] ldpath of the triple that holds the total number of available records for a search
196
+ # @see #service_subject_uri
197
+ def total_count_ldpath
198
+ search_config.key?(:total_count_ldpath) ? search_config[:total_count_ldpath] : nil
199
+ end
200
+
185
201
  def info
186
202
  return [] unless supports_search?
187
203
  auth_name = authority_name.downcase.to_s
@@ -15,8 +15,8 @@ module Qa::Authorities
15
15
  @term_config = term_config
16
16
  end
17
17
 
18
- attr_reader :term_config, :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
19
- private :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
18
+ attr_reader :term_config, :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :subauthority, :request_header
19
+ private :full_graph, :filtered_graph, :language, :id, :uri, :access_time_s, :normalize_time_s, :subauthority, :request_header
20
20
 
21
21
  delegate :term_subauthority?, :prefixes, :authority_name, to: :term_config
22
22
 
@@ -63,7 +63,6 @@ module Qa::Authorities
63
63
 
64
64
  access_end_dt = Time.now.utc
65
65
  @access_time_s = access_end_dt - access_start_dt
66
- @fetched_size = full_graph.triples.to_s.size if performance_data?
67
66
  Rails.logger.info("Time to receive data from authority: #{access_time_s}s")
68
67
  end
69
68
 
@@ -74,9 +73,8 @@ module Qa::Authorities
74
73
 
75
74
  normalize_end_dt = Time.now.utc
76
75
  @normalize_time_s = normalize_end_dt - normalize_start_dt
77
- @normalized_size = results.to_s.size if performance_data?
78
76
  Rails.logger.info("Time to normalize data: #{normalize_time_s}s")
79
- results = append_performance_data(results) if performance_data?
77
+ results = append_data_outside_results(results)
80
78
  results
81
79
  end
82
80
 
@@ -93,6 +91,7 @@ module Qa::Authorities
93
91
  end
94
92
 
95
93
  def unpack_request_header(request_header)
94
+ @request_header = request_header
96
95
  @subauthority = request_header.fetch(:subauthority, nil)
97
96
  @format = request_header.fetch(:format, 'json')
98
97
  @performance_data = request_header.fetch(:performance_data, false)
@@ -282,17 +281,20 @@ module Qa::Authorities
282
281
  predicates_hash
283
282
  end
284
283
 
285
- def append_performance_data(results)
286
- pred_count = results['predicates'].present? ? results['predicates'].size : 0
287
- performance = { predicate_count: pred_count,
288
- fetch_time_s: access_time_s,
289
- normalization_time_s: normalize_time_s,
290
- fetched_bytes: fetched_size,
291
- normalized_bytes: normalized_size,
292
- fetch_bytes_per_s: fetched_size / access_time_s,
293
- normalization_bytes_per_s: normalized_size / normalize_time_s,
294
- total_time_s: (access_time_s + normalize_time_s) }
295
- { performance: performance, results: results }
284
+ def append_data_outside_results(results)
285
+ return results unless performance_data?
286
+ full_results = {}
287
+ full_results[:results] = results
288
+ full_results[:performance] = performance(results)
289
+ full_results
290
+ end
291
+
292
+ def performance(results)
293
+ normalized_size = results.to_s.size
294
+ fetched_size = full_graph.triples.to_s.size
295
+ perf_data = Qa::LinkedData::PerformanceDataService.performance_data(access_time_s: access_time_s, normalize_time_s: normalize_time_s,
296
+ fetched_size: fetched_size, normalized_size: normalized_size)
297
+ perf_data
296
298
  end
297
299
 
298
300
  # This is providing support for calling build_url with individual parameters instead of the request_header.
@@ -15,8 +15,8 @@ module Qa::Authorities
15
15
  @search_config = search_config
16
16
  end
17
17
 
18
- attr_reader :search_config, :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
19
- private :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :fetched_size, :normalized_size, :subauthority
18
+ attr_reader :search_config, :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :subauthority, :request_header
19
+ private :full_graph, :filtered_graph, :language, :access_time_s, :normalize_time_s, :subauthority, :request_header
20
20
 
21
21
  delegate :subauthority?, :supports_sort?, :prefixes, :authority_name, to: :search_config
22
22
 
@@ -53,22 +53,20 @@ module Qa::Authorities
53
53
 
54
54
  access_end_dt = Time.now.utc
55
55
  @access_time_s = access_end_dt - access_start_dt
56
- @fetched_size = full_graph.triples.to_s.size if performance_data?
57
56
  Rails.logger.info("Time to receive data from authority: #{access_time_s}s")
58
57
  end
59
58
 
60
59
  def normalize_results
61
60
  normalize_start_dt = Time.now.utc
62
61
 
63
- @filtered_graph = graph_service.filter(graph: @full_graph, language: language)
62
+ @filtered_graph = graph_service.filter(graph: full_graph, language: language)
64
63
  results = map_results
65
64
  json = convert_results_to_json(results)
66
65
 
67
66
  normalize_end_dt = Time.now.utc
68
67
  @normalize_time_s = normalize_end_dt - normalize_start_dt
69
- @normalized_size = json.to_s.size if performance_data?
70
68
  Rails.logger.info("Time to normalize data: #{normalize_time_s}s")
71
- json = append_performance_data(json) if performance_data?
69
+ json = append_data_outside_results(json)
72
70
  json
73
71
  end
74
72
 
@@ -92,6 +90,7 @@ module Qa::Authorities
92
90
  end
93
91
 
94
92
  def unpack_request_header(request_header)
93
+ @request_header = request_header
95
94
  @subauthority = request_header.fetch(:subauthority, nil)
96
95
  @context = request_header.fetch(:context, false)
97
96
  @performance_data = request_header.fetch(:performance_data, false)
@@ -179,16 +178,19 @@ module Qa::Authorities
179
178
  lbl
180
179
  end
181
180
 
182
- def append_performance_data(results)
183
- performance = { result_count: results.size,
184
- fetch_time_s: access_time_s,
185
- normalization_time_s: normalize_time_s,
186
- fetched_bytes: fetched_size,
187
- normalized_bytes: normalized_size,
188
- fetch_bytes_per_s: fetched_size / access_time_s,
189
- normalization_bytes_per_s: normalized_size / normalize_time_s,
190
- total_time_s: (access_time_s + normalize_time_s) }
191
- { performance: performance, results: results }
181
+ def append_data_outside_results(results)
182
+ return results unless performance_data?
183
+ full_results = {}
184
+ full_results[:results] = results
185
+ full_results[:performance] = performance(results)
186
+ full_results
187
+ end
188
+
189
+ def performance(results)
190
+ normalized_size = results.to_s.size
191
+ fetched_size = full_graph.triples.to_s.size
192
+ Qa::LinkedData::PerformanceDataService.performance_data(access_time_s: access_time_s, normalize_time_s: normalize_time_s,
193
+ fetched_size: fetched_size, normalized_size: normalized_size)
192
194
  end
193
195
 
194
196
  # This is providing support for calling build_url with individual parameters instead of the request_header.
@@ -26,7 +26,7 @@ module Qa::Authorities
26
26
  def build_query_url(q)
27
27
  escaped_query = ERB::Util.url_encode(q)
28
28
  authority_fragment = Loc.get_url_for_authority(subauthority) + ERB::Util.url_encode(subauthority)
29
- "https://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
29
+ "http://id.loc.gov/search/?q=#{escaped_query}&q=#{authority_fragment}&format=json"
30
30
  end
31
31
 
32
32
  def find(id)
@@ -34,7 +34,7 @@ module Qa::Authorities
34
34
  end
35
35
 
36
36
  def find_url(id)
37
- "https://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
37
+ "http://id.loc.gov/authorities/#{@subauthority}/#{id}.json"
38
38
  end
39
39
 
40
40
  private
data/lib/qa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "4.3.0".freeze
2
+ VERSION = "5.0.0".freeze
3
3
  end
@@ -307,12 +307,10 @@ describe Qa::LinkedDataTermsController, type: :controller do
307
307
  results = JSON.parse(response.body)
308
308
  expect(results).to be_kind_of Hash
309
309
  expect(results.keys).to match_array ['performance', 'results']
310
- expect(results['performance'].keys).to match_array ['result_count', 'fetch_time_s', 'normalization_time_s',
310
+ expect(results['performance'].keys).to match_array ['fetch_time_s', 'normalization_time_s',
311
311
  'fetched_bytes', 'normalized_bytes', 'fetch_bytes_per_s',
312
312
  'normalization_bytes_per_s', 'total_time_s']
313
313
  expect(results['performance']['total_time_s']).to eq results['performance']['fetch_time_s'] + results['performance']['normalization_time_s']
314
- expect(results['performance']['result_count']).to eq 3
315
- expect(results['results'].count).to eq 3
316
314
  end
317
315
 
318
316
  it "returns basic data only when performance_data='false'" do
@@ -320,7 +318,6 @@ describe Qa::LinkedDataTermsController, type: :controller do
320
318
  expect(response).to be_successful
321
319
  results = JSON.parse(response.body)
322
320
  expect(results).to be_kind_of Array
323
- expect(results.size).to eq 3
324
321
  end
325
322
  end
326
323
  end
@@ -495,12 +492,9 @@ describe Qa::LinkedDataTermsController, type: :controller do
495
492
  results = JSON.parse(response.body)
496
493
  expect(results).to be_kind_of Hash
497
494
  expect(results.keys).to match_array ['performance', 'results']
498
- expect(results['performance'].keys).to match_array ['predicate_count', 'fetch_time_s', 'normalization_time_s',
499
- 'fetched_bytes', 'normalized_bytes', 'fetch_bytes_per_s',
500
- 'normalization_bytes_per_s', 'total_time_s']
495
+ expect(results['performance'].keys).to match_array ['fetch_time_s', 'normalization_time_s', 'fetched_bytes', 'normalized_bytes',
496
+ 'fetch_bytes_per_s', 'normalization_bytes_per_s', 'total_time_s']
501
497
  expect(results['performance']['total_time_s']).to eq results['performance']['fetch_time_s'] + results['performance']['normalization_time_s']
502
- expect(results['performance']['predicate_count']).to eq 15
503
- expect(results['results']['predicates'].count).to eq 15
504
498
  end
505
499
 
506
500
  it "returns basic data only when performance_data='false'" do
@@ -509,7 +503,6 @@ describe Qa::LinkedDataTermsController, type: :controller do
509
503
  results = JSON.parse(response.body)
510
504
  expect(results).to be_kind_of Hash
511
505
  expect(results.keys).not_to include('performance')
512
- expect(results['predicates'].size).to eq 15
513
506
  end
514
507
  end
515
508
  end
@@ -671,12 +664,10 @@ describe Qa::LinkedDataTermsController, type: :controller do
671
664
  results = JSON.parse(response.body)
672
665
  expect(results).to be_kind_of Hash
673
666
  expect(results.keys).to match_array ['performance', 'results']
674
- expect(results['performance'].keys).to match_array ['predicate_count', 'fetch_time_s', 'normalization_time_s',
667
+ expect(results['performance'].keys).to match_array ['fetch_time_s', 'normalization_time_s',
675
668
  'fetched_bytes', 'normalized_bytes', 'fetch_bytes_per_s',
676
669
  'normalization_bytes_per_s', 'total_time_s']
677
670
  expect(results['performance']['total_time_s']).to eq results['performance']['fetch_time_s'] + results['performance']['normalization_time_s']
678
- expect(results['performance']['predicate_count']).to eq 7
679
- expect(results['results']['predicates'].count).to eq 7
680
671
  end
681
672
 
682
673
  it "returns basic data only when performance_data='false'" do
@@ -685,7 +676,6 @@ describe Qa::LinkedDataTermsController, type: :controller do
685
676
  results = JSON.parse(response.body)
686
677
  expect(results).to be_kind_of Hash
687
678
  expect(results.keys).not_to include('performance')
688
- expect(results['predicates'].size).to eq 7
689
679
  end
690
680
  end
691
681
  end
@@ -82,7 +82,7 @@ describe Qa::TermsController, type: :controller do
82
82
 
83
83
  context "loc" do
84
84
  before do
85
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
85
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
86
86
  .with(headers: { 'Accept' => 'application/json' })
87
87
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
88
88
  end
@@ -188,7 +188,7 @@ describe Qa::TermsController, type: :controller do
188
188
  describe "#show" do
189
189
  context "with supported authorities" do
190
190
  before do
191
- stub_request(:get, "https://id.loc.gov/authorities/subjects/sh85077565.json")
191
+ stub_request(:get, "http://id.loc.gov/authorities/subjects/sh85077565.json")
192
192
  .with(headers: { 'Accept' => 'application/json' })
193
193
  .to_return(status: 200, body: webmock_fixture("loc-names-response.txt"), headers: {})
194
194
  end
@@ -1,5 +1,6 @@
1
1
  {
2
- "QA_CONFIG_VERSION": "2.0",
2
+ "QA_CONFIG_VERSION": "2.2",
3
+ "service_uri": "http://ld4l.org/ld4l_services/cache",
3
4
  "prefixes": {
4
5
  "schema": "http://www.w3.org/2000/01/rdf-schema#",
5
6
  "skos": "http://www.w3.org/2004/02/skos/core#"
@@ -114,9 +115,12 @@
114
115
  "qa_replacement_patterns": {
115
116
  "query": "query",
116
117
  "subauth": "subauth",
117
- "lang": "lang"
118
+ "lang": "lang",
119
+ "start_record": "startRecord",
120
+ "requested_records": "maxRecords"
118
121
  },
119
122
  "language": [ "en", "fr", "de" ],
123
+ "total_count_ldpath": "vivo:count",
120
124
  "results": {
121
125
  "id_predicate": "http://purl.org/dc/terms/identifier",
122
126
  "label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel",
@@ -25,7 +25,8 @@ describe Qa::Authorities::LinkedData::Config do
25
25
  describe '#authority_config' do
26
26
  let(:full_auth_config) do
27
27
  {
28
- QA_CONFIG_VERSION: "2.0",
28
+ QA_CONFIG_VERSION: "2.2",
29
+ service_uri: "http://ld4l.org/ld4l_services/cache",
29
30
  prefixes: {
30
31
  schema: "http://www.w3.org/2000/01/rdf-schema#",
31
32
  skos: "http://www.w3.org/2004/02/skos/core#"
@@ -140,9 +141,12 @@ describe Qa::Authorities::LinkedData::Config do
140
141
  qa_replacement_patterns: {
141
142
  query: 'query',
142
143
  subauth: 'subauth',
143
- lang: 'lang'
144
+ lang: 'lang',
145
+ start_record: 'startRecord',
146
+ requested_records: 'maxRecords'
144
147
  },
145
148
  language: ['en', 'fr', 'de'],
149
+ total_count_ldpath: "vivo:count",
146
150
  results: {
147
151
  id_predicate: 'http://purl.org/dc/terms/identifier',
148
152
  label_predicate: 'http://www.w3.org/2004/02/skos/core#prefLabel',
@@ -377,7 +381,7 @@ describe Qa::Authorities::LinkedData::Config do
377
381
  let(:authority_config) { full_config.authority_config }
378
382
  let(:authority_config_1_0) { full_config_1_0.authority_config }
379
383
 
380
- it 'returns hash of the full authority 2.0 configuration' do
384
+ it 'returns hash of the full authority 2.2 configuration' do
381
385
  expect(authority_config).to eq full_auth_config
382
386
  end
383
387
 
@@ -468,18 +472,18 @@ describe Qa::Authorities::LinkedData::Config do
468
472
 
469
473
  context 'when version is specified in the config file' do
470
474
  it 'returns the version from the config file' do
471
- expect(full_config.config_version).to eq '2.0'
475
+ expect(full_config.config_version).to eq '2.2'
472
476
  end
473
477
  end
474
478
  end
475
479
 
476
480
  describe '#config_version?' do
477
481
  it "returns true if the passed in version matches the authority's version" do
478
- expect(full_config.config_version?('2.0')).to eq true
482
+ expect(full_config.config_version?('2.2')).to eq true
479
483
  end
480
484
 
481
485
  it "returns false if the passed in version does NOT match the authority's version" do
482
- expect(full_config_1_0.config_version?('2.0')).to eq false
486
+ expect(full_config_1_0.config_version?('2.2')).to eq false
483
487
  end
484
488
  end
485
489
  end
@@ -28,10 +28,8 @@ RSpec.describe Qa::Authorities::LinkedData::FindTerm do
28
28
  end
29
29
  it 'includes performance in return hash' do
30
30
  expect(results.keys).to match_array [:performance, :results]
31
- expect(results[:performance].keys).to match_array [:predicate_count, :fetch_time_s, :normalization_time_s,
32
- :fetched_bytes, :normalized_bytes, :fetch_bytes_per_s,
33
- :normalization_bytes_per_s, :total_time_s]
34
- expect(results[:performance][:predicate_count]).to eq 7
31
+ expect(results[:performance].keys).to match_array [:fetch_time_s, :normalization_time_s, :fetched_bytes, :normalized_bytes,
32
+ :fetch_bytes_per_s, :normalization_bytes_per_s, :total_time_s]
35
33
  expect(results[:performance][:total_time_s]).to eq results[:performance][:fetch_time_s] + results[:performance][:normalization_time_s]
36
34
  end
37
35
  end
@@ -68,9 +68,12 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
68
68
  qa_replacement_patterns: {
69
69
  query: 'query',
70
70
  subauth: 'subauth',
71
- lang: 'lang'
71
+ lang: 'lang',
72
+ start_record: 'startRecord',
73
+ requested_records: 'maxRecords'
72
74
  },
73
75
  language: ['en', 'fr', 'de'],
76
+ total_count_ldpath: "vivo:count",
74
77
  results: {
75
78
  id_predicate: 'http://purl.org/dc/terms/identifier',
76
79
  label_predicate: 'http://www.w3.org/2004/02/skos/core#prefLabel',
@@ -408,6 +411,42 @@ RSpec.describe Qa::Authorities::LinkedData::SearchConfig do
408
411
  end
409
412
  end
410
413
 
414
+ describe '#start_record_parameter' do
415
+ it 'returns nil if only term configuration is defined' do
416
+ expect(term_only_config.start_record_parameter).to eq nil
417
+ end
418
+ it 'returns nil if not defined' do
419
+ expect(min_config.start_record_parameter).to eq nil
420
+ end
421
+ it 'returns parameter name if defined' do
422
+ expect(full_config.start_record_parameter).to eq 'startRecord'
423
+ end
424
+ end
425
+
426
+ describe '#requested_records_parameter' do
427
+ it 'returns nil if only term configuration is defined' do
428
+ expect(term_only_config.requested_records_parameter).to eq nil
429
+ end
430
+ it 'returns nil if not defined' do
431
+ expect(min_config.requested_records_parameter).to eq nil
432
+ end
433
+ it 'returns parameter name if defined' do
434
+ expect(full_config.requested_records_parameter).to eq 'maxRecords'
435
+ end
436
+ end
437
+
438
+ describe '#total_count_ldpath' do
439
+ it 'returns nil if only term configuration is defined' do
440
+ expect(term_only_config.total_count_ldpath).to eq nil
441
+ end
442
+ it 'returns nil if not defined' do
443
+ expect(min_config.total_count_ldpath).to eq nil
444
+ end
445
+ it 'returns parameter name if defined' do
446
+ expect(full_config.total_count_ldpath).to eq 'vivo:count'
447
+ end
448
+ end
449
+
411
450
  describe '#info' do
412
451
  let(:term_details) do
413
452
  {
@@ -16,11 +16,10 @@ RSpec.describe Qa::Authorities::LinkedData::SearchQuery do
16
16
  it 'includes performance in return hash' do
17
17
  expect(results).to be_kind_of Hash
18
18
  expect(results.keys).to match_array [:performance, :results]
19
- expect(results[:performance].keys).to match_array [:result_count, :fetch_time_s, :normalization_time_s,
19
+ expect(results[:performance].keys).to match_array [:fetch_time_s, :normalization_time_s,
20
20
  :fetched_bytes, :normalized_bytes, :fetch_bytes_per_s,
21
21
  :normalization_bytes_per_s, :total_time_s]
22
22
  expect(results[:performance][:total_time_s]).to eq results[:performance][:fetch_time_s] + results[:performance][:normalization_time_s]
23
- expect(results[:performance][:result_count]).to eq 3
24
23
  expect(results[:results].count).to eq 3
25
24
  end
26
25
  end
@@ -28,14 +28,14 @@ describe Qa::Authorities::Loc do
28
28
  end
29
29
 
30
30
  context "for searching" do
31
- let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
31
+ let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
32
32
  it "returns a url" do
33
33
  expect(authority.build_query_url("foo")).to eq(url)
34
34
  end
35
35
  end
36
36
 
37
37
  context "for returning single terms" do
38
- let(:url) { "https://id.loc.gov/authorities/subjects/sh2002003586.json" }
38
+ let(:url) { "http://id.loc.gov/authorities/subjects/sh2002003586.json" }
39
39
  it "returns a url with an authority and id" do
40
40
  expect(authority.find_url("sh2002003586")).to eq(url)
41
41
  end
@@ -49,15 +49,15 @@ describe Qa::Authorities::Loc do
49
49
  end
50
50
 
51
51
  before do
52
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
52
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=cs:http://id.loc.gov/authorities/subjects")
53
53
  .with(headers: { 'Accept' => 'application/json' })
54
54
  .to_return(status: 200, body: "")
55
55
  end
56
56
 
57
57
  context "with flat params encoded" do
58
- let(:url) { 'https://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
58
+ let(:url) { 'http://id.loc.gov/search/?q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects&format=json' }
59
59
  it "returns a response" do
60
- flat_params_url = "https://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
60
+ flat_params_url = "http://id.loc.gov/search/?format=json&q=foo&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
61
61
  expect(subject.env.url.to_s).to eq(flat_params_url)
62
62
  end
63
63
  end
@@ -66,7 +66,7 @@ describe Qa::Authorities::Loc do
66
66
  describe "#search" do
67
67
  context "any LOC authorities" do
68
68
  let :authority do
69
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
69
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=s&q=cs:http://id.loc.gov/vocabulary/geographicAreas")
70
70
  .with(headers: { 'Accept' => 'application/json' })
71
71
  .to_return(body: webmock_fixture("loc-response.txt"), status: 200)
72
72
  described_class.subauthority_for("geographicAreas")
@@ -95,7 +95,7 @@ describe Qa::Authorities::Loc do
95
95
 
96
96
  context "subject terms" do
97
97
  let :results do
98
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
98
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=History--&q=cs:http://id.loc.gov/authorities/subjects")
99
99
  .with(headers: { 'Accept' => 'application/json' })
100
100
  .to_return(body: webmock_fixture("loc-subjects-response.txt"), status: 200)
101
101
  described_class.subauthority_for("subjects").search("History--")
@@ -111,7 +111,7 @@ describe Qa::Authorities::Loc do
111
111
 
112
112
  context "name terms" do
113
113
  let :results do
114
- stub_request(:get, "https://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
114
+ stub_request(:get, "http://id.loc.gov/search/?format=json&q=Berry&q=cs:http://id.loc.gov/authorities/names")
115
115
  .with(headers: { 'Accept' => 'application/json' })
116
116
  .to_return(body: webmock_fixture("loc-names-response.txt"), status: 200)
117
117
  described_class.subauthority_for("names").search("Berry")
@@ -125,7 +125,7 @@ describe Qa::Authorities::Loc do
125
125
  describe "#find" do
126
126
  context "using a subject id" do
127
127
  let :results do
128
- stub_request(:get, "https://id.loc.gov/authorities/subjects/sh2002003586.json")
128
+ stub_request(:get, "http://id.loc.gov/authorities/subjects/sh2002003586.json")
129
129
  .with(headers: { 'Accept' => 'application/json' })
130
130
  .to_return(status: 200, body: webmock_fixture("loc-subject-find-response.txt"), headers: {})
131
131
  described_class.subauthority_for("subjects").find("sh2002003586")
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Qa::LinkedData::PerformanceDataService do
4
+ let(:request) { double }
5
+
6
+ describe '.performance_data' do
7
+ context 'when all data passed in' do
8
+ let(:access_time_s) { 0.5 }
9
+ let(:normalize_time_s) { 0.3 }
10
+ let(:fetched_size) { 11 }
11
+ let(:normalized_size) { 8 }
12
+ it 'uses passed in params' do
13
+ expected_results =
14
+ {
15
+ fetch_time_s: access_time_s,
16
+ normalization_time_s: normalize_time_s,
17
+ fetched_bytes: fetched_size,
18
+ normalized_bytes: normalized_size,
19
+ fetch_bytes_per_s: (fetched_size / access_time_s),
20
+ normalization_bytes_per_s: (normalized_size / normalize_time_s),
21
+ total_time_s: (access_time_s + normalize_time_s)
22
+ }
23
+ expect(described_class.performance_data(access_time_s: access_time_s, normalize_time_s: normalize_time_s, fetched_size: fetched_size, normalized_size: normalized_size)).to eq expected_results
24
+ end
25
+ end
26
+ end
27
+ end
@@ -25,7 +25,7 @@ RSpec.describe Qa::LinkedData::RequestHeaderService do
25
25
  subauthority: 'person',
26
26
  user_language: ['sp']
27
27
  }
28
- expect(described_class.new(request, search_params).search_header).to eq expected_results
28
+ expect(described_class.new(request: request, params: search_params).search_header).to eq expected_results
29
29
  end
30
30
  end
31
31
 
@@ -41,7 +41,7 @@ RSpec.describe Qa::LinkedData::RequestHeaderService do
41
41
  subauthority: nil,
42
42
  user_language: nil
43
43
  }
44
- expect(described_class.new(request, {}).search_header).to eq expected_results
44
+ expect(described_class.new(request: request, params: {}).search_header).to eq expected_results
45
45
  end
46
46
  end
47
47
 
@@ -56,7 +56,7 @@ RSpec.describe Qa::LinkedData::RequestHeaderService do
56
56
  subauthority: nil,
57
57
  user_language: ['de']
58
58
  }
59
- expect(described_class.new(request, {}).search_header).to eq expected_results
59
+ expect(described_class.new(request: request, params: {}).search_header).to eq expected_results
60
60
  end
61
61
  end
62
62
  end
@@ -85,7 +85,7 @@ RSpec.describe Qa::LinkedData::RequestHeaderService do
85
85
  subauthority: 'person',
86
86
  user_language: ['sp']
87
87
  }
88
- expect(described_class.new(request, fetch_params).fetch_header).to eq expected_results
88
+ expect(described_class.new(request: request, params: fetch_params).fetch_header).to eq expected_results
89
89
  end
90
90
  end
91
91
 
@@ -101,7 +101,7 @@ RSpec.describe Qa::LinkedData::RequestHeaderService do
101
101
  subauthority: nil,
102
102
  user_language: nil
103
103
  }
104
- expect(described_class.new(request, {}).fetch_header).to eq expected_results
104
+ expect(described_class.new(request: request, params: {}).fetch_header).to eq expected_results
105
105
  end
106
106
  end
107
107
 
@@ -116,7 +116,7 @@ RSpec.describe Qa::LinkedData::RequestHeaderService do
116
116
  subauthority: nil,
117
117
  user_language: ['de']
118
118
  }
119
- expect(described_class.new(request, {}).fetch_header).to eq expected_results
119
+ expect(described_class.new(request: request, params: {}).fetch_header).to eq expected_results
120
120
  end
121
121
  end
122
122
  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: 4.3.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Anderson
@@ -13,10 +13,10 @@ authors:
13
13
  - Mike Stroming
14
14
  - Adam Wead
15
15
  - E. Lynette Rayle
16
- autorequire:
16
+ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2020-08-14 00:00:00.000000000 Z
19
+ date: 2019-11-18 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord-import
@@ -322,6 +322,7 @@ files:
322
322
  - app/services/qa/linked_data/mapper/graph_predicate_mapper_service.rb
323
323
  - app/services/qa/linked_data/mapper/search_results_mapper_service.rb
324
324
  - app/services/qa/linked_data/mapper/term_results_mapper_service.rb
325
+ - app/services/qa/linked_data/performance_data_service.rb
325
326
  - app/services/qa/linked_data/request_header_service.rb
326
327
  - app/views/layouts/qa/application.html.erb
327
328
  - config/authorities.yml
@@ -556,6 +557,7 @@ files:
556
557
  - spec/services/linked_data/mapper/graph_predicate_mapper_service_spec.rb
557
558
  - spec/services/linked_data/mapper/search_results_mapper_service_spec.rb
558
559
  - spec/services/linked_data/mapper/term_results_mapper_service_spec.rb
560
+ - spec/services/linked_data/performance_data_service_spec.rb
559
561
  - spec/services/linked_data/request_header_service_spec.rb
560
562
  - spec/spec_helper.rb
561
563
  - spec/support/matchers/include_hash.rb
@@ -565,7 +567,7 @@ homepage: https://github.com/projecthydra/questioning_authority
565
567
  licenses:
566
568
  - APACHE-2
567
569
  metadata: {}
568
- post_install_message:
570
+ post_install_message:
569
571
  rdoc_options: []
570
572
  require_paths:
571
573
  - lib
@@ -580,8 +582,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
580
582
  - !ruby/object:Gem::Version
581
583
  version: '0'
582
584
  requirements: []
583
- rubygems_version: 3.0.8
584
- signing_key:
585
+ rubyforge_project:
586
+ rubygems_version: 2.6.14
587
+ signing_key:
585
588
  specification_version: 4
586
589
  summary: You should question your authorities.
587
590
  test_files:
@@ -724,6 +727,7 @@ test_files:
724
727
  - spec/services/linked_data/mapper/context_mapper_service_spec.rb
725
728
  - spec/services/linked_data/mapper/graph_predicate_mapper_service_spec.rb
726
729
  - spec/services/linked_data/deep_sort_service_spec.rb
730
+ - spec/services/linked_data/performance_data_service_spec.rb
727
731
  - spec/services/linked_data/language_service_spec.rb
728
732
  - spec/services/linked_data/authority_url_service_spec.rb
729
733
  - spec/services/iri_template_service_spec.rb