# Path: pyrseas/testutils.py
# class AugmentToMapTestCase(PyrseasTestCase):
# 
#     def to_map(self, stmts, augmap):
#         """Apply an augment map and return a map of the updated database.
# 
#         :param stmts: list of SQL statements to execute
#         :param augmap: dictionary describing the augmentations
#         :return: dictionary of the updated database
#         """
#         for stmt in stmts:
#             self.db.execute(stmt)
#         self.db.conn.commit()
#         self.config_options(schemas=[], tables=[], no_owner=True,
#                             no_privs=True, multiple_files=False)
#         db = AugmentDatabase(self.cfg)
#         return db.apply(augmap)


import pytest
from pyrseas.testutils import AugmentToMapTestCase
        "Add new (non-predefined) audit trigger using an inline definition"
        template = """
        BEGIN
          NEW.{{modified_by_user}} = SESSION_USER;
          NEW.{{modified_timestamp}} = CURRENT_TIMESTAMP::timestamp(0);
          RETURN NEW;
        END"""
        source = """
        BEGIN
          NEW.modified_by_user = SESSION_USER;
          NEW.modified_timestamp = CURRENT_TIMESTAMP::timestamp(0);
          RETURN NEW;
        END"""
        augmap = {
            'augmenter': {
                'audit_columns': {'custom': {
                    'columns': ['modified_by_user', 'modified_timestamp'],
                    'triggers': ['custom_audit']}},
                'functions': {'custom_audit()': {
                    'description': 'Maintain custom audit columns',
                    'language': 'plpgsql',
                    'returns': 'trigger',
                    'security_definer': True,
                    'source': template}},
                'triggers': {'custom_audit': {
                    'events': ['insert', 'update'],
                    'level': 'row',
                    'name': '{{table_name}}_20_custom_audit',
                    'procedure': 'custom_audit',
                    'timing': 'before'}}},

# Path: pyrseas/testutils.py
# class AugmentToMapTestCase(PyrseasTestCase):
# 
#     def to_map(self, stmts, augmap):
#         """Apply an augment map and return a map of the updated database.
# 
#         :param stmts: list of SQL statements to execute
#         :param augmap: dictionary describing the augmentations
#         :return: dictionary of the updated database
#         """
#         for stmt in stmts:
#             self.db.execute(stmt)
#         self.db.conn.commit()
#         self.config_options(schemas=[], tables=[], no_owner=True,
#                             no_privs=True, multiple_files=False)
#         db = AugmentDatabase(self.cfg)
#         return db.apply(augmap)


# Path: tests/augment/test_audit.py
import pytest
from pyrseas.testutils import AugmentToMapTestCase

        "Add new (non-predefined) audit trigger using an inline definition"
        template = """
        BEGIN
          NEW.{{modified_by_user}} = SESSION_USER;
          NEW.{{modified_timestamp}} = CURRENT_TIMESTAMP::timestamp(0);
          RETURN NEW;
        END"""
        source = """
        BEGIN
          NEW.modified_by_user = SESSION_USER;
          NEW.modified_timestamp = CURRENT_TIMESTAMP::timestamp(0);
          RETURN NEW;
        END"""
        augmap = {
            'augmenter': {
                'audit_columns': {'custom': {
                    'columns': ['modified_by_user', 'modified_timestamp'],
                    'triggers': ['custom_audit']}},
                'functions': {'custom_audit()': {
                    'description': 'Maintain custom audit columns',
                    'language': 'plpgsql',
                    'returns': 'trigger',
                    'security_definer': True,
                    'source': template}},
                'triggers': {'custom_audit': {
                    'events': ['insert', 'update'],
                    'level': 'row',
                    'name': '{{table_name}}_20_custom_audit',
                    'procedure': 'custom_audit',
                    'timing': 'before'}}},

            'schema sd': {'table t1': {