Beispiel #1
0
    def test_initial(self):
        """
        Test :py:meth:`.FormMixin.get_initial`.
        """
        mixin = FormMixin()
        mixin.initial = {'foo': 'bar'}

        self.assertEqual({'foo': 'bar'}, mixin.get_initial())
Beispiel #2
0
    def test_get_success_url(self):
        """
        Test :py:meth:`.FormMixin.get_success_url`.
        """
        mixin = FormMixin()
        mixin.success_url = 'foo/bar'

        self.assertEqual('foo/bar', mixin.get_success_url())
Beispiel #3
0
    def test_get_success_url(self):
        """
        Test :py:meth:`.FormMixin.get_success_url`.
        """
        mixin = FormMixin()
        mixin.success_url = 'foo/bar'

        self.assertEqual('foo/bar', mixin.get_success_url())
Beispiel #4
0
    def test_initial(self):
        """
        Test :py:meth:`.FormMixin.get_initial`.
        """
        mixin = FormMixin()
        mixin.initial = {'foo': 'bar'}

        self.assertEqual({'foo': 'bar'}, mixin.get_initial())
Beispiel #5
0
    def test_form_valid(self, redirect):
        """
        Test :py:meth:`.FormMixin.form_valid`.
        """
        redirect.return_value = 'redirect'

        mixin = FormMixin()
        mixin.get_success_url = Mock(return_value='foo/bar')

        self.assertEqual('redirect', mixin.form_valid(Mock()))
        redirect.assert_called_once_with('foo/bar')
Beispiel #6
0
    def test_get_form(self):
        """
        Test :py:meth:`.FormMixin.get_form`.
        """
        mixin = FormMixin()
        mixin.form_class = Mock(return_value='form-instance')
        mixin.get_form_kwargs = Mock(return_value={'foo': 'bar'})

        self.assertEqual('form-instance', mixin.get_form())
        mixin.get_form_kwargs.assert_called_once_with()
        mixin.form_class.assert_called_once_with(foo='bar')
Beispiel #7
0
    def test_form_valid(self, redirect):
        """
        Test :py:meth:`.FormMixin.form_valid`.
        """
        redirect.return_value = 'redirect'

        mixin = FormMixin()
        mixin.get_success_url = Mock(return_value='foo/bar')

        self.assertEqual('redirect', mixin.form_valid(Mock()))
        redirect.assert_called_once_with('foo/bar')
Beispiel #8
0
    def test_get_form(self):
        """
        Test :py:meth:`.FormMixin.get_form`.
        """
        mixin = FormMixin()
        mixin.form_class = Mock(return_value='form-instance')
        mixin.get_form_kwargs = Mock(return_value={'foo': 'bar'})

        self.assertEqual('form-instance', mixin.get_form())
        mixin.get_form_kwargs.assert_called_once_with()
        mixin.form_class.assert_called_once_with(foo='bar')
Beispiel #9
0
    def test_form_invalid(self):
        """
        Test :py:meth:`.FormMixin.form_invalid`.
        """
        mixin = FormMixin()
        mixin.get_context_data = Mock(return_value={'foo': 'bar'})
        mixin.render_to_response = Mock(return_value='response')

        form_mock = Mock()
        self.assertEqual('response', mixin.form_invalid(form=form_mock))
        mixin.get_context_data.assert_called_once_with(form=form_mock)
        mixin.render_to_response.assert_called_once_with({'foo': 'bar'})
Beispiel #10
0
    def test_form_invalid(self):
        """
        Test :py:meth:`.FormMixin.form_invalid`.
        """
        mixin = FormMixin()
        mixin.get_context_data = Mock(return_value={'foo': 'bar'})
        mixin.render_to_response = Mock(return_value='response')

        form_mock = Mock()
        self.assertEqual('response', mixin.form_invalid(form=form_mock))
        mixin.get_context_data.assert_called_once_with(form=form_mock)
        mixin.render_to_response.assert_called_once_with({'foo': 'bar'})
Beispiel #11
0
    def test_get_form_kwargs(self, request):
        """
        Test :py:meth:`.FormMixin.get_form_kwargs`.
        """
        request.form = {'foo': 'bar'}

        mixin = FormMixin()
        mixin.get_initial = Mock(return_value={'name': 'John'})

        self.assertEqual({
            'formdata': {'foo': 'bar'},
            'name': 'John',
        }, mixin.get_form_kwargs())
        mixin.get_initial.assert_called_once_with()
Beispiel #12
0
    def test_get_form_kwargs(self, request):
        """
        Test :py:meth:`.FormMixin.get_form_kwargs`.
        """
        request.form = {'foo': 'bar'}

        mixin = FormMixin()
        mixin.get_initial = Mock(return_value={'name': 'John'})

        self.assertEqual({
            'formdata': {
                'foo': 'bar'
            },
            'name': 'John',
        }, mixin.get_form_kwargs())
        mixin.get_initial.assert_called_once_with()
Beispiel #13
0
 def test_get_context_data(self):
     """
     Test :py:meth:`.FormMixin.get_context_data`.
     """
     mixin = FormMixin()
     self.assertEqual({'foo': 'bar'}, mixin.get_context_data(foo='bar'))
Beispiel #14
0
 def test_get_context_data(self):
     """
     Test :py:meth:`.FormMixin.get_context_data`.
     """
     mixin = FormMixin()
     self.assertEqual({'foo': 'bar'}, mixin.get_context_data(foo='bar'))