bento_search 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +299 -0
- data/Rakefile +40 -0
- data/app/assets/images/bento_search/large_loader.gif +0 -0
- data/app/assets/javascripts/bento_search.js +3 -0
- data/app/assets/javascripts/bento_search/ajax_load.js +22 -0
- data/app/assets/stylesheets/bento_search/bento.css +4 -0
- data/app/controllers/bento_search/bento_search_controller.rb +7 -0
- data/app/controllers/bento_search/search_controller.rb +72 -0
- data/app/helpers/bento_search_helper.rb +138 -0
- data/app/item_decorators/bento_search/only_premade_openurl.rb +16 -0
- data/app/item_decorators/bento_search/openurl_add_other_link.rb +35 -0
- data/app/item_decorators/bento_search/openurl_main_link.rb +30 -0
- data/app/models/bento_search/author.rb +25 -0
- data/app/models/bento_search/link.rb +30 -0
- data/app/models/bento_search/multi_searcher.rb +109 -0
- data/app/models/bento_search/openurl_creator.rb +128 -0
- data/app/models/bento_search/registrar.rb +70 -0
- data/app/models/bento_search/result_item.rb +203 -0
- data/app/models/bento_search/results.rb +54 -0
- data/app/models/bento_search/results/pagination.rb +67 -0
- data/app/models/bento_search/search_engine.rb +219 -0
- data/app/models/bento_search/search_engine/capabilities.rb +65 -0
- data/app/search_engines/bento_search/#Untitled-1# +11 -0
- data/app/search_engines/bento_search/ebsco_host_engine.rb +356 -0
- data/app/search_engines/bento_search/eds_engine.rb +557 -0
- data/app/search_engines/bento_search/google_books_engine.rb +184 -0
- data/app/search_engines/bento_search/primo_engine.rb +231 -0
- data/app/search_engines/bento_search/scopus_engine.rb +295 -0
- data/app/search_engines/bento_search/summon_engine.rb +398 -0
- data/app/search_engines/bento_search/xerxes_engine.rb +168 -0
- data/app/views/bento_search/_link.html.erb +4 -0
- data/app/views/bento_search/_search_error.html.erb +22 -0
- data/app/views/bento_search/_std_item.html.erb +39 -0
- data/app/views/bento_search/search/search.html.erb +1 -0
- data/config/locales/en.yml +25 -0
- data/lib/bento_search.rb +29 -0
- data/lib/bento_search/engine.rb +5 -0
- data/lib/bento_search/routes.rb +45 -0
- data/lib/bento_search/version.rb +3 -0
- data/lib/generators/bento_search/pull_ebsco_dbs_generator.rb +24 -0
- data/lib/generators/bento_search/templates/ebsco_global_var.erb +6 -0
- data/lib/http_client_patch/include_client.rb +86 -0
- data/lib/tasks/bento_search_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +3100 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/bento_search/search_controller_test.rb +81 -0
- data/test/helper/bento_search_helper_test.rb +125 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/support/mock_engine.rb +23 -0
- data/test/support/test_with_cassette.rb +38 -0
- data/test/test_helper.rb +52 -0
- data/test/unit/#vcr_test.rb# +68 -0
- data/test/unit/ebsco_host_engine_test.rb +134 -0
- data/test/unit/eds_engine_test.rb +105 -0
- data/test/unit/google_books_engine_test.rb +93 -0
- data/test/unit/item_decorators_test.rb +66 -0
- data/test/unit/multi_searcher_test.rb +49 -0
- data/test/unit/openurl_creator_test.rb +111 -0
- data/test/unit/pagination_test.rb +59 -0
- data/test/unit/primo_engine_test.rb +37 -0
- data/test/unit/register_engine_test.rb +50 -0
- data/test/unit/result_item_display_test.rb +39 -0
- data/test/unit/result_item_test.rb +36 -0
- data/test/unit/scopus_engine_test.rb +130 -0
- data/test/unit/search_engine_base_test.rb +178 -0
- data/test/unit/search_engine_test.rb +95 -0
- data/test/unit/summon_engine_test.rb +161 -0
- data/test/unit/xerxes_engine_test.rb +70 -0
- data/test/vcr_cassettes/ebscohost/error_bad_db.yml +45 -0
- data/test/vcr_cassettes/ebscohost/error_bad_password.yml +45 -0
- data/test/vcr_cassettes/ebscohost/get_info.yml +3626 -0
- data/test/vcr_cassettes/ebscohost/live_search.yml +45 -0
- data/test/vcr_cassettes/ebscohost/live_search_smoke_test.yml +1311 -0
- data/test/vcr_cassettes/eds/basic_search_smoke_test.yml +1811 -0
- data/test/vcr_cassettes/eds/get_auth_token.yml +75 -0
- data/test/vcr_cassettes/eds/get_auth_token_failure.yml +39 -0
- data/test/vcr_cassettes/eds/get_with_auth.yml +243 -0
- data/test/vcr_cassettes/eds/get_with_auth_recovers_from_bad_auth.yml +368 -0
- data/test/vcr_cassettes/gbs/error_condition.yml +40 -0
- data/test/vcr_cassettes/gbs/pagination.yml +702 -0
- data/test/vcr_cassettes/gbs/search.yml +340 -0
- data/test/vcr_cassettes/primo/search_smoke_test.yml +1112 -0
- data/test/vcr_cassettes/scopus/bad_api_key_should_return_error_response.yml +60 -0
- data/test/vcr_cassettes/scopus/escaped_chars.yml +187 -0
- data/test/vcr_cassettes/scopus/fielded_search.yml +176 -0
- data/test/vcr_cassettes/scopus/simple_search.yml +227 -0
- data/test/vcr_cassettes/scopus/zero_results_search.yml +67 -0
- data/test/vcr_cassettes/summon/bad_auth.yml +54 -0
- data/test/vcr_cassettes/summon/proper_tags_for_snippets.yml +216 -0
- data/test/vcr_cassettes/summon/search.yml +242 -0
- data/test/vcr_cassettes/xerxes/live_search.yml +2580 -0
- data/test/view/std_item_test.rb +98 -0
- metadata +421 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
class OpenurlCreatorTest < ActiveSupport::TestCase
|
|
2
|
+
|
|
3
|
+
def test_create_article
|
|
4
|
+
item = BentoSearch::ResultItem.new(
|
|
5
|
+
:format => "Article",
|
|
6
|
+
:title => "My Title",
|
|
7
|
+
:subtitle => "A Nice One",
|
|
8
|
+
:year => 2012,
|
|
9
|
+
:volume => "10",
|
|
10
|
+
:issue => "1",
|
|
11
|
+
:start_page => "1",
|
|
12
|
+
:end_page => "100",
|
|
13
|
+
:journal_title => "Journal of Fakes",
|
|
14
|
+
:issn => "12345678",
|
|
15
|
+
:doi => "XXXX",
|
|
16
|
+
)
|
|
17
|
+
item.authors << BentoSearch::Author.new(:first => "John", :last => "Smith")
|
|
18
|
+
|
|
19
|
+
r = BentoSearch::OpenurlCreator.new(item).to_openurl.referent
|
|
20
|
+
|
|
21
|
+
assert_equal "journal", r.format
|
|
22
|
+
|
|
23
|
+
assert_equal "article", r.metadata["genre"]
|
|
24
|
+
|
|
25
|
+
assert_equal "2012", r.metadata["date"]
|
|
26
|
+
assert_equal "10", r.metadata["volume"]
|
|
27
|
+
assert_equal "1", r.metadata["issue"]
|
|
28
|
+
assert_equal "1", r.metadata["spage"]
|
|
29
|
+
assert_equal "100", r.metadata["epage"]
|
|
30
|
+
assert_equal "Journal of Fakes", r.metadata["jtitle"]
|
|
31
|
+
assert_equal "12345678", r.metadata["issn"]
|
|
32
|
+
assert_include r.identifiers, "info:doi:XXXX"
|
|
33
|
+
|
|
34
|
+
assert_equal "John", r.metadata["aufirst"]
|
|
35
|
+
assert_equal "Smith", r.metadata["aulast"]
|
|
36
|
+
assert_equal "Smith, J", r.metadata["au"]
|
|
37
|
+
|
|
38
|
+
assert_equal "My Title: A Nice One", r.metadata["atitle"]
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_numeric_conversion
|
|
43
|
+
item = BentoSearch::ResultItem.new(
|
|
44
|
+
:format => "Article",
|
|
45
|
+
:title => "My Title",
|
|
46
|
+
:subtitle => "A Nice One",
|
|
47
|
+
:year => 2012,
|
|
48
|
+
:volume => 10,
|
|
49
|
+
:issue => 1,
|
|
50
|
+
:start_page => 1,
|
|
51
|
+
:end_page => 100,
|
|
52
|
+
:issn => "12345678",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
r = BentoSearch::OpenurlCreator.new(item).to_openurl.referent
|
|
57
|
+
|
|
58
|
+
assert_equal "1", r.metadata["issue"]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_create_book
|
|
62
|
+
item = BentoSearch::ResultItem.new(
|
|
63
|
+
:format => "Book",
|
|
64
|
+
:title => "My Book",
|
|
65
|
+
:year => 2012,
|
|
66
|
+
:publisher => "Brothers, Inc.",
|
|
67
|
+
:isbn => "1234567X"
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
item.authors << BentoSearch::Author.new(:first => "John", :last => "Smith")
|
|
71
|
+
|
|
72
|
+
r = BentoSearch::OpenurlCreator.new(item).to_openurl.referent
|
|
73
|
+
|
|
74
|
+
assert_equal "book", r.format
|
|
75
|
+
|
|
76
|
+
assert_equal "My Book", r.metadata["btitle"]
|
|
77
|
+
assert_equal "Brothers, Inc.", r.metadata["pub"]
|
|
78
|
+
assert_equal "1234567X", r.metadata["isbn"]
|
|
79
|
+
assert_equal "2012", r.metadata["date"]
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def create_hardcoded_kev
|
|
84
|
+
item = BentoSearch::ResultItem.new(
|
|
85
|
+
:format => "Book",
|
|
86
|
+
:title => "Something",
|
|
87
|
+
:openurl_kev_co => "rft.title=Foo+Bar&rft.au=Smith"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
r = BentoSearch::OpenurlCreator.new(item).to_openurl.referent
|
|
91
|
+
|
|
92
|
+
assert_equal "article", r.format
|
|
93
|
+
assert_equal "Foo Bar", r.metadata["title"]
|
|
94
|
+
assert_equal "Smith", r.metadata["au"]
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def result_item_to_openurl
|
|
99
|
+
item = BentoSearch::ResultItem.new(
|
|
100
|
+
:format => "Book",
|
|
101
|
+
:title => "Something",
|
|
102
|
+
:openurl_kev_co => "rft.title=Foo+Bar&rft.au=Smith"
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
openurl = item.to_openurl
|
|
106
|
+
|
|
107
|
+
assert_kind_of OpenURL::ContextObject, openurl
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
# Test the BentoSearch::Results::Pagination object
|
|
4
|
+
class PaginationTest < ActiveSupport::TestCase
|
|
5
|
+
Pagination = BentoSearch::Results::Pagination
|
|
6
|
+
|
|
7
|
+
def test_implicit_page
|
|
8
|
+
pag = Pagination.new(100, {:per_page => 10})
|
|
9
|
+
|
|
10
|
+
assert_equal 1, pag.current_page
|
|
11
|
+
assert_equal 1, pag.start_record
|
|
12
|
+
assert_equal 10, pag.end_record
|
|
13
|
+
assert pag.first_page?
|
|
14
|
+
assert ! pag.last_page?
|
|
15
|
+
assert_equal 100, pag.count_records
|
|
16
|
+
assert_equal 10, pag.total_pages
|
|
17
|
+
assert_equal 10, pag.per_page
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_last_page
|
|
21
|
+
pag = Pagination.new(100, {:page => 5, :start => 80, :per_page => 20})
|
|
22
|
+
|
|
23
|
+
assert_equal 5, pag.current_page
|
|
24
|
+
assert_equal 81, pag.start_record
|
|
25
|
+
assert_equal 100, pag.end_record
|
|
26
|
+
assert ! pag.first_page?
|
|
27
|
+
assert pag.last_page?
|
|
28
|
+
assert_equal 100, pag.count_records
|
|
29
|
+
assert_equal 5, pag.total_pages
|
|
30
|
+
assert_equal 20, pag.per_page
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_uneven_pages
|
|
34
|
+
pag = Pagination.new(95, {:page => 10, :start => 90, :per_page => 10})
|
|
35
|
+
|
|
36
|
+
assert_equal 10, pag.current_page
|
|
37
|
+
assert_equal 91, pag.start_record
|
|
38
|
+
assert_equal 95, pag.end_record
|
|
39
|
+
assert ! pag.first_page?
|
|
40
|
+
assert pag.last_page?
|
|
41
|
+
assert_equal 95, pag.count_records
|
|
42
|
+
assert_equal 10, pag.total_pages
|
|
43
|
+
assert_equal 10, pag.per_page
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_empty_args
|
|
47
|
+
pag = Pagination.new(nil, {})
|
|
48
|
+
|
|
49
|
+
assert_equal 1, pag.current_page
|
|
50
|
+
assert_equal 0, pag.start_record
|
|
51
|
+
assert_equal 0, pag.end_record
|
|
52
|
+
assert pag.first_page?
|
|
53
|
+
assert pag.last_page?
|
|
54
|
+
assert_equal 0, pag.count_records
|
|
55
|
+
assert_equal 0, pag.total_pages
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class PrimoEngineTest < ActiveSupport::TestCase
|
|
4
|
+
extend TestWithCassette
|
|
5
|
+
|
|
6
|
+
@@host_port = (ENV['PRIMO_HOST_PORT'] || 'EXAMPLE.ORG:80' )
|
|
7
|
+
@@institution = (ENV['PRIMO_INSTITUTION'] || 'DUMMY_INSTITUTION')
|
|
8
|
+
|
|
9
|
+
VCR.configure do |c|
|
|
10
|
+
c.filter_sensitive_data("EXAMPLE.ORG:80", :primo) { @@host_port }
|
|
11
|
+
c.filter_sensitive_data("DUMMY_INSTITUTION", :primo) { @@institution }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def setup
|
|
15
|
+
@engine = BentoSearch::PrimoEngine.new(:host_port => @@host_port, :institution => @@institution)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
test_with_cassette("search smoke test", :primo) do
|
|
20
|
+
results = @engine.search_implementation(:query => "globalization from below", :per_page => 10)
|
|
21
|
+
|
|
22
|
+
assert_present results, "has results"
|
|
23
|
+
|
|
24
|
+
assert_present results.total_items, "has total_items"
|
|
25
|
+
|
|
26
|
+
first = results[6]
|
|
27
|
+
|
|
28
|
+
# not every result has every field, but at time we recorded
|
|
29
|
+
# with VCR, this result for this search did. Sorry, a bit fragile.
|
|
30
|
+
# publisher
|
|
31
|
+
%w{format_str format title authors volume issue start_page end_page journal_title issn doi abstract}.each do |attr|
|
|
32
|
+
assert_present first.send(attr), "must have #{attr}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class RegisterEngineTest < ActiveSupport::TestCase
|
|
6
|
+
class BentoSearch::DummyEngine
|
|
7
|
+
include BentoSearch::SearchEngine
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def teardown
|
|
11
|
+
BentoSearch.reset_engine_registrations!
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "can register and retrieve engine" do
|
|
15
|
+
BentoSearch.register_engine("test_engine") do |conf|
|
|
16
|
+
conf.engine = "BentoSearch::DummyEngine"
|
|
17
|
+
conf.api_key = "dummy"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
engine = BentoSearch.get_engine("test_engine")
|
|
21
|
+
|
|
22
|
+
assert_kind_of BentoSearch::DummyEngine, engine
|
|
23
|
+
assert_equal "dummy", engine.configuration.api_key
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "can register with engine name assumed in BentoSearch::" do
|
|
28
|
+
BentoSearch.register_engine("test_engine") do |conf|
|
|
29
|
+
conf.engine = "DummyEngine"
|
|
30
|
+
conf.api_key = "dummy"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
assert_kind_of BentoSearch::DummyEngine, BentoSearch.get_engine("test_engine")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test "raises for no engine class" do
|
|
37
|
+
assert_raises(ArgumentError) do
|
|
38
|
+
BentoSearch.register_engine("test_engine") do |conf|
|
|
39
|
+
conf.api_key = "dummy"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
test "raises on unregistered engine access" do
|
|
46
|
+
assert_raise(BentoSearch::NoSuchEngine) { BentoSearch.get_engine("not_registered")}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ResultItemDisplayTest < ActiveSupport::TestCase
|
|
6
|
+
Author = BentoSearch::Author
|
|
7
|
+
ResultItem = BentoSearch::ResultItem
|
|
8
|
+
|
|
9
|
+
test "author with first and last" do
|
|
10
|
+
author = Author.new(:last => "Smith", :first => "John")
|
|
11
|
+
|
|
12
|
+
str = ResultItem.new.author_display(author)
|
|
13
|
+
|
|
14
|
+
assert_equal "Smith, J", str
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "author with display form and just last" do
|
|
18
|
+
author = Author.new(:last => "Smith", :display => "Display Form")
|
|
19
|
+
|
|
20
|
+
str = ResultItem.new.author_display(author)
|
|
21
|
+
|
|
22
|
+
assert_equal "Display Form", str
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test "Author with just last" do
|
|
26
|
+
author = Author.new(:last => "Johnson")
|
|
27
|
+
|
|
28
|
+
str = ResultItem.new.author_display(author)
|
|
29
|
+
|
|
30
|
+
assert_equal "Johnson", str
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
test "Missing title" do
|
|
35
|
+
assert_equal I18n.translate("bento_search.missing_title"), ResultItem.new.complete_title
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ResultItemTest < ActiveSupport::TestCase
|
|
6
|
+
ResultItem = BentoSearch::ResultItem
|
|
7
|
+
|
|
8
|
+
def test_has_custom_data
|
|
9
|
+
r = ResultItem.new
|
|
10
|
+
|
|
11
|
+
assert_not_nil r.custom_data
|
|
12
|
+
assert_kind_of Hash, r.custom_data
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_can_dup_and_set_attributes
|
|
16
|
+
# Need to be able to dup and set at least basic attributes without
|
|
17
|
+
# changing original. Used by SummonEngine for making sure
|
|
18
|
+
# openurl does not have highlighting tags in it when generated.
|
|
19
|
+
|
|
20
|
+
r = ResultItem.new(:title => "original")
|
|
21
|
+
|
|
22
|
+
assert_equal "original", r.title
|
|
23
|
+
|
|
24
|
+
dup = r.dup
|
|
25
|
+
dup.title = "new"
|
|
26
|
+
|
|
27
|
+
assert_equal "new", dup.title
|
|
28
|
+
assert_equal "original", r.title
|
|
29
|
+
|
|
30
|
+
assert_not_same dup, r
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
require 'cgi'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
# Set shell env SCOPUS_KEY to your api key to test fresh http
|
|
7
|
+
# connections, if you can't use the ones cached by VCR.
|
|
8
|
+
|
|
9
|
+
class ScopusEngineTest < ActiveSupport::TestCase
|
|
10
|
+
extend TestWithCassette
|
|
11
|
+
|
|
12
|
+
# Filter API key out of VCR cache for tag :scopus, which we'll use
|
|
13
|
+
# in this test.
|
|
14
|
+
@@api_key = (ENV["SCOPUS_KEY"] || "DUMMY_API_KEY")
|
|
15
|
+
VCR.configure do |c|
|
|
16
|
+
c.filter_sensitive_data("DUMMY_API_KEY", :scopus) { @@api_key }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def setup
|
|
20
|
+
@engine = BentoSearch::ScopusEngine.new(:api_key => @@api_key)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_construct_search_url
|
|
25
|
+
url = @engine.send(:scopus_url, :query => "one two")
|
|
26
|
+
|
|
27
|
+
assert_equal "http://api.elsevier.com/content/search/index:SCOPUS?query=one+two&sort=refeid", url
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_construct_fielded_search_url
|
|
31
|
+
url = @engine.send(:scopus_url, :query => "one two", :search_field => "AUTH")
|
|
32
|
+
|
|
33
|
+
assert_equal "http://api.elsevier.com/content/search/index:SCOPUS?query=AUTH%28one+two%29&sort=refeid", url
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_construct_search_with_per_page
|
|
37
|
+
url = @engine.send(:scopus_url, :query => "one two", :per_page => 30)
|
|
38
|
+
|
|
39
|
+
assert_equal "http://api.elsevier.com/content/search/index:SCOPUS?query=one+two&count=30&sort=refeid", url
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_construct_search_with_sort
|
|
43
|
+
url = @engine.send(:scopus_url, :query => "one two", :sort => "date_desc")
|
|
44
|
+
|
|
45
|
+
assert_equal "http://api.elsevier.com/content/search/index:SCOPUS?query=one+two&sort=-datesort%2C%2Bauth", url
|
|
46
|
+
|
|
47
|
+
url = @engine.send(:scopus_url, :query => "one two", :sort => "relevance")
|
|
48
|
+
|
|
49
|
+
assert_equal "http://api.elsevier.com/content/search/index:SCOPUS?query=one+two&sort=refeid", url
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_construct_default_relevance_sort
|
|
54
|
+
url_implicit = @engine.send(:scopus_url, :query => "one two")
|
|
55
|
+
url_explicit = @engine.send(:scopus_url, :query => "one two", :sort => "relevance")
|
|
56
|
+
|
|
57
|
+
assert_equal url_explicit, url_implicit
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_construct_with_pagination
|
|
62
|
+
url = @engine.send(:scopus_url, :query => "one two", :start => 20, :per_page => 10)
|
|
63
|
+
|
|
64
|
+
query_hash = CGI.parse(URI.parse(url).query)
|
|
65
|
+
|
|
66
|
+
assert_equal ["20"], query_hash["start"]
|
|
67
|
+
assert_equal ["10"], query_hash["count"]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
test_with_cassette("bad api key should return error response", :scopus) do
|
|
72
|
+
@engine = BentoSearch::ScopusEngine.new(:api_key => "BAD_KEY_ERROR")
|
|
73
|
+
|
|
74
|
+
results = @engine.search(:query => "cancer")
|
|
75
|
+
|
|
76
|
+
assert results.failed?, "response.failed? should be"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
test_with_cassette("simple search", :scopus) do
|
|
80
|
+
results = @engine.search(:query => "cancer")
|
|
81
|
+
|
|
82
|
+
assert_not_nil results.total_items, "total_items not nil"
|
|
83
|
+
assert_kind_of Fixnum, results.total_items
|
|
84
|
+
|
|
85
|
+
assert_not_nil results.start, "start not nil"
|
|
86
|
+
assert_not_nil results.per_page, "per_page not nil"
|
|
87
|
+
|
|
88
|
+
assert_equal 10, results.length
|
|
89
|
+
|
|
90
|
+
sample_result = results.first
|
|
91
|
+
|
|
92
|
+
assert_present sample_result.title
|
|
93
|
+
assert_present sample_result.link
|
|
94
|
+
assert_present sample_result.journal_title
|
|
95
|
+
assert_kind_of Integer, sample_result.year
|
|
96
|
+
assert_present sample_result.issn
|
|
97
|
+
assert_present sample_result.volume
|
|
98
|
+
assert_present sample_result.issue
|
|
99
|
+
assert_present sample_result.start_page
|
|
100
|
+
|
|
101
|
+
assert_present sample_result.authors
|
|
102
|
+
|
|
103
|
+
assert_present sample_result.format
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
test_with_cassette("zero results search", :scopus) do
|
|
108
|
+
results = @engine.search(:query => "aldfjkadf lakdj zdfzzzz")
|
|
109
|
+
assert ! results.failed?, "results not marked failed"
|
|
110
|
+
assert_equal 0, results.size
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
test_with_cassette("escaped chars", :scopus) do
|
|
114
|
+
results = @engine.search(:query => "monkey:(brain)")
|
|
115
|
+
|
|
116
|
+
assert ! results.failed?, "results not marked failed"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
test_with_cassette("fielded search", :scopus) do
|
|
122
|
+
results = @engine.search(:query => "cancer", :semantic_search_field => :title)
|
|
123
|
+
|
|
124
|
+
assert results.first.title.downcase.include?("cancer"), "Title includes query term"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
end
|