-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-elife.rb
39 lines (32 loc) · 1.09 KB
/
test-elife.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
require "test/unit"
require "multi_json"
require "faraday"
class TestElife < Test::Unit::TestCase
def setup
@doi = "10.7554/eLife.07404"
@elife = MultiJson.load(File.open('src/elife.json'))
end
def test_elife_keys
assert_equal(
@elife.keys().sort(),
["components", "cookies","crossref_member", "journals", "open_access",
"prefixes", "publisher", "publisher_parent", "regex", "urls", "use_crossref_links"]
)
assert_nil(@elife['urls'])
assert_not_nil(@elife['journals'])
end
def test_elife_xml
conndoi = Faraday.new(:url => 'http://api.crossref.org/works/%s' % @doi) do |f|
f.adapter Faraday.default_adapter
end
issn = MultiJson.load(conndoi.get.body)['message']['ISSN'][0]
conn = Faraday.new(
:url => @elife['journals'].select { |x| x['issn'] == issn }[0]['urls']['xml'] %
@doi.match(@elife['journals'][0]['components']['doi']['regex']).to_s) do |f|
f.adapter Faraday.default_adapter
end
res = conn.get
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
end
end