bento_search 1.5.0 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +27 -24
- data/Rakefile +30 -11
- data/app/assets/javascripts/bento_search/ajax_load.js +54 -22
- data/app/controllers/bento_search/search_controller.rb +31 -30
- data/app/helpers/bento_search_helper.rb +72 -74
- data/app/models/bento_search/concurrent_searcher.rb +136 -0
- data/app/models/bento_search/result_item.rb +15 -12
- data/app/models/bento_search/results/serialization.rb +22 -13
- data/app/models/bento_search/search_engine.rb +170 -140
- data/app/search_engines/bento_search/doaj_articles_engine.rb +20 -20
- data/app/search_engines/bento_search/ebsco_host_engine.rb +3 -3
- data/app/search_engines/bento_search/eds_engine.rb +326 -206
- data/app/search_engines/bento_search/google_books_engine.rb +2 -2
- data/app/search_engines/bento_search/scopus_engine.rb +87 -87
- data/app/search_engines/bento_search/summon_engine.rb +1 -1
- data/app/views/bento_search/_ajax_loading.html.erb +17 -0
- data/app/views/bento_search/_item_title.html.erb +2 -4
- data/app/views/bento_search/_link.html.erb +3 -3
- data/lib/bento_search.rb +24 -9
- data/lib/bento_search/engine.rb +2 -0
- data/lib/bento_search/version.rb +1 -1
- data/lib/generators/bento_search/install/ajax_load_js_generator.rb +15 -0
- data/test/decorator/standard_decorator_test.rb +30 -30
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/config/application.rb +7 -0
- data/test/dummy/config/boot.rb +4 -9
- data/test/dummy/config/environments/development.rb +2 -0
- data/test/dummy/config/environments/production.rb +7 -1
- data/test/dummy/config/environments/test.rb +10 -3
- data/test/functional/bento_search/search_controller_test.rb +68 -58
- data/test/helper/bento_search_helper_test.rb +103 -103
- data/test/search_engines/doaj_articles_engine_test.rb +9 -9
- data/test/search_engines/eds_engine_test.rb +91 -59
- data/test/search_engines/google_site_search_test.rb +48 -48
- data/test/search_engines/scopus_engine_test.rb +51 -51
- data/test/search_engines/search_engine_base_test.rb +108 -86
- data/test/search_engines/search_engine_test.rb +68 -56
- data/test/support/atom.xsd.xml +3 -3
- data/test/support/xml.xsd +117 -0
- data/test/test_helper.rb +23 -12
- data/test/unit/concurrent_searcher_test.rb +75 -0
- data/test/unit/pagination_test.rb +12 -12
- data/test/vcr_cassettes/eds/FullText_CustomLink.yml +198 -0
- data/test/vcr_cassettes/eds/basic_search_smoke_test.yml +1036 -1729
- data/test/vcr_cassettes/eds/catalog_ebook_query.yml +218 -0
- data/test/vcr_cassettes/eds/catalog_query.yml +255 -0
- data/test/vcr_cassettes/eds/get_auth_token.yml +11 -44
- data/test/vcr_cassettes/eds/get_auth_token_failure.yml +10 -7
- data/test/vcr_cassettes/eds/get_with_auth.yml +144 -153
- data/test/vcr_cassettes/eds/get_with_auth_recovers_from_bad_auth.yml +167 -223
- data/test/view/atom_results_test.rb +94 -94
- metadata +36 -46
- data/app/assets/javascripts/bento_search.js +0 -3
- data/app/item_decorators/bento_search/ebscohost/conditional_openurl_main_link.rb +0 -36
- data/app/item_decorators/bento_search/only_premade_openurl.rb +0 -20
- data/app/item_decorators/bento_search/openurl_add_other_link.rb +0 -39
- data/app/item_decorators/bento_search/openurl_main_link.rb +0 -34
- data/app/models/bento_search/multi_searcher.rb +0 -131
- data/test/dummy/config/initializers/secret_token.rb +0 -8
- data/test/unit/multi_searcher_test.rb +0 -49
@@ -1,246 +1,246 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
require 'nokogiri'
|
2
3
|
|
3
4
|
require 'test_helper'
|
4
5
|
|
5
6
|
class BentoSearchHelperTest < ActionView::TestCase
|
6
7
|
include BentoSearchHelper
|
7
|
-
|
8
|
+
|
8
9
|
MockEngine = BentoSearch::MockEngine
|
9
|
-
|
10
|
+
|
10
11
|
def teardown
|
11
12
|
BentoSearch.reset_engine_registrations!
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
def setup
|
15
16
|
# Make routing work
|
16
|
-
@routes = Rails.application.routes
|
17
|
-
|
17
|
+
@routes = Rails.application.routes
|
18
|
+
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
def test_with_results_arg
|
21
22
|
results = MockEngine.new.search(:query => "foo")
|
22
|
-
bento_search(results)
|
23
|
-
|
23
|
+
bento_search(results)
|
24
|
+
|
24
25
|
assert_select("div.bento_item", 10)
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
def test_custom_partial
|
28
29
|
results = MockEngine.new(:for_display => {:item_partial => "test_custom_item_partial"})
|
29
|
-
|
30
|
+
|
30
31
|
bento_search(results)
|
31
|
-
|
32
|
+
|
32
33
|
assert_select("p.custom_item_partial")
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
def test_with_failed_search
|
36
37
|
results = BentoSearch::Results.new
|
37
38
|
results.error = {:error => true}
|
38
|
-
|
39
|
+
|
39
40
|
assert results.failed?
|
40
|
-
|
41
|
-
response = HTML::Document.new(bento_search(results))
|
42
|
-
|
43
|
-
assert (no_results_div = response.find(:attributes => {:class => "bento_search_error alert alert-error"})), "has search_error div"
|
44
|
-
|
45
|
-
assert no_results_div.match(Regexp.new I18n.translate("bento_search.search_error")), "has error message"
|
46
41
|
|
47
|
-
|
42
|
+
response = Nokogiri::HTML(bento_search(results))
|
43
|
+
|
44
|
+
assert (no_results_div = response.at_css(".bento_search_error.alert.alert-error")), "has search_error div"
|
45
|
+
|
46
|
+
assert no_results_div.text =~ Regexp.new(I18n.translate("bento_search.search_error")), "has error message"
|
47
|
+
|
48
|
+
assert_nil response.at_css(".bento_item")
|
48
49
|
end
|
49
|
-
|
50
|
+
|
50
51
|
def test_with_empty_results
|
51
52
|
results = MockEngine.new(:num_results => 0).search(:query => "foo")
|
52
|
-
|
53
|
-
response = HTML::Document.new(bento_search(results))
|
54
|
-
|
55
|
-
assert (no_results_div = response.find(:attributes => {:class => "bento_search_no_results"})), "has no_results div"
|
56
|
-
assert no_results_div.match(Regexp.new(I18n.translate("bento_search.no_results")))
|
57
53
|
|
58
|
-
|
59
|
-
|
54
|
+
response = Nokogiri::HTML(bento_search(results))
|
55
|
+
|
56
|
+
assert (no_results_div = response.at_css(".bento_search_no_results")), "has no_results div"
|
57
|
+
assert no_results_div.text =~ (Regexp.new(I18n.translate("bento_search.no_results")))
|
58
|
+
|
59
|
+
assert_nil response.at_css(".bento_item"), "has no results message"
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_with_engine_arg
|
63
63
|
engine = MockEngine.new
|
64
64
|
bento_search(engine, :query => "QUERY")
|
65
|
-
|
65
|
+
|
66
66
|
assert_select("div.bento_item", 10).each_with_index do |node, i|
|
67
67
|
assert_select node, "*", /QUERY/
|
68
68
|
assert_select node, "*", /#{i +1 }/
|
69
|
-
end
|
69
|
+
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def test_with_registered_id
|
73
73
|
BentoSearch.register_engine("test_engine") do |conf|
|
74
74
|
conf.engine = "MockEngine"
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
bento_search("test_engine", :query => "QUERY")
|
78
|
-
|
78
|
+
|
79
79
|
assert_select("div.bento_item", 10).each_with_index do |node, i|
|
80
80
|
assert_select node, "*", /QUERY/
|
81
|
-
assert_select node, "*", /#{i +1 }/
|
82
|
-
end
|
81
|
+
assert_select node, "*", /#{i +1 }/
|
82
|
+
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
def test_ajax_load_without_registration
|
86
86
|
assert_raises(ArgumentError) { bento_search(MockEngine.new, :load => :ajax_auto) }
|
87
87
|
end
|
88
|
-
|
89
88
|
|
90
|
-
|
91
|
-
|
89
|
+
|
90
|
+
|
91
|
+
def test_ajax_load
|
92
92
|
BentoSearch.register_engine("test_engine") do |conf|
|
93
93
|
conf.engine = "MockEngine"
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
results = bento_search("test_engine", :query => "QUERY", :load => :ajax_auto)
|
97
|
-
results = HTML
|
98
|
-
|
99
|
-
|
100
|
-
div = results.
|
97
|
+
results = Nokogiri::HTML(results)
|
98
|
+
|
99
|
+
|
100
|
+
div = results.at_css(".bento_search_ajax_wait")
|
101
101
|
assert div, "produces div.bento_search_ajax_wait"
|
102
|
+
|
102
103
|
assert_equal "ajax_auto", div["data-bento-search-load"], "has data-bento-search-load attribute"
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
url = URI.parse(div.attributes["data-bento-ajax-url"])
|
105
|
+
assert_present div["data-bento-ajax-url"]
|
106
|
+
url = URI.parse(div["data-bento-ajax-url"])
|
107
107
|
assert_equal "/bento/test_engine", url.path
|
108
|
-
|
108
|
+
|
109
109
|
query = CGI.parse(url.query.gsub("&", "&")) # gsub weirdness of HTML::Tag
|
110
110
|
assert_equal ["QUERY"], query["query"]
|
111
111
|
assert_empty query["load"]
|
112
|
-
|
112
|
+
|
113
113
|
# hidden loading msg
|
114
|
-
loading_msg = div.
|
114
|
+
loading_msg = div.at_css(".bento_search_ajax_loading")
|
115
115
|
assert_present loading_msg, "bento_search_ajax_loading present"
|
116
116
|
assert_match /display\:none/, loading_msg["style"], "loading has CSS style hidden"
|
117
|
-
|
118
|
-
assert div.
|
119
|
-
|
120
|
-
assert (img = loading_msg.
|
121
|
-
assert_equal I18n.translate("bento_search.ajax_loading"), img
|
117
|
+
|
118
|
+
assert div.at_css("noscript"), "has <noscript> tag"
|
119
|
+
|
120
|
+
assert (img = loading_msg.at_css("img")), "Has spinner gif"
|
121
|
+
assert_equal I18n.translate("bento_search.ajax_loading"), img["alt"]
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def test_ajax_triggered_load
|
125
125
|
BentoSearch.register_engine("test_engine") do |conf|
|
126
126
|
conf.engine = "MockEngine"
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
results = bento_search("test_engine", :query => "QUERY", :load => :ajax_triggered)
|
130
|
-
results = HTML
|
130
|
+
results = Nokogiri::HTML(results)
|
131
131
|
|
132
|
-
div = results.
|
132
|
+
div = results.at_css(".bento_search_ajax_wait")
|
133
133
|
assert div, "produces div.bento_search_ajax_wait"
|
134
134
|
assert_equal "ajax_triggered", div["data-bento-search-load"], "has data-bento-search-load attribute"
|
135
135
|
|
136
136
|
# hidden loading msg
|
137
|
-
loading_msg = div.
|
137
|
+
loading_msg = div.at_css(".bento_search_ajax_loading")
|
138
138
|
assert_present loading_msg, "bento_search_ajax_loading present"
|
139
139
|
assert_match /display\:none/, loading_msg["style"], "loading has CSS style hidden"
|
140
140
|
end
|
141
|
-
|
142
|
-
|
141
|
+
|
142
|
+
|
143
143
|
def test_sort_hash_for
|
144
144
|
tested_keys = %w{title_asc date_desc relevance author_asc}
|
145
|
-
|
145
|
+
|
146
146
|
sort_definitions = {}
|
147
147
|
tested_keys.each {|k| sort_definitions[k] = {}}
|
148
|
-
|
148
|
+
|
149
149
|
engine = MockEngine.new(:sort_definitions => sort_definitions)
|
150
150
|
|
151
151
|
hash = bento_sort_hash_for(engine)
|
152
|
-
|
152
|
+
|
153
153
|
assert_present hash
|
154
|
-
|
154
|
+
|
155
155
|
tested_keys.each do |key|
|
156
156
|
assert_equal key, hash[ I18n.translate(key, :scope => "bento_search.sort_keys") ]
|
157
|
-
end
|
157
|
+
end
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
def test_sort_hash_for_no_i18n
|
161
|
-
# If there's no 18n key available, use reasonable humanized approximation
|
162
|
-
|
161
|
+
# If there's no 18n key available, use reasonable humanized approximation
|
162
|
+
|
163
163
|
engine = MockEngine.new(:sort_definitions => {"no_key_test" => {}})
|
164
|
-
|
164
|
+
|
165
165
|
hash = bento_sort_hash_for(engine)
|
166
|
-
|
166
|
+
|
167
167
|
assert_present hash
|
168
|
-
|
168
|
+
|
169
169
|
key = hash.key("no_key_test")
|
170
|
-
|
170
|
+
|
171
171
|
assert_no_match /translation missing/, key
|
172
|
-
|
172
|
+
|
173
173
|
assert_equal "No Key Test", key
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
def test_field_hash_for
|
177
177
|
# generic
|
178
178
|
hash = bento_field_hash_for(nil)
|
179
|
-
|
179
|
+
|
180
180
|
assert_equal I18n.t("bento_search.search_fields").invert, hash
|
181
|
-
|
181
|
+
|
182
182
|
# specific engine
|
183
183
|
engine = MockEngine.new(:search_field_definitions => {
|
184
184
|
:mytitle => {:semantic => :title},
|
185
185
|
:myauthor => {:semantic => :author},
|
186
186
|
:myissn => {:semantic => :issn},
|
187
|
-
:mycustom => {}
|
188
|
-
})
|
187
|
+
:mycustom => {}
|
188
|
+
})
|
189
189
|
hash = bento_field_hash_for(engine)
|
190
190
|
expected = { I18n.t("bento_search.search_fields.title") => 'title',
|
191
191
|
I18n.t("bento_search.search_fields.author") => 'author',
|
192
|
-
I18n.t("bento_search.search_fields.issn") => 'issn',
|
192
|
+
I18n.t("bento_search.search_fields.issn") => 'issn',
|
193
193
|
}
|
194
194
|
assert_equal expected, hash
|
195
|
-
|
195
|
+
|
196
196
|
# only
|
197
197
|
hash = bento_field_hash_for(engine, :only => :author)
|
198
198
|
assert_equal( {"Author" => "author"}, hash )
|
199
199
|
hash = bento_field_hash_for(engine, :only => ["author", "title"])
|
200
200
|
assert_equal( {"Title" => "title", "Author" => "author"}, hash )
|
201
|
-
|
201
|
+
|
202
202
|
# except
|
203
|
-
|
204
|
-
|
203
|
+
|
204
|
+
|
205
205
|
end
|
206
|
-
|
206
|
+
|
207
207
|
def test_bento_decorate
|
208
208
|
item = BentoSearch::ResultItem.new(:title => "foo")
|
209
|
-
|
209
|
+
|
210
210
|
decorated = bento_decorate(item)
|
211
|
-
|
211
|
+
|
212
212
|
assert_kind_of BentoSearch::StandardDecorator, decorated
|
213
|
-
|
213
|
+
|
214
214
|
assert_equal "foo", decorated.title
|
215
|
-
|
216
|
-
assert decorated.send("_h").respond_to?(:url_for), "has ActionView helpers available internally"
|
215
|
+
|
216
|
+
assert decorated.send("_h").respond_to?(:url_for), "has ActionView helpers available internally"
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
def test_bento_decorate_with_yield
|
220
220
|
item = BentoSearch::ResultItem.new(:title => "foo")
|
221
|
-
|
221
|
+
|
222
222
|
got_here = false
|
223
|
-
|
223
|
+
|
224
224
|
bento_decorate(item) do |decorated|
|
225
225
|
got_here = true
|
226
226
|
assert_equal "foo", decorated.title
|
227
227
|
end
|
228
|
-
|
228
|
+
|
229
229
|
assert got_here, "Yielded block is called"
|
230
|
-
|
230
|
+
|
231
231
|
end
|
232
|
-
|
232
|
+
|
233
233
|
class SomeDecorator < BentoSearch::StandardDecorator ; end
|
234
|
-
|
234
|
+
|
235
235
|
def test_bento_decorate_with_custom_decorator
|
236
236
|
item = BentoSearch::ResultItem.new(:title => "foo", :decorator => "BentoSearchHelperTest::SomeDecorator")
|
237
|
-
|
237
|
+
|
238
238
|
decorated = bento_decorate(item)
|
239
|
-
|
239
|
+
|
240
240
|
assert_kind_of BentoSearchHelperTest::SomeDecorator, decorated
|
241
241
|
end
|
242
242
|
|
243
|
-
|
244
243
|
|
245
|
-
|
244
|
+
|
245
|
+
|
246
246
|
end
|
@@ -5,7 +5,7 @@ require 'cgi'
|
|
5
5
|
class DoajArticlesEngineTest < ActiveSupport::TestCase
|
6
6
|
extend TestWithCassette
|
7
7
|
|
8
|
-
def setup
|
8
|
+
def setup
|
9
9
|
@engine = BentoSearch::DoajArticlesEngine.new
|
10
10
|
# tell it not to send our bad API key
|
11
11
|
end
|
@@ -13,15 +13,15 @@ class DoajArticlesEngineTest < ActiveSupport::TestCase
|
|
13
13
|
test_with_cassette("basic search", :doaj_articles) do
|
14
14
|
results = @engine.search("Breast cancer patients with lobular cancer more commonly have a father than a mother diagnosed with cancer")
|
15
15
|
|
16
|
-
assert_kind_of BentoSearch::Results, results
|
16
|
+
assert_kind_of BentoSearch::Results, results
|
17
17
|
assert ! results.failed?
|
18
18
|
|
19
19
|
assert_not_nil results.total_items
|
20
20
|
assert_equal 0, results.start
|
21
21
|
assert_equal 10, results.per_page
|
22
|
-
|
22
|
+
|
23
23
|
assert_not_empty results
|
24
|
-
|
24
|
+
|
25
25
|
first = results.first
|
26
26
|
|
27
27
|
assert_present first.unique_id
|
@@ -52,11 +52,11 @@ class DoajArticlesEngineTest < ActiveSupport::TestCase
|
|
52
52
|
|
53
53
|
test_with_cassette("pagination", :doaj_articles) do
|
54
54
|
results = @engine.search("cancer", :per_page => 20, :page => 3)
|
55
|
-
|
55
|
+
|
56
56
|
assert ! results.failed?
|
57
|
-
|
57
|
+
|
58
58
|
assert_equal 20, results.length
|
59
|
-
|
59
|
+
|
60
60
|
assert_equal 20, results.size
|
61
61
|
assert_equal 40, results.start
|
62
62
|
assert_equal 20, results.per_page
|
@@ -70,7 +70,7 @@ class DoajArticlesEngineTest < ActiveSupport::TestCase
|
|
70
70
|
assert results.failed?
|
71
71
|
assert_kind_of Hash, results.error
|
72
72
|
assert_present results.error[:message]
|
73
|
-
assert_present results.error[:status]
|
73
|
+
assert_present results.error[:status]
|
74
74
|
end
|
75
75
|
|
76
76
|
test_with_cassette("live #get(identifier) round trip", :doaj_articles) do
|
@@ -197,4 +197,4 @@ class DoajArticlesEngineTest < ActiveSupport::TestCase
|
|
197
197
|
assert_equal ["article.created_date:desc"], query["sort"]
|
198
198
|
end
|
199
199
|
|
200
|
-
end
|
200
|
+
end
|
@@ -2,12 +2,14 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class EdsEngineTest < ActiveSupport::TestCase
|
4
4
|
extend TestWithCassette
|
5
|
-
|
5
|
+
|
6
6
|
@@user_id = (ENV['EDS_USER_ID'] || 'DUMMY_USER_ID')
|
7
7
|
@@password = (ENV['EDS_PASSWORD'] || 'DUMMY_PWD')
|
8
|
-
@@profile = (ENV['EDS_PROFILE'] || '
|
9
|
-
|
10
|
-
|
8
|
+
@@profile = (ENV['EDS_PROFILE'] || 'wsapi')
|
9
|
+
# something where the first hit will be from catalog for the profile above
|
10
|
+
@@catalog_result_query = (ENV['EDS_CATALOG_RESULT_QUERY'] || 'New York exposed the gilded age police scandal that launched the progressive era Daniel Czitrom')
|
11
|
+
@@catalog_ebook_result_query = (ENV['EDS_CATALOG_EBOOK_RESULT_QUERY'] || 'Stakeholder forum on federal wetlands mitigation environmental law institute')
|
12
|
+
@@catalog_custom_result_query = (ENV['EDS_CATALOG_CUSTOM_RESULT_QUERY'] || 'Drafting New York Civil-Litigation Documents Part XXIV Summary-Judgment Motions Continued')
|
11
13
|
VCR.configure do |c|
|
12
14
|
c.filter_sensitive_data("DUMMY_USER_ID", :eds) { @@user_id }
|
13
15
|
c.filter_sensitive_data("DUMMY_PWD", :eds) { @@password }
|
@@ -16,140 +18,170 @@ class EdsEngineTest < ActiveSupport::TestCase
|
|
16
18
|
def setup
|
17
19
|
# Class-level remembered auth token messes up our VCR-recording,
|
18
20
|
# since one test will try to use an auth token fetched by a different
|
19
|
-
# test. For testing, blank out the cache before each test.
|
21
|
+
# test. For testing, blank out the cache before each test.
|
20
22
|
BentoSearch::EdsEngine.remembered_auth = nil
|
21
23
|
|
22
24
|
@config = {:user_id => @@user_id, :password => @@password, :profile => @@profile, :auth => true}
|
23
25
|
@engine = BentoSearch::EdsEngine.new(@config)
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
test "construct simple search, with comma escaping" do
|
27
29
|
url = @engine.construct_search_url(:query => "foo, bar,baz")
|
28
|
-
|
30
|
+
|
29
31
|
query_params = CGI.parse( URI.parse(url).query )
|
30
32
|
|
31
33
|
assert_equal ["all"], query_params["searchmode"]
|
32
|
-
|
34
|
+
|
33
35
|
assert_equal ["detailed"], query_params["view"]
|
34
|
-
|
35
|
-
assert_equal ["AND,foo bar baz"], query_params["query"]
|
36
|
+
|
37
|
+
assert_equal ["AND,foo bar baz"], query_params["query"]
|
36
38
|
end
|
37
|
-
|
39
|
+
|
38
40
|
test "only_source_types config" do
|
39
41
|
engine = BentoSearch::EdsEngine.new( @config.merge(:only_source_types => [
|
40
42
|
"Academic Journals", "Magazines"
|
41
43
|
]))
|
42
|
-
|
44
|
+
|
43
45
|
url = engine.construct_search_url(:query => "cancer", :per_page => 10)
|
44
|
-
|
46
|
+
|
45
47
|
query_params = CGI.parse( URI.parse(url).query )
|
46
|
-
|
48
|
+
|
47
49
|
# should be
|
48
50
|
# facetfilter=1,SourceType:Academic Journals,SourceType:Magazines
|
49
51
|
# but with value query encoded
|
50
|
-
|
52
|
+
|
51
53
|
assert_equal 1, query_params["facetfilter"].length
|
52
|
-
|
54
|
+
|
53
55
|
facetfilter = query_params["facetfilter"].first
|
54
|
-
|
56
|
+
|
55
57
|
parts = facetfilter.split(",")
|
56
|
-
|
58
|
+
|
57
59
|
assert_equal 3, parts.length
|
58
|
-
|
60
|
+
|
59
61
|
assert_equal "1", parts.first
|
60
|
-
|
62
|
+
|
61
63
|
assert_includes parts, "SourceType:Academic Journals"
|
62
|
-
assert_includes parts, "SourceType:Magazines"
|
64
|
+
assert_includes parts, "SourceType:Magazines"
|
63
65
|
end
|
64
|
-
|
66
|
+
|
65
67
|
def test_has_http_timeout_set
|
66
68
|
assert_equal BentoSearch::EdsEngine::HttpTimeout, @engine.http_client.receive_timeout
|
67
69
|
assert_equal BentoSearch::EdsEngine::HttpTimeout, @engine.http_client.send_timeout
|
68
70
|
assert_equal BentoSearch::EdsEngine::HttpTimeout, @engine.http_client.connect_timeout
|
69
|
-
end
|
71
|
+
end
|
72
|
+
|
70
73
|
|
71
|
-
|
72
74
|
test_with_cassette("get_auth_token failure", :eds) do
|
73
75
|
engine = BentoSearch::EdsEngine.new(:user_id => "bad", :password => "bad", :profile => "bad")
|
74
76
|
exception = assert_raise(BentoSearch::EdsEngine::EdsCommException) do
|
75
77
|
token = engine.get_auth_token
|
76
|
-
end
|
77
|
-
|
78
|
+
end
|
79
|
+
|
78
80
|
assert_present exception.http_status
|
79
|
-
assert_present exception.http_body
|
81
|
+
assert_present exception.http_body
|
80
82
|
end
|
81
|
-
|
83
|
+
|
82
84
|
test_with_cassette("get_auth_token", :eds) do
|
83
85
|
token = @engine.get_auth_token
|
84
|
-
|
86
|
+
|
85
87
|
assert_present token
|
86
88
|
end
|
87
|
-
|
89
|
+
|
88
90
|
# No idea why VCR is having buggy problems with record and playback of this request
|
89
|
-
# We'll emcompass it in the get_with_auth test
|
91
|
+
# We'll emcompass it in the get_with_auth test
|
90
92
|
#
|
91
|
-
#test_with_cassette("with_session", :eds, :match_requests_on => [:method, :uri, :headers, :body]) do
|
93
|
+
#test_with_cassette("with_session", :eds, :match_requests_on => [:method, :uri, :headers, :body]) do
|
92
94
|
# @engine.with_session do |session_token|
|
93
95
|
# assert_present session_token
|
94
|
-
# end
|
96
|
+
# end
|
95
97
|
#end
|
96
|
-
|
98
|
+
|
97
99
|
test_with_cassette("get_with_auth", :eds) do
|
98
100
|
@engine.with_session do |session_token|
|
99
101
|
assert_present session_token
|
100
|
-
|
102
|
+
|
101
103
|
# Coudln't get 'info' request to work even as a test, let's
|
102
|
-
# try a simple search.
|
104
|
+
# try a simple search.
|
103
105
|
url = "#{@engine.configuration.base_url}info"
|
104
106
|
response = @engine.get_with_auth(url, session_token)
|
105
|
-
|
107
|
+
|
106
108
|
assert_present response
|
107
109
|
assert_kind_of Nokogiri::XML::Document, response
|
108
|
-
|
109
|
-
assert_nil response.at_xpath("//ErrorNumber"), "no error report in result"
|
110
|
-
end
|
110
|
+
|
111
|
+
assert_nil response.at_xpath("//ErrorNumber"), "no error report in result"
|
112
|
+
end
|
111
113
|
end
|
112
|
-
|
114
|
+
|
113
115
|
test_with_cassette("get_with_auth recovers from bad auth", :eds) do
|
114
116
|
@engine.with_session do |session_token|
|
115
117
|
BentoSearch::EdsEngine.remembered_auth = "BAD"
|
116
|
-
|
118
|
+
|
117
119
|
url = "#{@engine.configuration.base_url}info"
|
118
120
|
response = @engine.get_with_auth(url, session_token)
|
119
|
-
|
121
|
+
|
120
122
|
assert_present response
|
121
123
|
assert_kind_of Nokogiri::XML::Document, response
|
122
|
-
|
123
|
-
assert_nil response.at_xpath("//ErrorNumber"), "no error report in result"
|
124
|
-
end
|
125
|
-
|
124
|
+
|
125
|
+
assert_nil response.at_xpath("//ErrorNumber"), "no error report in result"
|
126
|
+
end
|
127
|
+
|
126
128
|
BentoSearch::EdsEngine.remembered_auth = nil
|
127
129
|
end
|
128
|
-
|
130
|
+
|
129
131
|
test_with_cassette("basic search smoke test", :eds) do
|
130
|
-
results = @engine.search("cancer")
|
131
|
-
|
132
|
+
results = @engine.search("cancer")
|
133
|
+
|
132
134
|
assert_present results
|
133
|
-
|
135
|
+
|
134
136
|
assert_present results.total_items
|
135
|
-
|
137
|
+
|
136
138
|
first = results.first
|
137
139
|
|
138
140
|
assert_present first.title
|
139
141
|
assert first.title.html_safe? # yeah, for now we use EDS html
|
140
|
-
|
142
|
+
|
141
143
|
assert_present first.abstract
|
142
144
|
assert_present first.abstract.html_safe?
|
143
|
-
|
144
|
-
assert_present first.custom_data["citation_blob"]
|
145
|
-
|
145
|
+
|
146
|
+
assert_present first.custom_data["citation_blob"]
|
147
|
+
|
148
|
+
assert_present first.source_title
|
149
|
+
assert_present first.issn
|
150
|
+
assert_present first.volume
|
151
|
+
assert_present first.issue
|
152
|
+
assert_present first.year
|
153
|
+
assert_present first.publication_date
|
154
|
+
assert_present first.start_page
|
155
|
+
assert_present first.end_page
|
156
|
+
|
157
|
+
assert_present first.doi
|
158
|
+
|
146
159
|
assert_present first.format_str
|
147
|
-
|
160
|
+
|
148
161
|
assert_present first.unique_id
|
149
162
|
# EDS id is db name, colon, accession number
|
150
163
|
assert_match /.+\:.+/, first.unique_id
|
151
164
|
end
|
152
|
-
|
153
|
-
|
165
|
+
|
166
|
+
test_with_cassette("catalog query", :eds) do
|
167
|
+
results = @engine.search(@@catalog_result_query)
|
168
|
+
|
169
|
+
cat_result = results.first
|
170
|
+
|
171
|
+
assert_present cat_result.custom_data[:holdings]
|
172
|
+
assert cat_result.custom_data[:holdings].all? { |h| h.location.present? && h.call_number.present? }
|
173
|
+
end
|
174
|
+
|
175
|
+
test_with_cassette("catalog ebook query", :eds) do
|
176
|
+
result = @engine.search(@@catalog_ebook_result_query).first
|
177
|
+
|
178
|
+
assert_present result.other_links
|
179
|
+
end
|
180
|
+
|
181
|
+
test_with_cassette("FullText CustomLink", :eds) do
|
182
|
+
result = @engine.search(@@catalog_custom_result_query).first
|
183
|
+
assert_present result
|
184
|
+
assert result.other_links.any? { |r| r.label.present? && r.label != "Link" && r.url.present? && URI::regexp =~ r.url && r.rel == "alternate"}
|
185
|
+
end
|
154
186
|
end
|
155
187
|
|