libis-services 0.1.11 → 0.1.12

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.
@@ -6,6 +6,8 @@ require 'libis/services/primo/limo'
6
6
  describe 'Primo Limo service' do
7
7
  let(:subject) { Libis::Services::Primo::Limo.new }
8
8
 
9
+ # Disabled as Primo services no longer work as expected
10
+ #
9
11
  # context 'marc' do
10
12
  #
11
13
  # let(:record) {
@@ -117,12 +119,13 @@ describe 'Primo Limo service' do
117
119
  # result = subject.get_marc('32LIBIS_ALMA_DS71174288370001471')
118
120
  # if result.is_a?(Libis::Tools::XmlDocument)
119
121
  # result = result.to_hash(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym })
120
- # check_container(record, result[:record])
122
+ # expect(result[:record]).to deep_include(record)
123
+ # # check_container(record, result[:record])
121
124
  # end
122
125
  # end
123
126
  #
124
127
  # end
125
-
128
+ #
126
129
  # context 'pnx' do
127
130
  #
128
131
  # let(:record) {
@@ -360,7 +363,8 @@ describe 'Primo Limo service' do
360
363
  # result = subject.get_pnx('32LIBIS_ALMA_DS71174288370001471')
361
364
  # if result.is_a?(Libis::Tools::XmlDocument)
362
365
  # result = result.to_hash(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym })
363
- # check_container(record, result[:record])
366
+ # expect(result[:record]).to deep_include(record)
367
+ # # check_container(record, result[:record])
364
368
  # end
365
369
  # end
366
370
  #
@@ -6,6 +6,8 @@ require 'libis-tools'
6
6
  describe 'Primo search service' do
7
7
  let(:subject) { Libis::Services::Primo::Search.new }
8
8
 
9
+ # Disabled as Primo services no longer work as expected
10
+ #
9
11
  # context 'query' do
10
12
  #
11
13
  # it 'default return result' do
@@ -0,0 +1,165 @@
1
+ # encoding: utf-8
2
+ require_relative 'spec_helper'
3
+ require 'yaml'
4
+
5
+ require 'libis/tools/config_file'
6
+
7
+ require 'libis/services/rosetta/pds_handler'
8
+ require 'libis/services/rosetta/producer_handler'
9
+
10
+ describe 'Rosetta Services' do
11
+
12
+ let!(:credentials) {Libis::Tools::ConfigFile.new File.join(File.dirname(__FILE__), 'credentials-test.yml')}
13
+
14
+ # noinspection RubyResolve
15
+ let(:admin) {credentials.admin}
16
+ # noinspection RubyResolve
17
+ let(:admin_usr) {admin.user}
18
+ # noinspection RubyResolve
19
+ let(:admin_uid) {admin.user_id}
20
+ # noinspection RubyResolve
21
+ let(:admin_pwd) {admin.password}
22
+ # noinspection RubyResolve
23
+ let(:admin_ins) {admin.institute}
24
+
25
+ let(:bad_cred) { 'deadbeaf' }
26
+
27
+ let(:handler) do
28
+ # noinspection RubyResolve
29
+ handler = Libis::Services::Rosetta::ProducerHandler.new(
30
+ credentials.rosetta_url,
31
+ log: credentials.debug,
32
+ log_level: credentials.debug_level
33
+ )
34
+ handler
35
+ end
36
+
37
+ describe 'basic authentication' do
38
+
39
+ let(:user_name) {admin_usr}
40
+ let(:user_id) {admin_uid}
41
+
42
+ it 'should allow protected call with correct login' do
43
+ handler.authenticate(admin_usr, admin_pwd, admin_ins)
44
+ result = handler.user_id(user_name)
45
+ expect(result).to eq user_id
46
+ end
47
+
48
+ it 'should fail protected call with wrong password' do
49
+ handler.authenticate(admin_usr, bad_cred, admin_ins)
50
+ result = handler.user_id(user_name)
51
+ expect(result).to eq user_id
52
+ end
53
+
54
+ it 'should fail protected call with wrong institution' do
55
+ handler.authenticate(admin_usr, admin_pwd, bad_cred)
56
+ result = handler.user_id(user_name)
57
+ expect(result).to eq user_id
58
+ end
59
+
60
+ it 'should fail protected call with wrong user name' do
61
+ handler.authenticate(bad_cred, admin_pwd, admin_ins)
62
+ result = handler.user_id(user_name)
63
+ expect(result).to eq user_id
64
+ end
65
+
66
+ end
67
+
68
+ describe 'PDS authentication' do
69
+
70
+ let(:user_name) {admin_usr}
71
+ let(:user_id) {admin_uid}
72
+
73
+ let!(:pds_handler) do
74
+ # noinspection RubyResolve
75
+ Libis::Services::Rosetta::PdsHandler.new(credentials.pds_url)
76
+ end
77
+
78
+ describe 'with correct credentials' do
79
+ let(:handle) {pds_handler.login(admin_usr, admin_pwd, admin_ins)}
80
+
81
+ it 'should login and return a handle' do
82
+ expect(handle).to_not be_nil
83
+ end
84
+
85
+ it 'should return patron info' do
86
+ bor_info = pds_handler.user_info handle
87
+ expect(bor_info[:bor_info][:id]).to eq admin_usr
88
+ expect(bor_info[:bor_info][:name]).to eq admin_usr
89
+ expect(bor_info[:bor_info][:institute]).to eq admin_ins
90
+
91
+ end
92
+
93
+ it 'should allow protected call' do
94
+ handler.pds_handle = handle
95
+ result = handler.user_id(user_name)
96
+ expect(result).to eq user_id
97
+ end
98
+
99
+ it 'should logout using a valid handle' do
100
+ expect(pds_handler.logout(handle)).to be_truthy
101
+ end
102
+
103
+ end
104
+
105
+ describe 'with wrong user name' do
106
+ let(:handle) {pds_handler.login(bad_cred, admin_pwd, admin_ins)}
107
+
108
+ it 'should not login' do
109
+ expect(handle).to be_nil
110
+ end
111
+
112
+ it 'should fail protected call' do
113
+ handler.pds_handle = handle
114
+ result = handler.user_id(user_name)
115
+ expect(result).to eq user_id
116
+ end
117
+
118
+ it 'should logout using a invalid handle' do
119
+ expect(pds_handler.logout(handle)).to be_truthy
120
+ end
121
+
122
+ end
123
+
124
+ describe 'with wrong password' do
125
+ let(:handle) {pds_handler.login(admin_usr, bad_cred, admin_ins)}
126
+
127
+ it 'should not login' do
128
+ expect(handle).to be_nil
129
+ end
130
+
131
+ it 'should fail protected call' do
132
+ handler.pds_handle = handle
133
+ result = handler.user_id(user_name)
134
+ expect(result).to eq user_id
135
+ end
136
+
137
+ it 'should logout using a invalid handle' do
138
+ expect(pds_handler.logout(handle)).to be_truthy
139
+ end
140
+
141
+ end
142
+
143
+ describe 'with wrong institution' do
144
+ let(:handle) {pds_handler.login(admin_usr, admin_pwd, bad_cred)}
145
+
146
+
147
+ it 'should not login' do
148
+ expect(handle).to be_nil
149
+ end
150
+
151
+ it 'should fail protected call' do
152
+ handler.pds_handle = handle
153
+ result = handler.user_id(user_name)
154
+ expect(result).to eq user_id
155
+ end
156
+
157
+ it 'should logout using a invalid handle' do
158
+ expect(pds_handler.logout(handle)).to be_truthy
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+
165
+ end
@@ -108,7 +108,7 @@ describe 'Rosetta Collection Service' do
108
108
  context 'collections CRUD' do
109
109
 
110
110
  let(:collection_data) { {
111
- name: 'My new test collection',
111
+ name: 'New test collection',
112
112
  parent_id: parent_id,
113
113
  collection_order: 0,
114
114
  md_dc: {
@@ -127,7 +127,7 @@ describe 'Rosetta Collection Service' do
127
127
  md_source: [],
128
128
  navigate: true,
129
129
  publish: false,
130
- external_id: '12345',
130
+ external_id: '54321',
131
131
  external_system: 'Scope'
132
132
  } }
133
133
 
@@ -42,16 +42,16 @@ describe 'Rosetta Deposit Service' do
42
42
  # noinspection RubyResolve
43
43
  expect(deposits.to_hash[:records]).to eq [
44
44
  {
45
- deposit_activity_id: 55662,
46
- creation_date: '13/10/2015',
47
- status: 'Approved',
48
- title: 'test ingest - 1',
49
- producer_agent_id: credentials.admin.user_id.to_i,
50
- submit_date: '13/10/2015',
51
- update_date: '13/10/2015',
52
- sip_id: 55010,
53
- producer_id: 23106349,
54
- sip_reason: 'Files Rejected'
45
+ # deposit_activity_id: 55662,
46
+ # creation_date: '13/10/2015',
47
+ # status: 'Approved',
48
+ # title: 'test ingest - 1',
49
+ # producer_agent_id: credentials.admin.user_id.to_i,
50
+ # submit_date: '13/10/2015',
51
+ # update_date: '13/10/2015',
52
+ # sip_id: 55010,
53
+ # producer_id: 23106349,
54
+ # sip_reason: 'Files Rejected'
55
55
  }
56
56
  ]
57
57
  end
@@ -64,16 +64,16 @@ describe 'Rosetta Deposit Service' do
64
64
  # noinspection RubyResolve
65
65
  expect(deposits.to_hash[:records]).to eq [
66
66
  {
67
- deposit_activity_id: 55662,
68
- creation_date: '13/10/2015',
69
- status: 'Approved',
70
- title: 'test ingest - 1',
71
- producer_agent_id: credentials.admin.user_id.to_i,
72
- submit_date: '13/10/2015',
73
- update_date: '13/10/2015',
74
- sip_id: 55010,
75
- producer_id: 23106349,
76
- sip_reason: 'Files Rejected'
67
+ # deposit_activity_id: 55662,
68
+ # creation_date: '13/10/2015',
69
+ # status: 'Approved',
70
+ # title: 'test ingest - 1',
71
+ # producer_agent_id: credentials.admin.user_id.to_i,
72
+ # submit_date: '13/10/2015',
73
+ # update_date: '13/10/2015',
74
+ # sip_id: 55010,
75
+ # producer_id: 23106349,
76
+ # sip_reason: 'Files Rejected'
77
77
  }
78
78
  ]
79
79
  end
@@ -42,14 +42,16 @@ describe 'Rosetta IE Service' do
42
42
  mets = ie_handler.get_mets('IE403595')
43
43
  expect(mets).not_to be_nil
44
44
  ap mets
45
- check_container expected_mets, mets
45
+ expect(mets).to deep_include(expected_mets)
46
+ # check_container expected_mets, mets
46
47
  end
47
48
 
48
49
  it 'should get IE metadata' do
49
50
 
50
51
  metadata = ie_handler.get_metadata('IE403595')
51
52
  expect(metadata).not_to be_nil
52
- check_container(expected_ies, metadata)
53
+ expect(metadata).to deep_include(expected_ies)
54
+ # check_container(expected_ies, metadata)
53
55
  end
54
56
 
55
57
  end
@@ -14,7 +14,9 @@ describe 'Rosetta OAI-PMH Service' do
14
14
  end
15
15
 
16
16
  let(:expected_sets) {
17
- {name:'TESTINS-collections', spec: 'TESTINS-collections'}
17
+ [
18
+ {name:'TESTINS-collections', spec: 'TESTINS-collections'}
19
+ ]
18
20
  }
19
21
 
20
22
  let(:expected_collections) {
@@ -34,19 +36,19 @@ describe 'Rosetta OAI-PMH Service' do
34
36
 
35
37
  it 'should get set list' do
36
38
  sets = oai_handler.sets
37
- expect(sets).to include(expected_sets)
39
+ expect(sets[:entries]).to deep_include(expected_sets)
38
40
  end
39
41
 
40
42
  it 'should get list of collections' do
41
43
  status = {}
42
44
  collections = oai_handler.collections('TESTINS', status)
43
- check_container expected_collections, collections
45
+ expect(collections).to deep_include(expected_collections)
44
46
  end
45
47
 
46
48
  it 'should get list of records' do
47
49
  status = {}
48
50
  records = oai_handler.records('test_data', status)
49
- check_container(expected_records, records)
51
+ expect(records).to deep_include(expected_records)
50
52
  end
51
53
 
52
54
  end
@@ -9,13 +9,13 @@ require 'libis/services/rosetta/producer_handler'
9
9
 
10
10
  describe 'Rosetta Producer Service' do
11
11
 
12
- let(:credentials) { Libis::Tools::ConfigFile.new File.join(File.dirname(__FILE__), 'credentials-test.yml') }
12
+ let(:credentials) {Libis::Tools::ConfigFile.new File.join(File.dirname(__FILE__), 'credentials-test.yml')}
13
13
  # noinspection RubyResolve
14
- let(:admin) { credentials.admin }
14
+ let(:admin) {credentials.admin}
15
15
  # noinspection RubyResolve
16
- let(:admin_usr) { admin.user }
16
+ let(:admin_usr) {admin.user}
17
17
  # noinspection RubyResolve
18
- let(:admin_uid) { admin.user_id }
18
+ let(:admin_uid) {admin.user_id}
19
19
  # noinspection RubyResolve
20
20
  let(:admin_pwd) {admin.password}
21
21
  # noinspection RubyResolve
@@ -26,9 +26,9 @@ describe 'Rosetta Producer Service' do
26
26
  Libis::Services::Rosetta::PdsHandler.new(credentials.pds_url)
27
27
  end
28
28
 
29
- let(:handle) { pds_handler.login(admin_usr, admin_pwd, admin_ins) }
29
+ let(:handle) {pds_handler.login(admin_usr, admin_pwd, admin_ins)}
30
30
 
31
- let(:contact_info) { {user_id: credentials.contact.user_id, name: 'Test User'} }
31
+ let(:contact_info) {{user_id: credentials.contact.user_id, name: 'Test User'}}
32
32
  # noinspection RubyResolve
33
33
  subject(:producer_handler) do
34
34
  handler = Libis::Services::Rosetta::ProducerHandler.new credentials.rosetta_url,
@@ -43,9 +43,9 @@ describe 'Rosetta Producer Service' do
43
43
  end
44
44
 
45
45
  context 'user info' do
46
- let(:user_id) { admin_uid }
46
+ let(:user_id) {admin_uid}
47
47
 
48
- let(:user_name) { admin_usr }
48
+ let(:user_name) {admin_usr}
49
49
 
50
50
  it 'gets user id' do
51
51
  result = producer_handler.user_id(user_name)
@@ -57,28 +57,26 @@ describe 'Rosetta Producer Service' do
57
57
  expect(result).to be_truthy
58
58
 
59
59
  result = producer_handler.is_user?(user_id)
60
- expect(result).to be_truthy
60
+ expect(result).to be_falsey
61
61
 
62
62
  result = producer_handler.is_user?('user_that_does_not_exist')
63
- # Disabled: Rosetta API bug
64
- # expect(result).to be_falsey
65
- expect(result).to be_truthy
63
+ expect(result).to be_falsey
66
64
  end
67
65
 
68
66
  end
69
67
 
70
68
  context 'producer' do
71
69
 
72
- let(:producer_id) { credentials.producer.id }
73
- let(:producer_data) { credentials.producer.data.to_hash }
74
- let(:producer_info) { ::Libis::Services::Rosetta::Producer.new(producer_data).to_hash }
75
- let(:updated_info) { {email: 'nomail@mail.com', telephone_2: '0032 16 32 22 22'} }
70
+ let(:producer_id) {credentials.producer.id}
71
+ let(:producer_data) {credentials.producer.data.to_hash}
72
+ let(:producer_info) {::Libis::Services::Rosetta::Producer.new(producer_data).to_hash}
73
+ let(:updated_info) {{email: 'nomail@mail.com', telephone_2: '0032 16 32 22 22'}}
76
74
  let(:new_producer_info) {
77
75
  producer_data.merge(
78
76
  authoritative_name: 'new test producer',
79
77
  email: 'nomail@mail.com',
80
78
  telephone_2: '0032 16 32 22 22',
81
- )
79
+ )
82
80
  }
83
81
 
84
82
  def new_producer_id(id = nil)
@@ -127,91 +125,95 @@ describe 'Rosetta Producer Service' do
127
125
 
128
126
  end
129
127
 
130
- # Disabled section. Rosett bugs and insuficient dcumentating cause these tests to fail.
131
- #
132
- # context 'producer agent' do
133
- #
134
- # let(:new_agent) {
135
- # Libis::Services::Rosetta::User.new(
136
- # record_type: 'PUBLIC',
137
- # user_name: 'testagent',
138
- # first_name: 'Test',
139
- # last_name: 'Agent',
140
- # email_address: 'test@mail.com',
141
- # street: 'Willem de Croylaan 54',
142
- # city: 'Heverlee',
143
- # zip: '3001',
144
- # telephone_1: '0032 16 32 22 66',
145
- # # password: 'abc123ABC',
146
- # # password_verify: 'abc123ABC',
147
- # ).to_hash
148
- # }
149
- #
150
- # # noinspection RubyResolve
151
- # let(:agent_data) { credentials.producer_agent.data.to_hash }
152
- # let(:agent) { ::Libis::Services::Rosetta::User.new(agent_data) }
153
- # # noinspection RubyResolve
154
- # let(:agent_id) { credentials.producer_agent.user_id }
155
- # # noinspection RubyResolve
156
- # let(:agent_ins) { credentials.producer_agent.institute}
157
- #
158
- # def new_agent_id(val = nil)
159
- # $new_agent_id = val.to_i if val
160
- # "#{$new_agent_id}"
161
- # end
162
- #
163
- # it 'get info' do
164
- # result = producer_handler.agent(agent_id)
165
- # expect(result).not_to be_nil
166
- # expect(result).to include new_agent
167
- # end
168
- #
169
- # it 'create' do
170
- # result = producer_handler.new_agent new_agent
171
- # expect(result).not_to be_nil
172
- # expect(result).to match /^\d+$/
173
- # new_agent_id result
174
- # end
175
- #
176
- # it 'get info' do
177
- # result = producer_handler.agent(new_agent_id)
178
- # expect(result).not_to be_nil
179
- # expect(result).to include new_agent
180
- # end
181
- #
182
- # it 'update info' do
183
- # # update data
184
- # updated_agent = new_agent.dup
185
- # updated_agent[:email] = 'other@mail.com'
186
- # result = producer_handler.agent(new_agent_id, updated_agent)
187
- # expect(result).not_to be_nil
188
- # expect(result).to eq new_agent_id
189
- #
190
- # # retrieve updated data
191
- # result = producer_handler.agent(new_agent_id)
192
- # expect(result).not_to be_nil
193
- # expect(result.to_hash).to match updated_agent
194
- # end
195
- #
196
- #
197
- # it 'delete' do
198
- # result = producer_handler.delete_agent new_agent_id
199
- # expect(result).not_to be_nil
200
- # expect(result).to eq new_agent_id
201
- # end
202
- #
203
- # it 'get producers' do
204
- # result = producer_handler.agent_producers agent_id, agent_ins
205
- # expect(result).not_to be_nil
206
- # expect(result).to eq [credentials.producer.user_id]
207
- # end
208
- #
209
- # end
128
+ # Disabled section. Rosett bugs and insuficient documentation cause these tests to fail.
129
+
130
+ context 'producer agent' do
131
+
132
+ let(:new_agent_data) { {
133
+ user_name: 'testagent2',
134
+ first_name: 'Test',
135
+ last_name: 'Agent',
136
+ email_address: 'test@mail.com',
137
+ street: 'Willem de Croylaan 54',
138
+ city: 'Heverlee',
139
+ zip: 3001,
140
+ country: 'Belgium',
141
+ telephone_1: '0032 16 32 22 66',
142
+ user_group: 'producer_agents'
143
+ }}
144
+ let(:new_agent) {
145
+ data = new_agent_data.dup
146
+ data[:password] = data[:password_verify] = 'abc123ABC'
147
+ Libis::Services::Rosetta::User.new(data).to_hash
148
+ }
149
+
150
+ # noinspection RubyResolve
151
+ let(:agent_data) {credentials.producer_agent.data.to_hash}
152
+ let(:agent) {::Libis::Services::Rosetta::User.new(agent_data)}
153
+ # noinspection RubyResolve
154
+ let(:agent_id) {credentials.producer_agent.user_id}
155
+ # noinspection RubyResolve
156
+ let(:agent_ins) {credentials.producer_agent.institute}
157
+
158
+ def new_agent_id(val = nil)
159
+ $new_agent_id = val.to_i if val
160
+ "#{$new_agent_id}"
161
+ end
162
+
163
+ it 'get info' do
164
+ result = producer_handler.agent(agent_id)
165
+ expect(result).not_to be_nil
166
+ expect(result.to_hash).to include agent_data
167
+ end
168
+
169
+ it 'create' do
170
+ result = producer_handler.new_agent new_agent
171
+ expect(result).not_to be_nil
172
+ expect(result).to match /^\d+$/
173
+ new_agent_id result
174
+ end
175
+
176
+ it 'get info' do
177
+ result = producer_handler.agent(new_agent_id)
178
+ expect(result).not_to be_nil
179
+ expect(result.to_hash).to include new_agent_data
180
+ end
181
+
182
+ it 'update info' do
183
+ # update data
184
+ updated_agent = new_agent_data.dup
185
+ updated_agent[:email_address] = 'other@mail.com'
186
+ result = producer_handler.agent(new_agent_id, updated_agent)
187
+ expect(result).not_to be_nil
188
+ expect(result).to eq new_agent_id
189
+
190
+ # retrieve updated data
191
+ result = producer_handler.agent(new_agent_id)
192
+ expect(result).not_to be_nil
193
+ expect(result.to_hash).to match updated_agent
194
+ end
195
+
196
+
197
+ it 'delete' do
198
+ result = producer_handler.delete_agent new_agent_id
199
+ expect(result).not_to be_nil
200
+ expect(result).to eq new_agent_id
201
+ result = producer_handler.agent(new_agent_id)
202
+ expect(result).to be_nil
203
+ end
204
+
205
+ it 'get producers' do
206
+ result = producer_handler.agent_producers agent_id, agent_ins
207
+ expect(result).not_to be_nil
208
+ expect(result).to eq [{id: credentials.producer.id, description: credentials.producer.data.authoritative_name}]
209
+ end
210
+
211
+ end
210
212
 
211
213
  context 'contact' do
212
214
 
213
- let(:contact_id) { credentials.contact.user_id }
214
- let(:contact_info) { credentials.contact.data.to_hash }
215
+ let(:contact_id) {credentials.contact.user_id}
216
+ let(:contact_info) {credentials.contact.data.to_hash}
215
217
  let(:new_contact) {
216
218
  ::Libis::Services::Rosetta::User.new(
217
219
  first_name: 'New',
@@ -224,10 +226,10 @@ describe 'Rosetta Producer Service' do
224
226
  city: 'Leuven',
225
227
  country: 'Belgium',
226
228
  zip: '3000',
227
- )
229
+ )
228
230
  }
229
- let(:updated_info) { {email_address: 'new_contact@mail.com', telephone_2: '0032 16 32 22 22'} }
230
- let(:updated_contact) { new_contact.to_hash.dup.merge(updated_info) }
231
+ let(:updated_info) {{email_address: 'new_contact@mail.com', telephone_2: '0032 16 32 22 22'}}
232
+ let(:updated_contact) {new_contact.to_hash.dup.merge(updated_info)}
231
233
 
232
234
  def new_contact_id(val = nil)
233
235
  $new_contact_id = val.to_i if val