Ejemplo n.º 1
0
 def test_create_instead_rule(self):
     table = create_table("test")
     rule = Rule("test_select", table, "SELECT", "NOTHING", do_instead=True)
     stmt = CreateRule(rule)
     self.assertEqual(
         'CREATE RULE test_select AS ON SELECT TO test '
         'DO INSTEAD NOTHING', literal_compile(stmt))
Ejemplo n.º 2
0
 def test_create_update_rule(self, table, table2):
     rule = Rule("test_update", table, "UPDATE",
                 table2.update().values(id=text("NEW.id")))
     stmt = CreateRule(rule)
     assert literal_compile(stmt) == (
         'CREATE RULE test_update AS ON UPDATE TO test '
         'DO UPDATE test2 SET id=NEW.id')
Ejemplo n.º 3
0
 def test_create_or_replace_rule(self):
     table = create_table("test")
     rule = Rule("test_select", table, "SELECT", "NOTHING", do_instead=True)
     stmt = CreateRule(rule, or_replace=True)
     self.assertEqual(
         'CREATE OR REPLACE RULE test_select AS ON SELECT '
         'TO test DO INSTEAD NOTHING', literal_compile(stmt))
Ejemplo n.º 4
0
 def test_create_insert_rule(self, table, table2):
     rule = Rule("test_insert", table, "INSERT",
                 table2.insert().values(id=text("NEW.id")))
     stmt = CreateRule(rule)
     assert literal_compile(stmt) == (
         'CREATE RULE test_insert AS ON INSERT TO test '
         'DO INSERT INTO test2 (id) VALUES (NEW.id)')
Ejemplo n.º 5
0
 def test_create_delete_rule(self):
     table1 = create_table("test")
     table2 = create_table("other")
     rule = Rule("test_delete", table1, "DELETE", table2.delete())
     stmt = CreateRule(rule)
     self.assertEqual(
         'CREATE RULE test_delete AS ON DELETE TO test '
         'DO DELETE FROM other', literal_compile(stmt))
Ejemplo n.º 6
0
 def test_create_update_rule(self):
     table1 = create_table("test")
     table2 = create_table("other")
     rule = Rule("test_update", table1, "UPDATE",
                 table2.update().values(id=text("NEW.id")))
     stmt = CreateRule(rule)
     self.assertEqual(
         'CREATE RULE test_update AS ON UPDATE TO test '
         'DO UPDATE other SET id=NEW.id', literal_compile(stmt))
Ejemplo n.º 7
0
 def test_create_insert_rule(self):
     table1 = create_table("test")
     table2 = create_table("other")
     rule = Rule("test_insert", table1, "INSERT",
                 table2.insert().values(id=text("NEW.id")))
     stmt = CreateRule(rule)
     self.assertEqual(
         'CREATE RULE test_insert AS ON INSERT TO test '
         'DO INSERT INTO other (id) VALUES (NEW.id)', literal_compile(stmt))
Ejemplo n.º 8
0
 def test_create_multiple_command_rule(self, table, table2, table3):
     rule = Rule("test_insert", table, "INSERT", [
         table2.insert().values(id=text("NEW.id")),
         table3.insert().values(id=text("NEW.id")),
     ])
     stmt = CreateRule(rule)
     assert literal_compile(stmt) == (
         'CREATE RULE test_insert AS ON INSERT TO test '
         'DO ('
         'INSERT INTO test2 (id) VALUES (NEW.id); '
         'INSERT INTO test3 (id) VALUES (NEW.id)'
         ')')
Ejemplo n.º 9
0
 def test_create_multiple_command_rule(self):
     table1 = create_table("test")
     table2 = create_table("other")
     table3 = create_table("yet_other")
     rule = Rule("test_insert", table1, "INSERT", [
         table2.insert().values(id=text("NEW.id")),
         table3.insert().values(id=text("NEW.id")),
     ])
     stmt = CreateRule(rule)
     self.assertEqual(
         'CREATE RULE test_insert AS ON INSERT TO test '
         'DO ('
         'INSERT INTO other (id) VALUES (NEW.id); '
         'INSERT INTO yet_other (id) VALUES (NEW.id)'
         ')', literal_compile(stmt))
Ejemplo n.º 10
0
 def test_create_rule(self, table):
     rule = Rule("test_select", table, "SELECT", "NOTHING")
     stmt = CreateRule(rule)
     assert literal_compile(stmt) == (
         'CREATE RULE test_select AS ON SELECT TO test '
         'DO NOTHING')
Ejemplo n.º 11
0
 def test_create_delete_rule(self, table, table2):
     rule = Rule("test_delete", table, "DELETE", table2.delete())
     stmt = CreateRule(rule)
     assert literal_compile(stmt) == (
         'CREATE RULE test_delete AS ON DELETE TO test '
         'DO DELETE FROM test2')
Ejemplo n.º 12
0
 def test_create_instead_rule(self, table):
     rule = Rule("test_select", table, "SELECT", "NOTHING", do_instead=True)
     stmt = CreateRule(rule)
     assert literal_compile(stmt) == (
         'CREATE RULE test_select AS ON SELECT TO test '
         'DO INSTEAD NOTHING')