toccatore 0.1.4 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +2 -2
- data/lib/toccatore/base.rb +29 -24
- data/lib/toccatore/cli.rb +7 -18
- data/lib/toccatore/orcid_update.rb +18 -5
- data/lib/toccatore/version.rb +1 -1
- data/spec/cli_spec.rb +10 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_fail.yml +37 -2
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_DOI.yml +1816 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_ORCID_ID.yml +4218 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed.yml +318 -283
- data/spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed_with_no_works.yml +4 -4
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_allow_queries_by_DOI_of_the_Datacite_Metadata_Search_API.yml +483 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_allow_queries_by_ORCID_ID_of_the_Datacite_Metadata_Search_API.yml +171 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_catch_errors_with_the_Datacite_Metadata_Search_API.yml +38 -0
- data/spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/push_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml +280 -280
- data/spec/orcid_update_spec.rb +31 -23
- metadata +7 -2
data/spec/orcid_update_spec.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Toccatore::OrcidUpdate, vcr: true do
|
4
|
+
let(:query_options) { { from_date: "2015-04-07", until_date: "2015-04-08", rows: 1000, offset: 0 } }
|
5
|
+
|
4
6
|
before(:each) { allow(Time).to receive(:now).and_return(Time.mktime(2015, 4, 8)) }
|
5
7
|
|
6
8
|
context "get_query_url" do
|
7
9
|
it "default" do
|
8
|
-
expect(subject.get_query_url).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=1000&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
10
|
+
expect(subject.get_query_url(query_options)).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=1000&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
9
11
|
end
|
10
12
|
|
11
13
|
it "with zero rows" do
|
12
|
-
expect(subject.get_query_url(rows: 0)).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=0&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
14
|
+
expect(subject.get_query_url(query_options.merge(rows: 0))).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=0&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
13
15
|
end
|
14
16
|
|
15
17
|
it "with different from_date and until_date" do
|
16
|
-
expect(subject.get_query_url(from_date: "2015-04-05", until_date: "2015-04-05")).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=1000&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-05T00%3A00%3A00Z+TO+2015-04-05T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
18
|
+
expect(subject.get_query_url(query_options.merge(from_date: "2015-04-05", until_date: "2015-04-05"))).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=1000&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-05T00%3A00%3A00Z+TO+2015-04-05T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
17
19
|
end
|
18
20
|
|
19
21
|
it "with offset" do
|
20
|
-
expect(subject.get_query_url(offset: 250)).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=250&rows=1000&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
22
|
+
expect(subject.get_query_url(query_options.merge(offset: 250))).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=250&rows=1000&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
21
23
|
end
|
22
24
|
|
23
25
|
it "with rows" do
|
24
|
-
expect(subject.get_query_url(rows: 250)).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=250&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
26
|
+
expect(subject.get_query_url(query_options.merge(rows: 250))).to eq("https://search.datacite.org/api?q=nameIdentifier%3AORCID%5C%3A*&start=0&rows=250&fl=doi%2Ccreator%2Ctitle%2Cpublisher%2CpublicationYear%2CresourceTypeGeneral%2Cdatacentre_symbol%2CrelatedIdentifier%2CnameIdentifier%2Cxml%2Cminted%2Cupdated&fq=updated%3A%5B2015-04-07T00%3A00%3A00Z+TO+2015-04-08T23%3A59%3A59Z%5D+AND+has_metadata%3Atrue+AND+is_active%3Atrue&wt=json")
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
context "get_total" do
|
29
31
|
it "with works" do
|
30
|
-
expect(subject.get_total).to eq(55)
|
32
|
+
expect(subject.get_total(query_options)).to eq(55)
|
31
33
|
end
|
32
34
|
|
33
35
|
it "with no works" do
|
34
|
-
expect(subject.get_total(from_date: "2009-04-07", until_date: "2009-04-08")).to eq(0)
|
36
|
+
expect(subject.get_total(query_options.merge(from_date: "2009-04-07", until_date: "2009-04-08"))).to eq(0)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -49,20 +51,36 @@ describe Toccatore::OrcidUpdate, vcr: true do
|
|
49
51
|
|
50
52
|
context "get_data" do
|
51
53
|
it "should report if there are no works returned by the Datacite Metadata Search API" do
|
52
|
-
response = subject.get_data(from_date: "2009-04-07", until_date: "2009-04-08")
|
54
|
+
response = subject.get_data(query_options.merge(from_date: "2009-04-07", until_date: "2009-04-08"))
|
53
55
|
expect(response.body["data"]["response"]["numFound"]).to eq(0)
|
54
56
|
end
|
55
57
|
|
56
58
|
it "should report if there are works returned by the Datacite Metadata Search API" do
|
57
|
-
response = subject.get_data
|
59
|
+
response = subject.get_data(query_options)
|
58
60
|
expect(response.body["data"]["response"]["numFound"]).to eq(55)
|
59
61
|
doc = response.body["data"]["response"]["docs"].first
|
60
62
|
expect(doc["doi"]).to eq("10.6084/M9.FIGSHARE.1041547")
|
61
63
|
end
|
62
64
|
|
65
|
+
it "should allow queries by ORCID ID of the Datacite Metadata Search API" do
|
66
|
+
response = subject.get_data({ query: "nameIdentifier:ORCID\\:0000-0002-3546-1048", from_date: "2013-01-01", until_date: "2016-12-31", rows: 1000, offset: 0 })
|
67
|
+
expect(response.body["data"]["response"]["numFound"]).to eq(68)
|
68
|
+
doc = response.body["data"]["response"]["docs"].first
|
69
|
+
expect(doc["doi"]).to eq("10.6084/M9.FIGSHARE.1371005.V1")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should allow queries by DOI of the Datacite Metadata Search API" do
|
73
|
+
response = subject.get_data({ query: "doi:10.5438/6423", from_date: "2013-01-01", until_date: "2016-12-31", rows: 1000, offset: 0 })
|
74
|
+
expect(response.body["data"]["response"]["numFound"]).to eq(1)
|
75
|
+
doc = response.body["data"]["response"]["docs"].first
|
76
|
+
name_identifiers = doc["nameIdentifier"]
|
77
|
+
expect(name_identifiers.count).to eq(22)
|
78
|
+
expect(name_identifiers.first).to eq("ORCID:0000-0001-5331-6592")
|
79
|
+
end
|
80
|
+
|
63
81
|
it "should catch errors with the Datacite Metadata Search API" do
|
64
|
-
stub = stub_request(:get, subject.get_query_url(rows: 0, source_id: subject.source_id)).to_return(:status => [408])
|
65
|
-
response = subject.get_data(rows: 0, source_id: subject.source_id)
|
82
|
+
stub = stub_request(:get, subject.get_query_url(query_options.merge(rows: 0, source_id: subject.source_id))).to_return(:status => [408])
|
83
|
+
response = subject.get_data(query_options.merge(rows: 0, source_id: subject.source_id))
|
66
84
|
expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
|
67
85
|
expect(stub).to have_been_requested
|
68
86
|
end
|
@@ -97,8 +115,7 @@ describe Toccatore::OrcidUpdate, vcr: true do
|
|
97
115
|
context "push_data" do
|
98
116
|
it "should report if there are no works returned by the Datacite Metadata Search API" do
|
99
117
|
result = []
|
100
|
-
|
101
|
-
expect(response.count).to eq(0)
|
118
|
+
expect { subject.push_data(result, query_options) }.to output("No works found for date range 2015-04-07 - 2015-04-08.\n").to_stdout
|
102
119
|
end
|
103
120
|
|
104
121
|
it "should report if there are works returned by the Datacite Metadata Search API" do
|
@@ -106,16 +123,7 @@ describe Toccatore::OrcidUpdate, vcr: true do
|
|
106
123
|
result = OpenStruct.new(body: { "data" => JSON.parse(body) })
|
107
124
|
result = subject.parse_data(result)
|
108
125
|
options = { push_url: ENV['VOLPINO_URL'], access_token: ENV['VOLPINO_TOKEN'] }
|
109
|
-
|
110
|
-
response = subject.push_data(result, options)
|
111
|
-
expect(response.count).to eq(56)
|
112
|
-
claim = response.first
|
113
|
-
expect(claim.body["data"]["attributes"]).to eq("orcid"=>"0000-0001-8478-7549",
|
114
|
-
"doi"=>"10.6084/M9.FIGSHARE.1226424",
|
115
|
-
"source-id"=>"orcid_update",
|
116
|
-
"state"=>"waiting",
|
117
|
-
"claim-action"=>nil,
|
118
|
-
"claimed-at"=>nil)
|
126
|
+
expect { subject.push_data(result, options) }.to output(/DOI 10.6084\/M9.FIGSHARE.1041547 for ORCID ID 0000-0002-3546-1048 pushed to Profiles service.\n/).to_stdout
|
119
127
|
end
|
120
128
|
end
|
121
129
|
end
|
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
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Fenner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: maremma
|
@@ -262,8 +262,13 @@ files:
|
|
262
262
|
- spec/fixtures/orcid_update.json
|
263
263
|
- spec/fixtures/orcid_update_nil.json
|
264
264
|
- spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_fail.yml
|
265
|
+
- spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_DOI.yml
|
266
|
+
- spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_ORCID_ID.yml
|
265
267
|
- spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed.yml
|
266
268
|
- spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed_with_no_works.yml
|
269
|
+
- spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_allow_queries_by_DOI_of_the_Datacite_Metadata_Search_API.yml
|
270
|
+
- spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_allow_queries_by_ORCID_ID_of_the_Datacite_Metadata_Search_API.yml
|
271
|
+
- spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_catch_errors_with_the_Datacite_Metadata_Search_API.yml
|
267
272
|
- spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml
|
268
273
|
- spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml
|
269
274
|
- spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_no_works.yml
|