|
4 | 4 | describe Cloudinary::Api do |
5 | 5 | break puts("Please setup environment for api test to run") if Cloudinary.config.api_secret.blank? |
6 | 6 | include_context "cleanup", TIMESTAMP_TAG |
7 | | - |
| 7 | + TEST_WIDTH = rand(1000) |
| 8 | + TEST_TRANSFOMATION = "c_scale,w_#{TEST_WIDTH}" |
8 | 9 | prefix = "api_test_#{Time.now.to_i}" |
9 | 10 | test_id_1 = "#{prefix}_1" |
10 | 11 | test_id_2 = "#{prefix}_2" |
11 | 12 | test_id_3 = "#{prefix}_3" |
12 | 13 | before(:all) do |
13 | 14 |
|
14 | 15 | @api = Cloudinary::Api |
15 | | - Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>100, :crop =>:scale]) |
16 | | - Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_2, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>100, :crop =>:scale]) |
17 | | - Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>100, :crop =>:scale]) |
18 | | - Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=test", :eager =>[:width =>100, :crop =>:scale]) |
19 | | - Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=tasty", :eager =>[:width =>100, :crop =>:scale]) |
| 16 | + Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>TEST_WIDTH, :crop =>:scale]) |
| 17 | + Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_2, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>TEST_WIDTH, :crop =>:scale]) |
| 18 | + Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "key=value", :eager =>[:width =>TEST_WIDTH, :crop =>:scale]) |
| 19 | + Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_1, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=test", :eager =>[:width =>TEST_WIDTH, :crop =>:scale]) |
| 20 | + Cloudinary::Uploader.upload(TEST_IMG, :public_id => test_id_3, :tags => [TEST_TAG, TIMESTAMP_TAG], :context => "test-key=tasty", :eager =>[:width =>TEST_WIDTH, :crop =>:scale]) |
20 | 21 | end |
21 | 22 |
|
22 | 23 | after(:all) do |
|
198 | 199 |
|
199 | 200 | describe 'transformations' do |
200 | 201 | it "should allow listing transformations" do |
201 | | - transformation = @api.transformations()["transformations"].find { |transformation| transformation["name"] == "c_scale,w_100" } |
| 202 | + transformation = @api.transformations(max_results: 500)["transformations"].find { |transformation| transformation["name"] == TEST_TRANSFOMATION } |
202 | 203 | expect(transformation).not_to be_blank |
203 | 204 | expect(transformation["used"]).to eq(true) |
204 | 205 | end |
205 | 206 |
|
206 | 207 | it "should allow getting transformation metadata" do |
207 | | - transformation = @api.transformation("c_scale,w_100") |
| 208 | + transformation = @api.transformation(TEST_TRANSFOMATION) |
208 | 209 | expect(transformation).not_to be_blank |
209 | | - expect(transformation["info"]).to eq(["crop" => "scale", "width" => 100]) |
210 | | - transformation = @api.transformation("crop" => "scale", "width" => 100) |
| 210 | + expect(transformation["info"]).to eq(["crop" => "scale", "width" => TEST_WIDTH]) |
| 211 | + transformation = @api.transformation("crop" => "scale", "width" => TEST_WIDTH) |
211 | 212 | expect(transformation).not_to be_blank |
212 | | - expect(transformation["info"]).to eq(["crop" => "scale", "width" => 100]) |
| 213 | + expect(transformation["info"]).to eq(["crop" => "scale", "width" => TEST_WIDTH]) |
213 | 214 | end |
214 | 215 |
|
215 | 216 | it "should allow updating transformation allowed_for_strict" do |
216 | | - @api.update_transformation("c_scale,w_100", :allowed_for_strict => true) |
217 | | - transformation = @api.transformation("c_scale,w_100") |
| 217 | + @api.update_transformation(TEST_TRANSFOMATION, :allowed_for_strict => true) |
| 218 | + transformation = @api.transformation(TEST_TRANSFOMATION) |
218 | 219 | expect(transformation).not_to be_blank |
219 | 220 | expect(transformation["allowed_for_strict"]).to eq(true) |
220 | | - @api.update_transformation("c_scale,w_100", :allowed_for_strict => false) |
221 | | - transformation = @api.transformation("c_scale,w_100") |
| 221 | + @api.update_transformation(TEST_TRANSFOMATION, :allowed_for_strict => false) |
| 222 | + transformation = @api.transformation(TEST_TRANSFOMATION) |
222 | 223 | expect(transformation).not_to be_blank |
223 | 224 | expect(transformation["allowed_for_strict"]).to eq(false) |
224 | 225 | end |
225 | 226 |
|
226 | 227 | it "should fetch two different derived images using next_cursor" do |
227 | | - result = @api.transformation("c_scale,w_100", :max_results=>1) |
| 228 | + result = @api.transformation(TEST_TRANSFOMATION, :max_results=>1) |
228 | 229 | expect(result["derived"]).not_to be_blank |
229 | 230 | expect(result["derived"].length).to eq(1) |
230 | 231 | expect(result["next_cursor"]).not_to be_blank |
231 | | - result2 = @api.transformation("c_scale,w_100", :max_results=>1, :next_cursor=>result["next_cursor"]) |
| 232 | + result2 = @api.transformation(TEST_TRANSFOMATION, :max_results=>1, :next_cursor=>result["next_cursor"]) |
232 | 233 | expect(result2["derived"]).not_to be_blank |
233 | 234 | expect(result2["derived"].length).to eq(1) |
234 | 235 | expect(result2["derived"][0]["id"]).not_to eq(result["derived"][0]["id"] ) |
|
263 | 264 |
|
264 | 265 | end |
265 | 266 | it "should allow deleting implicit transformation" do |
266 | | - @api.transformation("c_scale,w_100") |
267 | | - @api.delete_transformation("c_scale,w_100") |
268 | | - expect { @api.transformation("c_scale,w_100") }.to raise_error(Cloudinary::Api::NotFound) |
| 267 | + @api.transformation(TEST_TRANSFOMATION) |
| 268 | + @api.delete_transformation(TEST_TRANSFOMATION) |
| 269 | + expect { @api.transformation(TEST_TRANSFOMATION) }.to raise_error(Cloudinary::Api::NotFound) |
269 | 270 | end |
270 | 271 | end |
271 | 272 |
|
|
0 commit comments