2019-05-02 08:34:10 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from django.db.models import FilePathField
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class FilePathFieldTests(SimpleTestCase):
|
|
|
|
def test_path(self):
|
|
|
|
path = os.path.dirname(__file__)
|
|
|
|
field = FilePathField(path=path)
|
|
|
|
self.assertEqual(field.path, path)
|
|
|
|
self.assertEqual(field.formfield().path, path)
|
2019-05-02 08:42:10 +00:00
|
|
|
|
|
|
|
def test_callable_path(self):
|
|
|
|
path = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
def generate_path():
|
|
|
|
return path
|
|
|
|
|
|
|
|
field = FilePathField(path=generate_path)
|
|
|
|
self.assertEqual(field.path(), path)
|
|
|
|
self.assertEqual(field.formfield().path, path)
|