from django.core.files import File
from django.test import TestCase
import mock
from forms import FooForm
from models import FooModel
from views import FooCreateView
class FooCreateViewTestCase(TestCase):
def test_form_valid(self):
"""
This test will check if after creating a FooModel
instance, its text field contains 'Is valid'
"""
file_mock = mock.MagicMock(spec=File)
file_mock.name = 'test.pdf'
form = FooForm(
data={ },
files={
'bar': file_mock,
}
)
FooCreateView().form_valid(form=form)
foo = FooModel.objects.get()
self.assertEqual(foo.bar.name, 'test.pdf')
self.assertEqual(foo.state, 'Is valid')