示例#1
0
    def test_model_add_node(self):
        from ptahcms.manage.model import ModelModule, AddRecord

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

        form = AddRecord(
            model,
            DummyRequest(POST={
                'title': 'Test content',
                'form.buttons.add': 'Add'
            }))
        form.csrf = False
        res = form.update()

        id = form.record.__id__
        transaction.commit()

        Session = ptah.get_session()
        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], './%s/' % id)
        self.assertEqual(len(Session.query(self.Content2).all()), 1)

        content = Session.query(self.Content2) \
            .filter(self.Content2.__id__ == id).first()
        self.assertEqual(content.title, 'Test content')
示例#2
0
    def test_model_add_errors(self):
        from ptahcms.manage.model import ModelModule, AddRecord

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

        form = AddRecord(model, DummyRequest(POST={'form.buttons.add': 'Add'}))
        form.csrf = False
        form.update()

        self.assertIn("Please fix indicated errors.",
                      ptah.view.render_messages(form.request))
示例#3
0
    def test_model_add_back(self):
        from ptahcms.manage.model import ModelModule, AddRecord

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

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

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '.')
示例#4
0
    def test_model_add_back(self):
        from ptahcms.manage.model import ModelModule, AddRecord

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

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

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '.')
示例#5
0
    def test_model_add_errors(self):
        from ptahcms.manage.model import ModelModule, AddRecord

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

        form = AddRecord(
            model, DummyRequest(POST={'form.buttons.add': 'Add'}))
        form.csrf = False
        form.update()

        self.assertIn("Please fix indicated errors.",
                      ptah.view.render_messages(form.request))
示例#6
0
    def test_model_add_node(self):
        from ptahcms.manage.model import ModelModule, AddRecord

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

        form = AddRecord(
            model, DummyRequest(
                POST={'title': 'Test content', 'form.buttons.add': 'Add'}))
        form.csrf = False
        res = form.update()

        id = form.record.__id__
        transaction.commit()

        Session = ptah.get_session()
        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], './%s/'%id)
        self.assertEqual(len(Session.query(self.Content2).all()), 1)

        content = Session.query(self.Content2) \
            .filter(self.Content2.__id__ == id).first()
        self.assertEqual(content.title, 'Test content')