resizing 1.0.2 → 1.1.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -7
- data/Gemfile +2 -6
- data/README.md +32 -59
- data/lib/resizing/active_storage/service/resizing_service.rb +2 -6
- data/lib/resizing/carrier_wave/storage/file.rb +16 -35
- data/lib/resizing/carrier_wave/storage/remote.rb +3 -7
- data/lib/resizing/carrier_wave.rb +11 -10
- data/lib/resizing/client.rb +24 -40
- data/lib/resizing/configurable.rb +1 -1
- data/lib/resizing/configuration.rb +16 -6
- data/lib/resizing/http_clientable.rb +3 -3
- data/lib/resizing/mock_client.rb +5 -6
- data/lib/resizing/public_id.rb +4 -5
- data/lib/resizing/version.rb +1 -1
- data/lib/resizing/video/client.rb +116 -0
- data/lib/resizing/video.rb +8 -0
- data/lib/resizing.rb +12 -15
- data/resizing.gemspec +11 -8
- data/test/resizing/carrier_wave/storage/file_test.rb +8 -149
- data/test/resizing/carrier_wave/storage/remote_test.rb +0 -75
- data/test/resizing/carrier_wave_test.rb +37 -99
- data/test/resizing/client_test.rb +11 -96
- data/test/resizing/configuration_test.rb +2 -118
- data/test/resizing/public_id_test.rb +1 -1
- data/test/resizing/video/client_test.rb +158 -0
- data/test/test_helper.rb +9 -89
- data/test/vcr/video/metadata/success.yml +47 -0
- data/test/vcr/video/prepare/success.yml +47 -0
- data/test/vcr/video/upload_completed/success.yml +47 -0
- metadata +53 -45
- data/lib/resizing/active_storage/service.rb +0 -9
- data/lib/resizing/active_storage.rb +0 -7
- data/test/resizing/active_storage_service_test.rb +0 -98
- data/test/resizing/configurable_test.rb +0 -82
- data/test/resizing/constants_test.rb +0 -25
- data/test/resizing/error_test.rb +0 -73
- data/test/resizing/http_clientable_test.rb +0 -84
- data/test/resizing/mock_client_test.rb +0 -75
- data/test/resizing_module_test.rb +0 -206
- /data/{bin → exe}/console +0 -0
- /data/{bin → exe}/generate-changelog +0 -0
- /data/{bin → exe}/setup +0 -0
|
@@ -34,40 +34,11 @@ module Resizing
|
|
|
34
34
|
assert_equal(client.config, config)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def
|
|
37
|
+
def test_is_postable_file
|
|
38
38
|
Resizing.configure = @configuration_template
|
|
39
39
|
|
|
40
40
|
client = Resizing::Client.new
|
|
41
|
-
VCR.use_cassette 'client/post', record: :once
|
|
42
|
-
r = client.post('test/data/images/sample1.jpg', content_type: 'image/jpeg')
|
|
43
|
-
assert_equal(r['id'], '87263920-2081-498e-a107-9625f4fde01b')
|
|
44
|
-
assert_equal(r['project_id'], Resizing.configure.project_id)
|
|
45
|
-
assert_equal(r['content_type'], 'image/jpeg')
|
|
46
|
-
assert(!r['latest_version_id'].nil?)
|
|
47
|
-
assert(!r['latest_etag'].nil?)
|
|
48
|
-
assert(!r['created_at'].nil?)
|
|
49
|
-
assert(!r['updated_at'].nil?)
|
|
50
|
-
assert_equal(r['public_id'], '/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/87263920-2081-498e-a107-9625f4fde01b/vHg9VFvdI6HRzLFbV495VdwVmHIspLRCo')
|
|
51
|
-
assert_equal(r['filename'], 'sample1.jpg')
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def test_is_unpostable_with_filename
|
|
56
|
-
Resizing.configure = @configuration_template
|
|
57
|
-
|
|
58
|
-
client = Resizing::Client.new
|
|
59
|
-
VCR.use_cassette 'client/post', record: :once do
|
|
60
|
-
assert_raises ArgumentError do
|
|
61
|
-
client.post('file_is_not_exists', content_type: 'image/jpeg')
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_is_postable_with_file
|
|
67
|
-
Resizing.configure = @configuration_template
|
|
68
|
-
|
|
69
|
-
client = Resizing::Client.new
|
|
70
|
-
VCR.use_cassette 'client/post', record: :once do
|
|
41
|
+
VCR.use_cassette 'client/post', record: :once do
|
|
71
42
|
f = File.open('test/data/images/sample1.jpg', 'r')
|
|
72
43
|
r = client.post(f, content_type: 'image/jpeg')
|
|
73
44
|
assert_equal(r['id'], '87263920-2081-498e-a107-9625f4fde01b')
|
|
@@ -122,7 +93,7 @@ module Resizing
|
|
|
122
93
|
f = File.open('test/data/images/sample1.jpg', 'r')
|
|
123
94
|
|
|
124
95
|
assert_raises Resizing::APIError do
|
|
125
|
-
|
|
96
|
+
r = client.put(name, f, content_type: 'image/jpeg')
|
|
126
97
|
end
|
|
127
98
|
end
|
|
128
99
|
|
|
@@ -152,7 +123,7 @@ module Resizing
|
|
|
152
123
|
rescue Resizing::APIError => e
|
|
153
124
|
response = e.decoded_body
|
|
154
125
|
end
|
|
155
|
-
assert_equal response, {
|
|
126
|
+
assert_equal response, {"error"=>"Magick::ImageMagickError", "message"=>"invalid image format found"}
|
|
156
127
|
end
|
|
157
128
|
end
|
|
158
129
|
|
|
@@ -165,76 +136,20 @@ module Resizing
|
|
|
165
136
|
VCR.use_cassette 'client/metadata', record: :once do
|
|
166
137
|
name = '87263920-2081-498e-a107-9625f4fde01b'
|
|
167
138
|
r = client.metadata(name)
|
|
168
|
-
# r.body
|
|
169
|
-
# {
|
|
170
|
-
# "id":"87263920-2081-498e-a107-9625f4fde01b",
|
|
171
|
-
# "project_id":"e06e710d-f026-4dcf-b2c0-eab0de8bb83f",
|
|
172
|
-
# "content_type":"image/jpeg",
|
|
173
|
-
# "latest_version_id":"Hg9VFvdI6HRzLFbV495VdwVmHIspLRCo",
|
|
174
|
-
# "latest_etag":"\"5766f95a7f28e6a53dd6fd179bf03a32\"",
|
|
175
|
-
# "size":848590,
|
|
176
|
-
# "created_at":"2020-10-11T05:02:25.912Z",
|
|
177
|
-
# "updated_at":"2020-10-11T05:02:25.912Z",
|
|
178
|
-
# "filename":"sample1.jpg",
|
|
179
|
-
# "width":4032,
|
|
180
|
-
# "height":3016,
|
|
181
|
-
# "format":"jpeg",
|
|
182
|
-
# "version":"Hg9VFvdI6HRzLFbV495VdwVmHIspLRCo",
|
|
183
|
-
# "public_id":"/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/87263920-2081-498e-a107-9625f4fde01b/vHg9VFvdI6HRzLFbV495VdwVmHIspLRCo"
|
|
184
|
-
# }
|
|
185
|
-
|
|
186
139
|
assert_equal(r['id'], name)
|
|
187
140
|
assert_equal(r['project_id'], Resizing.configure.project_id)
|
|
188
141
|
assert_equal(r['content_type'], 'image/jpeg')
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
assert_equal(r['format'], 'jpeg')
|
|
196
|
-
assert_equal(r['version'], 'Hg9VFvdI6HRzLFbV495VdwVmHIspLRCo')
|
|
142
|
+
assert(r['latest_version_id'] != nil)
|
|
143
|
+
assert(r['latest_etag'] != nil)
|
|
144
|
+
assert(r['created_at'] != nil)
|
|
145
|
+
assert(r['updated_at'] != nil)
|
|
146
|
+
assert(r['height'] != nil)
|
|
147
|
+
assert(r['width'] != nil)
|
|
197
148
|
assert_equal(
|
|
198
149
|
r['public_id'],
|
|
199
|
-
|
|
150
|
+
"/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/87263920-2081-498e-a107-9625f4fde01b/vHg9VFvdI6HRzLFbV495VdwVmHIspLRCo"
|
|
200
151
|
)
|
|
201
152
|
end
|
|
202
153
|
end
|
|
203
|
-
|
|
204
|
-
def test_get_raises_not_implemented_error
|
|
205
|
-
Resizing.configure = @configuration_template
|
|
206
|
-
client = Resizing::Client.new
|
|
207
|
-
|
|
208
|
-
assert_raises NotImplementedError do
|
|
209
|
-
client.get('some_image_id')
|
|
210
|
-
end
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def test_post_raises_error_without_content_type
|
|
214
|
-
Resizing.configure = @configuration_template
|
|
215
|
-
client = Resizing::Client.new
|
|
216
|
-
|
|
217
|
-
assert_raises ArgumentError do
|
|
218
|
-
client.post('test/data/images/sample1.jpg', {})
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
def test_post_raises_error_with_invalid_io
|
|
223
|
-
Resizing.configure = @configuration_template
|
|
224
|
-
client = Resizing::Client.new
|
|
225
|
-
|
|
226
|
-
assert_raises ArgumentError do
|
|
227
|
-
client.post(12_345, content_type: 'image/jpeg')
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def test_put_raises_error_without_content_type
|
|
232
|
-
Resizing.configure = @configuration_template
|
|
233
|
-
client = Resizing::Client.new
|
|
234
|
-
|
|
235
|
-
assert_raises ArgumentError do
|
|
236
|
-
client.put('image_id', 'test/data/images/sample1.jpg', {})
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
154
|
end
|
|
240
155
|
end
|
|
@@ -23,6 +23,7 @@ module Resizing
|
|
|
23
23
|
template = @template.dup
|
|
24
24
|
template.delete(:image_host)
|
|
25
25
|
config = Resizing::Configuration.new template
|
|
26
|
+
assert_equal(config.host, Resizing::Configuration::DEFAULT_IMAGE_HOST)
|
|
26
27
|
assert_equal(config.image_host, Resizing::Configuration::DEFAULT_IMAGE_HOST)
|
|
27
28
|
end
|
|
28
29
|
|
|
@@ -37,7 +38,7 @@ module Resizing
|
|
|
37
38
|
template = @template.dup
|
|
38
39
|
template[:host] = 'need raise execption if host is presented'
|
|
39
40
|
assert_raises ConfigurationError do
|
|
40
|
-
|
|
41
|
+
config = Resizing::Configuration.new template
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
|
|
@@ -146,122 +147,5 @@ module Resizing
|
|
|
146
147
|
config = Resizing::Configuration.new @template
|
|
147
148
|
assert_match %r{/projects/#{config.project_id}/upload/images/[\da-z-]}, config.generate_identifier
|
|
148
149
|
end
|
|
149
|
-
|
|
150
|
-
def test_generate_image_id_returns_uuid
|
|
151
|
-
config = Resizing::Configuration.new @template
|
|
152
|
-
image_id = config.generate_image_id
|
|
153
|
-
|
|
154
|
-
assert_instance_of String, image_id
|
|
155
|
-
# UUID format: 8-4-4-4-12
|
|
156
|
-
assert_match(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/, image_id)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def test_generate_image_id_returns_different_uuids
|
|
160
|
-
config = Resizing::Configuration.new @template
|
|
161
|
-
id1 = config.generate_image_id
|
|
162
|
-
id2 = config.generate_image_id
|
|
163
|
-
|
|
164
|
-
refute_equal id1, id2
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def test_equality_returns_true_for_same_configurations
|
|
168
|
-
config1 = Resizing::Configuration.new @template
|
|
169
|
-
config2 = Resizing::Configuration.new @template
|
|
170
|
-
|
|
171
|
-
assert_equal config1, config2
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def test_equality_returns_false_for_different_image_host
|
|
175
|
-
config1 = Resizing::Configuration.new @template
|
|
176
|
-
template2 = @template.dup
|
|
177
|
-
template2[:image_host] = 'http://different.host'
|
|
178
|
-
config2 = Resizing::Configuration.new template2
|
|
179
|
-
|
|
180
|
-
refute_equal config1, config2
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def test_equality_returns_false_for_different_project_id
|
|
184
|
-
config1 = Resizing::Configuration.new @template
|
|
185
|
-
template2 = @template.dup
|
|
186
|
-
template2[:project_id] = 'different-project-id'
|
|
187
|
-
config2 = Resizing::Configuration.new template2
|
|
188
|
-
|
|
189
|
-
refute_equal config1, config2
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def test_equality_returns_false_for_different_class
|
|
193
|
-
config = Resizing::Configuration.new @template
|
|
194
|
-
|
|
195
|
-
refute_equal config, 'not a configuration'
|
|
196
|
-
refute_equal config, @template
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
def test_transformation_path_with_multiple_transforms
|
|
200
|
-
config = Resizing::Configuration.new @template
|
|
201
|
-
transforms = [
|
|
202
|
-
{ w: 100, h: 200 },
|
|
203
|
-
{ f: 'webp', q: 80 }
|
|
204
|
-
]
|
|
205
|
-
|
|
206
|
-
path = config.transformation_path(transforms)
|
|
207
|
-
|
|
208
|
-
assert_equal 'w_100,h_200/f_webp,q_80', path
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
def test_transformation_path_with_single_hash
|
|
212
|
-
config = Resizing::Configuration.new @template
|
|
213
|
-
transform = { w: 300, h: 300, c: 'fill' }
|
|
214
|
-
|
|
215
|
-
path = config.transformation_path(transform)
|
|
216
|
-
|
|
217
|
-
assert_equal 'w_300,h_300,c_fill', path
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def test_transformation_path_ignores_unknown_options
|
|
221
|
-
config = Resizing::Configuration.new @template
|
|
222
|
-
transform = { w: 100, unknown_option: 'ignored', h: 200 }
|
|
223
|
-
|
|
224
|
-
path = config.transformation_path(transform)
|
|
225
|
-
|
|
226
|
-
assert_equal 'w_100,h_200', path
|
|
227
|
-
refute_includes path, 'unknown_option'
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
def test_transformation_path_with_empty_array
|
|
231
|
-
config = Resizing::Configuration.new @template
|
|
232
|
-
path = config.transformation_path([])
|
|
233
|
-
|
|
234
|
-
assert_equal '', path
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
def test_generate_identifier_includes_project_id
|
|
238
|
-
config = Resizing::Configuration.new @template
|
|
239
|
-
identifier = config.generate_identifier
|
|
240
|
-
|
|
241
|
-
assert_includes identifier, config.project_id
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
def test_generate_identifier_has_correct_format
|
|
245
|
-
config = Resizing::Configuration.new @template
|
|
246
|
-
identifier = config.generate_identifier
|
|
247
|
-
|
|
248
|
-
assert_match %r{\A/projects/[\da-z-]+/upload/images/[\da-z-]+\z}, identifier
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
def test_enable_mock_defaults_to_false
|
|
252
|
-
template = @template.dup
|
|
253
|
-
template.delete(:enable_mock)
|
|
254
|
-
config = Resizing::Configuration.new template
|
|
255
|
-
|
|
256
|
-
assert_equal false, config.enable_mock
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
def test_enable_mock_can_be_set_to_true
|
|
260
|
-
template = @template.dup
|
|
261
|
-
template[:enable_mock] = true
|
|
262
|
-
config = Resizing::Configuration.new template
|
|
263
|
-
|
|
264
|
-
assert_equal true, config.enable_mock
|
|
265
|
-
end
|
|
266
150
|
end
|
|
267
151
|
end
|
|
@@ -30,7 +30,7 @@ module Resizing
|
|
|
30
30
|
|
|
31
31
|
def test_expect_equal_identifier
|
|
32
32
|
public_id = Resizing::PublicId.new @public_id_as_string
|
|
33
|
-
assert_equal @public_id_as_string.gsub(
|
|
33
|
+
assert_equal @public_id_as_string.gsub(/\/v.*$/, ''), public_id.identifier
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def test_expect_equal_public_id
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
module Resizing
|
|
6
|
+
module Video
|
|
7
|
+
class ClientTest < Minitest::Test
|
|
8
|
+
def setup
|
|
9
|
+
# TODO
|
|
10
|
+
# refactoring
|
|
11
|
+
@configuration_template = {
|
|
12
|
+
image_host: 'http://192.168.56.101:5000',
|
|
13
|
+
video_host: 'http://192.168.56.101:5000',
|
|
14
|
+
project_id: 'f11dfad4-2247-4220-b3b2-efeb82864a97',
|
|
15
|
+
secret_token: 'xn2fkkrrp2uiragliaigkx3mwnmjis6dg35sa3kya12sq133t3xjp36s7iwamp64',
|
|
16
|
+
open_timeout: 10,
|
|
17
|
+
response_timeout: 20
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def teardown
|
|
22
|
+
# NOP
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_is_initialized
|
|
26
|
+
Resizing.configure = @configuration_template
|
|
27
|
+
|
|
28
|
+
client = Resizing::Video::Client.new
|
|
29
|
+
assert(!client.config.nil?)
|
|
30
|
+
assert_equal(client.config, Resizing.configure)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_is_initialized_with_configuration
|
|
34
|
+
config = Resizing::Configuration.new(@configuration_template)
|
|
35
|
+
client = Resizing::Video::Client.new(config)
|
|
36
|
+
assert(!client.config.nil?)
|
|
37
|
+
assert_equal(client.config, config)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_is_callable_build_prepare_url
|
|
41
|
+
Resizing.configure = @configuration_template
|
|
42
|
+
|
|
43
|
+
client = Resizing::Video::Client.new
|
|
44
|
+
url = client.build_prepare_url
|
|
45
|
+
assert_equal(url, 'http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/prepare')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_is_callable_prepare
|
|
49
|
+
Resizing.configure = @configuration_template
|
|
50
|
+
|
|
51
|
+
client = Resizing::Video::Client.new
|
|
52
|
+
VCR.use_cassette 'video/prepare/success', record: :once do
|
|
53
|
+
base_url = 'http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d'
|
|
54
|
+
r = client.prepare
|
|
55
|
+
assert_equal(r['id'], '3a101d25-e03f-4fac-a4ee-dbe882c6139d')
|
|
56
|
+
assert_equal(r['project_id'], Resizing.configure.project_id)
|
|
57
|
+
assert_equal(r['state'], 'initialized')
|
|
58
|
+
assert_nil(r['deleted_at'])
|
|
59
|
+
# assert_nil(r['source_uri']) # TODO: remove
|
|
60
|
+
assert(r['s3_presigned_url'] != nil)
|
|
61
|
+
assert_nil(r['converted_uri']) # TODO:remove
|
|
62
|
+
assert(r['created_at'] != nil)
|
|
63
|
+
assert(r['updated_at'] != nil)
|
|
64
|
+
assert(r['upload_completed_url'], "#{base_url}/upload_completed")
|
|
65
|
+
assert(r['self_url'], "#{base_url}.json")
|
|
66
|
+
assert_nil(r['m3u8_url'])
|
|
67
|
+
assert_nil(r['avc_url'])
|
|
68
|
+
assert_nil(r['hevc_url'])
|
|
69
|
+
assert_includes(r['thumbnail_url'], 'now-converting')
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_is_timeout_with_prepare_method
|
|
74
|
+
Resizing.configure = @configuration_template.merge(project_id: 'timeout_project_id')
|
|
75
|
+
|
|
76
|
+
client = Resizing::Video::Client.new
|
|
77
|
+
assert_raises Resizing::APIError do
|
|
78
|
+
client.prepare
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_is_callable_upload_complete_with_response
|
|
83
|
+
Resizing.configure = @configuration_template
|
|
84
|
+
|
|
85
|
+
client = Resizing::Video::Client.new
|
|
86
|
+
r = nil
|
|
87
|
+
VCR.use_cassette 'video/prepare/success', record: :once do
|
|
88
|
+
r = client.prepare
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
VCR.use_cassette 'video/upload_completed/success', record: :once do
|
|
92
|
+
r = client.upload_completed r
|
|
93
|
+
assert_upload_completed_response r
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_is_callable_upload_complete_with_string
|
|
98
|
+
Resizing.configure = @configuration_template
|
|
99
|
+
|
|
100
|
+
client = Resizing::Video::Client.new
|
|
101
|
+
r = nil
|
|
102
|
+
VCR.use_cassette 'video/prepare/success', record: :once do
|
|
103
|
+
r = client.prepare
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
VCR.use_cassette 'video/upload_completed/success', record: :once do
|
|
107
|
+
r = client.upload_completed r['upload_completed_url']
|
|
108
|
+
assert_upload_completed_response r
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_is_callable_metadata_with_response
|
|
113
|
+
Resizing.configure = @configuration_template
|
|
114
|
+
|
|
115
|
+
client = Resizing::Video::Client.new
|
|
116
|
+
r = nil
|
|
117
|
+
VCR.use_cassette 'video/prepare/success', record: :once do
|
|
118
|
+
r = client.prepare
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
completed_response = nil
|
|
122
|
+
VCR.use_cassette 'video/upload_completed/success', record: :once do
|
|
123
|
+
completed_response = client.upload_completed r['upload_completed_url']
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
VCR.use_cassette 'video/metadata/success', record: :once do
|
|
127
|
+
r = client.metadata r
|
|
128
|
+
assert_equal(completed_response, r)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def assert_upload_completed_response r
|
|
133
|
+
base_url = 'http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d'
|
|
134
|
+
assert_equal(r['id'], '3a101d25-e03f-4fac-a4ee-dbe882c6139d')
|
|
135
|
+
assert_equal(r['project_id'], Resizing.configure.project_id)
|
|
136
|
+
assert_equal(r['state'], 'uploaded')
|
|
137
|
+
assert_nil(r['deleted_at'])
|
|
138
|
+
# assert(r['source_uri'] != nil) # TODO: remove
|
|
139
|
+
assert(r['s3_presigned_url'] != nil)
|
|
140
|
+
# assert_equal(r['converted_uri'], "#{base_url}/") # TODO:remove
|
|
141
|
+
assert(r['created_at'] != nil)
|
|
142
|
+
assert(r['updated_at'] != nil)
|
|
143
|
+
assert(r['upload_completed_url'], "#{base_url}/upload_completed")
|
|
144
|
+
assert(r['self_url'], "#{base_url}.json")
|
|
145
|
+
assert_nil(r['m3u8_url'])
|
|
146
|
+
assert_nil(r['avc_url'])
|
|
147
|
+
assert_nil(r['hevc_url'])
|
|
148
|
+
assert_includes(r['thumbnail_url'], 'now-converting')
|
|
149
|
+
assert_equal(r['job_state']['id'], 'a586d38f-bdc3-4af2-9dbc-e0c18d2d54c5')
|
|
150
|
+
assert_equal(r['job_state']['upload_video_id'], '3a101d25-e03f-4fac-a4ee-dbe882c6139d')
|
|
151
|
+
assert_equal(r['job_state']['state'], 'initialized')
|
|
152
|
+
assert_equal(r['job_state']['job_percent_complete'], 0)
|
|
153
|
+
assert(r['job_state']['created_at'] != nil)
|
|
154
|
+
assert(r['job_state']['updated_at'] != nil)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
2
|
require 'simplecov'
|
|
4
3
|
require 'simplecov-cobertura'
|
|
5
4
|
|
|
6
5
|
SimpleCov.start do
|
|
7
|
-
add_filter
|
|
6
|
+
add_filter "/test/"
|
|
8
7
|
|
|
9
8
|
if ENV['CI']
|
|
10
9
|
formatter SimpleCov::Formatter::CoberturaFormatter
|
|
@@ -23,18 +22,15 @@ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
|
|
23
22
|
require 'time'
|
|
24
23
|
require 'timecop'
|
|
25
24
|
require 'vcr'
|
|
26
|
-
require 'logger'
|
|
27
25
|
|
|
28
26
|
require 'rails'
|
|
29
27
|
require 'active_record'
|
|
30
28
|
require 'fog-aws'
|
|
31
29
|
require 'carrierwave'
|
|
32
|
-
require 'carrierwave/orm/activerecord'
|
|
33
30
|
require 'resizing'
|
|
34
31
|
require 'pry-byebug'
|
|
35
32
|
|
|
36
33
|
require 'minitest/autorun'
|
|
37
|
-
require 'minitest/mock'
|
|
38
34
|
|
|
39
35
|
VCR.configure do |c|
|
|
40
36
|
c.cassette_library_dir = 'test/vcr'
|
|
@@ -42,93 +38,11 @@ VCR.configure do |c|
|
|
|
42
38
|
c.allow_http_connections_when_no_cassette = false
|
|
43
39
|
|
|
44
40
|
# raise Faraday::TimeoutError, when project_id is timeout_project_id
|
|
45
|
-
c.before_http_request(
|
|
41
|
+
c.before_http_request(lambda {|r| URI(r.uri).path.match? %r(/projects/timeout_project_id) } ) do
|
|
46
42
|
raise Faraday::TimeoutError
|
|
47
43
|
end
|
|
48
44
|
end
|
|
49
45
|
|
|
50
|
-
# VCRカセットのリクエストが実際に使用されたかを検証するヘルパー
|
|
51
|
-
module VCRRequestAssertions
|
|
52
|
-
# VCRカセット内でブロックを実行し、カセットのインタラクションがすべて使用されたことを確認
|
|
53
|
-
#
|
|
54
|
-
# @param cassette_name [String] VCRカセット名
|
|
55
|
-
# @param options [Hash] VCR.use_cassetteに渡すオプション
|
|
56
|
-
# @yield 実行するブロック
|
|
57
|
-
# @return [void]
|
|
58
|
-
#
|
|
59
|
-
# @example
|
|
60
|
-
# assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
|
|
61
|
-
# model.remove_resizing_picture!
|
|
62
|
-
# model.save!
|
|
63
|
-
# end
|
|
64
|
-
def assert_vcr_requests_made(cassette_name, options = {}, &block)
|
|
65
|
-
options = { record: :none }.merge(options)
|
|
66
|
-
|
|
67
|
-
VCR.use_cassette(cassette_name, options) do |cassette|
|
|
68
|
-
interaction_list = cassette.http_interactions
|
|
69
|
-
initial_count = interaction_list.remaining_unused_interaction_count
|
|
70
|
-
|
|
71
|
-
assert initial_count.positive?,
|
|
72
|
-
"Cassette '#{cassette_name}' should have at least 1 interaction"
|
|
73
|
-
|
|
74
|
-
yield cassette if block_given?
|
|
75
|
-
|
|
76
|
-
remaining_count = interaction_list.remaining_unused_interaction_count
|
|
77
|
-
used_count = initial_count - remaining_count
|
|
78
|
-
|
|
79
|
-
assert_equal 0, remaining_count,
|
|
80
|
-
"Expected all #{initial_count} cassette interactions to be used, " \
|
|
81
|
-
"but #{remaining_count} remain unused (#{used_count} were used)"
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# VCRカセット内でブロックを実行し、指定した数のインタラクションが使用されたことを確認
|
|
86
|
-
#
|
|
87
|
-
# @param cassette_name [String] VCRカセット名
|
|
88
|
-
# @param expected_count [Integer] 使用されるべきインタラクション数
|
|
89
|
-
# @param options [Hash] VCR.use_cassetteに渡すオプション
|
|
90
|
-
# @yield 実行するブロック
|
|
91
|
-
# @return [void]
|
|
92
|
-
#
|
|
93
|
-
# @example
|
|
94
|
-
# assert_vcr_requests_count 'client/post', 1 do
|
|
95
|
-
# Resizing.post(file)
|
|
96
|
-
# end
|
|
97
|
-
def assert_vcr_requests_count(cassette_name, expected_count, options = {}, &block)
|
|
98
|
-
options = { record: :none }.merge(options)
|
|
99
|
-
|
|
100
|
-
VCR.use_cassette(cassette_name, options) do |cassette|
|
|
101
|
-
interaction_list = cassette.http_interactions
|
|
102
|
-
initial_count = interaction_list.remaining_unused_interaction_count
|
|
103
|
-
|
|
104
|
-
yield cassette if block_given?
|
|
105
|
-
|
|
106
|
-
remaining_count = interaction_list.remaining_unused_interaction_count
|
|
107
|
-
used_count = initial_count - remaining_count
|
|
108
|
-
|
|
109
|
-
assert_equal expected_count, used_count,
|
|
110
|
-
"Expected #{expected_count} cassette interactions to be used, " \
|
|
111
|
-
"but #{used_count} were used"
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# VCRカセット内でブロックを実行し、リクエストが発行されないことを確認
|
|
116
|
-
#
|
|
117
|
-
# @param cassette_name [String] VCRカセット名
|
|
118
|
-
# @param options [Hash] VCR.use_cassetteに渡すオプション
|
|
119
|
-
# @yield 実行するブロック
|
|
120
|
-
# @return [void]
|
|
121
|
-
#
|
|
122
|
-
# @example
|
|
123
|
-
# assert_vcr_no_requests 'carrier_wave_test/remove_resizing_picture' do
|
|
124
|
-
# model.remove_resizing_picture = true
|
|
125
|
-
# # save!を呼ばないのでリクエストは発行されない
|
|
126
|
-
# end
|
|
127
|
-
def assert_vcr_no_requests(cassette_name, options = {}, &block)
|
|
128
|
-
assert_vcr_requests_count(cassette_name, 0, options, &block)
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
46
|
ActiveRecord::Base.establish_connection(
|
|
133
47
|
adapter: 'mysql2',
|
|
134
48
|
host: '127.0.0.1',
|
|
@@ -142,7 +56,7 @@ ActiveRecord::Base.establish_connection(
|
|
|
142
56
|
ActiveRecord::Schema.define do
|
|
143
57
|
self.verbose = false
|
|
144
58
|
|
|
145
|
-
%i
|
|
59
|
+
%i(test_models test_jpg_models test_model_with_default_urls).each do |model_name|
|
|
146
60
|
connection.execute "drop table if exists #{model_name}"
|
|
147
61
|
|
|
148
62
|
create_table model_name do |t|
|
|
@@ -187,13 +101,19 @@ class ResizingUploaderWithDefaultURL < CarrierWave::Uploader::Base
|
|
|
187
101
|
end
|
|
188
102
|
|
|
189
103
|
class TestModel < ::ActiveRecord::Base
|
|
104
|
+
extend CarrierWave::Mount
|
|
105
|
+
|
|
190
106
|
mount_uploader :resizing_picture, ResizingUploader
|
|
191
107
|
end
|
|
192
108
|
|
|
193
109
|
class TestJPGModel < ::ActiveRecord::Base
|
|
110
|
+
extend CarrierWave::Mount
|
|
111
|
+
|
|
194
112
|
mount_uploader :resizing_picture, ResizingJPGUploader
|
|
195
113
|
end
|
|
196
114
|
|
|
197
115
|
class TestModelWithDefaultURL < ::ActiveRecord::Base
|
|
116
|
+
extend CarrierWave::Mount
|
|
117
|
+
|
|
198
118
|
mount_uploader :resizing_picture, ResizingUploaderWithDefaultURL
|
|
199
119
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d.json
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- Faraday v1.0.1
|
|
12
|
+
X-ResizingToken:
|
|
13
|
+
- v1,1611308558,a02cf32edef894208f6d1bc17cc6182783728e2b2edfdca1bf6b3109fe37a58d
|
|
14
|
+
response:
|
|
15
|
+
status:
|
|
16
|
+
code: 200
|
|
17
|
+
message: OK
|
|
18
|
+
headers:
|
|
19
|
+
x-frame-options:
|
|
20
|
+
- SAMEORIGIN
|
|
21
|
+
x-xss-protection:
|
|
22
|
+
- 1; mode=block
|
|
23
|
+
x-content-type-options:
|
|
24
|
+
- nosniff
|
|
25
|
+
x-download-options:
|
|
26
|
+
- noopen
|
|
27
|
+
x-permitted-cross-domain-policies:
|
|
28
|
+
- none
|
|
29
|
+
referrer-policy:
|
|
30
|
+
- strict-origin-when-cross-origin
|
|
31
|
+
content-type:
|
|
32
|
+
- application/json; charset=utf-8
|
|
33
|
+
etag:
|
|
34
|
+
- W/"f2386fd24b9a80cecab7721608aa8902"
|
|
35
|
+
cache-control:
|
|
36
|
+
- max-age=0, private, must-revalidate
|
|
37
|
+
x-request-id:
|
|
38
|
+
- 84895278-9508-45c0-a7dc-d1087dc68813
|
|
39
|
+
x-runtime:
|
|
40
|
+
- '0.023674'
|
|
41
|
+
transfer-encoding:
|
|
42
|
+
- chunked
|
|
43
|
+
body:
|
|
44
|
+
encoding: UTF-8
|
|
45
|
+
string: '{"id":"3a101d25-e03f-4fac-a4ee-dbe882c6139d","project_id":"f11dfad4-2247-4220-b3b2-efeb82864a97","state":"uploaded","source_uri":"s3://resizing-bucket-development-video/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8","deleted_at":null,"s3_presigned_url":"https://resizing-bucket-development-video.s3.ap-northeast-1.amazonaws.com/videos/uploading/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8?X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=AKIXXXXXXXXXX%2F20210122%2Fap-northeast-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20210122T094237Z\u0026X-Amz-Expires=900\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Signature=c847ca1bfc20b7caeefcb999697df3cfd531aa2b7f0aa13f9066f289f693c22d","converted_uri":"s3://resizing-bucket-development-video/videos/converted/f11dfad4-2247-4220-b3b2-efeb82864a97/3a101d25-e03f-4fac-a4ee-dbe882c6139d/1dc40aae-29ab-4369-87da-10b146371fb8","created_at":"2021-01-22T09:42:37.670Z","updated_at":"2021-01-22T09:42:37.878Z","upload_completed_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d/upload_completed","self_url":"http://192.168.56.101:5000/projects/f11dfad4-2247-4220-b3b2-efeb82864a97/upload/videos/3a101d25-e03f-4fac-a4ee-dbe882c6139d.json","m3u8_url":null,"hevc_url":null,"avc_url":null,"thumbnail_url":"/assets/videos/now-converting-8a05d294385c14270a3662e01df5e50578cabcd2787123c18057ac06b101344c.png","job_state":{"id":"a586d38f-bdc3-4af2-9dbc-e0c18d2d54c5","upload_video_id":"3a101d25-e03f-4fac-a4ee-dbe882c6139d","state":"initialized","job_percent_complete":0,"created_at":"2021-01-22T09:42:38.501Z","updated_at":"2021-01-22T09:42:38.501Z"}}'
|
|
46
|
+
recorded_at: Fri, 22 Jan 2021 09:42:38 GMT
|
|
47
|
+
recorded_with: VCR 6.0.0
|