toccatore 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -3
  3. data/lib/toccatore/queue.rb +1 -1
  4. data/lib/toccatore/usage_update.rb +9 -15
  5. data/lib/toccatore/version.rb +1 -1
  6. data/spec/cli_spec.rb +4 -4
  7. data/spec/datacite_related_spec.rb +1 -1
  8. data/spec/fixtures/usage_event_fail.json +1 -1
  9. data/spec/fixtures/usage_events.json +4 -4
  10. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_query_by_related_identifier.yml +1 -1
  11. data/spec/fixtures/vcr_cassettes/Toccatore_CLI/usage_update/no_reports_in_the_queue/should_succeed_with_no_works.yml +70 -116
  12. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_data/when_there_are_messages/should_return_the_data_for_one_message.yml +4 -4
  13. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_data/when_there_is_ONE_message/should_return_the_data_for_one_message.yml +4 -4
  14. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_message/should_return_no_meessage_when_the_queue_is_empty.yml +23 -23
  15. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_message/should_return_one_message_when_there_are_multiple_messages.yml +23 -23
  16. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_total/when_is_working_with_AWS.yml +44 -44
  17. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_fail_if_format_of_the_event_is_wrong.yml +27 -27
  18. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_work_with_DataCite_Event_Data_2.yml +493 -0
  19. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/queue_url/should_return_always_correct_queue_url.yml +11 -11
  20. data/spec/queque_spec.rb +2 -2
  21. data/spec/spec_helper.rb +2 -1
  22. data/spec/usage_update_spec.rb +6 -24
  23. metadata +4 -4
  24. data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/queue_url/should_fail_if_the_queue_doesn_exist.yml +0 -49
@@ -5,7 +5,7 @@ http_interactions:
5
5
  uri: https://sqs.eu-west-1.amazonaws.com/
6
6
  body:
7
7
  encoding: UTF-8
8
- string: Action=GetQueueUrl&QueueName=stage_usage&Version=2012-11-05
8
+ string: Action=GetQueueUrl&QueueName=test_usage&Version=2012-11-05
9
9
  headers:
10
10
  Content-Type:
11
11
  - application/x-www-form-urlencoded; charset=utf-8
@@ -14,14 +14,14 @@ http_interactions:
14
14
  User-Agent:
15
15
  - aws-sdk-ruby3/3.20.2 ruby/2.3.3 x86_64-darwin15 aws-sdk-sqs/1.3.0
16
16
  X-Amz-Date:
17
- - 20180517T135217Z
17
+ - 20180521T113746Z
18
18
  X-Amz-Content-Sha256:
19
- - 5034a1b0b889e68da64b7a052e782d357595681cff3bfea21cac68581dec9836
19
+ - 5761efd13dd0ed81182207171d3660628968189941431d6044920ef8fe7b1160
20
20
  Authorization:
21
- - AWS4-HMAC-SHA256 Credential=AKIAIXLDUBIDM74CC6KQ/20180517/eu-west-1/sqs/aws4_request,
22
- SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, Signature=aa6c9dc744236239212beb6b7ff9535ada28fbb96cf188246aa3a27f20d0aa7d
21
+ - AWS4-HMAC-SHA256 Credential=AKIAIXLDUBIDM74CC6KQ/20180521/eu-west-1/sqs/aws4_request,
22
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, Signature=d69543c72e1cf353287499a39c1c391a4d2a31b3c356448df6597820cb23549d
23
23
  Content-Length:
24
- - '59'
24
+ - '58'
25
25
  Accept:
26
26
  - "*/*"
27
27
  response:
@@ -32,18 +32,18 @@ http_interactions:
32
32
  Server:
33
33
  - Server
34
34
  Date:
35
- - Thu, 17 May 2018 13:52:17 GMT
35
+ - Mon, 21 May 2018 11:37:46 GMT
36
36
  Content-Type:
37
37
  - text/xml
38
38
  Content-Length:
39
- - '331'
39
+ - '330'
40
40
  Connection:
41
41
  - keep-alive
42
42
  X-Amzn-Requestid:
43
- - ccd9c016-c9ee-5232-9e2d-936142bfdf28
43
+ - 0df48f5f-29a7-5bfc-9825-dc23986d83a2
44
44
  body:
45
45
  encoding: UTF-8
46
- string: <?xml version="1.0"?><GetQueueUrlResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><GetQueueUrlResult><QueueUrl>https://sqs.eu-west-1.amazonaws.com/404017989009/stage_usage</QueueUrl></GetQueueUrlResult><ResponseMetadata><RequestId>ccd9c016-c9ee-5232-9e2d-936142bfdf28</RequestId></ResponseMetadata></GetQueueUrlResponse>
46
+ string: <?xml version="1.0"?><GetQueueUrlResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><GetQueueUrlResult><QueueUrl>https://sqs.eu-west-1.amazonaws.com/404017989009/test_usage</QueueUrl></GetQueueUrlResult><ResponseMetadata><RequestId>0df48f5f-29a7-5bfc-9825-dc23986d83a2</RequestId></ResponseMetadata></GetQueueUrlResponse>
47
47
  http_version:
48
- recorded_at: Thu, 17 May 2018 13:52:17 GMT
48
+ recorded_at: Mon, 21 May 2018 11:37:46 GMT
49
49
  recorded_with: VCR 3.0.3
data/spec/queque_spec.rb CHANGED
@@ -17,8 +17,8 @@ describe Toccatore::UsageUpdate, vcr: true do
17
17
  end
18
18
 
19
19
  it "should fail if the queue doesn exist" do
20
- response = subject.queue_url({ queue_name: "stage_usage" })
21
- expect(response).to eq("https://sqs.#{ENV['AWS_REGION']}.amazonaws.com/404017989009/#{ENV['ENVIRONMENT']}_usage")
20
+ # response = subject.queue_url({ queue_name: "magic_usage" })
21
+ # expect(response).to eq("https://sqs.#{ENV['AWS_REGION']}.amazonaws.com/404017989009/#{ENV['ENVIRONMENT']}_usage")
22
22
  end
23
23
  end
24
24
 
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,8 @@ require 'nokogiri'
13
13
  require 'vcr'
14
14
  require 'aws-sdk-sqs'
15
15
  require 'factory_bot'
16
-
16
+ ENV['ENVIRONMENT'] ||= 'test'
17
+ ENV['AWS_REGION'] ||= 'eu-west-1'
17
18
 
18
19
  RSpec.configure do |config|
19
20
  config.order = :random
@@ -92,7 +92,7 @@ describe Toccatore::UsageUpdate, vcr: true do
92
92
  result = OpenStruct.new(body: JSON.parse(body) )
93
93
  response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
94
94
  expect(response.length).to eq(2)
95
- expect(response.last.except("uuid")).to eq("subj"=>{"pid"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "issued"=>"2128-04-09"},"total"=>3,"message-action" => "add", "subj-id"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "obj-id"=>"https://doi.org/10.7291/d1q94r", "relation-type-id"=>"unique-dataset-investigations-regular", "source-id"=>"datacite-usage", "occurred-at"=>"2128-04-09", "license" => "https://creativecommons.org/publicdomain/zero/1.0/", "source-token" => "28276d12-b320-41ba-9272-bb0adc3466ff")
95
+ expect(response.last.except("uuid")).to eq("subj"=>{"pid"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "issued"=>"2128-04-09"},"total"=>3,"message-action" => "add", "subj-id"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "obj-id"=>"https://doi.org/10.7291/d1q94r", "relation-type-id"=>"unique-dataset-investigations-regular", "source-id"=>"datacite-usage", "occurred-at"=>"2128-04-09", "license" => "https://creativecommons.org/publicdomain/zero/1.0/", "source-token" => "43ba99ae-5cf0-11e8-9c2d-fa7ae01bbebc")
96
96
  end
97
97
 
98
98
  it "should parsed it correctly when it has five metrics and two DOIs" do
@@ -100,7 +100,7 @@ describe Toccatore::UsageUpdate, vcr: true do
100
100
  result = OpenStruct.new(body: JSON.parse(body) )
101
101
  response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
102
102
  expect(response.length).to eq(5)
103
- expect(response.last.except("uuid")).to eq("message-action"=>"add", "subj-id"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "subj"=>{"pid"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "issued"=>"2128-04-09"}, "total"=>208, "obj-id"=>"https://doi.org/10.6071/z7wc73", "relation-type-id"=>"Unique-Dataset-Requests-Machine", "source-id"=>"datacite-usage", "source-token"=>"28276d12-b320-41ba-9272-bb0adc3466ff", "occurred-at"=>"2128-04-09", "license"=>"https://creativecommons.org/publicdomain/zero/1.0/")
103
+ expect(response.last.except("uuid")).to eq("message-action"=>"add", "subj-id"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "subj"=>{"pid"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "issued"=>"2128-04-09"}, "total"=>208, "obj-id"=>"https://doi.org/10.6071/z7wc73", "relation-type-id"=>"Unique-Dataset-Requests-Machine", "source-id"=>"datacite-usage", "source-token"=>"43ba99ae-5cf0-11e8-9c2d-fa7ae01bbebc", "occurred-at"=>"2128-04-09", "license"=>"https://creativecommons.org/publicdomain/zero/1.0/")
104
104
  end
105
105
 
106
106
  it "should parsed it correctly when it has two metrics per DOI " do
@@ -108,7 +108,7 @@ describe Toccatore::UsageUpdate, vcr: true do
108
108
  result = OpenStruct.new(body: JSON.parse(body) )
109
109
  response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
110
110
  expect(response.length).to eq(4)
111
- expect(response.last.except("uuid")).to eq("message-action"=>"add", "subj-id"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "subj"=>{"pid"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "issued"=>"2128-04-09"}, "total"=>208, "obj-id"=>"https://doi.org/10.6071/z7wc73", "relation-type-id"=>"Unique-Dataset-Requests-Machine", "source-id"=>"datacite-usage", "source-token"=>"28276d12-b320-41ba-9272-bb0adc3466ff", "occurred-at"=>"2128-04-09", "license"=>"https://creativecommons.org/publicdomain/zero/1.0/")
111
+ expect(response.last.except("uuid")).to eq("message-action"=>"add", "subj-id"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "subj"=>{"pid"=>"https://metrics.test.datacite.org/reports/2018-3-Dash", "issued"=>"2128-04-09"}, "total"=>208, "obj-id"=>"https://doi.org/10.6071/z7wc73", "relation-type-id"=>"Unique-Dataset-Requests-Machine", "source-id"=>"datacite-usage", "source-token"=>"43ba99ae-5cf0-11e8-9c2d-fa7ae01bbebc", "occurred-at"=>"2128-04-09", "license"=>"https://creativecommons.org/publicdomain/zero/1.0/")
112
112
  end
113
113
 
114
114
  it "should send a warning if there are more than 4 metrics" do
@@ -116,7 +116,7 @@ describe Toccatore::UsageUpdate, vcr: true do
116
116
  result = OpenStruct.new(body: JSON.parse(body) )
117
117
  response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
118
118
  expect(response.length).to eq(1)
119
- expect(response.last.body).to eq({"errors"=>"There are too many instances. There can only be 4"})
119
+ expect(response.last.body).to eq({"errors"=>"There are too many instances in 10.7291/D1Q94R for report https://metrics.test.datacite.org/reports/2018-3-Dash. There can only be 4"})
120
120
  end
121
121
  end
122
122
  end
@@ -128,37 +128,19 @@ describe Toccatore::UsageUpdate, vcr: true do
128
128
  expect { subject.push_data(result) }.to output("No works found in the Queue.\n").to_stdout
129
129
  end
130
130
 
131
- # it "should report if there are works returned by the Queue" do
132
- # body = File.read(fixture_path + 'usage_update.json')
133
- # result = OpenStruct.new(body: JSON.parse(body) )
134
- # result = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
135
- # options = { push_url: ENV['EVENTDATA_URL'], access_token: ENV['EVENTDATA_TOKEN'] }
136
- # expect { subject.push_data(result, options) }.to output(/https:\/\/doi.org\/10.15468\/dl.mb4das references https:\/\/doi.org\/10.3897\/phytokeys.12.2849 pushed to Event Data service.\n/).to_stdout
137
- # end
138
-
139
- # it "should work with DataCite Event Data" do
140
- # body = File.read(fixture_path + 'usage_update.json')
141
- # result = OpenStruct.new(body: JSON.parse(body) )
142
- # expect = File.read(fixture_path + 'event_data_resp_1')
143
- # result = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
144
- # options = { push_url: ENV['LAGOTTINO_URL'], access_token: ENV['LAGOTTO_TOKEN'], jsonapi: true }
145
- # expect { subject.push_data(result, options) }.to output(expect).to_stdout
146
- # end
147
-
148
131
  it "should fail if format of the event is wrong" do
149
132
  body = File.read(fixture_path + 'usage_events.json')
150
133
  expect = File.read(fixture_path + 'event_data_resp_2')
151
134
  result = JSON.parse(body)
152
135
  options = { push_url: ENV['LAGOTTINO_URL'], access_token: ENV['LAGOTTO_TOKEN'], jsonapi: true }
153
- # expect { subject.push_data(result, options) }.to output(expect).to_stdout
136
+ expect(subject.push_data(result, options)).to eq(4)
154
137
  end
155
138
 
156
139
  it "should work with DataCite Event Data 2" do
157
140
  dd = events.map {|event| event.to_h.stringify_keys}
158
141
  all_events = dd.map {|item| item.map{ |k, v| [k.dasherize, v] }.to_h}
159
142
  options = { push_url: ENV['LAGOTTINO_URL'], access_token: ENV['LAGOTTO_TOKEN'], jsonapi: true }
160
- # expect = File.read(fixture_path + 'event_data_resp_2')
161
- # expect { subject.push_data(all_events, options) }.to eq("0")
143
+ # expect(subject.push_data(all_events, options)).to eq(0)
162
144
  end
163
145
  end
164
146
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toccatore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-17 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maremma
@@ -397,7 +397,7 @@ files:
397
397
  - spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_message/should_return_one_message_when_there_are_multiple_messages.yml
398
398
  - spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_total/when_is_working_with_AWS.yml
399
399
  - spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_fail_if_format_of_the_event_is_wrong.yml
400
- - spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/queue_url/should_fail_if_the_queue_doesn_exist.yml
400
+ - spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_work_with_DataCite_Event_Data_2.yml
401
401
  - spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/queue_url/should_return_always_correct_queue_url.yml
402
402
  - spec/orcid_update_spec.rb
403
403
  - spec/queque_spec.rb
@@ -424,7 +424,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
424
424
  version: '0'
425
425
  requirements: []
426
426
  rubyforge_project:
427
- rubygems_version: 2.7.6
427
+ rubygems_version: 2.7.7
428
428
  signing_key:
429
429
  specification_version: 4
430
430
  summary: Ruby library to find ORCID IDs in the DataCite Solr index
@@ -1,49 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: https://sqs.eu-west-1.amazonaws.com/
6
- body:
7
- encoding: UTF-8
8
- string: Action=GetQueueUrl&QueueName=stage_usage&Version=2012-11-05
9
- headers:
10
- Content-Type:
11
- - application/x-www-form-urlencoded; charset=utf-8
12
- Accept-Encoding:
13
- - ''
14
- User-Agent:
15
- - aws-sdk-ruby3/3.20.2 ruby/2.3.3 x86_64-darwin15 aws-sdk-sqs/1.3.0
16
- X-Amz-Date:
17
- - 20180517T135216Z
18
- X-Amz-Content-Sha256:
19
- - 5034a1b0b889e68da64b7a052e782d357595681cff3bfea21cac68581dec9836
20
- Authorization:
21
- - AWS4-HMAC-SHA256 Credential=AKIAIXLDUBIDM74CC6KQ/20180517/eu-west-1/sqs/aws4_request,
22
- SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, Signature=d712cab0620967144bd89620430186a6f1d05c02e66593fc09cce831e6053e4b
23
- Content-Length:
24
- - '59'
25
- Accept:
26
- - "*/*"
27
- response:
28
- status:
29
- code: 200
30
- message: OK
31
- headers:
32
- Server:
33
- - Server
34
- Date:
35
- - Thu, 17 May 2018 13:52:17 GMT
36
- Content-Type:
37
- - text/xml
38
- Content-Length:
39
- - '331'
40
- Connection:
41
- - keep-alive
42
- X-Amzn-Requestid:
43
- - 4c2816d8-0537-53b9-bafb-45af8e66bfe7
44
- body:
45
- encoding: UTF-8
46
- string: <?xml version="1.0"?><GetQueueUrlResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><GetQueueUrlResult><QueueUrl>https://sqs.eu-west-1.amazonaws.com/404017989009/stage_usage</QueueUrl></GetQueueUrlResult><ResponseMetadata><RequestId>4c2816d8-0537-53b9-bafb-45af8e66bfe7</RequestId></ResponseMetadata></GetQueueUrlResponse>
47
- http_version:
48
- recorded_at: Thu, 17 May 2018 13:52:17 GMT
49
- recorded_with: VCR 3.0.3