bento_search 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +92 -90
- data/app/item_decorators/bento_search/decorator_base.rb +9 -6
- data/app/item_decorators/bento_search/standard_decorator.rb +24 -0
- data/app/search_engines/bento_search/ebsco_host_engine.rb +180 -179
- data/app/search_engines/bento_search/journal_tocs_for_journal.rb +179 -0
- data/app/views/bento_search/_std_item.html.erb +4 -4
- data/lib/bento_search/version.rb +1 -1
- data/test/decorator/decorator_base_test.rb +11 -1
- data/test/decorator/standard_decorator_test.rb +21 -0
- data/test/dummy/log/development.log +2 -0
- data/test/dummy/log/test.log +22324 -0
- data/test/{unit → search_engines}/ebsco_host_engine_test.rb +148 -130
- data/test/{unit → search_engines}/eds_engine_test.rb +0 -0
- data/test/{unit → search_engines}/google_books_engine_test.rb +0 -0
- data/test/{unit → search_engines}/google_site_search_test.rb +0 -0
- data/test/search_engines/journal_tocs_for_journal_test.rb +93 -0
- data/test/{unit → search_engines}/primo_engine_test.rb +0 -0
- data/test/{unit → search_engines}/scopus_engine_test.rb +0 -0
- data/test/{unit → search_engines}/search_engine_base_test.rb +0 -0
- data/test/{unit → search_engines}/search_engine_test.rb +0 -0
- data/test/{unit → search_engines}/summon_engine_test.rb +0 -0
- data/test/{unit → search_engines}/worldcat_sru_dc_engine_test.rb +0 -0
- data/test/{unit → search_engines}/xerxes_engine_test.rb +0 -0
- data/test/vcr_cassettes/ebscohost/RILM_record_with_ISSN_in__jid__element.yml +210 -0
- data/test/vcr_cassettes/journal_tocs/empty_results_on_bad_ISSN.yml +49 -0
- data/test/vcr_cassettes/journal_tocs/error_on_bad_registered_email.yml +41 -0
- data/test/vcr_cassettes/journal_tocs/error_on_error_response.yml +51 -0
- data/test/vcr_cassettes/journal_tocs/fetch_xml_with_hits.yml +328 -0
- data/test/vcr_cassettes/journal_tocs/fills_out_metadata.yml +396 -0
- data/test/vcr_cassettes/journal_tocs/smoke_test.yml +328 -0
- metadata +62 -61
@@ -5,311 +5,329 @@ require 'uri'
|
|
5
5
|
|
6
6
|
class EbscoHostEngineTest < ActiveSupport::TestCase
|
7
7
|
extend TestWithCassette
|
8
|
-
|
8
|
+
|
9
9
|
@@profile_id = (ENV['EBSCOHOST_PROFILE'] || 'DUMMY_PROFILE')
|
10
10
|
@@profile_pwd = (ENV['EBSCOHOST_PWD'] || 'DUMMY_PWD')
|
11
11
|
@@dbs_to_test = (ENV['EBSCOHOST_TEST_DBS'] || %w{a9h awn} )
|
12
|
-
|
12
|
+
|
13
13
|
VCR.configure do |c|
|
14
14
|
c.filter_sensitive_data("prof=DUMMY_PROFILE", :ebscohost) { "prof=#{@@profile_id}" }
|
15
15
|
c.filter_sensitive_data("pwd=DUMMY_PWD", :ebscohost) { "pwd=#{@@profile_pwd}" }
|
16
16
|
end
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
|
19
19
|
def setup
|
20
20
|
@config = {
|
21
21
|
:profile_id => @@profile_id,
|
22
22
|
:profile_password => @@profile_pwd,
|
23
23
|
:databases => @@dbs_to_test
|
24
24
|
}
|
25
|
-
|
26
|
-
@engine = BentoSearch::EbscoHostEngine.new( @config )
|
25
|
+
|
26
|
+
@engine = BentoSearch::EbscoHostEngine.new( @config )
|
27
27
|
end
|
28
|
-
|
29
|
-
|
28
|
+
|
29
|
+
|
30
30
|
def test_url_construction
|
31
31
|
url = @engine.query_url(:query => "cancer", :start => 10, :per_page => 5)
|
32
|
-
|
32
|
+
|
33
33
|
assert_present url
|
34
|
-
|
34
|
+
|
35
35
|
query_params = CGI.parse( URI.parse(url).query )
|
36
36
|
|
37
37
|
assert_equal [@engine.configuration.profile_id], query_params["prof"]
|
38
38
|
assert_equal [@engine.configuration.profile_password], query_params["pwd"]
|
39
|
-
|
39
|
+
|
40
40
|
assert_equal ["cancer"], query_params["query"]
|
41
|
-
|
41
|
+
|
42
42
|
assert_equal ["5"], query_params["numrec"]
|
43
43
|
assert_equal ["11"], query_params["startrec"]
|
44
|
-
|
44
|
+
|
45
45
|
# default sort relevance
|
46
46
|
assert_equal ["relevance"], query_params["sort"]
|
47
|
-
|
47
|
+
|
48
48
|
@engine.configuration.databases.each do |db|
|
49
49
|
assert_include query_params["db"], db
|
50
|
-
end
|
50
|
+
end
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def test_date_sort_construction
|
54
54
|
url = @engine.query_url(:query => "cancer", :sort => "date_desc")
|
55
|
-
|
55
|
+
|
56
56
|
query_params = CGI.parse( URI.parse(url).query )
|
57
|
-
|
57
|
+
|
58
58
|
assert_equal ["date"], query_params["sort"]
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def test_fielded_construction
|
62
62
|
url = @engine.query_url(:query => "cancer", :search_field => "SU")
|
63
|
-
|
63
|
+
|
64
64
|
query_params = CGI.parse( URI.parse(url).query )
|
65
|
-
|
65
|
+
|
66
66
|
assert_equal ["(SU cancer)"], query_params["query"]
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_peer_review_limit_construction
|
70
70
|
url = @engine.query_url(:query => "cancer", :search_field => "SU", :peer_reviewed_only => true)
|
71
|
-
|
71
|
+
|
72
72
|
query_params = CGI.parse( URI.parse(url).query )
|
73
|
-
|
73
|
+
|
74
74
|
assert_equal ["(SU cancer) AND (RV Y)"], query_params["query"]
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def test_date_limit_construction
|
78
|
-
url = @engine.query_url(:query => "cancer", :pubyear_start => "1980", :pubyear_end => "1989")
|
79
|
-
query_params = CGI.parse( URI.parse(url).query )
|
80
|
-
|
78
|
+
url = @engine.query_url(:query => "cancer", :pubyear_start => "1980", :pubyear_end => "1989")
|
79
|
+
query_params = CGI.parse( URI.parse(url).query )
|
80
|
+
|
81
81
|
assert_equal ["cancer AND (DT 1980-1989)"], query_params["query"]
|
82
|
-
|
82
|
+
|
83
83
|
# just one
|
84
84
|
url = @engine.query_url(:query => "cancer", :pubyear_start => "1980")
|
85
|
-
query_params = CGI.parse( URI.parse(url).query )
|
86
|
-
|
87
|
-
assert_equal ["cancer AND (DT 1980-)"], query_params["query"]
|
88
|
-
|
85
|
+
query_params = CGI.parse( URI.parse(url).query )
|
86
|
+
|
87
|
+
assert_equal ["cancer AND (DT 1980-)"], query_params["query"]
|
88
|
+
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def test_per_search_databases_construction
|
92
92
|
url = @engine.query_url(:query => "cancer", :databases => ["aaa", "bbb"])
|
93
|
-
|
93
|
+
|
94
94
|
query_params = CGI.parse( URI.parse(url).query )
|
95
|
-
|
96
|
-
assert_equal ["aaa", "bbb"].to_set, query_params["db"].to_set
|
95
|
+
|
96
|
+
assert_equal ["aaa", "bbb"].to_set, query_params["db"].to_set
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
def test_lookup_by_accession_number_construction
|
100
100
|
url = @engine.query_url(:query => "123456", :search_field => "AN")
|
101
|
-
|
101
|
+
|
102
102
|
query_params = CGI.parse( URI.parse(url).query )
|
103
|
-
|
103
|
+
|
104
104
|
assert_equal ["(AN 123456)"], query_params["query"]
|
105
105
|
end
|
106
|
-
|
107
|
-
|
106
|
+
|
107
|
+
|
108
108
|
def test_prepare_query
|
109
109
|
query = @engine.ebsco_query_prepare('one :. ; two "three four" and NOT OR five')
|
110
|
-
|
110
|
+
|
111
111
|
assert_equal 'one AND two AND "three four" AND "and" AND "NOT" AND "OR" AND five', query
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
def test_removes_paren_literals
|
115
115
|
url = @engine.query_url(:query => "cancer)", :sort => "date_desc")
|
116
|
-
|
116
|
+
|
117
117
|
query_params = CGI.parse( URI.parse(url).query )
|
118
|
-
|
118
|
+
|
119
119
|
assert_equal ["cancer "], query_params["query"]
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
def test_removes_question_marks
|
123
123
|
# who knows why, ebsco doesn't like question marks even inside
|
124
|
-
# quoted phrases, some special char to ebsco.
|
125
|
-
url = @engine.query_url(:query => "cancer?", :sort => "date_desc")
|
126
|
-
query_params = CGI.parse( URI.parse(url).query )
|
124
|
+
# quoted phrases, some special char to ebsco.
|
125
|
+
url = @engine.query_url(:query => "cancer?", :sort => "date_desc")
|
126
|
+
query_params = CGI.parse( URI.parse(url).query )
|
127
127
|
assert_equal ["cancer "], query_params["query"]
|
128
|
-
|
128
|
+
|
129
129
|
url = @engine.query_url(:query => '"cancer?"', :sort => "date_desc")
|
130
|
-
query_params = CGI.parse( URI.parse(url).query )
|
130
|
+
query_params = CGI.parse( URI.parse(url).query )
|
131
131
|
assert_equal ['"cancer "'], query_params["query"]
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
|
+
def test_removes_brackets
|
135
|
+
# Ebsco don't like brackets either
|
136
|
+
url = @engine.query_url(:query => "[cancer]")
|
137
|
+
query_params = CGI.parse( URI.parse(url).query )
|
138
|
+
assert_equal [" cancer "], query_params["query"]
|
139
|
+
end
|
140
|
+
|
134
141
|
def test_has_http_timeout_set
|
135
142
|
assert_equal BentoSearch::EbscoHostEngine::HttpTimeout, @engine.http_client.receive_timeout
|
136
143
|
assert_equal BentoSearch::EbscoHostEngine::HttpTimeout, @engine.http_client.send_timeout
|
137
144
|
assert_equal BentoSearch::EbscoHostEngine::HttpTimeout, @engine.http_client.connect_timeout
|
138
|
-
end
|
145
|
+
end
|
146
|
+
|
139
147
|
|
140
|
-
|
141
148
|
test_with_cassette("live search smoke test", :ebscohost) do
|
142
|
-
|
149
|
+
|
143
150
|
results = @engine.search(:query => "cancer")
|
144
|
-
|
151
|
+
|
145
152
|
assert_present results
|
146
153
|
assert ! results.failed?
|
147
|
-
|
154
|
+
|
148
155
|
first = results.first
|
149
|
-
|
156
|
+
|
150
157
|
assert_present first.title
|
151
|
-
assert_present first.authors
|
158
|
+
assert_present first.authors
|
152
159
|
assert_present first.year
|
153
|
-
|
160
|
+
|
154
161
|
assert_present first.format
|
155
162
|
assert_present first.format_str
|
156
|
-
|
163
|
+
|
157
164
|
assert_present first.language_code
|
158
165
|
assert_present first.language_str
|
159
|
-
|
166
|
+
|
160
167
|
assert_present first.unique_id
|
161
|
-
# db name, colon, accession number.
|
168
|
+
# db name, colon, accession number.
|
162
169
|
assert_match /.+\:.+/, first.unique_id
|
163
170
|
end
|
164
|
-
|
171
|
+
|
165
172
|
test_with_cassette("get_info", :ebscohost) do
|
166
173
|
xml = @engine.get_info
|
167
|
-
|
174
|
+
|
168
175
|
assert_present xml
|
169
|
-
|
170
|
-
assert_present xml.xpath("./info/dbInfo/db")
|
176
|
+
|
177
|
+
assert_present xml.xpath("./info/dbInfo/db")
|
171
178
|
end
|
172
|
-
|
173
|
-
test_with_cassette("error bad password", :ebscohost) do
|
179
|
+
|
180
|
+
test_with_cassette("error bad password", :ebscohost) do
|
174
181
|
error_engine = BentoSearch::EbscoHostEngine.new(
|
175
182
|
:profile_id => "bad",
|
176
183
|
:profile_password => "bad",
|
177
184
|
:databases => @@dbs_to_test
|
178
185
|
)
|
179
|
-
|
180
|
-
results = error_engine.search(:query => "cancer")
|
181
|
-
assert results.failed?
|
186
|
+
|
187
|
+
results = error_engine.search(:query => "cancer")
|
188
|
+
assert results.failed?
|
182
189
|
assert_present results.error[:error_info]
|
183
190
|
end
|
184
|
-
|
185
|
-
|
191
|
+
|
192
|
+
|
186
193
|
test_with_cassette("error bad db", :ebscohost) do
|
187
|
-
error_engine = BentoSearch::EbscoHostEngine.new(
|
194
|
+
error_engine = BentoSearch::EbscoHostEngine.new(
|
188
195
|
:profile_id => @@profile_id,
|
189
196
|
:profile_password => @@profile_pwd,
|
190
197
|
:databases => ["bad", "does_not_exist"]
|
191
|
-
)
|
192
|
-
|
193
|
-
results = error_engine.search(:query => "cancer")
|
194
|
-
assert results.failed?
|
195
|
-
assert_present results.error[:error_info]
|
196
|
-
|
198
|
+
)
|
199
|
+
|
200
|
+
results = error_engine.search(:query => "cancer")
|
201
|
+
assert results.failed?
|
202
|
+
assert_present results.error[:error_info]
|
203
|
+
|
197
204
|
end
|
198
|
-
|
205
|
+
|
199
206
|
test_with_cassette("fulltext info", :ebscohost) do
|
200
207
|
# We count on SOME records from first 10 for this query having fulltext,
|
201
208
|
# if you need to re-record VCR cassette and this query doesn't work
|
202
|
-
# for that anymore, then pick a different query.
|
209
|
+
# for that anymore, then pick a different query.
|
203
210
|
results = @engine.search("cancer")
|
204
|
-
|
211
|
+
|
205
212
|
results_with_fulltext = results.find_all {|r| r.custom_data["fulltext_formats"] }
|
206
|
-
|
213
|
+
|
207
214
|
assert_present results_with_fulltext
|
208
|
-
|
215
|
+
|
209
216
|
results_with_fulltext.each do |record|
|
210
217
|
array = record.custom_data["fulltext_formats"]
|
211
218
|
# it's an array
|
212
219
|
assert_kind_of Array, array
|
213
|
-
# who's only legal values are P, T, and C, the EBSCO vocab for formats.
|
220
|
+
# who's only legal values are P, T, and C, the EBSCO vocab for formats.
|
214
221
|
assert_equal array.length, array.find_all {|v| %w{P C T}.include?(v)}.length
|
215
|
-
|
222
|
+
|
216
223
|
assert record.link_is_fulltext?, "#link_is_fulltext set"
|
217
|
-
end
|
218
|
-
|
224
|
+
end
|
225
|
+
|
219
226
|
end
|
220
|
-
|
221
|
-
test_with_cassette("live book example", :ebscohost) do
|
227
|
+
|
228
|
+
test_with_cassette("live book example", :ebscohost) do
|
222
229
|
# We keep adjusting the EBSCOHost heuristics for guessing format,
|
223
|
-
# and causing regressions, this test guards against them.
|
224
|
-
|
230
|
+
# and causing regressions, this test guards against them.
|
231
|
+
|
225
232
|
# This particular example from RILM is a book, but
|
226
|
-
# is getting listed as a book chapter, sort of.
|
227
|
-
|
228
|
-
engine = BentoSearch::EbscoHostEngine.new( @config.merge(:databases => ["rih"]) )
|
229
|
-
|
233
|
+
# is getting listed as a book chapter, sort of.
|
234
|
+
|
235
|
+
engine = BentoSearch::EbscoHostEngine.new( @config.merge(:databases => ["rih"]) )
|
236
|
+
|
230
237
|
results = engine.search('"Funk: The music, the people, and the rhythm of the one"', :per_page => 1)
|
231
|
-
|
238
|
+
|
232
239
|
result = results.first
|
233
|
-
|
240
|
+
|
234
241
|
assert_equal "Book", result.format
|
235
242
|
assert_equal "St. Martin's Press", result.publisher
|
236
243
|
assert_equal "1996", result.year
|
237
|
-
|
244
|
+
|
238
245
|
assert_blank result.source_title
|
239
246
|
end
|
240
|
-
|
247
|
+
|
241
248
|
test_with_cassette("live pathological book_item example", :ebscohost) do
|
242
249
|
# this guy from RILM has really crappy metadata on EBSCO,
|
243
|
-
# but we still want to detect it as a book_item, not a book.
|
244
|
-
|
250
|
+
# but we still want to detect it as a book_item, not a book.
|
251
|
+
|
245
252
|
a = 'Heidegger and the management of the Haymarket Opera, 1713-1717'
|
246
|
-
|
253
|
+
|
247
254
|
engine = BentoSearch::EbscoHostEngine.new( @config.merge(:databases => ["rih"]) )
|
248
255
|
results = engine.search('"Heidegger and the management of the Haymarket Opera, 1713-1717"')
|
249
256
|
result = results.first
|
250
|
-
|
257
|
+
|
251
258
|
assert_equal :book_item, result.format
|
252
|
-
|
253
|
-
|
259
|
+
|
260
|
+
|
254
261
|
# for reasons I can't figure out, weird encoding in the hyphen makes us
|
255
262
|
# test start_with instead
|
256
263
|
assert result.title.starts_with?("Heidegger and the management of the Haymarket Opera, 1713")
|
257
264
|
assert result.source_title.starts_with?("Opera remade (1700")
|
258
265
|
end
|
259
|
-
|
266
|
+
|
260
267
|
test_with_cassette("dissertation example", :ebscohost) do
|
261
268
|
# yeah, all the weird ones are from RILM
|
262
269
|
engine = BentoSearch::EbscoHostEngine.new( @config.merge(:databases => ["rih"]) )
|
263
|
-
|
270
|
+
|
264
271
|
results = engine.search('"Research into free jazz in France, 1960-1975"')
|
265
272
|
result = results.first
|
266
|
-
|
273
|
+
|
267
274
|
assert_equal "Research into free jazz in France, 1960-1975", result.title
|
268
|
-
assert_equal :dissertation, result.format
|
275
|
+
assert_equal :dissertation, result.format
|
269
276
|
end
|
270
|
-
|
277
|
+
|
271
278
|
test_with_cassette("another dissertation", :ebscohost) do
|
272
279
|
# yeah, all the weird edge cases that make good tests are from RILM, it's
|
273
|
-
# got weird data.
|
274
|
-
|
280
|
+
# got weird data.
|
281
|
+
|
275
282
|
engine = BentoSearch::EbscoHostEngine.new( @config.merge(:databases => ["rih"]) )
|
276
283
|
results = engine.search('"Machine gun voices: Bandits, favelas, and utopia in Brazilian funk"')
|
277
284
|
result = results.first
|
278
|
-
|
285
|
+
|
279
286
|
assert_equal :dissertation, result.format
|
280
|
-
assert_equal "Machine gun voices: Bandits, favelas, and utopia in Brazilian funk", result.title
|
287
|
+
assert_equal "Machine gun voices: Bandits, favelas, and utopia in Brazilian funk", result.title
|
281
288
|
end
|
282
|
-
|
289
|
+
|
283
290
|
test_with_cassette("live #get(identifier) round trip", :ebscohost) do
|
284
291
|
results = @engine.search("cancer")
|
285
|
-
|
292
|
+
|
286
293
|
assert (! results.failed?)
|
287
|
-
|
294
|
+
|
288
295
|
item = @engine.get( results.first.unique_id )
|
289
|
-
|
296
|
+
|
290
297
|
assert_not_nil item
|
291
298
|
assert_kind_of BentoSearch::ResultItem, item
|
292
299
|
end
|
293
|
-
|
300
|
+
|
294
301
|
test_with_cassette("live get(id) with no results raises", :ebscohost) do
|
295
|
-
assert_raise(BentoSearch::NotFound) do
|
302
|
+
assert_raise(BentoSearch::NotFound) do
|
296
303
|
results = @engine.get("a9h:bar")
|
297
304
|
end
|
298
305
|
end
|
299
|
-
|
306
|
+
|
300
307
|
test_with_cassette("live get(id) on bad db raises", :ebscohost) do
|
301
308
|
assert_raise(Exception) do
|
302
309
|
results = @engine.get("badbad:bar")
|
303
310
|
end
|
304
311
|
end
|
305
|
-
|
306
|
-
|
312
|
+
|
313
|
+
|
307
314
|
test("illegal arg for get with id with no colon") do
|
308
315
|
assert_raise ArgumentError do
|
309
316
|
@engine.get("no_colon_in_here")
|
310
317
|
end
|
311
318
|
end
|
312
|
-
|
313
|
-
|
314
|
-
|
319
|
+
|
320
|
+
test_with_cassette("RILM record with ISSN in <jid> element", :ebscohost) do
|
321
|
+
engine = BentoSearch::EbscoHostEngine.new( @config.merge(:databases => ["rih"]) )
|
322
|
+
results = engine.search('"Schumann\'s Dichterliebe and early Romantic poetics: Fragmentation of desire"')
|
323
|
+
|
324
|
+
assert_present results
|
325
|
+
|
326
|
+
first = results.first
|
327
|
+
|
328
|
+
assert_present first.issn
|
329
|
+
end
|
330
|
+
|
331
|
+
|
332
|
+
|
315
333
|
end
|