-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for the THUMBNAIL_STORAGE and THUMBNAIL_STORAGE_ALIAS
- Loading branch information
1 parent
9b6542c
commit ec0480d
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
import os | ||
|
||
import django | ||
from django.core.files import File | ||
from django.core.files.uploadedfile import UploadedFile | ||
from django.test import TestCase | ||
|
||
from categories.models import Category | ||
from example.test_storages import MyTestStorage, MyTestStorageAlias | ||
|
||
|
||
class TestCategoryThumbnail(TestCase): | ||
def test_thumbnail(self): | ||
file_name = "test_image.jpg" | ||
|
||
with open(os.path.join(os.path.dirname(__file__), file_name), "rb") as f: | ||
test_image = UploadedFile(File(f), content_type="image/jpeg") | ||
category = Category.objects.create(name="Test Category", slug="test-category", thumbnail=test_image) | ||
|
||
self.assertEqual(category.pk, 1) | ||
self.assertEqual(category.thumbnail_width, 640) | ||
self.assertEqual(category.thumbnail_height, 480) | ||
|
||
if django.VERSION >= (4, 2): | ||
self.assertEqual(category.thumbnail.storage.__class__, MyTestStorageAlias) | ||
else: | ||
self.assertEqual(category.thumbnail.storage.__class__, MyTestStorage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Storages used for testing THUMBNAIL_STORAGE and THUMBNAIL_STORAGE_ALIAS | ||
from django.core.files.storage import FileSystemStorage | ||
|
||
|
||
class MyTestStorage(FileSystemStorage): | ||
pass | ||
|
||
|
||
class MyTestStorageAlias(FileSystemStorage): | ||
pass |