|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | from django.contrib.auth.models import Permission |
5 | | -from django.core.files.uploadedfile import SimpleUploadedFile |
6 | | -from django.core.exceptions import ValidationError |
7 | 5 | from django.utils.timezone import now |
8 | 6 | from model_bakery import baker |
9 | 7 |
|
@@ -64,52 +62,52 @@ def test_entry_absolute_url(tp): |
64 | 62 | assert entry.get_absolute_url() == tp.reverse("news-detail", "the-slug") |
65 | 63 |
|
66 | 64 |
|
67 | | -def test_entry_model_image_validator(tp): |
68 | | - """ |
69 | | - Test that the `image` field only accepts certain file types. |
70 | | - """ |
71 | | - author = baker.make("users.User") |
72 | | - entry = Entry.objects.create(title="😀 Foo Bar Baz!@! +", author=author) |
73 | | - # Valid image file |
74 | | - valid_image = SimpleUploadedFile( |
75 | | - "test.jpg", b"file_content", content_type="image/jpeg" |
76 | | - ) |
77 | | - entry.image = valid_image |
78 | | - # This should not raise any errors |
79 | | - entry.full_clean() |
80 | | - |
81 | | - # Invalid image file |
82 | | - invalid_image = SimpleUploadedFile( |
83 | | - "test.pdf", b"file_content", content_type="application/pdf" |
84 | | - ) |
85 | | - entry.image = invalid_image |
86 | | - # This should raise a ValidationError |
87 | | - with pytest.raises(ValidationError): |
88 | | - entry.full_clean() |
89 | | - |
90 | | - |
91 | | -def test_entry_model_image_file_size(tp): |
92 | | - """ |
93 | | - Test that the `image` field rejects files larger than a specific size. |
94 | | - """ |
95 | | - author = baker.make("users.User") |
96 | | - entry = Entry.objects.create(title="😀 Foo Bar Baz!@! +", author=author) |
97 | | - |
98 | | - valid_image = SimpleUploadedFile( |
99 | | - "test.jpg", b"a" * (1 * 1024 * 1024 - 1), content_type="image/jpeg" |
100 | | - ) |
101 | | - entry.image = valid_image |
102 | | - # This should not raise any errors |
103 | | - entry.full_clean() |
104 | | - |
105 | | - # This should fail (just over 1MB) |
106 | | - invalid_image = SimpleUploadedFile( |
107 | | - "too_large.jpg", b"a" * (1 * 1024 * 1024 + 1), content_type="image/jpeg" |
108 | | - ) |
109 | | - entry.image = invalid_image |
110 | | - # This should raise a ValidationError for file size |
111 | | - with pytest.raises(ValidationError): |
112 | | - entry.full_clean() |
| 65 | +# def test_entry_model_image_validator(tp): |
| 66 | +# """ |
| 67 | +# Test that the `image` field only accepts certain file types. |
| 68 | +# """ |
| 69 | +# author = baker.make("users.User") |
| 70 | +# entry = Entry.objects.create(title="😀 Foo Bar Baz!@! +", author=author) |
| 71 | +# # Valid image file |
| 72 | +# valid_image = SimpleUploadedFile( |
| 73 | +# "test.jpg", b"file_content", content_type="image/jpeg" |
| 74 | +# ) |
| 75 | +# entry.image = valid_image |
| 76 | +# # This should not raise any errors |
| 77 | +# entry.full_clean() |
| 78 | + |
| 79 | +# # Invalid image file |
| 80 | +# invalid_image = SimpleUploadedFile( |
| 81 | +# "test.pdf", b"file_content", content_type="application/pdf" |
| 82 | +# ) |
| 83 | +# entry.image = invalid_image |
| 84 | +# # This should raise a ValidationError |
| 85 | +# with pytest.raises(ValidationError): |
| 86 | +# entry.full_clean() |
| 87 | + |
| 88 | + |
| 89 | +# def test_entry_model_image_file_size(tp): |
| 90 | +# """ |
| 91 | +# Test that the `image` field rejects files larger than a specific size. |
| 92 | +# """ |
| 93 | +# author = baker.make("users.User") |
| 94 | +# entry = Entry.objects.create(title="😀 Foo Bar Baz!@! +", author=author) |
| 95 | + |
| 96 | +# valid_image = SimpleUploadedFile( |
| 97 | +# "test.jpg", b"a" * (1 * 1024 * 1024 - 1), content_type="image/jpeg" |
| 98 | +# ) |
| 99 | +# entry.image = valid_image |
| 100 | +# # This should not raise any errors |
| 101 | +# entry.full_clean() |
| 102 | + |
| 103 | +# # This should fail (just over 1MB) |
| 104 | +# invalid_image = SimpleUploadedFile( |
| 105 | +# "too_large.jpg", b"a" * (1 * 1024 * 1024 + 1), content_type="image/jpeg" |
| 106 | +# ) |
| 107 | +# entry.image = invalid_image |
| 108 | +# # This should raise a ValidationError for file size |
| 109 | +# with pytest.raises(ValidationError): |
| 110 | +# entry.full_clean() |
113 | 111 |
|
114 | 112 |
|
115 | 113 | def test_approve_entry(make_entry): |
|
0 commit comments