Beispiel #1
0
    def test_sqla_table_view_model_nodes(self):
        from ptah.manage.sqla import SQLAModule, TableView

        rec = TestSqlaModuleContent(title='test')
        ptah.cms.Session.add(rec)
        ptah.cms.Session.flush()

        uri = rec.__uri__
        type_uri = rec.__type__.__uri__

        request = DummyRequest(params={'batch': 1})

        mod = SQLAModule(None, request)
        table = mod['psqla-ptah_nodes']

        res = TableView.__renderer__(table, request).body
        self.assertIn(uri, res)
        self.assertIn(type_uri, res)

        request = DummyRequest(params={'batch': 'unknown'})
        res = TableView.__renderer__(table, request).body
        self.assertIn(uri, res)

        request = DummyRequest(params={'batch': '0'})
        res = TableView.__renderer__(table, request).body
        self.assertIn(uri, res)
Beispiel #2
0
    def test_sqla_table_add(self):
        from ptah.manage.sqla import SQLAModule, TableView

        mod = SQLAModule(None, DummyRequest())
        table = mod['psqla-test_sqla_table']

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

        form = TableView(table, request)
        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], 'add.html')
Beispiel #3
0
    def test_sqla_table_add(self):
        from ptah.manage.sqla import SQLAModule, TableView

        mod = SQLAModule(None, DummyRequest())
        table = mod['psqla-test_sqla_table']

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

        form = TableView(table, request)
        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], 'add.html')
Beispiel #4
0
    def test_sqla_table_add(self):
        from ptah.manage.sqla import SQLAModule, TableView

        mod = SQLAModule(None, DummyRequest())
        table = mod['psqla-test_sqla_table']

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

        form = TableView(table, request)
        try:
            form.update()
        except Exception, res:
            pass
Beispiel #5
0
    def test_table_view(self):
        from ptah.manage.sqla import SQLAModule, Table, TableView

        request = DummyRequest()

        mod = SQLAModule(None, request)
        table = mod['psqla-ptah_tokens']

        res = TableView.__renderer__(table, request)
        self.assertEqual(res.status, '200 OK')
Beispiel #6
0
    def test_sqla_table_view_model(self):
        from ptah.manage.sqla import SQLAModule, TableView

        ptah.cms.Session.add(TestSqlaModuleContent(title='test'))

        request = DummyRequest()

        mod = SQLAModule(None, request)
        table = mod['psqla-test_sqla_content']

        res = TableView.__renderer__(table, request).body
        self.assertIn('Inherits from:', res)
        self.assertIn('ptah_node', res)
        self.assertIn('ptah_content', res)
        self.assertNotIn('form.buttons.add', res)
Beispiel #7
0
    def test_sqla_table_remove(self):
        from ptah.manage.sqla import SQLAModule, TableView

        rec = TestSqlaModuleTable()
        rec.name = 'Test record'
        ptah.cms.Session.add(rec)
        ptah.cms.Session.flush()

        rec_id = rec.id

        mod = SQLAModule(None, DummyRequest())
        table = mod['psqla-test_sqla_table']

        request = DummyRequest(
            POST=MultiDict([('form.buttons.remove', 'Remove')]))

        form = TableView(table, request)
        form.csrf = False
        form.update()

        self.assertIn('lease select records for removing.',
                      ptah.view.render_messages(request))

        request = DummyRequest(
            POST=MultiDict([('form.buttons.remove', 'Remove'),
                            ('rowid', 'wrong')]))

        form = TableView(table, request)
        form.csrf = False
        form.update()

        self.assertIn('lease select records for removing.',
                      ptah.view.render_messages(request))

        request = DummyRequest(
            POST=MultiDict([('form.buttons.remove', 'Remove'),
                            ('rowid', rec_id)]))

        form = TableView(table, request)
        form.csrf = False
        form.update()

        self.assertIn('Select records have been removed.',
                      ptah.view.render_messages(request))

        rec = ptah.cms.Session.query(TestSqlaModuleTable).filter(
            TestSqlaModuleTable.id == rec_id).first()
        self.assertIsNone(rec, None)
Beispiel #8
0
    def test_sqla_table_remove(self):
        from ptah.manage.sqla import SQLAModule, TableView

        rec = TestSqlaModuleTable()
        rec.name = 'Test record'
        ptah.get_session().add(rec)
        ptah.get_session().flush()

        rec_id = rec.id

        request = self.make_request()
        mod = SQLAModule(None, request)
        table = mod['psqla-test_sqla_table']

        request = self.make_request(
            POST=MultiDict([('form.buttons.remove', 'Remove')]))

        form = TableView(table, request)
        form.csrf = False
        form.update_form()

        self.assertIn('lease select records for removing.',
                      request.render_messages())

        request = self.make_request(
            POST=MultiDict([('form.buttons.remove', 'Remove'),
                            ('rowid', 'wrong')]))

        form = TableView(table, request)
        form.csrf = False
        form.update_form()

        #self.assertIn('Please select records for removing.',
        #              request.render_messages())

        request = self.make_request(
            POST=MultiDict([('form.buttons.remove', 'Remove'),
                            ('rowid', rec_id),
                            ('csrf-token',
                             self.request.session.get_csrf_token())]))

        form = TableView(table, request)
        form.csrf = True
        form.update_form()

        self.assertIn('Select records have been removed.',
                      request.render_messages())

        rec = ptah.get_session().query(TestSqlaModuleTable).filter(
            TestSqlaModuleTable.id == rec_id).first()
        self.assertIsNone(rec, None)
Beispiel #9
0
    def test_sqla_table_remove(self):
        from ptah.manage.sqla import SQLAModule, TableView

        rec = TestSqlaModuleTable()
        rec.name = 'Test record'
        ptah.cms.Session.add(rec)
        ptah.cms.Session.flush()

        rec_id = rec.id

        mod = SQLAModule(None, DummyRequest())
        table = mod['psqla-test_sqla_table']

        request = DummyRequest(POST=MultiDict([('form.buttons.remove',
                                                'Remove')]))

        form = TableView(table, request)
        form.csrf = False
        form.update()

        self.assertIn('lease select records for removing.',
                      ptah.view.render_messages(request))

        request = DummyRequest(POST=MultiDict([('form.buttons.remove',
                                                'Remove'), ('rowid',
                                                            'wrong')]))

        form = TableView(table, request)
        form.csrf = False
        form.update()

        self.assertIn('lease select records for removing.',
                      ptah.view.render_messages(request))

        request = DummyRequest(POST=MultiDict([('form.buttons.remove',
                                                'Remove'), ('rowid', rec_id)]))

        form = TableView(table, request)
        form.csrf = False
        form.update()

        self.assertIn('Select records have been removed.',
                      ptah.view.render_messages(request))

        rec = ptah.cms.Session.query(TestSqlaModuleTable).filter(
            TestSqlaModuleTable.id == rec_id).first()
        self.assertIsNone(rec, None)