예제 #1
0
    def test_edit_form(self):
        from ptah.manage.settings import SettingsModule, EditForm

        ptah.register_settings(
            'test',
            ptah.form.TextField('node1', default='test1', required=False),
            ptah.form.TextField('node2', default='test2', required=False),
            title = 'Test settings',
            ttw = True,
            ttw_skip_fields = ('node2',))

        self.init_ptah()

        mod = SettingsModule(None, self.request)
        grp = mod['test']
        settings = grp.group

        form = EditForm(grp, self.request)

        self.assertEqual(form.label, settings.__title__)
        self.assertEqual(form.description, settings.__description__)
        self.assertIs(form.form_content(), settings)

        fields = form.fields
        self.assertIn('node1', fields)
        self.assertNotIn('node2', fields)

        res = form.back_handler()
        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '..')

        form.update_form()
        form.modify_handler()
        self.assertIn('Settings have been modified.',
                      self.request.render_messages())
예제 #2
0
파일: test_form.py 프로젝트: sidloki/ptah
    def test_form_content_from_update(self):
        from ptah.form.form import Form

        request = DummyRequest()
        form = Form(None, request)

        form_content = {'test': 'test1'}
        form.update_form(form_content)
        self.assertEqual(form.form_content(), form_content)
예제 #3
0
    def test_form_content_from_update(self):
        from ptah.form.form import Form

        request = DummyRequest()
        form = Form(None, request)

        form_content = {'test': 'test1'}
        form.update_form(form_content)
        self.assertEqual(form.form_content(), form_content)
예제 #4
0
    def test_form_extract_missing(self):
        """ Extract form data, composite field no data """
        fields=(ptah.form.TextField('firstname', missing='name'),
                ptah.form.TextField('lastname'))

        field = ptah.form.CompositeField('test', fields=fields)

        form = ptah.form.Form(object(), self.request, fields=(field,))
        form.update_form()

        data, errors = form.extract()
        self.assertEqual({'lastname': fields[1].missing,
                          'firstname': fields[0].missing}, data['test'])
예제 #5
0
    def test_form_extract_missing(self):
        """ Extract form data, composite field no data """
        fields = (ptah.form.TextField('firstname', missing='name'),
                  ptah.form.TextField('lastname'))

        field = ptah.form.CompositeField('test', fields=fields)

        form = ptah.form.Form(object(), self.request, fields=(field, ))
        form.update_form()

        data, errors = form.extract()
        self.assertEqual(
            {
                'lastname': fields[1].missing,
                'firstname': fields[0].missing
            }, data['test'])
예제 #6
0
    def test_edit_form(self):
        from ptah.manage.settings import SettingsModule, EditForm

        ptah.register_settings('test',
                               ptah.form.TextField('node1',
                                                   default='test1',
                                                   required=False),
                               ptah.form.TextField('node2',
                                                   default='test2',
                                                   required=False),
                               title='Test settings',
                               ttw=True,
                               ttw_skip_fields=('node2', ))

        self.init_ptah()

        mod = SettingsModule(None, self.request)
        grp = mod['test']
        settings = grp.group

        form = EditForm(grp, self.request)

        self.assertEqual(form.label, settings.__title__)
        self.assertEqual(form.description, settings.__description__)
        self.assertIs(form.form_content(), settings)

        fields = form.fields
        self.assertIn('node1', fields)
        self.assertNotIn('node2', fields)

        res = form.back_handler()
        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '..')

        form.update_form()
        form.modify_handler()
        self.assertIn('Settings have been modified.',
                      self.request.render_messages())
예제 #7
0
파일: test_form.py 프로젝트: sidloki/ptah
    def test_update_form(self):
        import ptah.form
        request = self.make_request()

        class CustomForm(ptah.form.Form):
            fields = ptah.form.Fieldset(ptah.form.TextField('test'))

            def update(self):
                return {1: 'test'}

        form = CustomForm(object(), request)

        res = form.update_form()
        self.assertEqual(res, {1: 'test'})
예제 #8
0
    def test_update_form(self):
        import ptah.form
        request = self.make_request()

        class CustomForm(ptah.form.Form):
            fields = ptah.form.Fieldset(ptah.form.TextField('test'))

            def update(self):
                return {1: 'test'}

        form = CustomForm(object(), request)

        res = form.update_form()
        self.assertEqual(res, {1: 'test'})
예제 #9
0
파일: test_form.py 프로젝트: sidloki/ptah
    def test_update_form_action_return_dict_combine_with_update(self):
        import ptah.form
        request = self.make_request(POST={'form.buttons.test': 'test'})

        class CustomForm(ptah.form.Form):
            fields = ptah.form.Fieldset(ptah.form.TextField('test'))

            def update(self):
                return {0: '0'}

            @ptah.form.button('test')
            def test_handler(self):
                return {1: 'test'}

        form = CustomForm(object(), request)

        res = form.update_form()
        self.assertEqual(res, {0: '0', 1: 'test'})
예제 #10
0
    def test_update_form_action_return_dict_combine_with_update(self):
        import ptah.form
        request = self.make_request(POST={'form.buttons.test': 'test'})

        class CustomForm(ptah.form.Form):
            fields = ptah.form.Fieldset(ptah.form.TextField('test'))

            def update(self):
                return {0: '0'}

            @ptah.form.button('test')
            def test_handler(self):
                return {1: 'test'}

        form = CustomForm(object(), request)

        res = form.update_form()
        self.assertEqual(res, {0: '0', 1: 'test'})