toccatore 0.3.9 → 0.4.15
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.
- checksums.yaml +5 -5
- data/Gemfile.lock +76 -54
- data/README.md +1 -1
- data/lib/toccatore/base.rb +15 -4
- data/lib/toccatore/cli.rb +12 -0
- data/lib/toccatore/datacite_related.rb +18 -3
- data/lib/toccatore/orcid_update.rb +6 -2
- data/lib/toccatore/queue.rb +56 -0
- data/lib/toccatore/usage_update.rb +183 -0
- data/lib/toccatore/version.rb +1 -1
- data/lib/toccatore.rb +2 -0
- data/spec/base_spec.rb +4 -4
- data/spec/cli_spec.rb +36 -3
- data/spec/datacite_related_spec.rb +10 -10
- data/spec/factories/default.rb +22 -0
- data/spec/fixtures/event_data_resp_1 +2 -0
- data/spec/fixtures/event_data_resp_2 +4 -0
- data/spec/fixtures/events_empty.json +33 -0
- data/spec/fixtures/usage_event.json +1 -0
- data/spec/fixtures/usage_event_fail.json +17 -0
- data/spec/fixtures/usage_events.json +63 -0
- data/spec/fixtures/usage_update.json +101 -0
- data/spec/fixtures/usage_update_1.json +36738 -0
- data/spec/fixtures/usage_update_2.json +171 -0
- data/spec/fixtures/usage_update_3.json +176 -0
- data/spec/fixtures/usage_update_4.json +101 -0
- data/spec/fixtures/usage_update_nil.json +6 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_Base/get_doi_ra/crossref.yml +21 -45
- data/spec/fixtures/vcr_cassettes/Toccatore_Base/get_doi_ra/datacite.yml +23 -47
- data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/datacite_related.yml +14 -12
- data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/datacite_related_no_works.yml +15 -13
- data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/orcid_update.yml +14 -12
- data/spec/fixtures/vcr_cassettes/Toccatore_Base/send_notification_to_slack/orcid_update_no_works.yml +15 -13
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_fail.yml +345 -852
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_query_by_DOI.yml +327 -409
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_query_by_related_identifier.yml +140 -117
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_succeed.yml +1267 -2068
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/datacite_related/should_succeed_with_no_works.yml +31 -25
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_fail.yml +47 -39
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_DOI.yml +673 -855
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_ORCID_ID.yml +1885 -2419
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed.yml +1555 -1991
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed_with_no_works.yml +31 -27
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/usage_update/no_reports_in_the_queue/should_succeed_with_no_works.yml +196 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/get_data/should_allow_queries_by_DOI_of_the_Datacite_Metadata_Search_API.yml +16 -12
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/get_data/should_allow_queries_by_related_identifier_of_the_Datacite_Metadata_Search_API.yml +17 -13
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/get_data/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml +16 -12
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/get_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml +16 -14
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/get_total/with_no_works.yml +15 -11
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/get_total/with_works.yml +16 -12
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/parse_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml +437 -869
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/push_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml +1240 -1662
- data/spec/fixtures/vcr_cassettes/Toccatore_DataciteRelated/push_data/should_work_with_DataCite_Event_Data.yml +4026 -6556
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_allow_queries_by_DOI_of_the_Datacite_Metadata_Search_API.yml +15 -13
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_allow_queries_by_ORCID_ID_of_the_Datacite_Metadata_Search_API.yml +15 -11
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml +15 -11
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml +15 -13
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_no_works.yml +15 -13
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_works.yml +15 -13
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/push_data/should_delete_claims.yml +25 -32
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/push_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml +1347 -1791
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/queue_jobs/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml +14 -10
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/queue_jobs/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml +29 -25
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_data/when_there_are_messages/should_return_the_data_for_one_message.yml +73 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_data/when_there_is_ONE_message/should_return_the_data_for_one_message.yml +73 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_message/should_return_no_meessage_when_the_queue_is_empty.yml +95 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_message/should_return_one_message_when_there_are_multiple_messages.yml +95 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/get_total/when_is_working_with_AWS.yml +187 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_fail_if_format_of_the_event_is_empty.yml +169 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_fail_if_format_of_the_event_is_wrong.yml +667 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_work_with_a_single_item.yml +169 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/queue_url/should_return_always_correct_queue_url.yml +49 -0
- data/spec/orcid_update_spec.rb +1 -1
- data/spec/queue_spec.rb +47 -0
- data/spec/spec_helper.rb +23 -1
- data/spec/usage_update_spec.rb +146 -0
- data/toccatore.gemspec +11 -5
- metadata +109 -26
data/spec/fixtures/vcr_cassettes/Toccatore_UsageUpdate/push_data/should_work_with_a_single_item.yml
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: put
|
|
5
|
+
uri: https://api.test.datacite.org/events/a17e783b-8214-451e-9b0d-077213c2acae
|
|
6
|
+
body:
|
|
7
|
+
encoding: UTF-8
|
|
8
|
+
string: '{"data":{"id":"a17e783b-8214-451e-9b0d-077213c2acae","type":"events","attributes":{"uuid":"a17e783b-8214-451e-9b0d-077213c2acae","message-action":"create","subj-id":"https://api.test.datacite.org/reports/2018-3-Dash","subj":{"pid":"https://api.test.datacite.org/reports/2018-3-Dash","issued":"2128-04-09"},"total":3,"obj-id":"https://doi.org/10.7291/d1q94r","relation-type-id":"total-dataset-investigations-regular","source-id":"datacite","source-token":"28276d12-b320-41ba-9272-bb0adc3466ff","occurred-at":"2128-04-09","license":"https://creativecommons.org/publicdomain/zero/1.0/"}}}'
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- Mozilla/5.0 (compatible; Maremma/4.1; +https://github.com/datacite/maremma)
|
|
12
|
+
Content-Type:
|
|
13
|
+
- application/json
|
|
14
|
+
Accept:
|
|
15
|
+
- text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5
|
|
16
|
+
Authorization:
|
|
17
|
+
- Bearer <LAGOTTINO_TOKEN>
|
|
18
|
+
response:
|
|
19
|
+
status:
|
|
20
|
+
code: 500
|
|
21
|
+
message: Internal Server Error
|
|
22
|
+
headers:
|
|
23
|
+
Date:
|
|
24
|
+
- Fri, 10 Aug 2018 17:13:54 GMT
|
|
25
|
+
Content-Type:
|
|
26
|
+
- application/json; charset=UTF-8
|
|
27
|
+
Content-Length:
|
|
28
|
+
- '14601'
|
|
29
|
+
Connection:
|
|
30
|
+
- keep-alive
|
|
31
|
+
Status:
|
|
32
|
+
- 500 Internal Server Error
|
|
33
|
+
Vary:
|
|
34
|
+
- Origin
|
|
35
|
+
X-Request-Id:
|
|
36
|
+
- 7596bb92-b7e0-42ec-90bf-1560980e9421
|
|
37
|
+
X-Runtime:
|
|
38
|
+
- '0.024621'
|
|
39
|
+
X-Powered-By:
|
|
40
|
+
- Phusion Passenger 5.3.4
|
|
41
|
+
Server:
|
|
42
|
+
- nginx/1.14.0 + Phusion Passenger 5.3.4
|
|
43
|
+
body:
|
|
44
|
+
encoding: ASCII-8BIT
|
|
45
|
+
string: '{"status":500,"error":"Internal Server Error","exception":"#<CanCan::AccessDenied:
|
|
46
|
+
You are not authorized to access this page.>","traces":{"Application Trace":[{"id":2,"trace":"app/controllers/events_controller.rb:30:in
|
|
47
|
+
`update''"}],"Framework Trace":[{"id":0,"trace":"vendor/bundle/ruby/2.4.0/gems/cancancan-2.2.0/lib/cancan/ability.rb:176:in
|
|
48
|
+
`authorize!''"},{"id":1,"trace":"vendor/bundle/ruby/2.4.0/gems/cancancan-2.2.0/lib/cancan/controller_additions.rb:336:in
|
|
49
|
+
`authorize!''"},{"id":3,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/basic_implicit_render.rb:6:in
|
|
50
|
+
`send_action''"},{"id":4,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/base.rb:194:in
|
|
51
|
+
`process_action''"},{"id":5,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/rendering.rb:30:in
|
|
52
|
+
`process_action''"},{"id":6,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/callbacks.rb:42:in
|
|
53
|
+
`block in process_action''"},{"id":7,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/callbacks.rb:132:in
|
|
54
|
+
`run_callbacks''"},{"id":8,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/callbacks.rb:41:in
|
|
55
|
+
`process_action''"},{"id":9,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/rescue.rb:22:in
|
|
56
|
+
`process_action''"},{"id":10,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/instrumentation.rb:34:in
|
|
57
|
+
`block in process_action''"},{"id":11,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications.rb:168:in
|
|
58
|
+
`block in instrument''"},{"id":12,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications/instrumenter.rb:23:in
|
|
59
|
+
`instrument''"},{"id":13,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications.rb:168:in
|
|
60
|
+
`instrument''"},{"id":14,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/instrumentation.rb:32:in
|
|
61
|
+
`process_action''"},{"id":15,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/params_wrapper.rb:256:in
|
|
62
|
+
`process_action''"},{"id":16,"trace":"vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.0/lib/active_record/railties/controller_runtime.rb:24:in
|
|
63
|
+
`process_action''"},{"id":17,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/base.rb:134:in
|
|
64
|
+
`process''"},{"id":18,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal.rb:191:in
|
|
65
|
+
`dispatch''"},{"id":19,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal.rb:252:in
|
|
66
|
+
`dispatch''"},{"id":20,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:52:in
|
|
67
|
+
`dispatch''"},{"id":21,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:34:in
|
|
68
|
+
`serve''"},{"id":22,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:52:in
|
|
69
|
+
`block in serve''"},{"id":23,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:35:in
|
|
70
|
+
`each''"},{"id":24,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:35:in
|
|
71
|
+
`serve''"},{"id":25,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:840:in
|
|
72
|
+
`call''"},{"id":26,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/deflater.rb:34:in
|
|
73
|
+
`call''"},{"id":27,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/etag.rb:25:in
|
|
74
|
+
`call''"},{"id":28,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/conditional_get.rb:38:in
|
|
75
|
+
`call''"},{"id":29,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/head.rb:12:in
|
|
76
|
+
`call''"},{"id":30,"trace":"vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.0/lib/active_record/migration.rb:559:in
|
|
77
|
+
`call''"},{"id":31,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/callbacks.rb:28:in
|
|
78
|
+
`block in call''"},{"id":32,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/callbacks.rb:98:in
|
|
79
|
+
`run_callbacks''"},{"id":33,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/callbacks.rb:26:in
|
|
80
|
+
`call''"},{"id":34,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in
|
|
81
|
+
`call''"},{"id":35,"trace":"vendor/bundle/ruby/2.4.0/gems/bugsnag-6.8.0/lib/bugsnag/integrations/rack.rb:46:in
|
|
82
|
+
`call''"},{"id":36,"trace":"vendor/bundle/ruby/2.4.0/gems/better_errors-2.4.0/lib/better_errors/middleware.rb:59:in
|
|
83
|
+
`call''"},{"id":37,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:61:in
|
|
84
|
+
`call''"},{"id":38,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in
|
|
85
|
+
`call''"},{"id":39,"trace":"vendor/bundle/ruby/2.4.0/gems/lograge-0.10.0/lib/lograge/rails_ext/rack/logger.rb:15:in
|
|
86
|
+
`call_app''"},{"id":40,"trace":"vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in
|
|
87
|
+
`block in call''"},{"id":41,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in
|
|
88
|
+
`block in tagged''"},{"id":42,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:28:in
|
|
89
|
+
`tagged''"},{"id":43,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in
|
|
90
|
+
`tagged''"},{"id":44,"trace":"vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in
|
|
91
|
+
`call''"},{"id":45,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/remote_ip.rb:81:in
|
|
92
|
+
`call''"},{"id":46,"trace":"vendor/bundle/ruby/2.4.0/gems/request_store-1.4.1/lib/request_store/middleware.rb:19:in
|
|
93
|
+
`call''"},{"id":47,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/request_id.rb:27:in
|
|
94
|
+
`call''"},{"id":48,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in
|
|
95
|
+
`call''"},{"id":49,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in
|
|
96
|
+
`call''"},{"id":50,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in
|
|
97
|
+
`call''"},{"id":51,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:127:in
|
|
98
|
+
`call''"},{"id":52,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in
|
|
99
|
+
`call''"},{"id":53,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in
|
|
100
|
+
`call''"},{"id":54,"trace":"vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/engine.rb:524:in
|
|
101
|
+
`call''"},{"id":55,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in
|
|
102
|
+
`process_request''"},{"id":56,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:157:in
|
|
103
|
+
`accept_and_process_next_request''"},{"id":57,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in
|
|
104
|
+
`main_loop''"},{"id":58,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in
|
|
105
|
+
`block (3 levels) in start_threads''"},{"id":59,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in
|
|
106
|
+
`block in create_thread_and_abort_on_exception''"}],"Full Trace":[{"id":0,"trace":"vendor/bundle/ruby/2.4.0/gems/cancancan-2.2.0/lib/cancan/ability.rb:176:in
|
|
107
|
+
`authorize!''"},{"id":1,"trace":"vendor/bundle/ruby/2.4.0/gems/cancancan-2.2.0/lib/cancan/controller_additions.rb:336:in
|
|
108
|
+
`authorize!''"},{"id":2,"trace":"app/controllers/events_controller.rb:30:in
|
|
109
|
+
`update''"},{"id":3,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/basic_implicit_render.rb:6:in
|
|
110
|
+
`send_action''"},{"id":4,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/base.rb:194:in
|
|
111
|
+
`process_action''"},{"id":5,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/rendering.rb:30:in
|
|
112
|
+
`process_action''"},{"id":6,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/callbacks.rb:42:in
|
|
113
|
+
`block in process_action''"},{"id":7,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/callbacks.rb:132:in
|
|
114
|
+
`run_callbacks''"},{"id":8,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/callbacks.rb:41:in
|
|
115
|
+
`process_action''"},{"id":9,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/rescue.rb:22:in
|
|
116
|
+
`process_action''"},{"id":10,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/instrumentation.rb:34:in
|
|
117
|
+
`block in process_action''"},{"id":11,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications.rb:168:in
|
|
118
|
+
`block in instrument''"},{"id":12,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications/instrumenter.rb:23:in
|
|
119
|
+
`instrument''"},{"id":13,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/notifications.rb:168:in
|
|
120
|
+
`instrument''"},{"id":14,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/instrumentation.rb:32:in
|
|
121
|
+
`process_action''"},{"id":15,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal/params_wrapper.rb:256:in
|
|
122
|
+
`process_action''"},{"id":16,"trace":"vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.0/lib/active_record/railties/controller_runtime.rb:24:in
|
|
123
|
+
`process_action''"},{"id":17,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/abstract_controller/base.rb:134:in
|
|
124
|
+
`process''"},{"id":18,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal.rb:191:in
|
|
125
|
+
`dispatch''"},{"id":19,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_controller/metal.rb:252:in
|
|
126
|
+
`dispatch''"},{"id":20,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:52:in
|
|
127
|
+
`dispatch''"},{"id":21,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:34:in
|
|
128
|
+
`serve''"},{"id":22,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:52:in
|
|
129
|
+
`block in serve''"},{"id":23,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:35:in
|
|
130
|
+
`each''"},{"id":24,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/journey/router.rb:35:in
|
|
131
|
+
`serve''"},{"id":25,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/routing/route_set.rb:840:in
|
|
132
|
+
`call''"},{"id":26,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/deflater.rb:34:in
|
|
133
|
+
`call''"},{"id":27,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/etag.rb:25:in
|
|
134
|
+
`call''"},{"id":28,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/conditional_get.rb:38:in
|
|
135
|
+
`call''"},{"id":29,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/head.rb:12:in
|
|
136
|
+
`call''"},{"id":30,"trace":"vendor/bundle/ruby/2.4.0/gems/activerecord-5.2.0/lib/active_record/migration.rb:559:in
|
|
137
|
+
`call''"},{"id":31,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/callbacks.rb:28:in
|
|
138
|
+
`block in call''"},{"id":32,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/callbacks.rb:98:in
|
|
139
|
+
`run_callbacks''"},{"id":33,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/callbacks.rb:26:in
|
|
140
|
+
`call''"},{"id":34,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in
|
|
141
|
+
`call''"},{"id":35,"trace":"vendor/bundle/ruby/2.4.0/gems/bugsnag-6.8.0/lib/bugsnag/integrations/rack.rb:46:in
|
|
142
|
+
`call''"},{"id":36,"trace":"vendor/bundle/ruby/2.4.0/gems/better_errors-2.4.0/lib/better_errors/middleware.rb:59:in
|
|
143
|
+
`call''"},{"id":37,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:61:in
|
|
144
|
+
`call''"},{"id":38,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/show_exceptions.rb:33:in
|
|
145
|
+
`call''"},{"id":39,"trace":"vendor/bundle/ruby/2.4.0/gems/lograge-0.10.0/lib/lograge/rails_ext/rack/logger.rb:15:in
|
|
146
|
+
`call_app''"},{"id":40,"trace":"vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in
|
|
147
|
+
`block in call''"},{"id":41,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in
|
|
148
|
+
`block in tagged''"},{"id":42,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:28:in
|
|
149
|
+
`tagged''"},{"id":43,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/tagged_logging.rb:71:in
|
|
150
|
+
`tagged''"},{"id":44,"trace":"vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/rack/logger.rb:26:in
|
|
151
|
+
`call''"},{"id":45,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/remote_ip.rb:81:in
|
|
152
|
+
`call''"},{"id":46,"trace":"vendor/bundle/ruby/2.4.0/gems/request_store-1.4.1/lib/request_store/middleware.rb:19:in
|
|
153
|
+
`call''"},{"id":47,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/request_id.rb:27:in
|
|
154
|
+
`call''"},{"id":48,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in
|
|
155
|
+
`call''"},{"id":49,"trace":"vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in
|
|
156
|
+
`call''"},{"id":50,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/executor.rb:14:in
|
|
157
|
+
`call''"},{"id":51,"trace":"vendor/bundle/ruby/2.4.0/gems/actionpack-5.2.0/lib/action_dispatch/middleware/static.rb:127:in
|
|
158
|
+
`call''"},{"id":52,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in
|
|
159
|
+
`call''"},{"id":53,"trace":"vendor/bundle/ruby/2.4.0/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in
|
|
160
|
+
`call''"},{"id":54,"trace":"vendor/bundle/ruby/2.4.0/gems/railties-5.2.0/lib/rails/engine.rb:524:in
|
|
161
|
+
`call''"},{"id":55,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in
|
|
162
|
+
`process_request''"},{"id":56,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:157:in
|
|
163
|
+
`accept_and_process_next_request''"},{"id":57,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:110:in
|
|
164
|
+
`main_loop''"},{"id":58,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in
|
|
165
|
+
`block (3 levels) in start_threads''"},{"id":59,"trace":"/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in
|
|
166
|
+
`block in create_thread_and_abort_on_exception''"}]}}'
|
|
167
|
+
http_version:
|
|
168
|
+
recorded_at: Fri, 10 Aug 2018 17:13:54 GMT
|
|
169
|
+
recorded_with: VCR 3.0.3
|
|
@@ -0,0 +1,49 @@
|
|
|
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=test_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.24.0 ruby/2.4.2 x86_64-darwin16 aws-sdk-sqs/1.4.0
|
|
16
|
+
X-Amz-Date:
|
|
17
|
+
- 20180810T162254Z
|
|
18
|
+
X-Amz-Content-Sha256:
|
|
19
|
+
- 5761efd13dd0ed81182207171d3660628968189941431d6044920ef8fe7b1160
|
|
20
|
+
Authorization:
|
|
21
|
+
- AWS4-HMAC-SHA256 Credential=AKIAIUG4XO77LTVIG3PA/20180810/eu-west-1/sqs/aws4_request,
|
|
22
|
+
SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, Signature=ac222f1bc09285fb32e9d97ca94a560d1a60e34aebe2ca3bfbc704bcf8bd657b
|
|
23
|
+
Content-Length:
|
|
24
|
+
- '58'
|
|
25
|
+
Accept:
|
|
26
|
+
- "*/*"
|
|
27
|
+
response:
|
|
28
|
+
status:
|
|
29
|
+
code: 200
|
|
30
|
+
message: OK
|
|
31
|
+
headers:
|
|
32
|
+
Server:
|
|
33
|
+
- Server
|
|
34
|
+
Date:
|
|
35
|
+
- Fri, 10 Aug 2018 16:22:54 GMT
|
|
36
|
+
Content-Type:
|
|
37
|
+
- text/xml
|
|
38
|
+
Content-Length:
|
|
39
|
+
- '330'
|
|
40
|
+
Connection:
|
|
41
|
+
- keep-alive
|
|
42
|
+
X-Amzn-Requestid:
|
|
43
|
+
- c51372f6-f34d-5077-83f7-21114d533798
|
|
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/test_usage</QueueUrl></GetQueueUrlResult><ResponseMetadata><RequestId>c51372f6-f34d-5077-83f7-21114d533798</RequestId></ResponseMetadata></GetQueueUrlResponse>
|
|
47
|
+
http_version:
|
|
48
|
+
recorded_at: Fri, 10 Aug 2018 16:22:54 GMT
|
|
49
|
+
recorded_with: VCR 3.0.3
|
data/spec/orcid_update_spec.rb
CHANGED
|
@@ -66,7 +66,7 @@ describe Toccatore::OrcidUpdate, vcr: true do
|
|
|
66
66
|
response = subject.get_data({ orcid: "0000-0002-3546-1048", from_date: "2013-01-01", until_date: "2016-12-31", rows: 1000, offset: 0 })
|
|
67
67
|
expect(response.body["data"]["response"]["numFound"]).to eq(68)
|
|
68
68
|
doc = response.body["data"]["response"]["docs"].first
|
|
69
|
-
expect(doc["doi"]).to eq("10.6084/M9.FIGSHARE.
|
|
69
|
+
expect(doc["doi"]).to eq("10.6084/M9.FIGSHARE.1371006")
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
it "should allow queries by DOI of the Datacite Metadata Search API" do
|
data/spec/queue_spec.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Toccatore::UsageUpdate, vcr: true do
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
context "get_total" do
|
|
7
|
+
it "when is working with AWS" do
|
|
8
|
+
expect(subject.get_total()).to respond_to(:+)
|
|
9
|
+
expect(subject.get_total()).not_to respond_to(:each)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context "queue_url" do
|
|
14
|
+
it "should return always correct queue url" do
|
|
15
|
+
response = subject.queue_url
|
|
16
|
+
expect(response).to eq("https://sqs.#{ENV['AWS_REGION']}.amazonaws.com/404017989009/#{ENV['ENVIRONMENT']}_usage")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should fail if the queue doesn exist" do
|
|
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
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "get_message" do
|
|
26
|
+
it "should return one message when there are multiple messages" do
|
|
27
|
+
expect(subject.get_message).to respond_to(:messages)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should return no meessage when the queue is empty" do
|
|
31
|
+
expect(subject.get_message).not_to respond_to(:+)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# context "delete_message" do
|
|
36
|
+
# it "should delete a message that exist" do
|
|
37
|
+
# msg = subject.get_message
|
|
38
|
+
# response = subject.delete_message msg
|
|
39
|
+
# expect(response.successful?).to eq(true)
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
# it "should return an error if a message doesnot exist" do
|
|
43
|
+
|
|
44
|
+
# end
|
|
45
|
+
# end
|
|
46
|
+
|
|
47
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -11,6 +11,10 @@ require 'rack/test'
|
|
|
11
11
|
require 'webmock/rspec'
|
|
12
12
|
require 'nokogiri'
|
|
13
13
|
require 'vcr'
|
|
14
|
+
require 'aws-sdk-sqs'
|
|
15
|
+
require 'factory_bot'
|
|
16
|
+
ENV['ENVIRONMENT'] ||= 'test'
|
|
17
|
+
ENV['AWS_REGION'] ||= 'eu-west-1'
|
|
14
18
|
|
|
15
19
|
RSpec.configure do |config|
|
|
16
20
|
config.order = :random
|
|
@@ -20,6 +24,12 @@ RSpec.configure do |config|
|
|
|
20
24
|
c.syntax = :expect
|
|
21
25
|
end
|
|
22
26
|
|
|
27
|
+
config.include FactoryBot::Syntax::Methods
|
|
28
|
+
|
|
29
|
+
config.before(:suite) do
|
|
30
|
+
FactoryBot.find_definitions
|
|
31
|
+
end
|
|
32
|
+
|
|
23
33
|
config.mock_with :rspec do |mocks|
|
|
24
34
|
mocks.allow_message_expectations_on_nil = false
|
|
25
35
|
end
|
|
@@ -27,6 +37,18 @@ RSpec.configure do |config|
|
|
|
27
37
|
config.before do
|
|
28
38
|
ARGV.replace []
|
|
29
39
|
end
|
|
40
|
+
|
|
41
|
+
# config.expect_with :rspec do |expectations|
|
|
42
|
+
# expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
43
|
+
# end
|
|
44
|
+
|
|
45
|
+
# config.mock_with :rspec do |mocks|
|
|
46
|
+
# mocks.verify_partial_doubles = true
|
|
47
|
+
# end
|
|
48
|
+
|
|
49
|
+
# config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
50
|
+
|
|
51
|
+
# Aws.config.update(stub_responses: true)
|
|
30
52
|
end
|
|
31
53
|
|
|
32
54
|
def fixture_path
|
|
@@ -89,6 +111,6 @@ VCR.configure do |c|
|
|
|
89
111
|
c.configure_rspec_metadata!
|
|
90
112
|
c.filter_sensitive_data("<VOLPINO_TOKEN>") { ENV['VOLPINO_TOKEN'] }
|
|
91
113
|
c.filter_sensitive_data("<EVENTDATA_TOKEN>") { ENV['EVENTDATA_TOKEN'] }
|
|
92
|
-
c.filter_sensitive_data("<
|
|
114
|
+
c.filter_sensitive_data("<LAGOTTINO_TOKEN>") { ENV['LAGOTTINO_TOKEN'] }
|
|
93
115
|
c.filter_sensitive_data("<SLACK_WEBHOOK_URL>") { ENV['SLACK_WEBHOOK_URL'] }
|
|
94
116
|
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Toccatore::UsageUpdate, vcr: true do
|
|
4
|
+
|
|
5
|
+
let(:queue_url){"https://sqs.#{ENV['AWS_REGION']}.amazonaws.com/404017989009/test_usage"}
|
|
6
|
+
let(:queue_name){:test_usage}
|
|
7
|
+
let!(:sqs) {Aws::SQS::Client.new(region: ENV['AWS_REGION'].to_s, stub_responses: true)}
|
|
8
|
+
let!(:body) {File.read(fixture_path + 'usage_event.json')}
|
|
9
|
+
let!(:message){[body: body]}
|
|
10
|
+
|
|
11
|
+
let(:dummy_message){sqs.receive_message(queue_url: queue_url, max_number_of_messages: 1, wait_time_seconds: 1)}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
describe "get_data" do
|
|
15
|
+
# context "when there are messages" do
|
|
16
|
+
# it "should return the data for one message" do
|
|
17
|
+
# sqs.stub_responses(:receive_message, messages: message)
|
|
18
|
+
# sqs.stub_responses(:receive_message, messages: message)
|
|
19
|
+
# sqs.stub_responses(:receive_message, messages: message)
|
|
20
|
+
# sqs.stub_responses(:receive_message, messages: message)
|
|
21
|
+
# response = sqs.receive_message({queue_url: queue_url})
|
|
22
|
+
# response = subject.get_data(response)
|
|
23
|
+
# expect(response.body["data"]["report"]["report-header"]["report-name"]).to eq("Dataset Master Report")
|
|
24
|
+
# end
|
|
25
|
+
# end
|
|
26
|
+
|
|
27
|
+
# context "when there is ONE message" do
|
|
28
|
+
# it "should return the data for one message" do
|
|
29
|
+
# sqs.stub_responses(:receive_message, messages: message)
|
|
30
|
+
# response = sqs.receive_message({queue_url: queue_url})
|
|
31
|
+
# response = subject.get_data(response)
|
|
32
|
+
# expect(response.body["data"]["report"]["report-header"]["report-name"]).to eq("Dataset Master Report")
|
|
33
|
+
# end
|
|
34
|
+
# end
|
|
35
|
+
|
|
36
|
+
# context "when there are NOT messages" do
|
|
37
|
+
# it "should return empty" do
|
|
38
|
+
# sqs.stub_responses(:receive_message, messages: [])
|
|
39
|
+
# response = sqs.receive_message({queue_url: queue_url})
|
|
40
|
+
# response = subject.get_data(response)
|
|
41
|
+
# expect(response.body["errors"]).to eq("Queue is empty")
|
|
42
|
+
# end
|
|
43
|
+
# end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe "parse_data" do
|
|
47
|
+
context "when the usage event was NOT found" do
|
|
48
|
+
it "should return errors" do
|
|
49
|
+
body = File.read(fixture_path + 'usage_update_nil.json')
|
|
50
|
+
result = OpenStruct.new(body: JSON.parse(body) )
|
|
51
|
+
expect(subject.parse_data(result)).to be_a(Array)
|
|
52
|
+
expect(subject.parse_data(result)).to eq([{"status"=>"404", "title"=>"The resource you are looking for doesn't exist."}])
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# context "when the queue is empty" do
|
|
57
|
+
# it "should return errors" do
|
|
58
|
+
# result = OpenStruct.new(body: { "errors" => "Queue is empty" })
|
|
59
|
+
# expect(subject.parse_data(result)).to be_a(Array)
|
|
60
|
+
# expect(subject.parse_data(result)).to eq([{"status"=>"404", "title"=>"The resource you are looking for doesn't exist."}])
|
|
61
|
+
# end
|
|
62
|
+
# end
|
|
63
|
+
|
|
64
|
+
context "when the usage report was NOT found" do
|
|
65
|
+
it "should return errors" do
|
|
66
|
+
body = File.read(fixture_path + 'usage_update_nil.json')
|
|
67
|
+
result = OpenStruct.new(body: JSON.parse(body) )
|
|
68
|
+
expect(subject.parse_data(result)).to be_a(Array)
|
|
69
|
+
expect(subject.parse_data(result)).to eq([{"status"=>"404", "title"=>"The resource you are looking for doesn't exist."}])
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context "when the report was found" do
|
|
74
|
+
it "should parsed it correctly" do
|
|
75
|
+
body = File.read(fixture_path + 'usage_update.json')
|
|
76
|
+
result = OpenStruct.new(body: JSON.parse(body), url:"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad" )
|
|
77
|
+
response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
|
|
78
|
+
expect(response.length).to eq(2)
|
|
79
|
+
expect(response.last.except("uuid")).to eq("subj"=>{"pid"=>"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad", "issued"=>"2128-04-09"},"total"=>3,"message-action" => "create", "subj-id"=>"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad", "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" => ENV['SOURCE_TOKEN'])
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should parsed it correctly when it has five metrics and two DOIs" do
|
|
83
|
+
body = File.read(fixture_path + 'usage_update_3.json')
|
|
84
|
+
result = OpenStruct.new(body: JSON.parse(body), url:"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad" )
|
|
85
|
+
response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
|
|
86
|
+
expect(response.length).to eq(5)
|
|
87
|
+
expect(response.last.except("uuid")).to eq("message-action"=>"create", "subj-id"=>"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad", "subj"=>{"pid"=>"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad", "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"=>ENV['SOURCE_TOKEN'], "occurred-at"=>"2128-04-09", "license"=>"https://creativecommons.org/publicdomain/zero/1.0/")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should parsed it correctly when it has two metrics per DOI " do
|
|
91
|
+
body = File.read(fixture_path + 'usage_update_2.json')
|
|
92
|
+
result = OpenStruct.new(body: JSON.parse(body), url:"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad")
|
|
93
|
+
response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
|
|
94
|
+
expect(response.length).to eq(4)
|
|
95
|
+
expect(response.last.except("uuid")).to eq("message-action"=>"create", "subj-id"=>"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad", "subj"=>{"pid"=>"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad", "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"=>ENV['SOURCE_TOKEN'], "occurred-at"=>"2128-04-09", "license"=>"https://creativecommons.org/publicdomain/zero/1.0/")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "should send a warning if there are more than 4 metrics" do
|
|
99
|
+
body = File.read(fixture_path + 'usage_update_1.json')
|
|
100
|
+
result = OpenStruct.new(body: JSON.parse(body), url:"https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad" )
|
|
101
|
+
response = subject.parse_data(result, source_token: ENV['SOURCE_TOKEN'])
|
|
102
|
+
expect(response.length).to eq(1)
|
|
103
|
+
expect(subject.parse_data(result)).to be_a(Array)
|
|
104
|
+
expect(response.last.body).to eq({"errors"=>"There are too many instances in 10.7291/D1Q94R for report https://api.test.datacite.org/reports/5cac6ca0-9391-4e1d-95cf-ba2f475cbfad. There can only be 4"})
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context "push_data" do
|
|
110
|
+
let!(:events) {create_list(:event,10)}
|
|
111
|
+
it "should report if there are no works returned by the Queue" do
|
|
112
|
+
result = []
|
|
113
|
+
expect { subject.push_data(result) }.to output("No works found in the Queue.\n").to_stdout
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "should fail if format of the event is wrong" do
|
|
117
|
+
body = File.read(fixture_path + 'usage_events.json')
|
|
118
|
+
expect = File.read(fixture_path + 'event_data_resp_2')
|
|
119
|
+
result = JSON.parse(body)
|
|
120
|
+
options = { push_url: ENV['LAGOTTINO_URL'], access_token: ENV['LAGOTTINO_TOKEN'], jsonapi: true }
|
|
121
|
+
expect(subject.push_data(result, options)).to eq(4)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "should fail if format of the event is empty" do
|
|
125
|
+
body = File.read(fixture_path + 'events_empty.json')
|
|
126
|
+
result = JSON.parse(body)
|
|
127
|
+
options = { push_url: ENV['LAGOTTINO_URL'], access_token: ENV['LAGOTTINO_TOKEN'], jsonapi: true }
|
|
128
|
+
expect(subject.push_data(result, options)).to eq(2)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# it "should work with DataCite Event Data 2" do
|
|
132
|
+
# dd = events.map {|event| event.to_h.stringify_keys}
|
|
133
|
+
# all_events = dd.map {|item| item.map{ |k, v| [k.dasherize, v] }.to_h}
|
|
134
|
+
# options = { push_url: ENV['LAGOTTINO_URL'], access_token: ENV['LAGOTTINO_TOKEN'], jsonapi: true }
|
|
135
|
+
# expect(subject.push_data(all_events, options)).to eq(0)
|
|
136
|
+
# end
|
|
137
|
+
|
|
138
|
+
it "should work with a single item" do
|
|
139
|
+
body = File.read(fixture_path + 'usage_events.json')
|
|
140
|
+
result = JSON.parse(body)
|
|
141
|
+
options = { push_url: ENV['LAGOTTINO_URL'], access_token: ENV['LAGOTTINO_TOKEN'], jsonapi: true }
|
|
142
|
+
expect(subject.push_item(result.first, options)).to eq(1)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
end
|
data/toccatore.gemspec
CHANGED
|
@@ -15,21 +15,27 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
s.license = 'MIT'
|
|
16
16
|
|
|
17
17
|
# Declary dependencies here, rather than in the Gemfile
|
|
18
|
-
|
|
19
|
-
s.add_dependency '
|
|
18
|
+
|
|
19
|
+
s.add_dependency 'maremma', '>= 3.5.7', '< 5'
|
|
20
|
+
s.add_dependency 'activesupport', '>= 4.2.5', '< 6'
|
|
20
21
|
s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
|
|
21
22
|
s.add_dependency 'namae', '~> 0.11.0'
|
|
22
23
|
s.add_dependency 'gender_detector', '~> 1.0'
|
|
23
24
|
s.add_dependency 'thor', '~> 0.19'
|
|
24
25
|
s.add_dependency 'slack-notifier', '~> 2.1'
|
|
26
|
+
s.add_dependency 'aws-sdk-sqs'
|
|
27
|
+
s.add_dependency 'factory_bot'
|
|
28
|
+
|
|
25
29
|
s.add_development_dependency 'bundler', '~> 1.0'
|
|
26
30
|
s.add_development_dependency 'rspec', '~> 3.4'
|
|
27
31
|
s.add_development_dependency 'rake', '~> 12.0'
|
|
28
32
|
s.add_development_dependency 'rack-test', '~> 0'
|
|
29
33
|
s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
|
30
|
-
s.add_development_dependency 'webmock', '~>
|
|
31
|
-
s.add_development_dependency 'codeclimate-test-reporter',
|
|
32
|
-
s.add_development_dependency 'simplecov'
|
|
34
|
+
s.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
|
|
35
|
+
s.add_development_dependency 'codeclimate-test-reporter', "~> 1.0"
|
|
36
|
+
s.add_development_dependency 'simplecov'
|
|
37
|
+
s.add_development_dependency 'factory_bot'
|
|
38
|
+
s.add_development_dependency 'faker'
|
|
33
39
|
|
|
34
40
|
s.require_paths = ["lib"]
|
|
35
41
|
s.files = `git ls-files`.split($/)
|