-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcwrc_preserver_test.rb
executable file
·104 lines (94 loc) · 3.06 KB
/
cwrc_preserver_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
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env ruby
require 'rubygems'
require 'test/unit'
require 'vcr'
require_relative 'cwrc_common'
VCR.configure do |config|
config.cassette_library_dir = 'fixtures/vcr_cassettes'
config.hook_into :webmock
end
class VCRTest < Test::Unit::TestCase
TEST_CONFIG = 'secrets_example.yml'.freeze
def test_init_environment
assert_nothing_raised do
CWRCPreserver.init_env(TEST_CONFIG)
end
refute_empty ENV['SWIFT_USERNAME']
refute_empty ENV['SWIFT_PASSWORD']
refute_empty ENV['SWIFT_TENANT']
refute_empty ENV['SWIFT_AUTH_URL']
refute_empty ENV['SWIFT_PROJECT']
refute_empty ENV['CWRC_HOSTNAME']
refute_empty ENV['CWRC_LOGIN_PATH']
refute_empty ENV['CWRC_PORT']
refute_empty ENV['CWRC_SWIFT_CONTAINER']
refute_empty ENV['CWRC_USERNAME']
refute_empty ENV['CWRC_PASSWORD']
end
def test_get_cookie
VCR.use_cassette('cookie') do
assert_nothing_raised do
CWRCPreserver.init_env(TEST_CONFIG)
refute_empty CWRCPreserver.retrieve_cookie
end
end
end
def test_list_all_objects
VCR.use_cassette('cookie') do
VCR.use_cassette('all_objects') do
assert_nothing_raised do
CWRCPreserver.init_env(TEST_CONFIG)
cookie = CWRCPreserver.retrieve_cookie
cwrc_objs = CWRCPreserver.get_cwrc_objs(cookie, '')
refute_empty cwrc_objs
assert cwrc_objs.count == 99_396
end
end
end
end
def test_list_updated_objects
VCR.use_cassette('cookie') do
VCR.use_cassette('updated_objects') do
assert_nothing_raised do
CWRCPreserver.init_env(TEST_CONFIG)
cookie = CWRCPreserver.retrieve_cookie
cwrc_objs = CWRCPreserver.get_cwrc_objs(cookie, '2017-01-01T15:29:21.374Z')
refute_empty cwrc_objs
assert cwrc_objs.count == 50
end
end
end
end
def test_download_object
VCR.use_cassette('cookie') do
VCR.use_cassette('download_object') do
cwrc_obj = { 'pid' => 'islandora:eb608bc8-059b-4cfc-bc13-358823009373' }
cwrc_file = cwrc_obj['pid']
assert_nothing_raised do
CWRCPreserver.init_env(TEST_CONFIG)
cookie = CWRCPreserver.retrieve_cookie
CWRCPreserver.download_cwrc_obj(cookie, cwrc_obj, cwrc_file)
end
assert !cwrc_obj['timestamp'].nil?
assert cwrc_obj['timestamp'] = '2015-02-13T18:24.492Z'
assert File.exist?(cwrc_file)
FileUtils.rm_rf(cwrc_file) if File.exist?(cwrc_file)
end
end
end
def test_download_object_http_error
VCR.use_cassette('cookie') do
VCR.use_cassette('download_object_http_error') do
cwrc_obj = { 'pid' => 'islandora:eb608bc8-059b-4cfc-bc13-358823009373' }
cwrc_file = cwrc_obj['pid']
assert_raise do
CWRCPreserver.init_env(TEST_CONFIG)
cookie = CWRCPreserver.retrieve_cookie
CWRCPreserver.download_cwrc_obj(cookie, cwrc_obj, cwrc_file)
end
assert !File.exist?(cwrc_file)
FileUtils.rm_rf(cwrc_file) if File.exist?(cwrc_file)
end
end
end
end