Пример #1
0
    def test_addform_update_type_check_context(self):
        from ptah.cms.forms import AddForm

        container = Container()

        form = AddForm(container, DummyRequest())

        Content.__type__.permission = ptah.cms.NOT_ALLOWED
        form.tinfo = Content.__type__

        self.assertRaises(HTTPForbidden, form.update)
Пример #2
0
    def test_addform_no_name_widgets(self):
        from ptah.cms.forms import AddForm

        form = AddForm(Container(), DummyRequest())

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.name_show = False
        form.update()

        self.assertIsNone(form.name_widgets)
Пример #3
0
    def test_addform_basics(self):
        from ptah.cms.forms import AddForm

        container = Container()

        form = AddForm(container, DummyRequest())
        form.tinfo = Content.__type__

        self.assertIs(form.fields, Content.__type__.fieldset)
        self.assertEqual(form.label, 'Add %s' % Content.__type__.title)
        self.assertEqual(form.description, Content.__type__.description)
Пример #4
0
    def test_addform_update_type_check_context(self):
        from ptah.cms.forms import AddForm

        container = Container()

        form = AddForm(container, DummyRequest())

        Content.__type__.permission = ptah.cms.NOT_ALLOWED
        form.tinfo = Content.__type__

        self.assertRaises(HTTPForbidden, form.update)
Пример #5
0
    def test_addform_basics(self):
        from ptah.cms.forms import AddForm

        container = Container()

        form = AddForm(container, DummyRequest())
        form.tinfo = Content.__type__

        self.assertIs(form.fields, Content.__type__.fieldset)
        self.assertEqual(form.label, 'Add %s'%Content.__type__.title)
        self.assertEqual(form.description, Content.__type__.description)
Пример #6
0
    def test_addform_no_name_widgets(self):
        from ptah.cms.forms import AddForm

        form = AddForm(Container(), DummyRequest())

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.name_show = False
        form.update()

        self.assertIsNone(form.name_widgets)
Пример #7
0
    def test_addform_add_errors(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(POST={'form.buttons.add': 'Add'})

        form = AddForm(container, request)
        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.update()

        self.assertIn('Please fix indicated errors.',
                      ptah.view.render_messages(request))
Пример #8
0
    def test_addform_add_errors(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(
            POST = {'form.buttons.add': 'Add'})

        form = AddForm(container, request)
        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.update()

        self.assertIn('Please fix indicated errors.',
                      ptah.view.render_messages(request))
Пример #9
0
    def test_addform_create_empty_name(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        form = AddForm(Container(), DummyRequest())

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.update()

        content = form.create(**{'title': 'Test Content'})

        self.assertEqual(content.__name__, 'test-content')
        self.assertEqual(content.title, 'Test Content')
        self.assertIsInstance(content, Content)
Пример #10
0
    def test_addform_create(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        form = AddForm(Container(), DummyRequest())

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.update()

        content = form.create(**{'title': 'Test Content',
                                 '__name__': 'page.html'})

        self.assertEqual(content.__name__, 'page.html')
        self.assertIsInstance(content, Content)
Пример #11
0
    def test_addform_cancel(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(POST={'form.buttons.cancel': 'Cancel'})

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '.')
Пример #12
0
    def test_addform_extract_with_errors_no_name(self):
        from ptah.cms.forms import AddForm

        form = AddForm(Container(),
                       DummyRequest(POST={'__name__': 't/est-content'}))

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.name_show = False
        form.update()

        data, errors = form.extract()

        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].field.name, 'title')
        self.assertEqual(errors[0].msg, 'Required')
Пример #13
0
    def test_addform_extract_with_errors_no_name(self):
        from ptah.cms.forms import AddForm

        form = AddForm(Container(), DummyRequest(
            POST={'__name__': 't/est-content'}))

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.name_show = False
        form.update()

        data, errors = form.extract()

        self.assertEqual(len(errors), 1)
        self.assertEqual(errors[0].field.name, 'title')
        self.assertEqual(errors[0].msg, 'Required')
Пример #14
0
    def test_addform_cancel(self):
        from ptah.cms.forms import AddForm
        ptah.authService.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(
            POST = {'form.buttons.cancel': 'Cancel'})

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        try:
            form.update()
        except Exception, res:
            pass
Пример #15
0
    def test_addform_update_suffix_from_type(self):
        from ptah.cms.forms import AddForm

        container = Container()

        form = AddForm(container, DummyRequest())

        Content.__type__.name_suffix = '.xml'
        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED

        form.tinfo = Content.__type__
        form.update()

        self.assertEqual(form.name_suffix, '.xml')

        Content.__type__.name_suffix = ''
        Content.__type__.permission = ptah.cms.NOT_ALLOWED
Пример #16
0
    def test_addform_cancel(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(
            POST = {'form.buttons.cancel': 'Cancel'})

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '.')
Пример #17
0
    def test_addform_update_suffix_from_type(self):
        from ptah.cms.forms import AddForm

        container = Container()

        form = AddForm(container, DummyRequest())

        Content.__type__.name_suffix = '.xml'
        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED

        form.tinfo = Content.__type__
        form.update()

        self.assertEqual(form.name_suffix, '.xml')

        Content.__type__.name_suffix = ''
        Content.__type__.permission = ptah.cms.NOT_ALLOWED
Пример #18
0
    def test_addform_extract_no_name(self):
        from ptah.cms.forms import AddForm

        form = AddForm(Container(), DummyRequest(
            POST={'title': 'Test Content',
                  '__name__': 'test-content'}))

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.name_show = False
        form.update()

        data, errors = form.extract()

        self.assertEqual(len(errors), 0)
        self.assertEqual(len(data), 2)
        self.assertIn('title', data)
        self.assertIn('description', data)
Пример #19
0
    def test_addform_add(self):
        from ptah.cms.forms import AddForm
        ptah.authService.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(
            POST = {'title': 'Test Content',
                    'form.buttons.add': 'Add'})
        request.root = container
        request.root.__path__ = '/'
        request.root.__root_path__ = '/'

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        try:
            form.update()
        except Exception, res:
            pass
Пример #20
0
    def test_addform_extract_no_name(self):
        from ptah.cms.forms import AddForm

        form = AddForm(
            Container(),
            DummyRequest(POST={
                'title': 'Test Content',
                '__name__': 'test-content'
            }))

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.name_show = False
        form.update()

        data, errors = form.extract()

        self.assertEqual(len(errors), 0)
        self.assertEqual(len(data), 2)
        self.assertIn('title', data)
        self.assertIn('description', data)
Пример #21
0
    def test_addform_validate_name(self):
        from ptah.cms.forms import AddForm

        container = Container()
        container['test'] = Content()

        form = AddForm(container, DummyRequest())

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.update()

        errors = []
        form.validate({'__name__': 'test'}, errors)

        self.assertEqual(len(errors), 1)
        self.assertIs(errors[0].field, form.name_widgets['__name__'])
        self.assertEqual(errors[0].msg, 'Name already in use')

        errors = []
        form.validate({'__name__': 'normal-name'}, errors)
        self.assertEqual(len(errors), 0)
Пример #22
0
    def test_addform_validate_name(self):
        from ptah.cms.forms import AddForm

        container = Container()
        container['test'] = Content()

        form = AddForm(container, DummyRequest())

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__
        form.update()

        errors = []
        form.validate({'__name__': 'test'}, errors)

        self.assertEqual(len(errors), 1)
        self.assertIs(errors[0].field, form.name_widgets['__name__'])
        self.assertEqual(errors[0].msg, 'Name already in use')

        errors = []
        form.validate({'__name__': 'normal-name'}, errors)
        self.assertEqual(len(errors), 0)
Пример #23
0
    def test_addform_add(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(
            POST = {'title': 'Test Content',
                    'form.buttons.add': 'Add'})
        request.root = container
        request.root.__path__ = '/'
        request.root.__root_path__ = '/'

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '/test-content/')
        self.assertIn('New content has been created.',
                      ptah.view.render_messages(request))
Пример #24
0
    def test_addform_add(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(POST={
            'title': 'Test Content',
            'form.buttons.add': 'Add'
        })
        request.root = container
        request.root.__path__ = '/'
        request.root.__root_path__ = '/'

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '/test-content/')
        self.assertIn('New content has been created.',
                      ptah.view.render_messages(request))