Exemplo n.º 1
0
    def test_model_edit_node(self):
        from ptah.manage.model import ModelModule, EditRecord

        content = Content2()
        content.title = u'Content test'

        ptah.cms.Session.add(content)
        ptah.cms.Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content2'][rowid]

        form = EditRecord(
            model, DummyRequest(
                POST=MultiDict({'title': 'Content',
                                'form.buttons.modify': 'Modify'})))
        form.csrf = False
        form.update()

        self.assertIn("Model record has been modified.",
                      form.request.session['msgservice'][0])
        transaction.commit()

        content = ptah.cms.Session.query(Content2) \
            .filter(Content2.__id__ == rowid).first()
        self.assertEqual(content.title, u'Content')
Exemplo n.º 2
0
    def test_model_edit(self):
        from ptah.manage.model import ModelModule, EditRecord

        content = Content1()
        content.title = 'Content test'

        ptah.cms.Session.add(content)
        ptah.cms.Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content1'][rowid]

        form = EditRecord(
            model, DummyRequest(
                POST={'title': 'Content', 'form.buttons.modify': 'Modify'}))
        form.csrf = False
        form.update()

        self.assertEqual(form.label, 'Record id: %s'%rowid)

        self.assertIn("Model record has been modified.",
                      ptah.view.render_messages(form.request))
        transaction.commit()

        content = ptah.cms.Session.query(Content1) \
            .filter(Content1.__id__ == rowid).first()
        self.assertEqual(content.title, 'Content')
Exemplo n.º 3
0
    def test_model_edit_errors(self):
        from ptah.manage.model import ModelModule, EditRecord

        content = Content1()
        content.title = 'Content test'

        ptah.cms.Session.add(content)
        ptah.cms.Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content1'][rowid]

        form = EditRecord(
            model, DummyRequest(POST={'form.buttons.modify': 'Modify'}))
        form.csrf = False
        form.update()

        self.assertIn("Please fix indicated errors.",
                      ptah.view.render_messages(form.request))
Exemplo n.º 4
0
    def test_model_edit_back(self):
        from ptah.manage.model import ModelModule, EditRecord

        content = Content1()
        content.title = 'Content test'

        ptah.cms.Session.add(content)
        ptah.cms.Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content1'][rowid]

        form = EditRecord(
            model, DummyRequest(POST={'form.buttons.back': 'Back'}))
        form.csrf = False
        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '../')
Exemplo n.º 5
0
    def test_model_edit_back(self):
        from ptah.manage.model import ModelModule, EditRecord

        content = Content1()
        content.title = u'Content test'

        ptah.cms.Session.add(content)
        ptah.cms.Session.flush()

        rowid = content.__id__
        transaction.commit()

        mod = ModelModule(None, DummyRequest())
        model = mod['content1'][rowid]

        form = EditRecord(
            model, DummyRequest(
                POST=MultiDict({'form.buttons.back': 'Back'})))
        form.csrf = False
        try:
            form.update()
        except Exception, res:
            pass