|
1 | 1 | import pytest |
2 | 2 |
|
3 | | -from pictures.templatetags.pictures import picture |
| 3 | +from pictures.templatetags.pictures import img_url, picture |
4 | 4 | from tests.testapp.models import Profile |
5 | 5 |
|
6 | 6 | picture_html = b""" |
@@ -61,3 +61,28 @@ def test_picture__additional_attrs(image_upload_file): |
61 | 61 | profile = Profile.objects.create(name="Spiderman", picture=image_upload_file) |
62 | 62 | html = picture(profile.picture, ratio="3/2", loading="lazy") |
63 | 63 | assert ' loading="lazy"' in html |
| 64 | + |
| 65 | + |
| 66 | +@pytest.mark.django_db |
| 67 | +def test_img_url(image_upload_file): |
| 68 | + profile = Profile.objects.create(name="Spiderman", picture=image_upload_file) |
| 69 | + assert ( |
| 70 | + img_url(profile.picture, ratio="3/2", file_type="webp", width=800) |
| 71 | + == "/_pictures/image/3x2/800w.WEBP" |
| 72 | + ) |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.django_db |
| 76 | +def test_img_url__raise_wrong_ratio(image_upload_file): |
| 77 | + profile = Profile.objects.create(name="Spiderman", picture=image_upload_file) |
| 78 | + with pytest.raises(ValueError) as e: |
| 79 | + img_url(profile.picture, ratio="2/3", file_type="webp", width=800) |
| 80 | + assert "Invalid ratio: 2/3. Choices are: 1/1, 3/2, 16/9" in str(e.value) |
| 81 | + |
| 82 | + |
| 83 | +@pytest.mark.django_db |
| 84 | +def test_img_url__raise_wrong_file_type(image_upload_file): |
| 85 | + profile = Profile.objects.create(name="Spiderman", picture=image_upload_file) |
| 86 | + with pytest.raises(ValueError) as e: |
| 87 | + img_url(profile.picture, ratio="3/2", file_type="gif", width=800) |
| 88 | + assert "Invalid file type: gif. Choices are: WEBP" in str(e.value) |
0 commit comments