-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest-thieme.rb
87 lines (73 loc) · 2.79 KB
/
test-thieme.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
require "fileutils"
require "test/unit"
require "multi_json"
require "faraday"
class TestThieme < Test::Unit::TestCase
def setup
@doi1 = '10.1055/s-0042-103414'
@doi2 = '10.1055/s-0036-1579629'
@doi3 = '10.1055/s-0042-102460'
@thieme = MultiJson.load(File.open('src/thieme.json'));
end
def test_thieme_keys
assert_equal(
@thieme.keys().sort(),
["components", "cookies","crossref_member", "journals", "open_access",
"prefixes", "publisher", "publisher_parent", "regex", "urls", "use_crossref_links"]
)
assert_nil(@thieme['urls'])
assert_not_nil(@thieme['journals'])
end
def test_thieme_xml
# no xml for this publisher
assert_nil(@thieme['journals'].collect{ |x| x['urls']['xml'] }.uniq[0])
end
def test_thieme_pdf_1
conndoi = Faraday.new(:url => 'http://api.crossref.org/works/%s' % @doi1) do |f|
f.adapter Faraday.default_adapter
end
issn = MultiJson.load(conndoi.get.body)['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@thieme['journals'].select { |x| Array(x['issn']).select{ |z| !!z.match(issn) }.any? }[0]['urls']['pdf'] %
@doi1.match(@thieme['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)
assert_equal("application/pdf", res.headers['content-type'])
end
def test_thieme_pdf_2
conndoi = Faraday.new(:url => 'http://api.crossref.org/works/%s' % @doi2) do |f|
f.adapter Faraday.default_adapter
end
issn = MultiJson.load(conndoi.get.body)['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@thieme['journals'].select { |x| Array(x['issn']).select{ |z| !!z.match(issn) }.any? }[0]['urls']['pdf'] %
@doi2.match(@thieme['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)
assert_equal("application/pdf", res.headers['content-type'])
end
def test_thieme_pdf_3
conndoi = Faraday.new(:url => 'http://api.crossref.org/works/%s' % @doi2) do |f|
f.adapter Faraday.default_adapter
end
issn = MultiJson.load(conndoi.get.body)['message']['ISSN'][0]
conn = Faraday.new(
:url =>
@thieme['journals'].select { |x| Array(x['issn']).select{ |z| !!z.match(issn) }.any? }[0]['urls']['pdf'] %
@doi2.match(@thieme['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)
assert_equal("application/pdf", res.headers['content-type'])
end
end