httpthumbnailer-client 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe HTTPThumbnailerClient do
4
- it 'should provide service URL that is set up to use' do
5
- HTTPThumbnailerClient.new('http://123.213.213.231').server_url.should == 'http://123.213.213.231'
6
- HTTPThumbnailerClient.new('http://123.213.213.1').server_url.should == 'http://123.213.213.1'
7
- end
8
-
9
- it 'should provide keep alive setting' do
10
- HTTPThumbnailerClient.new('http://123.213.213.231').keep_alive.should be_false
11
- HTTPThumbnailerClient.new('http://123.213.213.231', keep_alive: true).keep_alive.should be_true
12
- end
13
-
14
- it 'should provide nice inspect string' do
15
- HTTPThumbnailerClient.new('http://123.213.213.231', keep_alive: true).inspect.should == '#<HTTPThumbnailerClient server_url="http://123.213.213.231" keep_alive=true>'
16
- end
17
- end
18
-
@@ -1,44 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe HTTPThumbnailerClient, 'identify API' do
4
- before :all do
5
- log = support_dir + 'server.log'
6
- start_server(
7
- "httpthumbnailer -f -d -x XID -l #{log}",
8
- '/tmp/httpthumbnailer.pid',
9
- log,
10
- 'http://localhost:3100/'
11
- )
12
- end
13
-
14
- after :all do
15
- stop_server('/tmp/httpthumbnailer.pid')
16
- end
17
-
18
- it 'should return input image identification information' do
19
- input_id = HTTPThumbnailerClient.new('http://localhost:3100').identify((support_dir + 'test.jpg').read)
20
- input_id.mime_type.should == 'image/jpeg'
21
- input_id.width.should == 509
22
- input_id.height.should == 719
23
- end
24
-
25
- describe 'general error handling' do
26
- it 'should raise HTTPThumbnailerClient::UnsupportedMediaTypeError error on unsupported media type error' do
27
- lambda {
28
- HTTPThumbnailerClient.new('http://localhost:3100').identify((support_dir + 'test.txt').read)
29
- }.should raise_error HTTPThumbnailerClient::UnsupportedMediaTypeError
30
- end
31
- end
32
-
33
- describe 'passing custom HTTP request headers' do
34
- it '#with_headers should add headers to given request' do
35
- xid = rand(0..1000)
36
-
37
- input_id = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).identify((support_dir + 'test.jpg').read)
38
- input_id.mime_type.should == 'image/jpeg'
39
-
40
- (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
41
- end
42
- end
43
- end
44
-
@@ -1,83 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
-
5
- require 'httpthumbnailer-client'
6
-
7
- # Requires supporting files with custom matchers and macros, etc,
8
- # in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
-
11
- RSpec.configure do |config|
12
-
13
- end
14
-
15
- require 'daemon'
16
- require 'RMagick'
17
-
18
- def gem_dir
19
- Pathname.new(__FILE__).dirname + '..'
20
- end
21
-
22
- def spec_dir
23
- gem_dir + 'spec'
24
- end
25
-
26
- def support_dir
27
- spec_dir + 'support'
28
- end
29
-
30
- def identify(data)
31
- image = Magick::Image.from_blob(data).first
32
- out = Struct.new(:format, :width, :height).new(image.format, image.columns, image.rows)
33
- image.destroy!
34
- out
35
- end
36
-
37
- def get(url)
38
- HTTPClient.new.get_content(url)
39
- end
40
-
41
- def start_server(cmd, pid_file, log_file, test_url)
42
- fork do
43
- Daemon.daemonize(pid_file, log_file)
44
- log_file = Pathname.new(log_file)
45
- log_file.truncate(0) if log_file.exist?
46
- exec(cmd)
47
- end
48
- return unless Process.wait2.last.exitstatus == 0
49
-
50
- ppid = Process.pid
51
- at_exit do
52
- stop_server(pid_file) if Process.pid == ppid
53
- end
54
-
55
- Timeout.timeout(6) do
56
- begin
57
- get test_url
58
- rescue Errno::ECONNREFUSED
59
- sleep 0.1
60
- retry
61
- end
62
- end
63
- end
64
-
65
- def stop_server(pid_file)
66
- pid_file = Pathname.new(pid_file)
67
- return unless pid_file.exist?
68
-
69
- #STDERR.puts HTTPClient.new.get_content("http://localhost:3100/stats")
70
- pid = pid_file.read.strip.to_i
71
-
72
- Timeout.timeout(20) do
73
- begin
74
- loop do
75
- Process.kill("TERM", pid)
76
- sleep 0.1
77
- end
78
- rescue Errno::ESRCH
79
- pid_file.unlink
80
- end
81
- end
82
- end
83
-
Binary file
Binary file
@@ -1 +0,0 @@
1
- hello world
@@ -1,102 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe HTTPThumbnailerClient, 'single thumbnail API' do
4
- before :all do
5
- log = support_dir + 'server.log'
6
- start_server(
7
- "httpthumbnailer -f -d -x XID -l #{log}",
8
- '/tmp/httpthumbnailer.pid',
9
- log,
10
- 'http://localhost:3100/'
11
- )
12
- end
13
-
14
- after :all do
15
- stop_server('/tmp/httpthumbnailer.pid')
16
- end
17
-
18
- it 'should return single thumbnail matching specification' do
19
- thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
20
-
21
- thumbnail.should be_kind_of HTTPThumbnailerClient::Thumbnail
22
- thumbnail.mime_type.should == 'image/jpeg'
23
- thumbnail.width.should == 6
24
- thumbnail.height.should == 3
25
-
26
- i = identify(thumbnail.data)
27
- i.format.should == 'JPEG'
28
- i.width.should == 6
29
- i.height.should == 3
30
- end
31
-
32
- describe 'meta data' do
33
- it 'should provide input image mime type' do
34
- thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
35
- thumbnail.input_mime_type.should == 'image/jpeg'
36
- end
37
-
38
- it 'should provide input image size' do
39
- thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
40
- thumbnail.input_width.should == 509
41
- thumbnail.input_height.should == 719
42
- end
43
- end
44
-
45
- describe 'general error handling' do
46
- it 'should raise HTTPThumbnailerClient::InvalidThumbnailSpecificationError error on bad request error' do
47
- lambda {
48
- HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read, 'crop', 0, 0, 'jpeg')
49
- }.should raise_error HTTPThumbnailerClient::InvalidThumbnailSpecificationError
50
-
51
- lambda {
52
- HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read, 'blah', 4, 4, 'jpeg')
53
- }.should raise_error HTTPThumbnailerClient::InvalidThumbnailSpecificationError
54
- end
55
-
56
- it 'should raise HTTPThumbnailerClient::ServerResourceNotFoundError error on not found error' do
57
- lambda {
58
- HTTPThumbnailerClient.new('http://localhost:3100/blah').thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
59
- }.should raise_error HTTPThumbnailerClient::ServerResourceNotFoundError
60
- end
61
-
62
- it 'should raise HTTPThumbnailerClient::UnsupportedMediaTypeError error on unsupported media type error' do
63
- lambda {
64
- HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.txt').read, 'crop', 6, 3, 'jpeg')
65
- }.should raise_error HTTPThumbnailerClient::UnsupportedMediaTypeError
66
- end
67
-
68
- it 'should raise HTTPThumbnailerClient::ImageTooLargeError error on request entity too large error' do
69
- lambda {
70
- HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test-large.jpg').read, 'crop', 7000, 7000, 'png')
71
- }.should raise_error HTTPThumbnailerClient::ImageTooLargeError
72
- end
73
- end
74
-
75
- describe 'passing custom HTTP request headers' do
76
- it 'should add headers provided with :headers option' do
77
- xid = rand(0..1000)
78
-
79
- thumbnail = HTTPThumbnailerClient.new('http://localhost:3100', headers: {'XID' => xid}).thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
80
- thumbnail.should be_kind_of HTTPThumbnailerClient::Thumbnail
81
-
82
- (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
83
- end
84
-
85
- it '#with_headers should add headers to given request' do
86
- xid = rand(0..1000)
87
-
88
- thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
89
- thumbnail.should be_kind_of HTTPThumbnailerClient::Thumbnail
90
-
91
- (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
92
-
93
- xid = rand(1000..2000)
94
-
95
- thumbnail = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).thumbnail((support_dir + 'test.jpg').read, 'crop', 6, 3, 'jpeg')
96
- thumbnail.should be_kind_of HTTPThumbnailerClient::Thumbnail
97
-
98
- (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
99
- end
100
- end
101
- end
102
-
@@ -1,139 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe HTTPThumbnailerClient, 'multipart API' do
4
- before :all do
5
- log = support_dir + 'server.log'
6
- start_server(
7
- "httpthumbnailer -f -d -x XID -l #{log}",
8
- '/tmp/httpthumbnailer.pid',
9
- log,
10
- 'http://localhost:3100/'
11
- )
12
- end
13
-
14
- after :all do
15
- stop_server('/tmp/httpthumbnailer.pid')
16
- end
17
-
18
- it 'should return set of thumbnails matching specifications' do
19
- thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
20
- thumbnail 'crop', 60, 30, 'jpeg'
21
- thumbnail 'crop', 80, 80, 'png'
22
- thumbnail 'crop', 40, 40, 'png'
23
- end
24
-
25
- thumbs[0].should be_kind_of HTTPThumbnailerClient::Thumbnail
26
- thumbs[0].mime_type.should == 'image/jpeg'
27
- thumbs[0].width.should == 60
28
- thumbs[0].height.should == 30
29
- i = identify(thumbs[0].data)
30
- i.format.should == 'JPEG'
31
- i.width.should == 60
32
- i.height.should == 30
33
-
34
- thumbs[1].should be_kind_of HTTPThumbnailerClient::Thumbnail
35
- thumbs[1].mime_type.should == 'image/png'
36
- thumbs[1].width.should == 80
37
- thumbs[1].height.should == 80
38
- i = identify(thumbs[1].data)
39
- i.format.should == 'PNG'
40
- i.width.should == 80
41
- i.height.should == 80
42
-
43
- thumbs[2].should be_kind_of HTTPThumbnailerClient::Thumbnail
44
- thumbs[2].mime_type.should == 'image/png'
45
- thumbs[2].width.should == 40
46
- thumbs[2].height.should == 40
47
- i = identify(thumbs[2].data)
48
- i.format.should == 'PNG'
49
- i.width.should == 40
50
- i.height.should == 40
51
- end
52
-
53
- describe 'meta data' do
54
- it 'should provide input image mime type' do
55
- thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
56
- thumbnail 'crop', 6, 3, 'jpeg'
57
- end
58
- thumbs.input_mime_type.should == 'image/jpeg'
59
- end
60
-
61
- it 'should provide input image size' do
62
- thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
63
- thumbnail 'crop', 6, 3, 'jpeg'
64
- end
65
- thumbs.input_width.should == 509
66
- thumbs.input_height.should == 719
67
- end
68
- end
69
-
70
- describe 'returns HTTPThumbnailerClient::HTTPThumbnailerClientError object within set of returned thumbnails' do
71
- it 'in case of error with particluar thumbanil' do
72
- thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
73
- thumbnail 'crop', 6, 3, 'jpeg'
74
- thumbnail 'crop', 0, 0, 'png'
75
- thumbnail 'crop', 4, 4, 'png'
76
- end
77
-
78
- thumbs[0].should be_kind_of HTTPThumbnailerClient::Thumbnail
79
- thumbs[0].mime_type.should == 'image/jpeg'
80
- i = identify(thumbs[0].data)
81
- i.format.should == 'JPEG'
82
- i.width.should == 6
83
- i.height.should == 3
84
-
85
- thumbs[1].should be_kind_of HTTPThumbnailerClient::HTTPThumbnailerClientError
86
- thumbs[1].message.should =~ /^at least one image dimension is zero/
87
- thumbs[1].status.should == 400
88
-
89
- thumbs[2].should be_kind_of HTTPThumbnailerClient::Thumbnail
90
- thumbs[2].mime_type.should == 'image/png'
91
- i = identify(thumbs[2].data)
92
- i.format.should == 'PNG'
93
- i.width.should == 4
94
- i.height.should == 4
95
- end
96
-
97
- it 'in case of memory exhaustion while thumbnailing' do
98
- thumbs = HTTPThumbnailerClient.new('http://localhost:3100').thumbnail((support_dir + 'test.jpg').read) do
99
- thumbnail 'crop', 6, 3, 'jpeg'
100
- thumbnail 'crop', 16000, 16000, 'png'
101
- thumbnail 'crop', 4, 4, 'png'
102
- end
103
-
104
- thumbs[0].should be_kind_of HTTPThumbnailerClient::Thumbnail
105
- thumbs[0].mime_type.should == 'image/jpeg'
106
- i = identify(thumbs[0].data)
107
- i.format.should == 'JPEG'
108
- i.width.should == 6
109
- i.height.should == 3
110
-
111
- thumbs[1].should be_kind_of HTTPThumbnailerClient::HTTPThumbnailerClientError
112
- thumbs[1].message.should =~ /^image too large/
113
- thumbs[1].status.should == 413
114
-
115
- thumbs[2].should be_kind_of HTTPThumbnailerClient::Thumbnail
116
- thumbs[2].mime_type.should == 'image/png'
117
- i = identify(thumbs[2].data)
118
- i.format.should == 'PNG'
119
- i.width.should == 4
120
- i.height.should == 4
121
- end
122
- end
123
-
124
- describe 'passing custom HTTP request headers' do
125
- it '#with_headers should add headers to given request' do
126
- xid = rand(0..1000)
127
-
128
- thumbs = HTTPThumbnailerClient.new('http://localhost:3100').with_headers('XID' => xid).thumbnail((support_dir + 'test.jpg').read) do
129
- thumbnail 'crop', 60, 30, 'jpeg'
130
- thumbnail 'crop', 80, 80, 'png'
131
- thumbnail 'crop', 40, 40, 'png'
132
- end
133
- thumbs[0].should be_kind_of HTTPThumbnailerClient::Thumbnail
134
-
135
- (support_dir + 'server.log').read.should include "xid=\"#{xid}\""
136
- end
137
- end
138
- end
139
-
@@ -1,16 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe HTTPThumbnailerClient::URIBuilder do
4
- it 'should allow building request for single thumbnail' do
5
- HTTPThumbnailerClient::URIBuilder.thumbnail('pad', 32, 64, 'png', magick: 'xdfa', number: 2)
6
- .should == '/thumbnail/pad,32,64,png,magick:xdfa,number:2'
7
- end
8
-
9
- it 'should allow building request for thumbnail set' do
10
- HTTPThumbnailerClient::URIBuilder.thumbnails do
11
- thumbnail 'crop', 16, 16, 'jpeg'
12
- thumbnail 'pad', 32, 64, 'png', magick: 'xdfa', number: 2
13
- end.should == '/thumbnails/crop,16,16,jpeg/pad,32,64,png,magick:xdfa,number:2'
14
- end
15
- end
16
-