Skip to content

Commit fa89e78

Browse files
committed
tidy up tests
1 parent 945411c commit fa89e78

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

tests/test_app/tests/bucket_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_static_storage_cannot_be_initialized_without_bucket(self):
2929
with self.assertRaises(OSError):
3030
MinioStaticStorage()
3131

32-
def test_get_setting_throws_early(self):
32+
def test_get_setting_raises_exception(self):
3333
with self.assertRaises(ImproperlyConfigured):
3434
get_setting("INEXISTENT_SETTING")
3535

tests/test_app/tests/custom_storage_class_tests.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919

2020

2121
@deconstructible
22-
class SecretStorage(MinioStorage):
23-
"""The SecretStorage MinioStorage subclass can be used directly, as a storage in
22+
class PrivateStorage(MinioStorage):
23+
"""The PrivateStorage MinioStorage subclass can be used directly, as a storage in
2424
settings.DEFAULT_FILE_STORAGE or after instantiated used individually on any django
2525
FileField:
2626
2727
from django.db import models
2828
29-
ss = SecretStorage(bucket_name='invoices')
29+
private_storage = PrivateStorage(bucket_name='invoices')
3030
3131
class Invoice(models.Model):
3232
...
33-
pdf = models.FileField(storage=ss)
33+
pdf = models.FileField(storage=private_storage)
3434
3535
"""
3636

@@ -51,7 +51,7 @@ def __init__(self, bucket_name=None):
5151
# or use our own Django setting
5252
#
5353
if bucket_name is None:
54-
bucket_name = get_setting("SECRET_BUCKET_NAME")
54+
bucket_name = get_setting("PRIVATE_BUCKET_NAME")
5555

5656
# Run the super constructor and make a choice to only use presigned urls with
5757
# this bucket so that we can keep files more private here than how media files
@@ -67,12 +67,12 @@ def __init__(self, bucket_name=None):
6767

6868

6969
class CustomStorageTests(BaseTestMixin, TestCase):
70-
@override_settings(SECRET_BUCKET_NAME=create_test_bucket_name("my-secret-bucket"))
70+
@override_settings(PRIVATE_BUCKET_NAME=create_test_bucket_name("my-private-bucket"))
7171
def test_custom_storage(self):
7272
# Instansiate a storage class and put a file in it so that we have something to
7373
# work with.
7474
#
75-
storage = SecretStorage()
75+
storage = PrivateStorage()
7676
storage_filename = storage.save("secret.txt", ContentFile(b"abcd"))
7777

7878
# Create a temporary workspace directory.

tests/test_app/tests/retrieve_tests.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import datetime
22
import io
33
import os
4-
import unittest
54

65
import requests
76
from django.core.files.base import ContentFile
87
from django.test import TestCase, override_settings
98
from freezegun import freeze_time
109
from minio.error import S3Error
1110

12-
from minio_storage.errors import MinIOError
1311
from minio_storage.storage import MinioMediaStorage
1412

1513
from .utils import BaseTestMixin
@@ -41,7 +39,7 @@ def test_file_size(self):
4139
test_file = self.media_storage.save("sizetest.txt", ContentFile(b"1234"))
4240
self.assertEqual(4, self.media_storage.size(test_file))
4341

44-
def test_size_of_non_existent_throws(self):
42+
def test_size_of_non_existent_raises_exception(self):
4543
test_file = self.media_storage.save("sizetest.txt", ContentFile(b"1234"))
4644
self.media_storage.delete(test_file)
4745
with self.assertRaises(S3Error):
@@ -62,7 +60,7 @@ def test_created_time(self):
6260
self.media_storage.created_time(self.new_file), datetime.datetime
6361
)
6462

65-
def test_modified_time_of_non_existent_throws(self):
63+
def test_modified_time_of_non_existent_raises_exception(self):
6664
with self.assertRaises(S3Error):
6765
self.media_storage.modified_time("nonexistent.jpg")
6866

@@ -116,19 +114,10 @@ def test_file_exists(self):
116114
def test_file_exists_failure(self):
117115
self.assertFalse(self.media_storage.exists("nonexistent.txt"))
118116

119-
@unittest.skip("Skipping this test because undecided if it should raise exception")
120-
def test_opening_non_existing_file_raises_oserror(self):
121-
with self.assertRaises(OSError):
122-
self.media_storage.open("this does not exist")
123-
124-
@unittest.skip("Skipping this test because undecided if it should raise exception")
125-
def test_opening_non_existing_file_raises_minioerror(self):
126-
with self.assertRaises(MinIOError):
127-
self.media_storage.open("this does not exist")
128-
try:
129-
self.media_storage.open("this does not exist")
130-
except MinIOError as e:
131-
assert e.cause.__class__ == S3Error
117+
def test_reading_non_existing_file_raises_exception(self):
118+
with self.assertRaises(Exception):
119+
f = self.media_storage.open("this does not exist")
120+
f.read()
132121

133122
def test_file_names_are_properly_sanitized(self):
134123
self.media_storage.save("./meh22222.txt", io.BytesIO(b"stuff"))

tests/test_app/tests/upload_tests.py

-9
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ def test_files_seekable(self):
6666
def test_upload_and_get_back_file_with_funky_name(self):
6767
self.media_storage.save("áčďěščřžýŽŇůúť.txt", ContentFile(b"12345"))
6868

69-
def test_uploaded_and_downloaded_file_sizes_match(self):
70-
pass
71-
72-
def test_uploaded_files_end_up_in_the_right_bucket(self):
73-
pass
74-
75-
def test_static_files_end_up_in_the_right_bucket(self):
76-
pass
77-
7869
def test_upload_file_beggining_with_dot(self):
7970
self.media_storage.save(
8071
".hidden_file", ContentFile(b"Not really, but whatever")

0 commit comments

Comments
 (0)