-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest-arxiv.rb
37 lines (31 loc) · 999 Bytes
/
test-arxiv.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
require "test/unit"
require "multi_json"
require "faraday"
require "faraday_middleware"
class TestArxiv < Test::Unit::TestCase
def setup
@id = "1504.06224"
@arxiv = MultiJson.load(File.open('src/arxiv.json'))
end
def test_arxiv_keys
assert_equal(
@arxiv.keys().sort(),
["components", "cookies", "crossref_member", "journals", "open_access", "prefixes",
"publisher", "publisher_parent", "regex", "urls", "use_crossref_links"]
)
assert_not_nil(@arxiv['urls'])
assert_nil(@arxiv['journals'])
end
def test_arxiv_pdf
url = @arxiv['urls']['pdf'] % @id.match(@arxiv['components']['doi']['regex'])[0]
conn = Faraday.new(:url => url) do |f|
f.use FaradayMiddleware::FollowRedirects
f.adapter :net_http
end
res = conn.get;
assert_equal(Faraday::Response, res.class)
assert_equal(String, res.body.class)
assert_equal(200, res.status)
assert_equal(res.headers['content-type'], "application/pdf")
end
end