-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-mdpi.rb
142 lines (119 loc) · 4.62 KB
/
test-mdpi.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
require "fileutils"
require "test/unit"
require "multi_json"
require "faraday"
require "faraday_middleware"
class TestMdpi < Test::Unit::TestCase
def setup
@doi1 = '10.3390/a7010032'
@doi2 = '10.3390/ani4010082'
@doi3 = '10.3390/econometrics3020240'
@mdpi = MultiJson.load(File.open('src/mdpi.json'))
end
def test_mdpi_keys
assert_equal(
@mdpi.keys().sort(),
["components", "cookies","crossref_member", "journals", "open_access",
"prefixes", "publisher", "publisher_parent", "regex", "urls", "use_crossref_links"]
)
assert_not_nil(@mdpi['urls'])
assert_nil(@mdpi['journals'])
end
def test_mdpi_xml_1
conndoi = Faraday.new(:url => 'https://api.crossref.org/works/%s' % @doi1) do |f|
f.adapter Faraday.default_adapter
end
bod = MultiJson.load(conndoi.get.body)
issn = bod['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@mdpi['urls']['xml'] % [issn, bod['message']['volume'], bod['message']['issue'], @doi1.match(@mdpi['components']['doi']['regex']).to_s.sub!(/^[0]+/, "") ]) do |f|
f.adapter Faraday.default_adapter
end
res = conn.get
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
end
def test_mdpi_pdf_1
conndoi = Faraday.new(:url => 'https://api.crossref.org/works/%s' % @doi1) do |f|
f.adapter Faraday.default_adapter
end
bod = MultiJson.load(conndoi.get.body)
issn = bod['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@mdpi['urls']['pdf'] % [issn, bod['message']['volume'], bod['message']['issue'], @doi1.match(@mdpi['components']['doi']['regex']).to_s.sub!(/^[0]+/, "") ]) do |f|
f.use FaradayMiddleware::FollowRedirects, limit: 3
f.adapter Faraday.default_adapter
end
res = conn.get;
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
assert_equal("application/pdf", res.headers['content-type'])
end
def test_mdpi_xml_2
conndoi = Faraday.new(:url => 'https://api.crossref.org/works/%s' % @doi2) do |f|
f.adapter Faraday.default_adapter
end
bod = MultiJson.load(conndoi.get.body)
issn = bod['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@mdpi['urls']['xml'] % [issn, bod['message']['volume'], bod['message']['issue'], @doi2.match(@mdpi['components']['doi']['regex']).to_s.sub!(/^[0]+/, "") ]) do |f|
f.use FaradayMiddleware::FollowRedirects, limit: 3
f.adapter Faraday.default_adapter
end
res = conn.get
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
end
def test_mdpi_pdf_2
conndoi = Faraday.new(:url => 'https://api.crossref.org/works/%s' % @doi2) do |f|
f.adapter Faraday.default_adapter
end
bod = MultiJson.load(conndoi.get.body)
issn = bod['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@mdpi['urls']['pdf'] % [issn, bod['message']['volume'], bod['message']['issue'], @doi2.match(@mdpi['components']['doi']['regex']).to_s.sub!(/^[0]+/, "") ]) do |f|
f.use FaradayMiddleware::FollowRedirects, limit: 3
f.adapter Faraday.default_adapter
end
res = conn.get
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
assert_equal("application/pdf", res.headers['content-type'])
end
def test_mdpi_xml_3
conndoi = Faraday.new(:url => 'https://api.crossref.org/works/%s' % @doi3) do |f|
f.adapter Faraday.default_adapter
end
bod = MultiJson.load(conndoi.get.body)
issn = bod['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@mdpi['urls']['xml'] % [issn, bod['message']['volume'], bod['message']['issue'], @doi3.match(@mdpi['components']['doi']['regex']).to_s.sub!(/^[0]+/, "") ]) do |f|
f.adapter Faraday.default_adapter
end
res = conn.get
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
end
def test_mdpi_pdf_3
conndoi = Faraday.new(:url => 'https://api.crossref.org/works/%s' % @doi3) do |f|
f.adapter Faraday.default_adapter
end
bod = MultiJson.load(conndoi.get.body)
issn = bod['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@mdpi['urls']['pdf'] % [issn, bod['message']['volume'], bod['message']['issue'], @doi3.match(@mdpi['components']['doi']['regex']).to_s.sub!(/^[0]+/, "") ]) do |f|
f.use FaradayMiddleware::FollowRedirects, limit: 3
f.adapter Faraday.default_adapter
end
res = conn.get
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
assert_equal("application/pdf", res.headers['content-type'])
end
end