summaryrefslogtreecommitdiff
path: root/tests/file_uploads
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-06-28 11:21:26 -0400
committerGitHub <noreply@github.com>2016-06-28 11:21:26 -0400
commitc9ae09addffb839403312131d4251e9d8b454508 (patch)
tree74913fbe2e90d88e094f8594947ebf313ec5f12f /tests/file_uploads
parentc1b6f554e405fe733e8d80f7e3d77c277810e707 (diff)
downloaddjango-c9ae09addffb839403312131d4251e9d8b454508.tar.gz
Replaced use of TestCase.fail() with assertRaises().
Also removed try/except/fail antipattern that hides exceptions.
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"""