Created
September 10, 2014 10:16
-
-
Save yuheiomori/55e41db7fc0c89bd8c15 to your computer and use it in GitHub Desktop.
ファイルアップロードのテスト時にMEDIA_ROOTを差し替える
This file contains hidden or 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
# coding=utf-8 | |
import os | |
import tempfile | |
import shutil | |
from django.test import TestCase, override_settings | |
TEST_MEDIA_ROOT = tempfile.mkdtemp() | |
@override_settings(MEDIA_ROOT=TEST_MEDIA_ROOT) | |
class FileUploadViewTest(TestCase): | |
@classmethod | |
def setUpClass(cls): | |
if not os.path.isdir(TEST_MEDIA_ROOT): | |
os.makedirs(TEST_MEDIA_ROOT) | |
@classmethod | |
def tearDownClass(cls): | |
shutil.rmtree(TEST_MEDIA_ROOT) | |
def test_something(self): | |
self.client.post(self.url) | |
# assert ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment