Changeset 769 for trunk/tests


Ignore:
Timestamp:
Jan 19, 2016, 12:00:26 PM (4 years ago)
Author:
cito
Message:

Removed misleading sentence from docs

The insert() method does in fact support inserting into views in newer
PostgreSQL versions or when the necessary rules have been created.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/test_classic_dbwrapper.py

    r768 r769  
    13601360        self.assertEqual(r['Questions?'], 'What?')
    13611361
     1362    def testInsertIntoView(self):
     1363        insert = self.db.insert
     1364        query = self.db.query
     1365        query("truncate test")
     1366        q = 'select * from test_view order by i4 limit 3'
     1367        r = query(q).getresult()
     1368        self.assertEqual(r, [])
     1369        r = dict(i4=1234, v4='abcd')
     1370        insert('test', r)
     1371        self.assertIsNone(r['i2'])
     1372        self.assertEqual(r['i4'], 1234)
     1373        self.assertIsNone(r['i8'])
     1374        self.assertEqual(r['v4'], 'abcd')
     1375        self.assertIsNone(r['c4'])
     1376        r = query(q).getresult()
     1377        self.assertEqual(r, [(1234, 'abcd')])
     1378        r = dict(i4=5678, v4='efgh')
     1379        try:
     1380            insert('test_view', r)
     1381        except pg.ProgrammingError as error:
     1382            if self.db.server_version < 90300:
     1383                # must setup rules in older PostgreSQL versions
     1384                self.skipTest('database cannot insert into view')
     1385            self.fail(str(error))
     1386        self.assertNotIn('i2', r)
     1387        self.assertEqual(r['i4'], 5678)
     1388        self.assertNotIn('i8', r)
     1389        self.assertEqual(r['v4'], 'efgh')
     1390        self.assertNotIn('c4', r)
     1391        r = query(q).getresult()
     1392        self.assertEqual(r, [(1234, 'abcd'), (5678, 'efgh')])
     1393
    13621394    def testUpdate(self):
    13631395        update = self.db.update
     
    16151647        self.assertEqual('n', self.db.pkey('test_table', flush=True))
    16161648        s = dict(n=2)
    1617         r = upsert('test_table', s)
     1649        try:
     1650            r = upsert('test_table', s)
     1651        except pg.ProgrammingError as error:
     1652            if self.db.server_version < 90500:
     1653                self.skipTest('database does not support upsert')
     1654            self.fail(str(error))
    16181655        self.assertIs(r, s)
    16191656        self.assertEqual(r['n'], 2)
Note: See TracChangeset for help on using the changeset viewer.