exlibris-primo 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/README.rdoc +5 -2
  2. data/Rakefile +1 -5
  3. data/lib/exlibris/primo/eshelf.rb +4 -3
  4. data/lib/exlibris/primo/holding.rb +2 -10
  5. data/lib/exlibris/primo/record.rb +11 -6
  6. data/lib/exlibris/primo/searcher.rb +2 -4
  7. data/lib/exlibris/primo/version.rb +2 -2
  8. data/test/exlibris-primo_test.rb +3 -3
  9. data/test/test_helper.rb +33 -7
  10. data/test/unit/eshelf_test.rb +106 -87
  11. data/test/unit/record_test.rb +64 -45
  12. data/test/unit/searcher_benchmarks.rb +20 -28
  13. data/test/unit/searcher_test.rb +298 -273
  14. data/test/unit/web_service_benchmarks.rb +19 -21
  15. data/test/unit/web_service_test.rb +130 -102
  16. data/test/vcr_cassettes/eshelf_add_invalid_records.yml +107 -0
  17. data/test/vcr_cassettes/eshelf_add_same_record_twice.yml +159 -0
  18. data/test/vcr_cassettes/eshelf_add_to_empty_basket.yml +107 -0
  19. data/test/vcr_cassettes/eshelf_add_to_invalid_basket.yml +55 -0
  20. data/test/vcr_cassettes/eshelf_invalid_eshelf.yml +55 -0
  21. data/test/vcr_cassettes/eshelf_invalid_institution.yml +55 -0
  22. data/test/vcr_cassettes/eshelf_valid_eshelf.yml +2553 -0
  23. data/test/vcr_cassettes/eshelf_valid_eshelf_structure.yml +47 -0
  24. data/test/vcr_cassettes/record.yml +212 -0
  25. data/test/vcr_cassettes/record_invalid_record.yml +55 -0
  26. data/test/vcr_cassettes/record_sub_record.yml +212 -0
  27. data/test/vcr_cassettes/record_valid_record.yml +212 -0
  28. data/test/vcr_cassettes/searcher_base_holdings_by_id.yml +212 -0
  29. data/test/vcr_cassettes/searcher_dedupmrg_by_id.yml +347 -0
  30. data/test/vcr_cassettes/searcher_diacritics1_by_id.yml +207 -0
  31. data/test/vcr_cassettes/searcher_diacritics2_by_id.yml +232 -0
  32. data/test/vcr_cassettes/searcher_holdings_by_id.yml +212 -0
  33. data/test/vcr_cassettes/searcher_invalid_id.yml +55 -0
  34. data/test/vcr_cassettes/searcher_rsrcs_by_id.yml +270 -0
  35. data/test/vcr_cassettes/searcher_search_by_isbn.yml +278 -0
  36. data/test/vcr_cassettes/searcher_search_by_issn.yml +297 -0
  37. data/test/vcr_cassettes/searcher_search_by_title_author_genre.yml +671 -0
  38. data/test/vcr_cassettes/searcher_test_bug_1361.yml +224 -0
  39. data/test/vcr_cassettes/searcher_test_problem_by_id.yml +194 -0
  40. data/test/vcr_cassettes/searcher_tocs_by_id.yml +217 -0
  41. data/test/vcr_cassettes/web_service_author_search.yml +1269 -0
  42. data/test/vcr_cassettes/web_service_bogus_200.yml +392 -0
  43. data/test/vcr_cassettes/web_service_brief_search.yml +299 -0
  44. data/test/vcr_cassettes/web_service_get_eshelf.yml +11823 -0
  45. data/test/vcr_cassettes/web_service_get_eshelf_structure_search.yml +47 -0
  46. data/test/vcr_cassettes/web_service_invalid_document.yml +54 -0
  47. data/test/vcr_cassettes/web_service_isbn_search.yml +299 -0
  48. data/test/vcr_cassettes/web_service_issn_search.yml +293 -0
  49. data/test/vcr_cassettes/web_service_problem_document.yml +193 -0
  50. data/test/vcr_cassettes/web_service_single_document.yml +233 -0
  51. data/test/vcr_cassettes/web_service_title_author_genre_search.yml +719 -0
  52. data/test/vcr_cassettes/web_service_title_search.yml +1035 -0
  53. metadata +147 -77
  54. data/lib/tasks/exlibris-primo_tasks.rake +0 -4
  55. data/test/dummy/README.rdoc +0 -261
  56. data/test/dummy/Rakefile +0 -7
  57. data/test/dummy/app/assets/javascripts/application.js +0 -15
  58. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  59. data/test/dummy/app/controllers/application_controller.rb +0 -3
  60. data/test/dummy/app/helpers/application_helper.rb +0 -2
  61. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  62. data/test/dummy/config.ru +0 -4
  63. data/test/dummy/config/application.rb +0 -56
  64. data/test/dummy/config/boot.rb +0 -10
  65. data/test/dummy/config/database.yml +0 -25
  66. data/test/dummy/config/environment.rb +0 -5
  67. data/test/dummy/config/environments/development.rb +0 -37
  68. data/test/dummy/config/environments/production.rb +0 -67
  69. data/test/dummy/config/environments/test.rb +0 -37
  70. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  71. data/test/dummy/config/initializers/inflections.rb +0 -15
  72. data/test/dummy/config/initializers/mime_types.rb +0 -5
  73. data/test/dummy/config/initializers/secret_token.rb +0 -7
  74. data/test/dummy/config/initializers/session_store.rb +0 -8
  75. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  76. data/test/dummy/config/locales/en.yml +0 -5
  77. data/test/dummy/config/routes.rb +0 -58
  78. data/test/dummy/db/README +0 -0
  79. data/test/dummy/db/test.sqlite3 +0 -0
  80. data/test/dummy/log/test.log +0 -1704
  81. data/test/dummy/public/404.html +0 -26
  82. data/test/dummy/public/422.html +0 -26
  83. data/test/dummy/public/500.html +0 -25
  84. data/test/dummy/public/favicon.ico +0 -0
  85. data/test/dummy/script/rails +0 -6
@@ -1,4 +1,7 @@
1
1
  = Exlibris::Primo
2
+ {<img src="https://secure.travis-ci.org/scotdalton/exlibris-primo.png" alt="Build Status" />}[https://secure.travis-ci.org/scotdalton/exlibris-primo]
3
+ {<img src="https://gemnasium.com/scotdalton/exlibris-primo.png" alt="Dependency Status" />}[https://gemnasium.com/scotdalton/exlibris-primo]
4
+ {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/scotdalton/exlibris-primo]
2
5
 
3
6
  Exlibris::Primo offers a set of libraries for interacting with the ExLibris Primo APIs.
4
7
 
@@ -38,7 +41,7 @@ as instance variables.
38
41
  === Example of Exlibris::Primo::Record in action
39
42
  setup = {
40
43
  :base_url => "http://primo.institution.edu",
41
- :resolver_base_url => "http://sfx.institution.edu",
44
+ :resolver_base_url => "http://resolver.institution.edu",
42
45
  :vid => "VID",
43
46
  :institution => "DEFAULT",
44
47
  :record_id => "PrimoRecordId"
@@ -55,7 +58,7 @@ The Exlibris::Primo::EShelf class provides methods for reading a given user's Pr
55
58
  setup = {
56
59
  :base_url => "http://primo.institution.edu",
57
60
  :vid => "VID",
58
- :resolver_base_url => "http://sfx.institution.edu"
61
+ :resolver_base_url => "http://resolver.institution.edu"
59
62
  }
60
63
  eshelf = Exlibris::Primo::EShelf.new(setup, "USER_ID", "PRIMO")
61
64
  records = eshelf.records
data/Rakefile CHANGED
@@ -20,9 +20,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
-
24
-
25
-
26
23
  Bundler::GemHelper.install_tasks
27
24
 
28
25
  require 'rake/testtask'
@@ -34,5 +31,4 @@ Rake::TestTask.new(:test) do |t|
34
31
  t.verbose = false
35
32
  end
36
33
 
37
-
38
- task :default => :test
34
+ task :default => :test
@@ -8,13 +8,14 @@ module Exlibris
8
8
  # :base_url, :resolver_base_url, :vid, :config
9
9
  #
10
10
  # == Examples of usage
11
- # Exlibris::Primo::EShelf.new({ :base_url => "http://primo.institution.edu", :vid => "VID", :resolver_base_url => "http://sfx.institution.edu"} , "USER_ID", "PRIMO").count
11
+ # Exlibris::Primo::EShelf.new({ :base_url => "http://primo.institution.edu", :vid => "VID", :resolver_base_url => "http://resolver.institution.edu"} , "USER_ID", "PRIMO").count
12
12
  # Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).basket_id
13
13
  class EShelf
14
14
 
15
15
  #Namespaces
16
16
  SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
17
17
  PRIM_NS = {'prim' => 'http://www.exlibris.com/primo/xsd/primoeshelffolder'}
18
+ PRIM_BIB_NS = {'bib' => 'http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'}
18
19
 
19
20
  def initialize(setup, user_id, institution)
20
21
  @base_url = setup[:base_url]
@@ -49,7 +50,7 @@ module Exlibris
49
50
  # Fetch all records from user's Eshelf as an array of Primo Record objects
50
51
  def records
51
52
  eshelf.search("//sear:DOC", SEAR_NS).each { |doc|
52
- @records.push(Record.new({ :base_url => @base_url, :resolver_base_url => @resolver_base_url, :vid => @vid, :record => doc.at("//xmlns:record", doc.namespaces), :institution => @institution }))
53
+ @records.push(Record.new({ :base_url => @base_url, :resolver_base_url => @resolver_base_url, :vid => @vid, :record => doc.at("//bib:record", PRIM_BIB_NS), :institution => @institution }))
53
54
  } if @records.empty?
54
55
  return @records
55
56
  end
@@ -77,4 +78,4 @@ module Exlibris
77
78
  end
78
79
  end
79
80
  end
80
- end
81
+ end
@@ -143,16 +143,8 @@ module Exlibris
143
143
  # Return this holding as a new holdings subclass instance based on source
144
144
  def to_source
145
145
  return self if @source_class.nil?
146
- begin
147
- # Get source class in Primo::Source module
148
- return Exlibris::Primo::Source.const_get(@source_class).new(:holding => self)
149
- rescue Exception => e
150
- Rails.logger.error("#{e.message}")
151
- Rails.logger.error("Class #{@source_class} can't be found in Exlibris::Primo::Source.
152
- Please check primo.yml to ensure the class_name is defined correctly.
153
- Not converting to source.")
154
- return self
155
- end
146
+ # Get source class in Primo::Source module
147
+ return Exlibris::Primo::Source.const_get(@source_class).new(:holding => self)
156
148
  end
157
149
 
158
150
  # Convenience method for making base attributes accessible via Hash-like syntax.
@@ -23,7 +23,10 @@ module Exlibris
23
23
  # == Examples of usage
24
24
  # Record.new({ :base_url => @base_url, :vid => @vid, :record => doc.at("//record") })
25
25
  class Record
26
-
26
+ # Leverage ActiveSupport's Hash#from_xml method to transform PNX to JSON.
27
+ require 'active_support/core_ext'
28
+ require 'json'
29
+
27
30
  SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
28
31
  attr_reader :record_id, :type, :title, :url, :openurl, :creator, :raw_xml
29
32
 
@@ -65,13 +68,15 @@ module Exlibris
65
68
  }
66
69
  end
67
70
 
71
+ # Return a JSON representation of the PNX record
72
+ def to_json
73
+ # Leverage ActiveSupport's Hash#from_xml method to transform PNX to JSON.
74
+ Hash.from_xml(raw_xml).to_json
75
+ end
76
+
68
77
  # Method for cleaning up raw xml from record
69
78
  def raw(record)
70
- raw = "<record>"
71
- # Hack to strip out spacing in record
72
- record.children.each{|child| raw << child.to_xml.gsub(/\n\s*/, "").gsub(/\s$/, "")}
73
- raw << "</record>"
74
- return raw
79
+ record.to_xml(:indent => 0, :encoding => 'UTF-8')
75
80
  end
76
81
 
77
82
  private
@@ -8,7 +8,7 @@ module Exlibris
8
8
  # * We have either an isbn OR an issn
9
9
  # * We have a title AND an author AND a genre
10
10
  # If none of these criteria are met, Exlibris::Primo::Searcher.search
11
- # will log a warning in the Rails log.
11
+ # will not perform the search.
12
12
  # Exlibris::Primo::Searcher will populate the following instance variables
13
13
  # accessible through readers:
14
14
  # :count, :holdings, :rsrcs, :tocs, :related_links
@@ -59,9 +59,7 @@ module Exlibris
59
59
  # Process URLs based on links/linktorsrc
60
60
  # Process TOCs based on links/linktotoc
61
61
  def search
62
- Rails.logger.warn("Insufficient search terms for #{self.class}. "+
63
- "Please refer to #{self.class}'s documentation to determine how to structure "+
64
- "a sufficient query.") and return if insufficient_query?
62
+ return if insufficient_query?
65
63
  # Call Primo Web Services
66
64
  unless @primo_id.nil? or @primo_id.empty?
67
65
  get_record = Exlibris::Primo::WebService::GetRecord.new(@primo_id, @base_url, {:institution => @institution})
@@ -1,5 +1,5 @@
1
1
  module Exlibris
2
2
  module Primo
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.4"
4
4
  end
5
- end
5
+ end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
- class ExlibrisPrimoTest < ActiveSupport::TestCase
4
- test "truth" do
3
+ class ExlibrisPrimoTest < Test::Unit::TestCase
4
+ def test_truth
5
5
  assert_kind_of Module, Exlibris::Primo
6
6
  end
7
- end
7
+ end
@@ -1,10 +1,36 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
1
+ require 'test/unit'
2
+ require File.expand_path("../../lib/exlibris-primo.rb", __FILE__)
3
3
 
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
4
+ # VCR is used to 'record' HTTP interactions with
5
+ # third party services used in tests, and play em
6
+ # back. Useful for efficiency, also useful for
7
+ # testing code against API's that not everyone
8
+ # has access to -- the responses can be cached
9
+ # and re-used.
10
+ require 'vcr'
11
+ require 'webmock'
6
12
 
7
- Rails.backtrace_cleaner.remove_silencers!
13
+ # To allow us to do real HTTP requests in a VCR.turned_off, we
14
+ # have to tell webmock to let us.
15
+ WebMock.allow_net_connect!(:net_http_connect_on_start => true)
16
+
17
+ without_ctx_tim = VCR.request_matchers.uri_without_param(:ctx_tim)
18
+ VCR.configure do |c|
19
+ c.cassette_library_dir = 'test/vcr_cassettes'
20
+ # webmock needed for HTTPClient testing
21
+ c.hook_into :webmock
22
+ c.register_request_matcher(:uri_without_ctx_tim, &without_ctx_tim)
23
+ # c.debug_logger = $stderr
24
+ end
25
+
26
+ # Silly way to not have to rewrite all our tests if we
27
+ # temporarily disable VCR, make VCR.use_cassette a no-op
28
+ # instead of no-such-method.
29
+ if ! defined? VCR
30
+ module VCR
31
+ def self.use_cassette(*args)
32
+ yield
33
+ end
34
+ end
35
+ end
8
36
 
9
- # Load support files
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@@ -1,152 +1,171 @@
1
1
  require 'test_helper'
2
2
 
3
- class EShelfTest < ActiveSupport::TestCase
3
+ class EShelfTest < Test::Unit::TestCase
4
4
  PNX_NS = {'pnx' => 'http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib'}
5
5
  SEARCH_NS = {'search' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
6
6
  SEAR_NS = {'sear' => 'http://www.exlibrisgroup.com/xsd/jaguar/search'}
7
7
  PRIM_NS = {'prim' => 'http://www.exlibris.com/primo/xsd/primoeshelffolder'}
8
8
 
9
9
  def setup
10
- @primo_definition = YAML.load( %{
11
- type: PrimoService
12
- priority: 2 # After SFX, to get SFX metadata enhancement
13
- status: active
14
- base_url: http://bobcat.library.nyu.edu
15
- resolver_base_url: https://getit.library.nyu.edu/resolve
16
- vid: NYU
17
- institution: NYU
18
- holding_search_institution: NYU
19
- holding_search_text: Search for this title in BobCat.
20
- suppress_holdings: [ !ruby/regexp '/\$\$LBWEB/', !ruby/regexp '/\$\$LNWEB/', !ruby/regexp '/\$\$LTWEB/', !ruby/regexp '/\$\$LWEB/', !ruby/regexp '/\$\$1Restricted Internet Resources/' ]
21
- ez_proxy: !ruby/regexp '/https\:\/\/ezproxy\.library\.nyu\.edu\/login\?url=/'
22
- service_types:
23
- - primo_source
24
- - holding_search
25
- - fulltext
26
- - table_of_contents
27
- - referent_enhance
28
- - cover_image
29
- })
30
-
31
- @base_url = @primo_definition["base_url"]
32
- @vid = @primo_definition["vid"]
33
- @valid_user_id = "N18158418"
34
- @invalid_user_id = "INVALID_USER"
35
- @eshelf_setup = {
36
- :base_url => @base_url,
37
- :vid => @vid,
38
- :resolver_base_url => @primo_definition["resolver_base_url"]
39
- }
40
- @valid_institute = "NYU"
41
- @invalid_institute = "INVALID_INST"
42
- @valid_doc_ids = ["nyu_aleph000062856"]
43
- @invalid_doc_ids = ["INVALID_DOC_ID"]
44
- @valid_basket = "298560007"
45
- #@valid_folder = "344619707"
46
- @invalid_basket = "INVALID_BASKET"
10
+ @primo_definition = YAML.load( %{
11
+ type: PrimoService
12
+ priority: 2 # After SFX, to get SFX metadata enhancement
13
+ status: active
14
+ base_url: http://bobcat.library.nyu.edu
15
+ resolver_base_url: https://getit.library.nyu.edu/resolve
16
+ vid: NYU
17
+ institution: NYU
18
+ holding_search_institution: NYU
19
+ holding_search_text: Search for this title in BobCat.
20
+ suppress_holdings: [ !ruby/regexp '/\$\$LBWEB/', !ruby/regexp '/\$\$LNWEB/', !ruby/regexp '/\$\$LTWEB/', !ruby/regexp '/\$\$LWEB/', !ruby/regexp '/\$\$1Restricted Internet Resources/' ]
21
+ ez_proxy: !ruby/regexp '/https\:\/\/ezproxy\.library\.nyu\.edu\/login\?url=/'
22
+ service_types:
23
+ - primo_source
24
+ - holding_search
25
+ - fulltext
26
+ - table_of_contents
27
+ - referent_enhance
28
+ - cover_image })
29
+ @base_url = @primo_definition["base_url"]
30
+ @vid = @primo_definition["vid"]
31
+ @valid_user_id = "N18158418"
32
+ @invalid_user_id = "INVALID_USER"
33
+ @eshelf_setup = {
34
+ :base_url => @base_url,
35
+ :vid => @vid,
36
+ :resolver_base_url => @primo_definition["resolver_base_url"] }
37
+ @valid_institute = "NYU"
38
+ @invalid_institute = "INVALID_INST"
39
+ @valid_doc_ids = ["nyu_aleph000062856"]
40
+ @invalid_doc_ids = ["INVALID_DOC_ID"]
41
+ @valid_basket = "298560007"
42
+ #@valid_folder = "344619707"
43
+ @invalid_basket = "INVALID_BASKET"
47
44
  end
48
45
 
49
- test "new" do
50
- eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
51
- assert_not_nil(eshelf, "#{eshelf.class} returned nil when instantiated.")
52
-
53
- assert_equal(@base_url, eshelf.instance_variable_get(:@base_url))
54
- assert_equal(@vid, eshelf.instance_variable_get(:@vid))
55
- assert_equal(@valid_user_id, eshelf.instance_variable_get(:@user_id))
56
- assert_equal(@valid_institute, eshelf.instance_variable_get(:@institution))
57
-
58
- assert_nothing_raised{Exlibris::Primo::EShelf.new({:base_url => @base_url}, @valid_user_id, @valid_institute)}
59
- assert_nothing_raised{Exlibris::Primo::EShelf.new({:base_url => @base_url, :vid => @vid}, @valid_user_id, @valid_institute)}
60
-
61
- assert_raise(ArgumentError){Exlibris::Primo::EShelf.new({}, @valid_user_id, @valid_institute)}
62
- assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, nil, nil)}
63
- assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, nil, nil)}
64
- assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, nil)}
65
-
46
+ def test_new
47
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
48
+ assert_not_nil(eshelf, "#{eshelf.class} returned nil when instantiated.")
49
+ assert_equal(@base_url, eshelf.instance_variable_get(:@base_url))
50
+ assert_equal(@vid, eshelf.instance_variable_get(:@vid))
51
+ assert_equal(@valid_user_id, eshelf.instance_variable_get(:@user_id))
52
+ assert_equal(@valid_institute, eshelf.instance_variable_get(:@institution))
53
+ assert_nothing_raised{Exlibris::Primo::EShelf.new({:base_url => @base_url}, @valid_user_id, @valid_institute)}
54
+ assert_nothing_raised{Exlibris::Primo::EShelf.new({:base_url => @base_url, :vid => @vid}, @valid_user_id, @valid_institute)}
55
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new({}, @valid_user_id, @valid_institute)}
56
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, nil, nil)}
57
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, nil, nil)}
58
+ assert_raise(ArgumentError){Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, nil)}
66
59
  end
67
60
 
68
- test "valid_eshelf" do
69
- eshelf = nil
61
+ def test_valid_eshelf
62
+ eshelf = nil
63
+ assert_nil(eshelf)
64
+ VCR.use_cassette('eshelf valid eshelf') do
70
65
  assert_nothing_raised{eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).eshelf}
71
66
  assert_not_nil(eshelf)
72
67
  assert_instance_of(Nokogiri::XML::Document, eshelf)
68
+ end
73
69
  end
74
70
 
75
- test "valid_eshelf_structure" do
71
+ def test_valid_eshelf_structure
72
+ VCR.use_cassette('eshelf valid eshelf structure') do
76
73
  eshelfStructure = nil
74
+ assert_nil(eshelfStructure)
77
75
  assert_nothing_raised{eshelfStructure = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).eshelfStructure}
78
76
  assert_not_nil(eshelfStructure)
79
77
  assert(eshelfStructure.is_a? Nokogiri::XML::Document)
78
+ end
80
79
  end
81
-
82
- test "basket_id" do
80
+
81
+ def test_basket_id
82
+ VCR.use_cassette('eshelf valid eshelf structure') do
83
83
  assert_equal(@valid_basket, Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).basket_id)
84
+ end
84
85
  end
85
86
 
86
- test "invalid_user_eshelf" do
87
- ws = nil
88
- assert_nothing_raised(){ws = Exlibris::Primo::EShelf.new(@eshelf_setup, @invalid_user_id, @valid_institute)}
89
- assert_not_nil(ws)
90
- eshelf = nil
87
+ def test_invalid_user_eshelf
88
+ ws = nil
89
+ assert_nil(ws)
90
+ assert_nothing_raised(){ws = Exlibris::Primo::EShelf.new(@eshelf_setup, @invalid_user_id, @valid_institute)}
91
+ assert_not_nil(ws)
92
+ eshelf = nil
93
+ assert_nil(eshelf)
94
+ VCR.use_cassette('eshelf invalid eshelf') do
91
95
  assert_nothing_raised(){eshelf = ws.eshelf}
92
96
  assert_not_nil(eshelf)
93
97
  assert_instance_of(Nokogiri::XML::Document, eshelf)
94
98
  assert_equal(0, ws.count)
99
+ end
95
100
  end
96
-
97
- test "invalid_institution_eshelf" do
98
- ws = nil
99
- assert_nothing_raised(){ws = Exlibris::Primo::EShelf.new(@eshelf_setup, @invalid_user_id, @valid_institute)}
100
- assert_not_nil(ws)
101
- eshelf = nil
101
+
102
+ def test_invalid_institution_eshelf
103
+ ws = nil
104
+ assert_nil(ws)
105
+ assert_nothing_raised(){ws = Exlibris::Primo::EShelf.new(@eshelf_setup, @invalid_user_id, @valid_institute)}
106
+ assert_not_nil(ws)
107
+ eshelf = nil
108
+ assert_nil(eshelf)
109
+ VCR.use_cassette('eshelf invalid institution') do
102
110
  assert_nothing_raised(){eshelf = ws.eshelf}
103
111
  assert_not_nil(eshelf)
104
112
  assert_instance_of(Nokogiri::XML::Document, eshelf)
105
113
  assert_equal(0, ws.count)
114
+ end
106
115
  end
107
116
 
108
- test "records" do
109
- records = nil
117
+ def test_records
118
+ records = nil
119
+ assert_nil(records)
120
+ VCR.use_cassette('eshelf valid eshelf') do
110
121
  assert_nothing_raised(){records = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute).records}
111
122
  assert_not_nil(records)
112
123
  assert_instance_of(Array, records)
113
124
  assert(!records.empty?, "Eshelf records returned empty")
125
+ end
114
126
  end
115
127
 
116
- test "cant_add_same_record_twice" do
117
- eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
118
- assert_not_nil(eshelf)
128
+ def test_cant_add_same_record_twice
129
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
130
+ assert_not_nil(eshelf)
131
+ VCR.use_cassette('eshelf add same record twice') do
119
132
  # Add record
120
133
  assert_nothing_raised(){ eshelf.add_records(@valid_doc_ids, @valid_basket) }
121
134
  # Add same record again
122
135
  assert_raise(RuntimeError){ eshelf.add_records(@valid_doc_ids, @valid_basket) }
123
136
  # Remove record
124
137
  assert_nothing_raised(){ eshelf.remove_records(@valid_doc_ids, @valid_basket) }
138
+ end
125
139
  end
126
140
 
127
- test "cant_add_invalid_records" do
128
- eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
129
- assert_not_nil(eshelf)
141
+ def test_cant_add_invalid_records
142
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
143
+ assert_not_nil(eshelf)
144
+ VCR.use_cassette('eshelf add invalid records') do
130
145
  # Attempt to add record
131
146
  assert_raise(RuntimeError){ eshelf.add_records(@invalid_doc_ids, @valid_basket) }
132
147
  # Attempt to remove record which was never added
133
148
  assert_raise(RuntimeError){ eshelf.remove_records(@invalid_doc_ids, @valid_basket) }
149
+ end
134
150
  end
135
151
 
136
- test "cant_add_to_invalid_basket" do
137
- eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
138
- assert_not_nil(eshelf)
152
+ def test_cant_add_to_invalid_basket
153
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
154
+ assert_not_nil(eshelf)
155
+ VCR.use_cassette('eshelf add to invalid basket') do
139
156
  # Attempt to add record to basket with invalid folder name
140
157
  assert_raise(RuntimeError){ eshelf.add_records(@valid_doc_ids, @invalid_basket) }
158
+ end
141
159
  end
142
160
 
143
- test "can_add_to_empty_folder" do
144
- eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
145
- assert_not_nil(eshelf)
161
+ def test_can_add_to_empty_folder
162
+ eshelf = Exlibris::Primo::EShelf.new(@eshelf_setup, @valid_user_id, @valid_institute)
163
+ assert_not_nil(eshelf)
164
+ VCR.use_cassette('eshelf add to empty basket') do
146
165
  # Add record to basket with no folder id
147
166
  assert_nothing_raised(){ eshelf.add_records(@valid_doc_ids, nil) }
148
167
  # Remove record from basket with no folder id
149
168
  assert_nothing_raised(){ eshelf.remove_records(@valid_doc_ids, @valid_basket) }
169
+ end
150
170
  end
151
-
152
- end
171
+ end