Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 11th, 2018 63 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  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')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top