コード例 #1
0
    def test_sql_create_function_insert(self):
        trig = TriggerPostgreSQL()
        res = trig.sql_create_function_insert('book_nbpage_insert()',
                                              'book',
                                              'nbpage',
                                              'book_nbpage')

        attend = u"""CREATE OR REPLACE FUNCTION book_nbpage_insert() RETURNS TRIGGER AS $BODY$
BEGIN
IF (SELECT nbpage FROM book_nbpage WHERE nbpage=NEW.nbpage) IS NOT NULL THEN
    UPDATE book_nbpage SET agg_count=agg_count+1 WHERE nbpage=NEW.nbpage;
ELSE
    INSERT INTO book_nbpage VALUES (NEW.nbpage, 1);
END IF;
RETURN NEW;
END;
$BODY$ LANGUAGE plpgsql;"""
        self.assertEqual(res, attend)
コード例 #2
0
 def setUp(self):
     self.agg = TriggerPostgreSQL()
     self.maxDiff = None
コード例 #3
0
 def test_init(self):
     trig = TriggerPostgreSQL()
     self.assertEqual('PostgreSQL', trig.name)
コード例 #4
0
class utilTests(unittest.TestCase):

    def setUp(self):
        self.agg = TriggerPostgreSQL()
        self.maxDiff = None

    def test_init(self):
        trig = TriggerPostgreSQL()
        self.assertEqual('PostgreSQL', trig.name)

    def test_sql_drop_trigger(self):
        res = self.agg.sql_drop_trigger('foo', 'table_bar')
        self.assertTrue(isinstance(res, str))
        #  TODO mov test to pgTests
        #  self.assertEqual(res, 'DROP TRIGGER IF EXISTS foo ON table_bar')

    def test_sql_drop_function(self):
        res = self.agg.sql_drop_function('foo')
        self.assertTrue(isinstance(res, str))

    def test_sql_drop_table(self):
        res = self.agg.sql_drop_table('table_bar')
        self.assertTrue(isinstance(res, str))

    def test_sql_create_function_insert(self):
        trig = TriggerPostgreSQL()
        res = trig.sql_create_function_insert('book_nbpage_insert()',
                                              'book',
                                              'nbpage',
                                              'book_nbpage')

        attend = u"""CREATE OR REPLACE FUNCTION book_nbpage_insert() RETURNS TRIGGER AS $BODY$
BEGIN
IF (SELECT nbpage FROM book_nbpage WHERE nbpage=NEW.nbpage) IS NOT NULL THEN
    UPDATE book_nbpage SET agg_count=agg_count+1 WHERE nbpage=NEW.nbpage;
ELSE
    INSERT INTO book_nbpage VALUES (NEW.nbpage, 1);
END IF;
RETURN NEW;
END;
$BODY$ LANGUAGE plpgsql;"""
        self.assertEqual(res, attend)

    def test_sql_create_table(self):
        """Test with only one aggregat
        """
        res = self.agg.sql_create_table('book', 'nbpage', ['count'])

        attend = u"""CREATE TABLE book (nbpage int4, agg_count int4);
CREATE INDEX ON book (nbpage);"""

        self.assertEqual(res, attend)

    def test_sql_create_table_twoagg(self):
        """Test with two aggregats
        """
        res = self.agg.sql_create_table('book', 'nbpage', ['count', 'min'])

        attend = u"""CREATE TABLE book (nbpage int4, agg_count int4, agg_min int4);
CREATE INDEX ON book (nbpage);"""

        self.assertEqual(res, attend)