summaryrefslogtreecommitdiff
path: root/tests/file_uploads
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-06-28 11:21:26 -0400
committerTim Graham <timograham@gmail.com>2016-07-01 09:58:56 -0400
commit567cfc1601a5f475eea12bc5de53b849fa5dadea (patch)
treec471ba1af748008e4fbe9faee8cf51d4dffcd263 /tests/file_uploads
parent9c48e17480432b8723fcdcc262d8d62866e93a4f (diff)
[1.10.x] Replaced use of TestCase.fail() with assertRaises().
Also removed try/except/fail antipattern that hides exceptions. Backport of c9ae09addffb839403312131d4251e9d8b454508 from master
Diffstat (limited to 'tests/file_uploads')
-rw-r--r--tests/file_uploads/tests.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py
index 2712cf668a..9e77e6b0f0 100644
--- a/tests/file_uploads/tests.py
+++ b/tests/file_uploads/tests.py
@@ -7,6 +7,7 @@ import hashlib
import json
import os
import shutil
+import sys
import tempfile as sys_tempfile
import unittest
from io import BytesIO
@@ -564,16 +565,14 @@ class DirectoryCreationTests(SimpleTestCase):
def setUp(self):
self.obj = FileModel()
+ @unittest.skipIf(sys.platform == 'win32', "Python on Windows doesn't have working os.chmod().")
def test_readonly_root(self):
"""Permission errors are not swallowed"""
os.chmod(MEDIA_ROOT, 0o500)
self.addCleanup(os.chmod, MEDIA_ROOT, 0o700)
- try:
+ with self.assertRaises(OSError) as cm:
self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', b'x'), save=False)
- except OSError as err:
- self.assertEqual(err.errno, errno.EACCES)
- except Exception:
- self.fail("OSError [Errno %s] not raised." % errno.EACCES)
+ self.assertEqual(cm.exception.errno, errno.EACCES)
def test_not_a_directory(self):
"""The correct IOError is raised when the upload directory name exists but isn't a directory"""