Example #1
0
    def test_model_edit_node(self):
        from ptahcms.manage.model import ModelModule, EditRecord

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

        Session = ptah.get_session()
        Session.add(content)
        Session.flush()

        rowid = content.__id__
        transaction.commit()

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

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

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

        Session = ptah.get_session()
        content = Session.query(Content2) \
            .filter(Content2.__id__ == rowid).first()
        self.assertEqual(content.title, 'Content')
Example #2
0
    def test_model_edit_node(self):
        from ptahcms.manage.model import ModelModule, EditRecord

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

        Session = ptah.get_session()
        Session.add(content)
        Session.flush()

        rowid = content.__id__
        transaction.commit()

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

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

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

        Session = ptah.get_session()
        content = Session.query(Content2) \
            .filter(Content2.__id__ == rowid).first()
        self.assertEqual(content.title, 'Content')
Example #3
0
    def test_model_edit_errors(self):
        from ptahcms.manage.model import ModelModule, EditRecord

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

        Session = ptah.get_session()
        Session.add(content)
        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))
Example #4
0
    def test_model_edit_back(self):
        from ptahcms.manage.model import ModelModule, EditRecord

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

        Session = ptah.get_session()
        Session.add(content)
        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'], '../')
Example #5
0
    def test_model_edit_errors(self):
        from ptahcms.manage.model import ModelModule, EditRecord

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

        Session = ptah.get_session()
        Session.add(content)
        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))
Example #6
0
    def test_model_edit_back(self):
        from ptahcms.manage.model import ModelModule, EditRecord

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

        Session = ptah.get_session()
        Session.add(content)
        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'], '../')