|
2 | 2 |
|
3 | 3 | from imagekitio.client import ImageKit
|
4 | 4 | from imagekitio.constants.defaults import Default
|
5 |
| - |
| 5 | +from imagekitio.url import Url |
6 | 6 |
|
7 | 7 | class TestGenerateURL(unittest.TestCase):
|
8 | 8 | def setUp(self) -> None:
|
@@ -326,6 +326,90 @@ def test_url_signed_with_expire_in_seconds(self):
|
326 | 326 | url = self.client.url(options)
|
327 | 327 | self.assertIn("ik-t", url)
|
328 | 328 |
|
| 329 | + def test_url_signed_with_diacritic_in_filename(self): |
| 330 | + url = "https://test-domain.com/test-endpoint/test_é_path_alt.jpg" |
| 331 | + encodedUrl = Url.encode_string_if_required(url) |
| 332 | + self.assertEqual( |
| 333 | + encodedUrl, |
| 334 | + "https://test-domain.com/test-endpoint/test_%C3%A9_path_alt.jpg", |
| 335 | + ) |
| 336 | + signature = Url.get_signature("private_key_test", url, "https://test-domain.com/test-endpoint", 9999999999) |
| 337 | + options = { |
| 338 | + "path": "/test_é_path_alt.jpg", |
| 339 | + "signed": True, |
| 340 | + } |
| 341 | + url = self.client.url(options) |
| 342 | + self.assertEqual( |
| 343 | + url, |
| 344 | + "https://test-domain.com/test-endpoint/test_é_path_alt.jpg?ik-s="+signature, |
| 345 | + ) |
| 346 | + |
| 347 | + def test_url_signed_with_diacritic_in_filename_and_path(self): |
| 348 | + url = "https://test-domain.com/test-endpoint/aéb/test_é_path_alt.jpg" |
| 349 | + encodedUrl = Url.encode_string_if_required(url) |
| 350 | + self.assertEqual( |
| 351 | + encodedUrl, |
| 352 | + "https://test-domain.com/test-endpoint/a%C3%A9b/test_%C3%A9_path_alt.jpg", |
| 353 | + ) |
| 354 | + signature = Url.get_signature("private_key_test", url, "https://test-domain.com/test-endpoint", 9999999999) |
| 355 | + options = { |
| 356 | + "path": "/aéb/test_é_path_alt.jpg", |
| 357 | + "signed": True, |
| 358 | + } |
| 359 | + url = self.client.url(options) |
| 360 | + self.assertEqual( |
| 361 | + url, |
| 362 | + "https://test-domain.com/test-endpoint/aéb/test_é_path_alt.jpg?ik-s="+signature, |
| 363 | + ) |
| 364 | + |
| 365 | + def test_url_signed_with_diacritic_in_filename_path_transforamtion_in_path(self): |
| 366 | + url = "https://test-domain.com/test-endpoint/tr:l-text,i-Imagekité,fs-50,l-end/aéb/test_é_path_alt.jpg" |
| 367 | + encodedUrl = Url.encode_string_if_required(url) |
| 368 | + self.assertEqual( |
| 369 | + encodedUrl, |
| 370 | + "https://test-domain.com/test-endpoint/tr:l-text,i-Imagekit%C3%A9,fs-50,l-end/a%C3%A9b/test_%C3%A9_path_alt.jpg", |
| 371 | + ) |
| 372 | + signature = Url.get_signature("private_key_test", url, "https://test-domain.com/test-endpoint", 9999999999) |
| 373 | + options = { |
| 374 | + "path": "/aéb/test_é_path_alt.jpg", |
| 375 | + "transformation": [ |
| 376 | + { |
| 377 | + "raw": "l-text,i-Imagekité,fs-50,l-end" |
| 378 | + }, |
| 379 | + ], |
| 380 | + "signed": True, |
| 381 | + "transformation_position": "path" |
| 382 | + } |
| 383 | + url = self.client.url(options) |
| 384 | + self.assertEqual( |
| 385 | + url, |
| 386 | + "https://test-domain.com/test-endpoint/tr:l-text,i-Imagekité,fs-50,l-end/aéb/test_é_path_alt.jpg?ik-s="+signature, |
| 387 | + ) |
| 388 | + |
| 389 | + def test_url_signed_with_diacritic_in_filename_path_transforamtion_in_query(self): |
| 390 | + url = "https://test-domain.com/test-endpoint/aéb/test_é_path_alt.jpg?tr=l-text%2Ci-Imagekit%C3%A9%2Cfs-50%2Cl-end" |
| 391 | + encodedUrl = Url.encode_string_if_required(url) |
| 392 | + self.assertEqual( |
| 393 | + encodedUrl, |
| 394 | + "https://test-domain.com/test-endpoint/a%C3%A9b/test_%C3%A9_path_alt.jpg?tr=l-text%2Ci-Imagekit%C3%A9%2Cfs-50%2Cl-end", |
| 395 | + ) |
| 396 | + signature = Url.get_signature("private_key_test", url, "https://test-domain.com/test-endpoint", 9999999999) |
| 397 | + options = { |
| 398 | + "path": "/aéb/test_é_path_alt.jpg", |
| 399 | + "transformation": [ |
| 400 | + { |
| 401 | + "raw": "l-text,i-Imagekité,fs-50,l-end" |
| 402 | + }, |
| 403 | + ], |
| 404 | + "signed": True, |
| 405 | + "transformation_position": "query" |
| 406 | + } |
| 407 | + url = self.client.url(options) |
| 408 | + self.assertEqual( |
| 409 | + url, |
| 410 | + "https://test-domain.com/test-endpoint/aéb/test_é_path_alt.jpg?tr=l-text%2Ci-Imagekit%C3%A9%2Cfs-50%2Cl-end&ik-s="+signature, |
| 411 | + ) |
| 412 | + |
329 | 413 | def test_generate_url_with_path_and_src_uses_path(self):
|
330 | 414 | """
|
331 | 415 | In case when both path and src fields are provided, the `path` should be preferred
|
|
0 commit comments