Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created September 10, 2014 10:16
Show Gist options
  • Save yuheiomori/55e41db7fc0c89bd8c15 to your computer and use it in GitHub Desktop.
Save yuheiomori/55e41db7fc0c89bd8c15 to your computer and use it in GitHub Desktop.
ファイルアップロードのテスト時にMEDIA_ROOTを差し替える
# 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