Guest User

Untitled

a guest
Oct 11th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. from django.core.files import File
  2. from django.test import TestCase
  3.  
  4. import mock
  5.  
  6. from forms import FooForm
  7. from models import FooModel
  8. from views import FooCreateView
  9.  
  10.  
  11. class FooCreateViewTestCase(TestCase):
  12. def test_form_valid(self):
  13. """
  14. This test will check if after creating a FooModel
  15. instance, its text field contains 'Is valid'
  16. """
  17.  
  18. file_mock = mock.MagicMock(spec=File)
  19. file_mock.name = 'test.pdf'
  20.  
  21. form = FooForm(
  22. data={ },
  23. files={
  24. 'bar': file_mock,
  25. }
  26. )
  27. FooCreateView().form_valid(form=form)
  28.  
  29. foo = FooModel.objects.get()
  30. self.assertEqual(foo.bar.name, 'test.pdf')
  31. self.assertEqual(foo.state, 'Is valid')
Add Comment
Please, Sign In to add comment