-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_test.rb
91 lines (81 loc) · 2.33 KB
/
export_test.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
# encoding: utf-8
require 'test_helper'
class ExportTest < Test::Unit::TestCase
def setup
@client = Enigma::Client.new(key: TEST_KEY)
Enigma::Download.any_instance.stubs(:sleep)
# These are identical, just one is zipped
@old_zipped = File.read 'test/fixtures/download.zip'
@zipped = File.read 'test/fixtures/download.csv.gz'
@unzipped = File.read 'test/fixtures/download.csv'
# www.example.com is the URL in the response to the export
# cassette
stub_request(:get, 'www.example.com/us.gov.whitehouse.visitor-list.csv.gz').to_return do
if @tried
{ body: @zipped }
else
@tried = true
{ status: 404 }
end
end
# www.example.com is the URL in the response to the export
# cassette
stub_request(:get, 'www.example.com/us.gov.whitehouse.visitor-list.zip').to_return do
if @tried
{ body: @old_zipped }
else
@tried = true
{ status: 404 }
end
end
end
def test_export_no_dl
VCR.use_cassette('export') do
dl = @client.export('us.gov.whitehouse.visitor-list')
assert dl.response.export_url
end
end
def test_export_with_dl
VCR.use_cassette('export') do
dl = @client.export('us.gov.whitehouse.visitor-list')
dl.get
assert_equal @zipped, dl.raw_download
end
end
def test_writing_zip
VCR.use_cassette('export') do
dl = @client.export('us.gov.whitehouse.visitor-list')
dl.get
testIO = StringIO.new
dl.write(testIO)
assert_equal @zipped, testIO.string
end
end
def test_writing_csv
VCR.use_cassette('export') do
dl = @client.export('us.gov.whitehouse.visitor-list')
dl.get
testIO = StringIO.new
dl.write_csv(testIO)
assert_equal @unzipped, testIO.string
end
end
def test_parse_as_csv
VCR.use_cassette('export') do
dl = @client.export('us.gov.whitehouse.visitor-list')
parsed = dl.parse
assert_equal 'Steve', parsed.first[:name]
end
end
def test_writing_csv_from_old_format
VCR.use_cassette('export_old') do
# www.example.com is the URL in the response to the export
# cassette
dl = @client.export('us.gov.whitehouse.visitor-list')
dl.get
testIO = StringIO.new
dl.write_csv(testIO)
assert_equal @unzipped, testIO.string
end
end
end